X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fqtui%2Fqtuistyle.cpp;h=1e8cc354d3e423869d943e37ea55326c50c43a55;hb=27fe4e6f46547c45d19fa39c175fa2104a5feb28;hp=f195dfb49d278e438796495752c95ccf59d7976d;hpb=6b2bda5908bc1ddcc242d13adc3390eb1510f4e0;p=quassel.git diff --git a/src/qtui/qtuistyle.cpp b/src/qtui/qtuistyle.cpp index f195dfb4..1e8cc354 100644 --- a/src/qtui/qtuistyle.cpp +++ b/src/qtui/qtuistyle.cpp @@ -27,15 +27,26 @@ QtUiStyle::QtUiStyle(QObject *parent) : UiStyle(parent) { ChatViewSettings s; + s.notify("UseCustomTimestampFormat", this, SLOT(updateUseCustomTimestampFormat())); + updateUseCustomTimestampFormat(); s.notify("TimestampFormat", this, SLOT(updateTimestampFormatString())); updateTimestampFormatString(); s.notify("ShowSenderBrackets", this, SLOT(updateShowSenderBrackets())); updateShowSenderBrackets(); + + // If no style sheet exists, generate it on first run. + initializeSettingsQss(); } QtUiStyle::~QtUiStyle() {} +void QtUiStyle::updateUseCustomTimestampFormat() +{ + ChatViewSettings s; + setUseCustomTimestampFormat(s.useCustomTimestampFormat()); +} + void QtUiStyle::updateTimestampFormatString() { ChatViewSettings s; @@ -49,9 +60,22 @@ void QtUiStyle::updateShowSenderBrackets() } +void QtUiStyle::initializeSettingsQss() +{ + QFileInfo settingsQss(Quassel::configDirPath() + "settings.qss"); + // Only initialize if it doesn't already exist + if (settingsQss.exists()) + return; + + // Generate and load the new stylesheet + generateSettingsQss(); + reload(); +} + void QtUiStyle::generateSettingsQss() const { QFile settingsQss(Quassel::configDirPath() + "settings.qss"); + if (!settingsQss.open(QFile::WriteOnly|QFile::Truncate)) { qWarning() << "Could not open" << settingsQss.fileName() << "for writing!"; return; @@ -102,25 +126,26 @@ void QtUiStyle::generateSettingsQss() const << "\n"; } - if (s.value("UseSenderColors").toBool()) { + if (s.value("UseSenderColors", true).toBool()) { out << "\n// Sender Colors\n" - << "ChatLine::sender#plain[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n"; + << "ChatLine::sender#plain[sender=\"self\"] { foreground: " << color("SenderSelf", s, defaultSenderColorSelf) << "; }\n\n"; // Matches qssparser.cpp for UiStyle::PlainMsg - for (int i = 0; i < 16; i++) + for (int i = 0; i < defaultSenderColors.count(); i++) out << senderQss(i, s, "plain"); // Only color the nicks in CTCP ACTIONs if sender colors are enabled - if (s.value("UseSenderActionColors").toBool()) { + 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) << "; }\n" - << "ChatLine::nick#action[sender=\"self\"] { foreground: " << color("SenderSelf", s) << "; }\n\n"; + << "ChatLine::sender#action[sender=\"self\"] { foreground: " << color("SenderSelf", s, defaultSenderColorSelf) << "; }\n" + << "ChatLine::nick#action[sender=\"self\"] { foreground: " << color("SenderSelf", s, defaultSenderColorSelf) << "; }\n\n"; // Matches qssparser.cpp for UiStyle::ActionMsg - for (int i = 0; i < 16; i++) + for (int i = 0; i < defaultSenderColors.count(); i++) out << senderQss(i, s, "action", true); } + } // ItemViews @@ -155,9 +180,9 @@ void QtUiStyle::generateSettingsQss() const } -QString QtUiStyle::color(const QString &key, UiSettings &settings) const +QString QtUiStyle::color(const QString &key, UiSettings &settings, const QColor &defaultColor) const { - return settings.value(key).value().name(); + return settings.value(key, defaultColor).value().name(); } @@ -190,10 +215,10 @@ QString QtUiStyle::senderQss(int i, UiSettings &settings, const QString &message // 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)); + .arg(messageType, QString::number(i, 16), color("Sender"+dez, settings, defaultSenderColors[i])); } else { return QString("ChatLine::sender#%1[sender=\"0%2\"] { foreground: %3; }\n") - .arg(messageType, QString::number(i, 16), color("Sender"+dez, settings)); + .arg(messageType, QString::number(i, 16), color("Sender"+dez, settings, defaultSenderColors[i])); } }