Optionally color sender nicks in Action messages
authorShane Synan <digitalcircuit36939@gmail.com>
Mon, 27 Jun 2016 23:51:48 +0000 (19:51 -0400)
committerManuel Nickschas <sputnick@quassel-irc.org>
Tue, 6 Sep 2016 20:14:48 +0000 (22:14 +0200)
Add checkbox to ChatViewSettings to color sender/nick of action
messages, using the same sender colors as regular messages.

This -significantly- improves readability for long action messages,
such as those on story-telling channels.

src/qtui/qtuistyle.cpp
src/qtui/qtuistyle.h
src/qtui/settingspages/chatviewsettingspage.ui

index f596ab4..f195dfb 100644 (file)
@@ -106,8 +106,21 @@ void QtUiStyle::generateSettingsQss() const
         out << "\n// Sender Colors\n"
             << "ChatLine::sender#plain[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n";
 
         out << "\n// Sender Colors\n"
             << "ChatLine::sender#plain[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n";
 
+        // Matches qssparser.cpp for UiStyle::PlainMsg
         for (int i = 0; i < 16; i++)
         for (int i = 0; i < 16; i++)
-            out << senderQss(i, s);
+            out << senderQss(i, s, "plain");
+
+        // Only color the nicks in CTCP ACTIONs if sender colors are enabled
+        if (s.value("UseSenderActionColors").toBool()) {
+            // For action messages, color the 'sender' column -and- the nick itself
+            out << "\n// Sender Nickname Colors for action messages\n"
+                << "ChatLine::sender#action[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n"
+                << "ChatLine::nick#action[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n";
+
+            // Matches qssparser.cpp for UiStyle::ActionMsg
+            for (int i = 0; i < 16; i++)
+                out << senderQss(i, s, "action", true);
+        }
     }
 
     // ItemViews
     }
 
     // ItemViews
@@ -168,12 +181,20 @@ QString QtUiStyle::msgTypeQss(const QString &msgType, const QString &key, UiSett
 }
 
 
 }
 
 
-QString QtUiStyle::senderQss(int i, UiSettings &settings) const
+QString QtUiStyle::senderQss(int i, UiSettings &settings, const QString &messageType, bool includeNick) const
 {
     QString dez = QString::number(i);
     if (dez.length() == 1) dez.prepend('0');
 
 {
     QString dez = QString::number(i);
     if (dez.length() == 1) dez.prepend('0');
 
-    return QString("ChatLine::sender#plain[sender=\"0%1\"] { foreground: %2; }\n").arg(QString::number(i, 16), color("Sender"+dez, settings));
+    if (includeNick) {
+        // Include the nickname in the color rules
+        return QString("ChatLine::sender#%1[sender=\"0%2\"] { foreground: %3; }\n"
+                       "ChatLine::nick#%1[sender=\"0%2\"]   { foreground: %3; }\n")
+                .arg(messageType, QString::number(i, 16), color("Sender"+dez, settings));
+    } else {
+        return QString("ChatLine::sender#%1[sender=\"0%2\"] { foreground: %3; }\n")
+                .arg(messageType, QString::number(i, 16), color("Sender"+dez, settings));
+    }
 }
 
 
 }
 
 
index 03dac9a..365640c 100644 (file)
@@ -50,7 +50,18 @@ private:
     QString color(const QString &key, UiSettings &settings) const;
 
     QString msgTypeQss(const QString &msgType, const QString &key, UiSettings &settings) const;
     QString color(const QString &key, UiSettings &settings) const;
 
     QString msgTypeQss(const QString &msgType, const QString &key, UiSettings &settings) const;
-    QString senderQss(int i, UiSettings &settings) const;
+
+    /**
+     * Generate a snippet of Qss stylesheet for a given sender-hash index
+     *
+     * @param[in] i            Sender hash index from 0 - 15
+     * @param[in] settings     Reference to current UI settings, used for loading color values
+     * @param[in] messageType  Type of message to filter, e.g. 'plain' or 'action'
+     * @param[in] includeNick  Also apply foreground color to Nick
+     * @return Snippet of Quassel-theme-compatible Qss stylesheet
+     */
+    QString senderQss(int i, UiSettings &settings, const QString &messageType,
+                      bool includeNick = false) const;
     QString chatListItemQss(const QString &state, const QString &key, UiSettings &settings) const;
 };
 
     QString chatListItemQss(const QString &state, const QString &key, UiSettings &settings) const;
 };
 
index 75ccc81..f37821a 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>582</height>
+    <height>610</height>
    </rect>
   </property>
   <property name="windowTitle">
    </rect>
   </property>
   <property name="windowTitle">
         </item>
        </layout>
       </item>
         </item>
        </layout>
       </item>
+      <item>
+       <widget class="QCheckBox" name="useSenderActionColors">
+        <property name="toolTip">
+         <string>Color sender nicknames in action messages, e.g.&lt;br/&gt;-*- &lt;span style=&quot; font-style:italic;&quot;&gt;Nick&lt;/span&gt; does an action</string>
+        </property>
+        <property name="text">
+         <string>Color senders in action messages</string>
+        </property>
+        <property name="checked">
+         <bool>false</bool>
+        </property>
+        <property name="settingsKey" stdset="0">
+         <string notr="true">/QtUiStyle/Colors/UseSenderActionColors</string>
+        </property>
+       </widget>
+      </item>
      </layout>
     </widget>
    </item>
      </layout>
     </widget>
    </item>
   <tabstop>senderColor14</tabstop>
   <tabstop>senderColor15</tabstop>
   <tabstop>senderColorSelf</tabstop>
   <tabstop>senderColor14</tabstop>
   <tabstop>senderColor15</tabstop>
   <tabstop>senderColorSelf</tabstop>
+  <tabstop>useSenderActionColors</tabstop>
  </tabstops>
  <resources/>
  <connections>
  </tabstops>
  <resources/>
  <connections>