From 104fc173064beb7bd8848c962581a7b8e529f94d Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Tue, 17 Jul 2018 12:56:10 -0500 Subject: [PATCH] client: Unify CoreHighlightSettingsPage tooltips Move setting tooltips to a generic function, setupTableTooltips(), to keep tooltips consistent. This fixes outdated tooltips in the highlight ignore rules table and reduces duplication. Add another function getTableTooltip() for getting the tooltips themselves. Unfortunately, QTableWidgetItem does not inherit from QWidget, so function overloading (or equivalent) is necessary. Alas, std::variant is C++17... --- .../corehighlightsettingspage.cpp | 254 ++++++++++-------- .../settingspages/corehighlightsettingspage.h | 35 +++ 2 files changed, 177 insertions(+), 112 deletions(-) diff --git a/src/qtui/settingspages/corehighlightsettingspage.cpp b/src/qtui/settingspages/corehighlightsettingspage.cpp index 9d2f155b..fb0a1004 100644 --- a/src/qtui/settingspages/corehighlightsettingspage.cpp +++ b/src/qtui/settingspages/corehighlightsettingspage.cpp @@ -129,60 +129,12 @@ void CoreHighlightSettingsPage::setupRuleTable(QTableWidget *table) const table->verticalHeader()->hide(); table->setShowGrid(false); - table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn)->setToolTip( - tr("Enable/disable this rule")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn)->toolTip()); - - table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn)->setToolTip( - tr("Phrase to match")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn)->toolTip()); - - table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn)->setToolTip( - tr("RegEx: This option determines if the highlight rule, Sender, and " - "Channel should be interpreted as regular expressions or just as " - "keywords.")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn)->toolTip()); - - table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn)->setToolTip( - tr("CS: This option determines if the highlight rule, Sender, and " - "Channel should be interpreted case sensitive.")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn)->toolTip()); - - table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn)->setToolTip( - tr("

Sender: Semicolon separated list of nick!ident@host names, " - "leave blank to match any nickname.

" - "

Example:
" - "Alice!*; Bob!*@example.com; Carol*!*; !Caroline!*
" - "would match on Alice, Bob with hostmask example.com, and " - "any nickname starting with Carol except for Caroline
" - "

If only inverted names are specified, it will match anything except for " - "what's specified (implicit wildcard).

" - "

Example:
" - "!Announce*!*; !Wheatley!aperture@*
" - "would match anything except for Wheatley with ident aperture or " - "any nickname starting with Announce

")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn)->toolTip()); - - table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)->setToolTip( - tr("

Channel: Semicolon separated list of channel names, leave blank to " - "match any name.

" - "

Example:
" - "#quassel*; #foobar; !#quasseldroid
" - "would match on #foobar and any channel starting with #quassel " - "except for #quasseldroid
" - "

If only inverted names are specified, it will match anything except for " - "what's specified (implicit wildcard).

" - "

Example:
" - "!#quassel*; !#foobar
" - "would match anything except for #foobar or any channel starting with " - "#quassel

")); - table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)->setWhatsThis( - table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)->toolTip()); + setupTableTooltips(table->horizontalHeaderItem(CoreHighlightSettingsPage::EnableColumn), + table->horizontalHeaderItem(CoreHighlightSettingsPage::NameColumn), + table->horizontalHeaderItem(CoreHighlightSettingsPage::RegExColumn), + table->horizontalHeaderItem(CoreHighlightSettingsPage::CsColumn), + table->horizontalHeaderItem(CoreHighlightSettingsPage::SenderColumn), + table->horizontalHeaderItem(CoreHighlightSettingsPage::ChanColumn)); #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0) table->horizontalHeader()->setResizeMode(CoreHighlightSettingsPage::EnableColumn, QHeaderView::ResizeToContents); @@ -200,6 +152,140 @@ void CoreHighlightSettingsPage::setupRuleTable(QTableWidget *table) const } +QString CoreHighlightSettingsPage::getTableTooltip(column tableColumn) const +{ + switch (tableColumn) { + case CoreHighlightSettingsPage::EnableColumn: + return tr("Enable/disable this rule"); + + case CoreHighlightSettingsPage::NameColumn: + return tr("Phrase to match"); + + case CoreHighlightSettingsPage::RegExColumn: + return tr("RegEx: This option determines if the highlight rule, Sender, and " + "Channel should be interpreted as regular expressions or just as " + "keywords."); + + case CoreHighlightSettingsPage::CsColumn: + return tr("CS: This option determines if the highlight rule, Sender, and " + "Channel should be interpreted case sensitive."); + + case CoreHighlightSettingsPage::SenderColumn: + return tr("

Sender: Semicolon separated list of nick!ident@host names, " + "leave blank to match any nickname.

" + "

Example:
" + "Alice!*; Bob!*@example.com; Carol*!*; !Caroline!*
" + "would match on Alice, Bob with hostmask example.com, and " + "any nickname starting with Carol except for Caroline
" + "

If only inverted names are specified, it will match anything except for " + "what's specified (implicit wildcard).

" + "

Example:
" + "!Announce*!*; !Wheatley!aperture@*
" + "would match anything except for Wheatley with ident aperture or " + "any nickname starting with Announce

"); + + case CoreHighlightSettingsPage::ChanColumn: + return tr("

Channel: Semicolon separated list of channel names, leave blank to " + "match any name.

" + "

Example:
" + "#quassel*; #foobar; !#quasseldroid
" + "would match on #foobar and any channel starting with #quassel " + "except for #quasseldroid
" + "

If only inverted names are specified, it will match anything except for " + "what's specified (implicit wildcard).

" + "

Example:
" + "!#quassel*; !#foobar
" + "would match anything except for #foobar or any channel starting with " + "#quassel

"); + + default: + // This shouldn't happen + return "Invalid column type in CoreHighlightSettingsPage::getTableTooltip()"; + } +} + + +void CoreHighlightSettingsPage::setupTableTooltips(QWidget *enableWidget, QWidget *nameWidget, + QWidget *regExWidget, QWidget *csWidget, + QWidget *senderWidget, QWidget *chanWidget) const +{ + // Make sure everything's valid + Q_ASSERT(enableWidget); + Q_ASSERT(nameWidget); + Q_ASSERT(regExWidget); + Q_ASSERT(csWidget); + Q_ASSERT(senderWidget); + Q_ASSERT(chanWidget); + + // Set tooltips and "What's this?" prompts + // Enabled + enableWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::EnableColumn)); + enableWidget->setWhatsThis(enableWidget->toolTip()); + + // Name + nameWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::NameColumn)); + nameWidget->setWhatsThis(nameWidget->toolTip()); + + // RegEx enabled + regExWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::RegExColumn)); + regExWidget->setWhatsThis(regExWidget->toolTip()); + + // Case-sensitivity + csWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::CsColumn)); + csWidget->setWhatsThis(csWidget->toolTip()); + + // Sender + senderWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::SenderColumn)); + senderWidget->setWhatsThis(senderWidget->toolTip()); + + // Channel/buffer name + chanWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::ChanColumn)); + chanWidget->setWhatsThis(chanWidget->toolTip()); +} + + +void CoreHighlightSettingsPage::setupTableTooltips(QTableWidgetItem *enableWidget, + QTableWidgetItem *nameWidget, + QTableWidgetItem *regExWidget, + QTableWidgetItem *csWidget, + QTableWidgetItem *senderWidget, + QTableWidgetItem *chanWidget) const +{ + // Make sure everything's valid + Q_ASSERT(enableWidget); + Q_ASSERT(nameWidget); + Q_ASSERT(regExWidget); + Q_ASSERT(csWidget); + Q_ASSERT(senderWidget); + Q_ASSERT(chanWidget); + + // Set tooltips and "What's this?" prompts + // Enabled + enableWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::EnableColumn)); + enableWidget->setWhatsThis(enableWidget->toolTip()); + + // Name + nameWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::NameColumn)); + nameWidget->setWhatsThis(nameWidget->toolTip()); + + // RegEx enabled + regExWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::RegExColumn)); + regExWidget->setWhatsThis(regExWidget->toolTip()); + + // Case-sensitivity + csWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::CsColumn)); + csWidget->setWhatsThis(csWidget->toolTip()); + + // Sender + senderWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::SenderColumn)); + senderWidget->setWhatsThis(senderWidget->toolTip()); + + // Channel/buffer name + chanWidget->setToolTip(getTableTooltip(CoreHighlightSettingsPage::ChanColumn)); + chanWidget->setWhatsThis(chanWidget->toolTip()); +} + + void CoreHighlightSettingsPage::updateCoreSupportStatus(bool state) { // Assume connected state as enforced by the settings page UI @@ -287,41 +373,7 @@ void CoreHighlightSettingsPage::addNewHighlightRow(bool enable, int id, const QS auto *chanNameItem = new QTableWidgetItem(chanName); - enableItem->setToolTip(tr("Enable/disable this rule")); - nameItem->setToolTip(tr("Phrase to match")); - regexItem->setToolTip( - tr("RegEx: This option determines if the highlight rule, Sender, and " - "Channel should be interpreted as regular expressions or just as " - "keywords.")); - csItem->setToolTip( - tr("CS: This option determines if the highlight rule, Sender, and " - "Channel should be interpreted case sensitive.")); - senderItem->setToolTip( - tr("

Sender: Semicolon separated list of nick!ident@host names, " - "leave blank to match any nickname.

" - "

Example:
" - "Alice!*; Bob!*@example.com; Carol*!*; !Caroline!*
" - "would match on Alice, Bob with hostmask example.com, and " - "any nickname starting with Carol except for Caroline
" - "

If only inverted names are specified, it will match anything except for " - "what's specified (implicit wildcard).

" - "

Example:
" - "!Announce*!*; !Wheatley!aperture@*
" - "would match anything except for Wheatley with ident aperture or " - "any nickname starting with Announce

")); - chanNameItem->setToolTip( - tr("

Channel: Semicolon separated list of channel names, leave blank to " - "match any name.

" - "

Example:
" - "#quassel*; #foobar; !#quasseldroid
" - "would match on #foobar and any channel starting with #quassel " - "except for #quasseldroid
" - "

If only inverted names are specified, it will match anything except for " - "what's specified (implicit wildcard).

" - "

Example:
" - "!#quassel*; !#foobar
" - "would match anything except for #foobar or any channel starting with " - "#quassel

")); + setupTableTooltips(enableItem, nameItem, regexItem, csItem, senderItem, chanNameItem); int lastRow = ui.highlightTable->rowCount() - 1; ui.highlightTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem); @@ -374,29 +426,7 @@ void CoreHighlightSettingsPage::addNewIgnoredRow(bool enable, int id, const QStr auto *senderItem = new QTableWidgetItem(sender); - enableItem->setToolTip(tr("Enable/disable this rule")); - nameItem->setToolTip(tr("Phrase to match")); - regexItem->setToolTip( - tr("RegEx: This option determines if the highlight rule should be " - "interpreted as a regular expression or just as a keyword.")); - csItem->setToolTip( - tr("CS: This option determines if the highlight rule should be interpreted " - "case sensitive.")); - senderItem->setToolTip( - tr("Sender: This option specifies which sender nicknames match. Leave " - "blank to match any nickname.")); - chanNameItem->setToolTip( - tr("

Channel: Semicolon separated list of channel names.

" - "

Example:
" - "#quassel*; #foobar; !#quasseldroid
" - "would match on #foobar and any channel starting with #quassel except " - "for #quasseldroid
" - "

If only inverted names are specified, it will match anything except for " - "what's specified (implicit wildcard).

" - "

Example:
" - "!#quassel*; !#foobar
" - "would match anything except for #foobar or any channel starting with " - "#quassel

")); + setupTableTooltips(enableItem, nameItem, regexItem, csItem, senderItem, chanNameItem); int lastRow = ui.ignoredTable->rowCount() - 1; ui.ignoredTable->setItem(lastRow, CoreHighlightSettingsPage::NameColumn, nameItem); diff --git a/src/qtui/settingspages/corehighlightsettingspage.h b/src/qtui/settingspages/corehighlightsettingspage.h index d4682ec1..0d9150da 100644 --- a/src/qtui/settingspages/corehighlightsettingspage.h +++ b/src/qtui/settingspages/corehighlightsettingspage.h @@ -94,6 +94,41 @@ private: void setupRuleTable(QTableWidget *highlightTable) const; + /** + * Get tooltip for the specified rule table column + * + * @param tableColumn Column to retrieve tooltip + * @return Translated tooltip for the specified column + */ + QString getTableTooltip(column tableColumn) const; + + /** + * Setup tooltips and "What's this?" prompts for table entries + * + * @param enableWidget Enabled checkbox + * @param nameWidget Rule name + * @param regExWidget RegEx enabled + * @param csWidget Case-sensitive + * @param senderWidget Sender name + * @param chanWidget Channel name + */ + void setupTableTooltips(QWidget *enableWidget, QWidget *nameWidget, QWidget *regExWidget, + QWidget *csWidget, QWidget *senderWidget, QWidget *chanWidget) const; + + /** + * Setup tooltips and "What's this?" prompts for table entries + * + * @param enableWidget Enabled checkbox + * @param nameWidget Rule name + * @param regExWidget RegEx enabled + * @param csWidget Case-sensitive + * @param senderWidget Sender name + * @param chanWidget Channel name + */ + void setupTableTooltips(QTableWidgetItem *enableWidget, QTableWidgetItem *nameWidget, + QTableWidgetItem *regExWidget, QTableWidgetItem *csWidget, + QTableWidgetItem *senderWidget, QTableWidgetItem *chanWidget) const; + /** Update the UI to show core support for highlights * * Shows or hides the UI warnings around core-side highlights according to core connection and -- 2.20.1