From 6cccf948b2db553285aeb90e3173d65040854c8c Mon Sep 17 00:00:00 2001 From: jakob Date: Fri, 28 Nov 2008 18:01:40 +0100 Subject: [PATCH] - Implemented: Settings option to enable/disable sender auto coloring --- src/qtui/settingspages/colorsettingspage.cpp | 9 + src/qtui/settingspages/colorsettingspage.ui | 260 ++++++++++++++++++-------- src/uisupport/uistyle.cpp | 27 ++- src/uisupport/uistyle.h | 3 +- 4 files changed, 215 insertions(+), 84 deletions(-) diff --git a/src/qtui/settingspages/colorsettingspage.cpp b/src/qtui/settingspages/colorsettingspage.cpp index 2a8ee4c..daa7608 100644 --- a/src/qtui/settingspages/colorsettingspage.cpp +++ b/src/qtui/settingspages/colorsettingspage.cpp @@ -170,6 +170,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); /* @@ -348,6 +349,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()); @@ -460,6 +466,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()); /* @@ -590,6 +598,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 99f3ff8..8854445 100644 --- a/src/qtui/settingspages/colorsettingspage.ui +++ b/src/qtui/settingspages/colorsettingspage.ui @@ -6,7 +6,7 @@ 0 0 517 - 532 + 561 @@ -542,8 +542,8 @@ - - + + Qt::Vertical @@ -872,14 +872,27 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + Message - - + + Foreground @@ -889,7 +902,7 @@ - + Background @@ -899,7 +912,7 @@ - + Use BG @@ -916,14 +929,14 @@ - + - + false @@ -933,7 +946,7 @@ - + @@ -949,61 +962,21 @@ - - - - Sender: - - - - - - - - - - - - - - false - - - - - - - - - - - 0 - 0 - - - - Qt::LeftToRight - - - - - - - + Nick: - + - + false @@ -1013,7 +986,7 @@ - + @@ -1029,21 +1002,21 @@ - + Hostmask: - + - + false @@ -1053,7 +1026,7 @@ - + @@ -1069,21 +1042,21 @@ - + Channelname: - + - + false @@ -1093,7 +1066,7 @@ - + @@ -1109,21 +1082,21 @@ - + Mode flags: - + - + false @@ -1133,7 +1106,7 @@ - + @@ -1149,21 +1122,21 @@ - + Url: - + - + false @@ -1173,7 +1146,7 @@ - + @@ -1189,21 +1162,136 @@ - + New Message Marker: - + + + + + Sender: + + + + + + + Sender auto coloring: + + + + + + + Enable + + + + + + + QFrame::NoFrame + + + QFrame::Plain + + + + 0 + + + 0 + + + 18 + + + 0 + + + + + + + + false + + + + + + + false + + + + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + + + + + + + + label_37 + label_38 + label_9 + label_29 + timestampFG + timestampBG + timestampUseBG + label_30 + nickFG + nickBG + nickUseBG + label_31 + hostmaskFG + hostmaskBG + hostmaskUseBG + label_32 + channelnameFG + channelnameBG + channelnameUseBG + label_33 + modeFlagsFG + modeFlagsBG + modeFlagsUseBG + label_34 + urlFG + urlBG + urlUseBG + label_11 + newMsgMarkerFG + label_28 + label_12 + senderAutoColor + label_13 + senderFrame @@ -1219,8 +1307,16 @@ Preview: + + QLayout::SetDefaultConstraint + + + 9 + - + + tabWidget_2 + @@ -1972,7 +2068,7 @@ senderUseBG - clicked(bool) + toggled(bool) senderBG setEnabled(bool) @@ -2066,5 +2162,21 @@ + + senderAutoColor + clicked(bool) + senderFrame + setDisabled(bool) + + + 234 + 173 + + + 327 + 143 + + + diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index 4fb9048..86ef806 100644 --- a/src/uisupport/uistyle.cpp +++ b/src/uisupport/uistyle.cpp @@ -69,6 +69,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; @@ -148,11 +151,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); @@ -444,11 +453,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 83a9444..a062c7f 100644 --- a/src/uisupport/uistyle.h +++ b/src/uisupport/uistyle.h @@ -153,6 +153,7 @@ class UiStyle { 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); @@ -165,7 +166,7 @@ class UiStyle { QList toTextLayoutList(const FormatList &, int textLength); protected: - + bool _senderAutoColor; private: -- 1.6.0.4