From: Manuel Nickschas Date: Mon, 22 Jun 2009 19:54:35 +0000 (+0200) Subject: Make sender-hash based styling ("colored nicks") work again X-Git-Tag: 0.5-rc1~136 X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=commitdiff_plain;h=2b5d210cb6e61a25a6a9d0c119aec025322b3b84;ds=inline Make sender-hash based styling ("colored nicks") work again Plain messages now obtain their format depending on the sender hash. This can be used to implement colored nicks, but with our new style engine, we can now solve several problems like using other colors for highlighted messages. Note that the number of hashed is currently hard-coded to 16; waiting for a nice way to make this number configurable in a stylesheet. --- diff --git a/src/qtui/chatlinemodelitem.cpp b/src/qtui/chatlinemodelitem.cpp index 0bcc7a78..1653962e 100644 --- a/src/qtui/chatlinemodelitem.cpp +++ b/src/qtui/chatlinemodelitem.cpp @@ -124,7 +124,7 @@ QVariant ChatLineModelItem::contentsData(int role) const { } quint32 ChatLineModelItem::messageLabel() const { - quint32 label = 0; + quint32 label = _styledMsg.senderHash() << 16; if(_styledMsg.flags() & Message::Self) label |= UiStyle::OwnMsg; if(_styledMsg.flags() & Message::Highlight) diff --git a/src/uisupport/qssparser.cpp b/src/uisupport/qssparser.cpp index d7a788e9..c25bceb8 100644 --- a/src/uisupport/qssparser.cpp +++ b/src/uisupport/qssparser.cpp @@ -237,8 +237,8 @@ quint64 QssParser::parseFormatType(const QString &decl) { qWarning() << Q_FUNC_INFO << tr("Invalid senderhash specification: %1").arg(condValue); return UiStyle::Invalid; } - if(val >= 255) { - qWarning() << Q_FUNC_INFO << tr("Senderhash can be at most \"fe\"!"); + if(val >= 16) { + qWarning() << Q_FUNC_INFO << tr("Senderhash can be at most \"0x0f\"!"); return UiStyle::Invalid; } fmtType |= val << 48; diff --git a/src/uisupport/uistyle.cpp b/src/uisupport/uistyle.cpp index 229e4bab..b5e8911b 100644 --- a/src/uisupport/uistyle.cpp +++ b/src/uisupport/uistyle.cpp @@ -98,8 +98,12 @@ QTextCharFormat UiStyle::format(quint32 ftype, quint32 label) { fmt.merge(cachedFormat(key & 0x0000000000000000)); // basic fmt.merge(cachedFormat(key & 0x000000000000000f)); // msgtype + fmt.merge(cachedFormat(key & 0xffff000000000000)); // nickhash + fmt.merge(cachedFormat(key & 0xffff00000000000f)); // nickhash + msgtype fmt.merge(cachedFormat(key & 0x0000ffff00000000)); // label fmt.merge(cachedFormat(key & 0x0000ffff0000000f)); // label + msgtype + fmt.merge(cachedFormat(key & 0xffffffff00000000)); // label + nickhash + fmt.merge(cachedFormat(key & 0xffffffff0000000f)); // label + nickhash + msgtype // TODO: allow combinations for mirc formats and colors (each), e.g. setting a special format for "bold and italic" // or "foreground 01 and background 03" @@ -308,6 +312,10 @@ QString UiStyle::mircToInternal(const QString &mirc_) { UiStyle::StyledMessage::StyledMessage(const Message &msg) : Message(msg) { + if(type() == Message::Plain) + _senderHash = 0xff; + else + _senderHash = 0x00; // this means we never compute the hash for msgs that aren't plain } void UiStyle::StyledMessage::style() const { @@ -497,6 +505,22 @@ UiStyle::FormatType UiStyle::StyledMessage::senderFormat() const { } } +// FIXME hardcoded to 16 sender hashes +quint8 UiStyle::StyledMessage::senderHash() const { + if(_senderHash != 0xff) + return _senderHash; + + QString nick = nickFromMask(sender()).toLower(); + if(!nick.isEmpty()) { + int chopCount = 0; + while(nick.at(nick.count() - 1 - chopCount) == '_') + chopCount++; + nick.chop(chopCount); + } + quint16 hash = qChecksum(nick.toAscii().data(), nick.toAscii().size()); + return (_senderHash = (hash & 0xf) + 1); +} + /***********************************************************************************/ QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList) { diff --git a/src/uisupport/uistyle.h b/src/uisupport/uistyle.h index 22ade27a..f031085e 100644 --- a/src/uisupport/uistyle.h +++ b/src/uisupport/uistyle.h @@ -148,6 +148,9 @@ public: inline FormatType timestampFormat() const { return UiStyle::Timestamp; } FormatType senderFormat() const; const FormatList &contentsFormatList() const; + + quint8 senderHash() const; + protected: //! Styling is only needed for calls to plainContents() and contentsFormatList() void style() const; @@ -155,6 +158,7 @@ protected: private: mutable StyledString _contents; + mutable quint8 _senderHash; }; QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList);