modernize: Use raw string literals instead of escaped strings
[quassel.git] / src / qtui / qtuistyle.cpp
index a81f929..efca13a 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2016 by the Quassel Project                        *
+ *   Copyright (C) 2005-2018 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -22,6 +22,7 @@
 #include "qtuistyle.h"
 
 #include <QFile>
+#include <QFileInfo>
 #include <QTextStream>
 
 QtUiStyle::QtUiStyle(QObject *parent) : UiStyle(parent)
@@ -31,6 +32,8 @@ QtUiStyle::QtUiStyle(QObject *parent) : UiStyle(parent)
     updateUseCustomTimestampFormat();
     s.notify("TimestampFormat", this, SLOT(updateTimestampFormatString()));
     updateTimestampFormatString();
+    s.notify("SenderPrefixMode", this, SLOT(updateSenderPrefixDisplay()));
+    updateSenderPrefixDisplay();
     s.notify("ShowSenderBrackets", this, SLOT(updateShowSenderBrackets()));
     updateShowSenderBrackets();
 
@@ -39,8 +42,6 @@ QtUiStyle::QtUiStyle(QObject *parent) : UiStyle(parent)
 }
 
 
-QtUiStyle::~QtUiStyle() {}
-
 void QtUiStyle::updateUseCustomTimestampFormat()
 {
     ChatViewSettings s;
@@ -53,6 +54,12 @@ void QtUiStyle::updateTimestampFormatString()
     setTimestampFormatString(s.timestampFormatString());
 }
 
+void QtUiStyle::updateSenderPrefixDisplay()
+{
+    ChatViewSettings s;
+    setSenderPrefixDisplay(s.SenderPrefixDisplay());
+}
+
 void QtUiStyle::updateShowSenderBrackets()
 {
     ChatViewSettings s;
@@ -153,6 +160,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
@@ -180,7 +198,7 @@ void QtUiStyle::generateSettingsQss() const
         out << "\n// NickView Colors\n"
             << "NickListItem[type=\"category\"] { foreground: " << color("DefaultBuffer", uiColors) << "; }\n"
             << "NickListItem[type=\"user\"] { foreground: " << color("OnlineNick", uiColors) << "; }\n"
-            << "NickListItem[type=\"user\", state=\"away\"] { foreground: " << color("AwayNick", uiColors) << "; }\n";
+            << R"(NickListItem[type="user", state="away"] { foreground: )" << color("AwayNick", uiColors) << "; }\n";
     }
 
     settingsQss.close();
@@ -195,15 +213,16 @@ QString QtUiStyle::color(const QString &key, UiSettings &settings, const QColor
 
 QString QtUiStyle::fontDescription(const QFont &font) const
 {
-    QString desc = "font: ";
-    if (font.italic())
-        desc += "italic ";
-    if (font.bold())
-        desc += "bold ";
-    if (!font.italic() && !font.bold())
-        desc += "normal ";
-    desc += QString("%1pt \"%2\"").arg(font.pointSize()).arg(font.family());
-    return desc;
+    QFont::Style style = font.style();
+    int weight = font.weight();
+
+    return QString("font: %1 %2 %3pt \"%4\"")
+        .arg(style == QFont::StyleItalic  ? "italic"  :
+             style == QFont::StyleOblique ? "oblique" :
+                                            "normal")
+        .arg(100 * qBound(1, (weight * 8 + 50) / 100, 9))
+        .arg(font.pointSize())
+        .arg(font.family());
 }
 
 
@@ -251,6 +270,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));