From 43d98369becca673bd6a25bde5c7abf0cece8e48 Mon Sep 17 00:00:00 2001 From: jakob Date: Fri, 28 Nov 2008 06:51:43 +0100 Subject: [PATCH] - Implemented: Sender auto coloring based on the tango colorscheme --- src/qtui/qtuistyle.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ src/qtui/qtuistyle.h | 3 +++ src/uisupport/uistyle.cpp | 15 ++++++++++++++- src/uisupport/uistyle.h | 26 +++++++++++++++++++++++++- 4 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/qtui/qtuistyle.cpp b/src/qtui/qtuistyle.cpp index bdcfc9f..c6539b6 100644 --- a/src/qtui/qtuistyle.cpp +++ b/src/qtui/qtuistyle.cpp @@ -75,11 +75,46 @@ QtUiStyle::QtUiStyle() : UiStyle("QtUiStyle") { ts.setForeground(QBrush("grey")); setFormat(Timestamp, ts, Settings::Default); + // Set the default sender color QTextCharFormat sender; sender.setAnchor(true); sender.setForeground(QBrush("navy")); setFormat(Sender, sender, Settings::Default); + /* + * Fillup the list of colors used for sender auto coloring In this case + * this are all tango colors without the grey tones + * See "http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines" for details + */ + // Butter + addSenderAutoColor(SenderCol01, "#fce94f"); + addSenderAutoColor(SenderCol02, "#edd400"); + addSenderAutoColor(SenderCol03, "#c4a000"); + // Orange + addSenderAutoColor(SenderCol04, "#fcaf3e"); + addSenderAutoColor(SenderCol05, "#f57900"); + addSenderAutoColor(SenderCol06, "#ce5c00"); + // Chocolate + addSenderAutoColor(SenderCol07, "#e9b96e"); + addSenderAutoColor(SenderCol08, "#c17d11"); + addSenderAutoColor(SenderCol09, "#8f5902"); + // Chameleon + addSenderAutoColor(SenderCol10, "#8ae234"); + addSenderAutoColor(SenderCol11, "#73d216"); + addSenderAutoColor(SenderCol12, "#4e9a06"); + // Sky Blue + addSenderAutoColor(SenderCol13, "#729fcf"); + addSenderAutoColor(SenderCol14, "#3465a4"); + addSenderAutoColor(SenderCol15, "#204a87"); + // Plum + addSenderAutoColor(SenderCol16, "#ad7fa8"); + addSenderAutoColor(SenderCol17, "#75507b"); + addSenderAutoColor(SenderCol18, "#5c3566"); + // Scarlet Red + addSenderAutoColor(SenderCol19, "#ef2929"); + addSenderAutoColor(SenderCol20, "#cc0000"); + addSenderAutoColor(SenderCol21, "#a40000"); + QTextCharFormat nick; nick.setAnchor(true); nick.setFontWeight(QFont::Bold); @@ -115,3 +150,11 @@ void QtUiStyle::setHighlightColor(const QColor &col) { QtUiStyleSettings s; s.setHighlightColor(col); } + +void QtUiStyle::addSenderAutoColor(FormatType type, const QString name) +{ + QTextCharFormat autoColor; + autoColor.setAnchor(true); + autoColor.setForeground(QBrush(QColor(name))); + setFormat(type, autoColor, Settings::Default); +} diff --git a/src/qtui/qtuistyle.h b/src/qtui/qtuistyle.h index d3276f1..e4e2b36 100644 --- a/src/qtui/qtuistyle.h +++ b/src/qtui/qtuistyle.h @@ -34,6 +34,9 @@ public: virtual inline QColor highlightColor() const { return _highlightColor; } virtual void setHighlightColor(const QColor &); +protected: + void inline addSenderAutoColor( FormatType type, const QString name ); + private: QColor _highlightColor; }; diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index d97302a..4fb9048 100644 --- a/src/uisupport/uistyle.cpp +++ b/src/uisupport/uistyle.cpp @@ -149,6 +149,12 @@ void UiStyle::setFormat(FormatType ftype, QTextCharFormat fmt, Settings::Mode mo } 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 + } + if(mode == Settings::Custom && _customFormats.contains(ftype)) return _customFormats.value(ftype); else return _defaultFormats.value(ftype, QTextCharFormat()); } @@ -169,6 +175,8 @@ QTextCharFormat UiStyle::mergedFormat(quint32 ftype) { // color codes! if(ftype & 0x00400000) fmt.merge(format((FormatType)(ftype & 0x0f400000))); // foreground if(ftype & 0x00800000) fmt.merge(format((FormatType)(ftype & 0xf0800000))); // background + // Sender auto colors + if((ftype & 0xfff) == 0x200 && (ftype & 0xff000200) != 0x200) fmt.merge(format((FormatType)(ftype & 0xff000200))); // URL if(ftype & Url) fmt.merge(format(Url)); return _cachedFormats[ftype] = fmt; @@ -433,9 +441,14 @@ UiStyle::FormatType UiStyle::StyledMessage::timestampFormat() const { } UiStyle::FormatType UiStyle::StyledMessage::senderFormat() const { + quint16 hash; switch(type()) { case Message::Plain: - return UiStyle::Sender; break; + // 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 64ad506..83a9444 100644 --- a/src/uisupport/uistyle.h +++ b/src/uisupport/uistyle.h @@ -108,7 +108,31 @@ class UiStyle { BgCol12 = 0xc0800000, BgCol13 = 0xd0800000, BgCol14 = 0xe0800000, - BgCol15 = 0xf0800000 + BgCol15 = 0xf0800000, + + // Colors used for sender auto coloring + // (starting at 01 because 00 is the default Sender format) + SenderCol01 = 0x01000200, + SenderCol02 = 0x02000200, + SenderCol03 = 0x03000200, + SenderCol04 = 0x04000200, + SenderCol05 = 0x05000200, + SenderCol06 = 0x06000200, + SenderCol07 = 0x07000200, + SenderCol08 = 0x08000200, + SenderCol09 = 0x09000200, + SenderCol10 = 0x0a000200, + SenderCol11 = 0x0b000200, + SenderCol12 = 0x0c000200, + SenderCol13 = 0x0d000200, + SenderCol14 = 0x0e000200, + SenderCol15 = 0x0f000200, + SenderCol16 = 0x10000200, + SenderCol17 = 0x11000200, + SenderCol18 = 0x12000200, + SenderCol19 = 0x13000200, + SenderCol20 = 0x14000200, + SenderCol21 = 0x15000200 }; -- 1.6.0.4