+QString UiStyle::StyledMessage::decoratedTimestamp() const {
+ return QString("[%1]").arg(timestamp().toLocalTime().toString("hh:mm:ss"));
+}
+
+QString UiStyle::StyledMessage::plainSender() const {
+ switch(type()) {
+ case Message::Plain:
+ case Message::Notice:
+ return nickFromMask(sender());
+ default:
+ return QString();
+ }
+}
+
+QString UiStyle::StyledMessage::decoratedSender() const {
+ switch(type()) {
+ case Message::Plain:
+ return tr("<%1>").arg(plainSender()); break;
+ case Message::Notice:
+ return tr("[%1]").arg(plainSender()); break;
+ case Message::Server:
+ return tr("*"); break;
+ case Message::Error:
+ return tr("*"); break;
+ case Message::Join:
+ return tr("-->"); break;
+ case Message::Part:
+ return tr("<--"); break;
+ case Message::Quit:
+ return tr("<--"); break;
+ case Message::Kick:
+ return tr("<-*"); break;
+ case Message::Nick:
+ return tr("<->"); break;
+ case Message::Mode:
+ return tr("***"); break;
+ case Message::Action:
+ return tr("-*-"); break;
+ default:
+ return tr("%1").arg(plainSender());
+ }
+}
+
+UiStyle::FormatType UiStyle::StyledMessage::senderFormat() const {
+ quint16 hash;
+ switch(type()) {
+ case Message::Plain:
+ // 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 % 12) + 1) << 24) + 0x200); // FIXME: amount of sender colors hardwired
+ case Message::Notice:
+ return UiStyle::NoticeMsg; break;
+ case Message::Server:
+ return UiStyle::ServerMsg; break;
+ case Message::Error:
+ return UiStyle::ErrorMsg; break;
+ case Message::Join:
+ return UiStyle::JoinMsg; break;
+ case Message::Part:
+ return UiStyle::PartMsg; break;
+ case Message::Quit:
+ return UiStyle::QuitMsg; break;
+ case Message::Kick:
+ return UiStyle::KickMsg; break;
+ case Message::Nick:
+ return UiStyle::RenameMsg; break;
+ case Message::Mode:
+ return UiStyle::ModeMsg; break;
+ case Message::Action:
+ return UiStyle::ActionMsg; break;
+ default:
+ return UiStyle::ErrorMsg;
+ }
+}
+
+
+/***********************************************************************************/
+