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.
}
quint32 ChatLineModelItem::messageLabel() const {
}
quint32 ChatLineModelItem::messageLabel() const {
+ quint32 label = _styledMsg.senderHash() << 16;
if(_styledMsg.flags() & Message::Self)
label |= UiStyle::OwnMsg;
if(_styledMsg.flags() & Message::Highlight)
if(_styledMsg.flags() & Message::Self)
label |= UiStyle::OwnMsg;
if(_styledMsg.flags() & Message::Highlight)
qWarning() << Q_FUNC_INFO << tr("Invalid senderhash specification: %1").arg(condValue);
return UiStyle::Invalid;
}
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;
return UiStyle::Invalid;
}
fmtType |= val << 48;
fmt.merge(cachedFormat(key & 0x0000000000000000)); // basic
fmt.merge(cachedFormat(key & 0x000000000000000f)); // msgtype
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 & 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"
// 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"
UiStyle::StyledMessage::StyledMessage(const Message &msg)
: Message(msg)
{
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 {
}
void UiStyle::StyledMessage::style() 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) {
/***********************************************************************************/
QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList) {
inline FormatType timestampFormat() const { return UiStyle::Timestamp; }
FormatType senderFormat() const;
const FormatList &contentsFormatList() const;
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;
protected:
//! Styling is only needed for calls to plainContents() and contentsFormatList()
void style() const;
private:
mutable StyledString _contents;
private:
mutable StyledString _contents;
+ mutable quint8 _senderHash;
};
QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList);
};
QDataStream &operator<<(QDataStream &out, const UiStyle::FormatList &formatList);