From 6b2bda5908bc1ddcc242d13adc3390eb1510f4e0 Mon Sep 17 00:00:00 2001 From: Shane Synan Date: Mon, 27 Jun 2016 19:51:48 -0400 Subject: [PATCH] Optionally color sender nicks in Action messages 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 | 27 ++++++++++++++++--- src/qtui/qtuistyle.h | 13 ++++++++- .../settingspages/chatviewsettingspage.ui | 19 ++++++++++++- 3 files changed, 54 insertions(+), 5 deletions(-) diff --git a/src/qtui/qtuistyle.cpp b/src/qtui/qtuistyle.cpp index f596ab40..f195dfb4 100644 --- a/src/qtui/qtuistyle.cpp +++ b/src/qtui/qtuistyle.cpp @@ -106,8 +106,21 @@ void QtUiStyle::generateSettingsQss() const 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++) - 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 @@ -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'); - 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)); + } } diff --git a/src/qtui/qtuistyle.h b/src/qtui/qtuistyle.h index 03dac9ae..365640c7 100644 --- a/src/qtui/qtuistyle.h +++ b/src/qtui/qtuistyle.h @@ -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 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; }; diff --git a/src/qtui/settingspages/chatviewsettingspage.ui b/src/qtui/settingspages/chatviewsettingspage.ui index 75ccc813..f37821a8 100644 --- a/src/qtui/settingspages/chatviewsettingspage.ui +++ b/src/qtui/settingspages/chatviewsettingspage.ui @@ -7,7 +7,7 @@ 0 0 486 - 582 + 610 @@ -824,6 +824,22 @@ + + + + Color sender nicknames in action messages, e.g.<br/>-*- <span style=" font-style:italic;">Nick</span> does an action + + + Color senders in action messages + + + false + + + /QtUiStyle/Colors/UseSenderActionColors + + + @@ -891,6 +907,7 @@ senderColor14 senderColor15 senderColorSelf + useSenderActionColors -- 2.20.1