Optionally color nicknames in all messages
authorShane Synan <digitalcircuit36939@gmail.com>
Sat, 3 Dec 2016 00:40:30 +0000 (18:40 -0600)
committerManuel Nickschas <sputnick@quassel-irc.org>
Wed, 12 Apr 2017 20:51:18 +0000 (22:51 +0200)
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.

src/qtui/qtuiapplication.cpp
src/qtui/qtuistyle.cpp
src/qtui/qtuistyle.h
src/qtui/settingspages/chatviewcolorsettingspage.ui
src/uisupport/uistyle.cpp

index b77d0af..eada318 100644 (file)
@@ -210,7 +210,7 @@ bool QtUiApplication::migrateSettings()
     // --------
     // Check minor settings version, handling upgrades/downgrades as needed
     // Current minor version
     // --------
     // 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();
 
     // 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.
     //
     // 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
     case 4:
     {
         // New default changes: system locale used to generate a timestamp format string, deciding
index a81f929..9dc997f 100644 (file)
@@ -153,6 +153,17 @@ void QtUiStyle::generateSettingsQss() const
                 out << senderQss(i, "action", true);
         }
 
                 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
     }
 
     // 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));
 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));
index 9d1d5fa..733e73e 100644 (file)
@@ -101,6 +101,17 @@ private:
      * @return Snippet of Quassel-theme-compatible Qss stylesheet
      */
     QString senderQss(int i, const QString &messageType, bool includeNick = false) const;
      * @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;
 };
 
     QString chatListItemQss(const QString &state, const QString &key, UiSettings &settings) const;
 };
 
index 7b05a1f..c5da8b9 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>486</width>
     <x>0</x>
     <y>0</y>
     <width>486</width>
-    <height>428</height>
+    <height>456</height>
    </rect>
   </property>
   <property name="windowTitle">
    </rect>
   </property>
   <property name="windowTitle">
         </property>
        </widget>
       </item>
         </property>
        </widget>
       </item>
+      <item>
+       <widget class="QCheckBox" name="useNicknameGeneralColors">
+        <property name="toolTip">
+         <string>Color nicknames in joins, parts, quits, and other messages, e.g.&lt;br/&gt;--&gt; &lt;span style=&quot; font-style:italic;&quot;&gt;Nick&lt;/span&gt; joined #quassel</string>
+        </property>
+        <property name="text">
+         <string>Color nicknames in other messages</string>
+        </property>
+        <property name="checked">
+         <bool>true</bool>
+        </property>
+        <property name="settingsKey" stdset="0">
+         <string notr="true">/QtUiStyle/Colors/UseNickGeneralColors</string>
+        </property>
+        <property name="defaultValue" stdset="0">
+         <bool>true</bool>
+        </property>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>
      </layout>
     </widget>
    </item>
index fd2bee5..6c6e999 100644 (file)
@@ -735,11 +735,28 @@ QString UiStyle::timestampFormatString()
 UiStyle::StyledMessage::StyledMessage(const Message &msg)
     : Message(msg)
 {
 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;
+    }
 }
 
 
 }