- Implemented: Sender auto coloring based on the tango colorscheme
authorjakob <jakob@ezekiel.(none)>
Fri, 28 Nov 2008 05:51:43 +0000 (06:51 +0100)
committerManuel Nickschas <sputnick@quassel-irc.org>
Sun, 15 Feb 2009 18:09:53 +0000 (19:09 +0100)
src/qtui/qtuistyle.cpp
src/qtui/qtuistyle.h
src/uisupport/uistyle.cpp
src/uisupport/uistyle.h

index 1aa2ff0..d1b455d 100644 (file)
@@ -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);
+}
index 270e248..805ce4f 100644 (file)
@@ -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;
 };
index 4e1bd77..f610e62 100644 (file)
@@ -128,6 +128,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());
 }
@@ -148,6 +154,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;
@@ -393,9 +401,14 @@ QString UiStyle::StyledMessage::decoratedSender() 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:
index 7f0614b..14d60a1 100644 (file)
@@ -108,7 +108,31 @@ public:
     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
 
   };