From: Shane Synan Date: Sat, 3 Dec 2016 00:40:30 +0000 (-0600) Subject: Optionally color nicknames in all messages X-Git-Tag: travis-deploy-test~324 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=cbe2482dca16e13aa3a170213f299179d20526af Optionally color nicknames in all messages Find senderHash for all nickname-relevant messages that don't have multiple nicknames (e.g. netsplits). Add new preference "UseNickGeneralColors" to toggle sender coloring on all available nicknames, not just action messages. This might be undesired by some given the level of colors, so it's kept as a separate preference from ACTION message coloring. Bump settings minor version to keep nickname coloring disabled for existing setups. --- diff --git a/src/qtui/qtuiapplication.cpp b/src/qtui/qtuiapplication.cpp index b77d0af2..eada318c 100644 --- a/src/qtui/qtuiapplication.cpp +++ b/src/qtui/qtuiapplication.cpp @@ -210,7 +210,7 @@ bool QtUiApplication::migrateSettings() // -------- // Check minor settings version, handling upgrades/downgrades as needed // Current minor version - const uint VERSION_MINOR_CURRENT = 4; + const uint VERSION_MINOR_CURRENT = 5; // Stored minor version uint versionMinor = s.versionMinor(); @@ -273,6 +273,27 @@ bool QtUiApplication::applySettingsMigration(QtUiSettings settings, const uint n // // In most cases, the goal is to preserve the older default values for keys that haven't been // saved. Exceptions will be noted below. + case 5: + { + // New default changes: sender colors apply to nearly all messages with nicks + + // -------- + // QtUiStyle settings + QtUiStyleSettings settingsUiStyleColors("Colors"); + const QString useNickGeneralColorsId = "UseNickGeneralColors"; + if (!settingsUiStyleColors.valueExists(useNickGeneralColorsId)) { + // New default is true, preserve previous behavior by setting to false + settingsUiStyleColors.setValue(useNickGeneralColorsId, false); + } + + // Update the settings stylesheet with old defaults + QtUiStyle qtUiStyle; + qtUiStyle.generateSettingsQss(); + // -------- + + // Migration complete! + return true; + } case 4: { // New default changes: system locale used to generate a timestamp format string, deciding diff --git a/src/qtui/qtuistyle.cpp b/src/qtui/qtuistyle.cpp index a81f9295..9dc997f4 100644 --- a/src/qtui/qtuistyle.cpp +++ b/src/qtui/qtuistyle.cpp @@ -153,6 +153,17 @@ void QtUiStyle::generateSettingsQss() const out << senderQss(i, "action", true); } + // Only color the nicks in CTCP ACTIONs if sender colors are enabled + if (s.value("UseNickGeneralColors", true).toBool()) { + // For action messages, color the 'sender' column -and- the nick itself + out << "\n// Nickname colors for all messages\n" + << "ChatLine::nick[sender=\"self\"] { foreground: palette(sender-color-self); }\n\n"; + + // Matches qssparser.cpp for any style of message (UiStyle::...) + for (int i = 0; i < defaultSenderColors.count(); i++) + out << nickQss(i); + } + } // ItemViews @@ -251,6 +262,16 @@ QString QtUiStyle::senderQss(int i, const QString &messageType, bool includeNick } +QString QtUiStyle::nickQss(int i) const +{ + QString dez = QString::number(i); + if (dez.length() == 1) dez.prepend('0'); + + return QString("ChatLine::nick[sender=\"0%1\"] { foreground: palette(sender-color-0%1); }\n") + .arg(QString::number(i, 16)); +} + + QString QtUiStyle::chatListItemQss(const QString &state, const QString &key, UiSettings &settings) const { return QString("ChatListItem[state=\"%1\"] { foreground: %2; }\n").arg(state, color(key, settings)); diff --git a/src/qtui/qtuistyle.h b/src/qtui/qtuistyle.h index 9d1d5fa4..733e73e5 100644 --- a/src/qtui/qtuistyle.h +++ b/src/qtui/qtuistyle.h @@ -101,6 +101,17 @@ private: * @return Snippet of Quassel-theme-compatible Qss stylesheet */ QString senderQss(int i, const QString &messageType, bool includeNick = false) const; + + /** + * Generate a snippet of Qss stylesheet for a given IRC nickname sender-hash index + * + * This depends on the color palette generated by QtUiStyle::senderPaletteQss() + * + * @param[in] i Sender hash index from 0 - 15 + * @return Snippet of Quassel-theme-compatible Qss stylesheet + */ + QString nickQss(int i) const; + QString chatListItemQss(const QString &state, const QString &key, UiSettings &settings) const; }; diff --git a/src/qtui/settingspages/chatviewcolorsettingspage.ui b/src/qtui/settingspages/chatviewcolorsettingspage.ui index 7b05a1f0..c5da8b9b 100644 --- a/src/qtui/settingspages/chatviewcolorsettingspage.ui +++ b/src/qtui/settingspages/chatviewcolorsettingspage.ui @@ -7,7 +7,7 @@ 0 0 486 - 428 + 456 @@ -702,6 +702,25 @@ + + + + Color nicknames in joins, parts, quits, and other messages, e.g.<br/>--> <span style=" font-style:italic;">Nick</span> joined #quassel + + + Color nicknames in other messages + + + true + + + /QtUiStyle/Colors/UseNickGeneralColors + + + true + + + diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index fd2bee52..6c6e999d 100644 --- a/src/uisupport/uistyle.cpp +++ b/src/uisupport/uistyle.cpp @@ -735,11 +735,28 @@ QString UiStyle::timestampFormatString() UiStyle::StyledMessage::StyledMessage(const Message &msg) : Message(msg) { - if (type() == Message::Plain || type() == Message::Action) - _senderHash = 0xff; - else - _senderHash = 0x00; - // This means we never compute the hash for msgs that aren't Plain or Action + switch (type()) { + // Don't compute the sender hash for message types without a nickname embedded + case Message::Server: + case Message::Info: + case Message::Error: + case Message::DayChange: + case Message::Topic: + case Message::Invite: + // Don't compute the sender hash for messages with multiple nicks + // Fixing this without breaking themes would be.. complex. + case Message::NetsplitJoin: + case Message::NetsplitQuit: + case Message::Kick: + // Don't compute the sender hash for message types that are not yet completed elsewhere + case Message::Kill: + _senderHash = 0x00; + break; + default: + // Compute the sender hash for all other message types + _senderHash = 0xff; + break; + } }