Project

General

Profile

0001--Implemented-Sender-auto-coloring-based-on-the-ta.patch

admin, 11/28/2008 06:34 PM

View differences:

src/qtui/qtuistyle.cpp
75 75
  ts.setForeground(QBrush("grey"));
76 76
  setFormat(Timestamp, ts, Settings::Default);
77 77

  
78
  // Set the default sender color
78 79
  QTextCharFormat sender;
79 80
  sender.setAnchor(true);
80 81
  sender.setForeground(QBrush("navy"));
81 82
  setFormat(Sender, sender, Settings::Default);
82 83

  
84
  /*
85
   * Fillup the list of colors used for sender auto coloring In this case
86
   * this are all tango colors without the grey tones 
87
   * See "http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines" for details
88
   */
89
  // Butter
90
  addSenderAutoColor(SenderCol01, "#fce94f");
91
  addSenderAutoColor(SenderCol02, "#edd400");
92
  addSenderAutoColor(SenderCol03,  "#c4a000");
93
  // Orange
94
  addSenderAutoColor(SenderCol04,  "#fcaf3e");
95
  addSenderAutoColor(SenderCol05,  "#f57900");
96
  addSenderAutoColor(SenderCol06,  "#ce5c00");
97
  // Chocolate
98
  addSenderAutoColor(SenderCol07, "#e9b96e");
99
  addSenderAutoColor(SenderCol08, "#c17d11");
100
  addSenderAutoColor(SenderCol09, "#8f5902");
101
  // Chameleon
102
  addSenderAutoColor(SenderCol10, "#8ae234");
103
  addSenderAutoColor(SenderCol11, "#73d216");
104
  addSenderAutoColor(SenderCol12, "#4e9a06");
105
  // Sky Blue
106
  addSenderAutoColor(SenderCol13, "#729fcf");
107
  addSenderAutoColor(SenderCol14, "#3465a4");
108
  addSenderAutoColor(SenderCol15, "#204a87");
109
  // Plum
110
  addSenderAutoColor(SenderCol16, "#ad7fa8");
111
  addSenderAutoColor(SenderCol17, "#75507b");
112
  addSenderAutoColor(SenderCol18, "#5c3566");
113
  // Scarlet Red
114
  addSenderAutoColor(SenderCol19, "#ef2929");
115
  addSenderAutoColor(SenderCol20, "#cc0000");
116
  addSenderAutoColor(SenderCol21, "#a40000");
117

  
83 118
  QTextCharFormat nick;
84 119
  nick.setAnchor(true);
85 120
  nick.setFontWeight(QFont::Bold);
......
115 150
  QtUiStyleSettings s;
116 151
  s.setHighlightColor(col);
117 152
}
153

  
154
void QtUiStyle::addSenderAutoColor(FormatType type, const QString name) 
155
{
156
  QTextCharFormat autoColor;
157
  autoColor.setAnchor(true);
158
  autoColor.setForeground(QBrush(QColor(name)));
159
  setFormat(type, autoColor, Settings::Default);
160
}
src/qtui/qtuistyle.h
34 34
  virtual inline QColor highlightColor() const { return _highlightColor; }
35 35
  virtual void setHighlightColor(const QColor &);
36 36

  
37
protected:
38
  void inline addSenderAutoColor( FormatType type, const QString name );
39

  
37 40
private:
38 41
  QColor _highlightColor;
39 42
};
src/uisupport/uistyle.cpp
149 149
}
150 150

  
151 151
QTextCharFormat UiStyle::format(FormatType ftype, Settings::Mode mode) const {
152
  // TODO: implement setting for nick autocoloring and make a check for it here
153
  if ( (ftype & 0x00000fff) == Sender ) 
154
  {
155
    // If it is not enabled just set ftype to Sender and go on
156
  }
157

  
152 158
  if(mode == Settings::Custom && _customFormats.contains(ftype)) return _customFormats.value(ftype);
153 159
  else return _defaultFormats.value(ftype, QTextCharFormat());
154 160
}
......
169 175
  // color codes!
170 176
  if(ftype & 0x00400000) fmt.merge(format((FormatType)(ftype & 0x0f400000))); // foreground
171 177
  if(ftype & 0x00800000) fmt.merge(format((FormatType)(ftype & 0xf0800000))); // background
178
  // Sender auto colors
179
  if((ftype & 0xfff) == 0x200 && (ftype & 0xff000200) != 0x200) fmt.merge(format((FormatType)(ftype & 0xff000200)));
172 180
  // URL
173 181
  if(ftype & Url) fmt.merge(format(Url));
174 182
  return _cachedFormats[ftype] = fmt;
......
433 441
}
434 442

  
435 443
UiStyle::FormatType UiStyle::StyledMessage::senderFormat() const {
444
  quint16 hash;
436 445
  switch(type()) {
437 446
    case Message::Plain:
438
      return UiStyle::Sender; break;
447
    // To produce random like but stable nick colorings some sort of hashing should work best.
448
    // In this case we just use the qt function qChecksum which produces a
449
    // CRC16 hash. This should be fast and 16 bits are more than enough.
450
    hash = qChecksum(_sender.toAscii().data(), _sender.toAscii().size());
451
    return (UiStyle::FormatType)((((hash % 21) + 1) << 24) + 0x200);
439 452
    case Message::Notice:
440 453
      return UiStyle::NoticeMsg; break;
441 454
    case Message::Server:
src/uisupport/uistyle.h
108 108
      BgCol12         = 0xc0800000,
109 109
      BgCol13         = 0xd0800000,
110 110
      BgCol14         = 0xe0800000,
111
      BgCol15         = 0xf0800000
111
      BgCol15         = 0xf0800000,
112

  
113
      // Colors used for sender auto coloring
114
      // (starting at 01 because 00 is the default Sender format)
115
      SenderCol01     = 0x01000200,
116
      SenderCol02     = 0x02000200,
117
      SenderCol03     = 0x03000200,
118
      SenderCol04     = 0x04000200,
119
      SenderCol05     = 0x05000200,
120
      SenderCol06     = 0x06000200,
121
      SenderCol07     = 0x07000200,
122
      SenderCol08     = 0x08000200,
123
      SenderCol09     = 0x09000200,
124
      SenderCol10     = 0x0a000200,
125
      SenderCol11     = 0x0b000200,
126
      SenderCol12     = 0x0c000200,
127
      SenderCol13     = 0x0d000200,
128
      SenderCol14     = 0x0e000200,
129
      SenderCol15     = 0x0f000200,
130
      SenderCol16     = 0x10000200,
131
      SenderCol17     = 0x11000200,
132
      SenderCol18     = 0x12000200,
133
      SenderCol19     = 0x13000200,
134
      SenderCol20     = 0x14000200,
135
      SenderCol21     = 0x15000200
112 136

  
113 137
    };
114 138

  
115
-