}
if (s.value("UseSenderColors", true).toBool()) {
- out << "\n// Sender Colors\n"
- << "ChatLine::sender#plain[sender=\"self\"] { foreground: " << color("SenderSelf", s, defaultSenderColorSelf) << "; }\n\n";
+ out << "\n// Sender Colors\n";
+ // Generate a color palette for easy reuse elsewhere
+ // NOTE: A color palette is not a complete replacement for specifying the colors below, as
+ // specifying the colors one-by-one instead of with QtUi::style()->brush(...) makes it easy
+ // to toggle the specific coloring of sender/nick at the cost of regenerating this file.
+ // See UiStyle::ColorRole
+ out << senderPaletteQss(s);
+
+ out << "ChatLine::sender#plain[sender=\"self\"] { foreground: palette(sender-color-self); }\n\n";
// Matches qssparser.cpp for UiStyle::PlainMsg
for (int i = 0; i < defaultSenderColors.count(); i++)
- out << senderQss(i, s, "plain");
+ out << senderQss(i, "plain");
// Only color the nicks in CTCP ACTIONs if sender colors are enabled
if (s.value("UseSenderActionColors", true).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, defaultSenderColorSelf) << "; }\n"
- << "ChatLine::nick#action[sender=\"self\"] { foreground: " << color("SenderSelf", s, defaultSenderColorSelf) << "; }\n\n";
+ << "ChatLine::sender#action[sender=\"self\"] { foreground: palette(sender-color-self); }\n"
+ << "ChatLine::nick#action[sender=\"self\"] { foreground: palette(sender-color-self); }\n\n";
// Matches qssparser.cpp for UiStyle::ActionMsg
for (int i = 0; i < defaultSenderColors.count(); i++)
- out << senderQss(i, s, "action", true);
+ out << senderQss(i, "action", true);
}
}
}
-QString QtUiStyle::senderQss(int i, UiSettings &settings, const QString &messageType, bool includeNick) const
+QString QtUiStyle::senderPaletteQss(UiSettings &settings) const
+{
+ QString result;
+ result += "Palette {\n";
+
+ // Generate entries for sender-color-self
+ result += QString(" sender-color-self: %1;\n")
+ .arg(color("SenderSelf", settings, defaultSenderColorSelf));
+
+ // Generate entries for sender-color-HASH
+ for (int i = 0; i < defaultSenderColors.count(); i++) {
+ QString dez = QString::number(i);
+ if (dez.length() == 1) dez.prepend('0');
+ result += QString(" sender-color-0%1: %2;\n")
+ .arg(QString::number(i, 16), color("Sender"+dez, settings, defaultSenderColors[i]));
+ }
+ result += "}\n\n";
+ return result;
+}
+
+
+QString QtUiStyle::senderQss(int i, const QString &messageType, bool includeNick) const
{
QString dez = QString::number(i);
if (dez.length() == 1) dez.prepend('0');
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, defaultSenderColors[i]));
+ return QString("ChatLine::sender#%1[sender=\"0%2\"] { foreground: palette(sender-color-0%2); }\n"
+ "ChatLine::nick#%1[sender=\"0%2\"] { foreground: palette(sender-color-0%2); }\n")
+ .arg(messageType, QString::number(i, 16));
} else {
- return QString("ChatLine::sender#%1[sender=\"0%2\"] { foreground: %3; }\n")
- .arg(messageType, QString::number(i, 16), color("Sender"+dez, settings, defaultSenderColors[i]));
+ return QString("ChatLine::sender#%1[sender=\"0%2\"] { foreground: palette(sender-color-0%2); }\n")
+ .arg(messageType, QString::number(i, 16));
}
}
QString msgTypeQss(const QString &msgType, const QString &key, UiSettings &settings) const;
+ /**
+ * Generates the Qss color palette stylesheet for sender colors
+ *
+ * This must be called before generating any Qss dependent on these colors.
+ *
+ * @see QtUiStyle::senderQss()
+ * @param[in] settings Reference to current UI settings, used for loading color values
+ * @return Quassel-theme-compatible Qss color palette
+ */
+ QString senderPaletteQss(UiSettings &settings) const;
+
/**
* Generate a snippet of Qss stylesheet for a given sender-hash index
*
+ * This depends on the color palette generated by QtUiStyle::senderPaletteQss()
+ *
* @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 senderQss(int i, const QString &messageType, bool includeNick = false) const;
QString chatListItemQss(const QString &state, const QString &key, UiSettings &settings) const;
};
_uiStylePalette = QVector<QBrush>(UiStyle::NumRoles, QBrush());
_uiStyleColorRoles["marker-line"] = UiStyle::MarkerLine;
+ // Sender colors
+ _uiStyleColorRoles["sender-color-self"] = UiStyle::SenderColorSelf;
+ _uiStyleColorRoles["sender-color-00"] = UiStyle::SenderColor00;
+ _uiStyleColorRoles["sender-color-01"] = UiStyle::SenderColor01;
+ _uiStyleColorRoles["sender-color-02"] = UiStyle::SenderColor02;
+ _uiStyleColorRoles["sender-color-03"] = UiStyle::SenderColor03;
+ _uiStyleColorRoles["sender-color-04"] = UiStyle::SenderColor04;
+ _uiStyleColorRoles["sender-color-05"] = UiStyle::SenderColor05;
+ _uiStyleColorRoles["sender-color-06"] = UiStyle::SenderColor06;
+ _uiStyleColorRoles["sender-color-07"] = UiStyle::SenderColor07;
+ _uiStyleColorRoles["sender-color-08"] = UiStyle::SenderColor08;
+ _uiStyleColorRoles["sender-color-09"] = UiStyle::SenderColor09;
+ _uiStyleColorRoles["sender-color-0a"] = UiStyle::SenderColor0a;
+ _uiStyleColorRoles["sender-color-0b"] = UiStyle::SenderColor0b;
+ _uiStyleColorRoles["sender-color-0c"] = UiStyle::SenderColor0c;
+ _uiStyleColorRoles["sender-color-0d"] = UiStyle::SenderColor0d;
+ _uiStyleColorRoles["sender-color-0e"] = UiStyle::SenderColor0e;
+ _uiStyleColorRoles["sender-color-0f"] = UiStyle::SenderColor0f;
}
enum ColorRole {
MarkerLine,
+ // Sender colors (16 + self)
+ // These aren't used directly to avoid having storing all of the sender color options in the
+ // rendering routine of each item. Also, I couldn't figure out how to do that.
+ // It would be nice to have the UseSenderColors preference also toggle sender colors set by
+ // themes, so hopefully this can be extended in the future.
+ // Furthermore, using this palette directly would mean separate sets of colors couldn't be
+ // used for different message types.
+ SenderColorSelf,
+ SenderColor00,
+ SenderColor01,
+ SenderColor02,
+ SenderColor03,
+ SenderColor04,
+ SenderColor05,
+ SenderColor06,
+ SenderColor07,
+ SenderColor08,
+ SenderColor09,
+ SenderColor0a,
+ SenderColor0b,
+ SenderColor0c,
+ SenderColor0d,
+ SenderColor0e,
+ SenderColor0f,
NumRoles // must be last!
};
* List of default sender colors
*
* In order from 1 - 16, matching the Sender## format in the settings file.
- * Don't change the length or values of the colors without updating the UI, too.
+ * Don't change the length or values of the colors without updating the UI and color roles, too.
*
* @see ../qtui/settingspages/chatviewsettingspage.ui
+ * @see UiStyle::ColorRole
*/
const QList<QColor> defaultSenderColors = QList<QColor> {
QColor(233, 13, 127), /// Sender00