From: jakob Date: Fri, 28 Nov 2008 17:01:40 +0000 (+0100) Subject: - Implemented: Settings option to enable/disable sender auto coloring X-Git-Tag: 0.4.0~36 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=4e394a809cbc7def74fb1ea3d89dc372bc9ffca4 - Implemented: Settings option to enable/disable sender auto coloring --- diff --git a/src/qtui/settingspages/colorsettingspage.cpp b/src/qtui/settingspages/colorsettingspage.cpp index 3038c180..bd4c8c20 100644 --- a/src/qtui/settingspages/colorsettingspage.cpp +++ b/src/qtui/settingspages/colorsettingspage.cpp @@ -153,6 +153,7 @@ void ColorSettingsPage::defaultMessage() { ui.senderBG->setColor(QColor("white")); ui.senderBG->setEnabled(false); ui.senderUseBG->setChecked(false); + ui.senderAutoColor->setChecked(true); ui.newMsgMarkerFG->setColor(Qt::red); /* @@ -331,6 +332,11 @@ void ColorSettingsPage::load() { ui.timestampBG->setColor(QtUi::style()->format(UiStyle::Timestamp).background().color()); ui.senderFG->setColor(QtUi::style()->format(UiStyle::Sender).foreground().color()); ui.senderBG->setColor(QtUi::style()->format(UiStyle::Sender).background().color()); + settings["SenderAutoColor"] = s.value("senderAutoColor", QVariant(true)); + if (settings["SenderAutoColor"].toBool()) { + ui.senderAutoColor->setChecked(true); + ui.senderFrame->setEnabled(false); + } settings["NewMsgMarkerFG"] = s.value("newMsgMarkerFG", QColor(Qt::red)); ui.newMsgMarkerFG->setColor(settings["NewMsgMarkerFG"].value()); @@ -443,6 +449,8 @@ void ColorSettingsPage::save() { s.setValue("timestampUseBG", ui.timestampUseBG->isChecked()); saveColor(UiStyle::Sender, ui.senderFG->color(), ui.senderBG->color(), ui.senderUseBG->isChecked()); s.setValue("senderUseBG", ui.senderUseBG->isChecked()); + s.setValue("senderAutoColor", ui.senderAutoColor->isChecked()); + QtUi::style()->setSenderAutoColor(ui.senderAutoColor->isChecked()); s.setValue("newMsgMarkerFG", ui.newMsgMarkerFG->color()); /* @@ -573,6 +581,7 @@ bool ColorSettingsPage::testHasChanged() { if(QtUi::style()->format(UiStyle::Sender).foreground().color() != ui.senderFG->color()) return true; if(QtUi::style()->format(UiStyle::Sender).background().color() != ui.senderBG->color()) return true; if(settings["SenderUseBG"].toBool() != ui.senderUseBG->isChecked()) return true; + if(settings["SenderAutoColor"].toBool() != ui.senderAutoColor->isChecked()) return true; if(settings["NewMsgMarkerFG"].value() != ui.newMsgMarkerFG->color()) return true; /* diff --git a/src/qtui/settingspages/colorsettingspage.ui b/src/qtui/settingspages/colorsettingspage.ui index bc55f955..453aae43 100644 --- a/src/qtui/settingspages/colorsettingspage.ui +++ b/src/qtui/settingspages/colorsettingspage.ui @@ -6,7 +6,7 @@ 0 0 516 - 401 + 427 @@ -22,7 +22,7 @@ - 0 + 1 @@ -364,13 +364,26 @@ - 0 + 2 Server Activity + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -605,42 +618,7 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - label_44 - label_45 - label_7 - label_20 - errorMessageFG - errorMessageBG - errorMessageUseBG - label_18 - noticeMessageFG - noticeMessageBG - noticeMessageUseBG - label_17 - plainMessageFG - plainMessageBG - plainMessageUseBG - label_19 - serverMessageFG - serverMessageBG - serverMessageUseBG - label_10 - highlightColor - groupBox_5 @@ -1101,60 +1079,21 @@ - - - - - - - - - - - false - - - - - - true - - - - - - - - 0 - 0 - - - - Qt::LeftToRight - - - - - - true - - - - + Nick: - + - + false @@ -1167,7 +1106,7 @@ - + @@ -1186,21 +1125,21 @@ - + Hostmask: - + - + false @@ -1213,7 +1152,7 @@ - + @@ -1232,21 +1171,21 @@ - + Channelname: - + - + false @@ -1259,7 +1198,7 @@ - + @@ -1278,21 +1217,21 @@ - + Mode flags: - + - + false @@ -1305,7 +1244,7 @@ - + @@ -1324,21 +1263,21 @@ - + Url: - + - + false @@ -1351,7 +1290,7 @@ - + @@ -1370,20 +1309,94 @@ - + New Message Marker: - + + + + + QFrame::NoFrame + + + QFrame::Plain + + + + 0 + + + 0 + + + 18 + + + 0 + + + + + + + + false + + + + + + + false + + + + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + + + + + + + + + + + Enable + + + + + + + Sender auto coloring: + + + @@ -2146,22 +2159,6 @@ - - senderUseBG - clicked(bool) - senderBG - setEnabled(bool) - - - 372 - 157 - - - 273 - 157 - - - nickUseBG clicked(bool) @@ -2242,5 +2239,37 @@ + + senderUseBG + clicked(bool) + senderBG + setEnabled(bool) + + + 463 + 143 + + + 376 + 143 + + + + + senderAutoColor + clicked(bool) + senderFrame + setEnabled(bool) + + + 232 + 173 + + + 329 + 143 + + + diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index f610e624..bd3f247b 100644 --- a/src/uisupport/uistyle.cpp +++ b/src/uisupport/uistyle.cpp @@ -48,6 +48,9 @@ UiStyle::UiStyle(const QString &settingsKey) : _settingsKey(settingsKey) { _customFormats[type] = s.customFormat(type); } + // Check for the sender auto coloring option + _senderAutoColor = s.value("Flags/senderAutoColor", QVariant(true)).toBool(); + // Now initialize the mapping between FormatCodes and FormatTypes... _formatCodes["%O"] = None; _formatCodes["%B"] = Bold; @@ -127,11 +130,17 @@ void UiStyle::setFormat(FormatType ftype, QTextCharFormat fmt, Settings::Mode mo _cachedFontMetrics.clear(); } +void UiStyle::setSenderAutoColor( bool state ) { + _senderAutoColor = state; + UiStyleSettings s(_settingsKey); + s.setValue("Flags/senderAutoColor", QVariant(state)); +} + QTextCharFormat UiStyle::format(FormatType ftype, Settings::Mode mode) const { - // TODO: implement setting for nick autocoloring and make a check for it here - if ( (ftype & 0x00000fff) == Sender ) - { - // If it is not enabled just set ftype to Sender and go on + // Check for enabled sender auto coloring + if ( (ftype & 0x00000fff) == Sender && !_senderAutoColor ) { + // Just use the default sender style if auto coloring is disabled + ftype = Sender; } if(mode == Settings::Custom && _customFormats.contains(ftype)) return _customFormats.value(ftype); @@ -404,11 +413,11 @@ UiStyle::FormatType UiStyle::StyledMessage::senderFormat() const { quint16 hash; switch(type()) { case Message::Plain: - // To produce random like but stable nick colorings some sort of hashing should work best. - // In this case we just use the qt function qChecksum which produces a - // CRC16 hash. This should be fast and 16 bits are more than enough. - hash = qChecksum(_sender.toAscii().data(), _sender.toAscii().size()); - return (UiStyle::FormatType)((((hash % 21) + 1) << 24) + 0x200); + // To produce random like but stable nick colorings some sort of hashing should work best. + // In this case we just use the qt function qChecksum which produces a + // CRC16 hash. This should be fast and 16 bits are more than enough. + hash = qChecksum(_sender.toAscii().data(), _sender.toAscii().size()); + return (UiStyle::FormatType)((((hash % 21) + 1) << 24) + 0x200); case Message::Notice: return UiStyle::NoticeMsg; break; case Message::Server: diff --git a/src/uisupport/uistyle.h b/src/uisupport/uistyle.h index 14d60a1d..69947fc0 100644 --- a/src/uisupport/uistyle.h +++ b/src/uisupport/uistyle.h @@ -152,6 +152,7 @@ public: QString mircToInternal(const QString &) const; void setFormat(FormatType, QTextCharFormat, Settings::Mode mode/* = Settings::Custom*/); + void setSenderAutoColor(bool state); QTextCharFormat format(FormatType, Settings::Mode mode = Settings::Custom) const; QTextCharFormat mergedFormat(quint32 formatType); QFontMetricsF *fontMetrics(quint32 formatType); @@ -164,6 +165,7 @@ public: QList toTextLayoutList(const FormatList &, int textLength); protected: + bool _senderAutoColor; private: QFont _defaultFont; QTextCharFormat _defaultPlainFormat;