From d3e2eb1f54e59b10ab7be85c607cbff3d3c83eaa Mon Sep 17 00:00:00 2001 From: thunder2 Date: Fri, 3 Feb 2012 21:43:09 +0000 Subject: [PATCH] Added new variant to the compact chat style with colored nicknames calculated from the name. It's disabled by default. You can enable it with the define COLORED_NICKNAMES in ChatStyle.cpp. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4884 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- .../src/gui/chat/ChatLobbyDialog.cpp | 4 +- retroshare-gui/src/gui/chat/ChatStyle.cpp | 69 +++++++++++-------- retroshare-gui/src/gui/chat/ChatStyle.h | 1 + retroshare-gui/src/gui/chat/ChatWidget.cpp | 4 ++ retroshare-gui/src/gui/chat/ChatWidget.h | 4 +- retroshare-gui/src/gui/images.qrc | 2 + .../compact/history/variants/Standard.css | 19 +++++ .../src/gui/qss/chat/compact/private/main.css | 20 ------ .../chat/compact/private/variants/Colored.css | 19 +++++ .../compact/private/variants/Standard.css | 19 +++++ .../src/gui/qss/chat/compact/public/main.css | 20 ------ .../chat/compact/public/variants/Colored.css | 19 +++++ .../chat/compact/public/variants/Standard.css | 19 +++++ .../src/gui/qss/chat/standard/public/main.css | 2 +- 14 files changed, 146 insertions(+), 75 deletions(-) create mode 100644 retroshare-gui/src/gui/qss/chat/compact/private/variants/Colored.css create mode 100644 retroshare-gui/src/gui/qss/chat/compact/public/variants/Colored.css diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp index 3ec9f1db1..89976e473 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -164,10 +164,10 @@ void ChatLobbyDialog::displayLobbyEvent(int event_type, const QString& nickname, { switch (event_type) { case RS_CHAT_LOBBY_EVENT_PEER_LEFT: - ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(str), ChatWidget::TYPE_NORMAL); + ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 has left the lobby.").arg(str), ChatWidget::TYPE_SYSTEM); break; case RS_CHAT_LOBBY_EVENT_PEER_JOINED: - ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(str), ChatWidget::TYPE_NORMAL); + ui.chatWidget->addChatMsg(true, tr("Lobby management"), QDateTime::currentDateTime(), QDateTime::currentDateTime(), tr("%1 joined the lobby.").arg(str), ChatWidget::TYPE_SYSTEM); break; case RS_CHAT_LOBBY_EVENT_PEER_STATUS: ui.chatWidget->updateStatusString(nickname + " %1", str); diff --git a/retroshare-gui/src/gui/chat/ChatStyle.cpp b/retroshare-gui/src/gui/chat/ChatStyle.cpp index cdaa5b134..968b20500 100644 --- a/retroshare-gui/src/gui/chat/ChatStyle.cpp +++ b/retroshare-gui/src/gui/chat/ChatStyle.cpp @@ -99,6 +99,7 @@ */ #include +#include #include "ChatStyle.h" #include "gui/settings/rsharesettings.h" @@ -107,6 +108,8 @@ #include +//#define COLORED_NICKNAMES + enum enumGetStyle { GETSTYLE_INCOMING, @@ -223,15 +226,19 @@ static QString getStyle(const QDir &styleDir, const QString &styleVariant, enumG fileCss.close(); } - if (styleVariant.isEmpty() == false) { - QFile fileCssVariant(QFileInfo(styleDir, "variants/" + styleVariant + ".css").absoluteFilePath()); - QString cssVariant; - if (fileCssVariant.open(QIODevice::ReadOnly)) { - cssVariant = fileCssVariant.readAll(); - fileCssVariant.close(); + QString variant = styleVariant; + if (styleVariant.isEmpty()) { + // use standard + variant = "Standard"; + } - css += "\n" + cssVariant; - } + QFile fileCssVariant(QFileInfo(styleDir, "variants/" + variant + ".css").absoluteFilePath()); + QString cssVariant; + if (fileCssVariant.open(QIODevice::ReadOnly)) { + cssVariant = fileCssVariant.readAll(); + fileCssVariant.close(); + + css += "\n" + cssVariant; } style.replace("%css-style%", css); @@ -281,34 +288,31 @@ QString ChatStyle::formatMessage(enumFormatMessage type, const QString &name, co QString msg = RsHtml::formatText(message, formatFlag); -// //replace http://, https:// and www. with links -// QRegExp rx("(retroshare://[^ <>]*)|(https?://[^ <>]*)|(www\\.[^ <>]*)"); -// int count = 0; -// int pos = 100; //ignore the first 100 char because of the standard DTD ref -// while ( (pos = rx.indexIn(message, pos)) != -1 ) { -// //we need to look ahead to see if it's already a well formed link -// if (message.mid(pos - 6, 6) != "href=\"" && message.mid(pos - 6, 6) != "href='" && message.mid(pos - 6, 6) != "ttp://" ) { -// QString tempMessg = message.left(pos) + "" + rx.cap(count) + "" + message.mid(pos + rx.matchedLength(), -1); -// message = tempMessg; + QColor color; +#ifdef COLORED_NICKNAMES + if (flag & CHAT_FORMATMSG_SYSTEM) { + color = Qt::darkBlue; + } else { + // Calculate color from the name +// uint hash = 0x73ffe23a; +// for (int i = 0; i < name.length(); ++i) { +// hash = (hash ^ 0x28594888) + ((uint32_t) name[i].toAscii() << (i % 4)); // } -// pos += rx.matchedLength() + 15; -// count ++; -// } -// { -// QHashIterator i(smileys); -// while(i.hasNext()) -// { -// i.next(); -// foreach(QString code, i.key().split("|")) -// message.replace(code, ""); -// } -// } + uint hash = 0; + for (int i = 0; i < name.length(); ++i) { + hash = (((hash << 1) + (hash >> 14)) ^ ((int) name[i].toAscii())) & 0x3fff; + } + + color.setHsv(hash, 255, 150); + } +#endif QString formatMsg = style.replace("%name%", name) .replace("%date%", timestamp.date().toString("dd.MM.yyyy")) .replace("%time%", timestamp.time().toString("hh:mm:ss")) - .replace("%message%", msg); + .replace("%message%", msg) + .replace("%color%", color.name()); return formatMsg; } @@ -519,6 +523,11 @@ static QString getBaseDir() // iterate variants for (QFileInfoList::iterator file = fileList.begin(); file != fileList.end(); file++) { +#ifndef COLORED_NICKNAMES + if (file->baseName().toLower() == "colored") { + continue; + } +#endif variants.append(file->baseName()); } diff --git a/retroshare-gui/src/gui/chat/ChatStyle.h b/retroshare-gui/src/gui/chat/ChatStyle.h index c1c1f2009..50609abf9 100644 --- a/retroshare-gui/src/gui/chat/ChatStyle.h +++ b/retroshare-gui/src/gui/chat/ChatStyle.h @@ -32,6 +32,7 @@ /* Flags for ChatStyle::formatMessage */ #define CHAT_FORMATMSG_EMBED_SMILEYS 1 #define CHAT_FORMATMSG_EMBED_LINKS 2 +#define CHAT_FORMATMSG_SYSTEM 4 /* Flags for ChatStyle::formatText */ #define CHAT_FORMATTEXT_EMBED_SMILEYS 1 diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 6fb2271f9..3e80da721 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -309,6 +309,10 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const QDateTime type = incoming ? ChatStyle::FORMATMSG_INCOMING : ChatStyle::FORMATMSG_OUTGOING; } + if (chatType == TYPE_SYSTEM) { + formatFlag |= CHAT_FORMATMSG_SYSTEM; + } + QString formatMsg = chatStyle.formatMessage(type, name, incoming ? sendTime : recvTime, message, formatFlag); ui->textBrowser->append(formatMsg); diff --git a/retroshare-gui/src/gui/chat/ChatWidget.h b/retroshare-gui/src/gui/chat/ChatWidget.h index d768707f6..45fa9fc40 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.h +++ b/retroshare-gui/src/gui/chat/ChatWidget.h @@ -41,9 +41,9 @@ class ChatWidget; class ChatWidget : public QWidget { Q_OBJECT - + public: - enum enumChatType { TYPE_NORMAL, TYPE_HISTORY, TYPE_OFFLINE }; + enum enumChatType { TYPE_NORMAL, TYPE_HISTORY, TYPE_OFFLINE, TYPE_SYSTEM }; public: explicit ChatWidget(QWidget *parent = 0); diff --git a/retroshare-gui/src/gui/images.qrc b/retroshare-gui/src/gui/images.qrc index 4a3147d57..294490cdb 100644 --- a/retroshare-gui/src/gui/images.qrc +++ b/retroshare-gui/src/gui/images.qrc @@ -506,6 +506,7 @@ qss/chat/compact/private/ooutgoing.htm qss/chat/compact/private/main.css qss/chat/compact/private/variants/Standard.css + qss/chat/compact/private/variants/Colored.css qss/chat/compact/public/info.xml qss/chat/compact/public/incoming.htm qss/chat/compact/public/outgoing.htm @@ -514,6 +515,7 @@ qss/chat/compact/public/ooutgoing.htm qss/chat/compact/public/main.css qss/chat/compact/public/variants/Standard.css + qss/chat/compact/public/variants/Colored.css qss/chat/compact/history/info.xml qss/chat/compact/history/incoming.htm qss/chat/compact/history/outgoing.htm diff --git a/retroshare-gui/src/gui/qss/chat/compact/history/variants/Standard.css b/retroshare-gui/src/gui/qss/chat/compact/history/variants/Standard.css index e69de29bb..92fe4d80b 100644 --- a/retroshare-gui/src/gui/qss/chat/compact/history/variants/Standard.css +++ b/retroshare-gui/src/gui/qss/chat/compact/history/variants/Standard.css @@ -0,0 +1,19 @@ +.incomingName { + color:#2D84C9; +} + +.outgoingName { + color:#2D84C9; +} + +.hincomingName { + color:#1E5684; +} + +.houtgoingName { + color:#1E5684; +} + +.ooutgoingName { + color:#ff0000; +} diff --git a/retroshare-gui/src/gui/qss/chat/compact/private/main.css b/retroshare-gui/src/gui/qss/chat/compact/private/main.css index 614f8661d..67f7c85f0 100644 --- a/retroshare-gui/src/gui/qss/chat/compact/private/main.css +++ b/retroshare-gui/src/gui/qss/chat/compact/private/main.css @@ -5,23 +5,3 @@ .time { color:#808080; } - -.incomingName { - color:#42940C; -} - -.outgoingName { - color:#2F5A9B; -} - -.hincomingName { - color:#88f042; -} - -.houtgoingName { - color:#6491d2; -} - -.ooutgoingName { - color:#ff0000; -} diff --git a/retroshare-gui/src/gui/qss/chat/compact/private/variants/Colored.css b/retroshare-gui/src/gui/qss/chat/compact/private/variants/Colored.css new file mode 100644 index 000000000..e56d18a62 --- /dev/null +++ b/retroshare-gui/src/gui/qss/chat/compact/private/variants/Colored.css @@ -0,0 +1,19 @@ +.incomingName { + color:%color%; +} + +.outgoingName { + color:%color%; +} + +.hincomingName { + color:%color%; +} + +.houtgoingName { + color:%color%; +} + +.ooutgoingName { + color:%color%; +} diff --git a/retroshare-gui/src/gui/qss/chat/compact/private/variants/Standard.css b/retroshare-gui/src/gui/qss/chat/compact/private/variants/Standard.css index e69de29bb..f7412571c 100644 --- a/retroshare-gui/src/gui/qss/chat/compact/private/variants/Standard.css +++ b/retroshare-gui/src/gui/qss/chat/compact/private/variants/Standard.css @@ -0,0 +1,19 @@ +.incomingName { + color:#42940C; +} + +.outgoingName { + color:#2F5A9B; +} + +.hincomingName { + color:#88f042; +} + +.houtgoingName { + color:#6491d2; +} + +.ooutgoingName { + color:#ff0000; +} diff --git a/retroshare-gui/src/gui/qss/chat/compact/public/main.css b/retroshare-gui/src/gui/qss/chat/compact/public/main.css index 25b2f4686..50387e017 100644 --- a/retroshare-gui/src/gui/qss/chat/compact/public/main.css +++ b/retroshare-gui/src/gui/qss/chat/compact/public/main.css @@ -6,38 +6,18 @@ color:#C00000; } -.incomingName { - color:#2D84C9; -} - .outgoingTime { color:#C00000; } -.outgoingName { - color:#2D84C9; -} - .hincomingTime { color:#800000; } -.hincomingName { - color:#1E5684; -} - .houtgoingTime { color:#800000; } -.houtgoingName { - color:#1E5684; -} - .ooutgoingTime { color:#C00000; } - -.ooutgoingName { - color:#ff0000; -} diff --git a/retroshare-gui/src/gui/qss/chat/compact/public/variants/Colored.css b/retroshare-gui/src/gui/qss/chat/compact/public/variants/Colored.css new file mode 100644 index 000000000..e56d18a62 --- /dev/null +++ b/retroshare-gui/src/gui/qss/chat/compact/public/variants/Colored.css @@ -0,0 +1,19 @@ +.incomingName { + color:%color%; +} + +.outgoingName { + color:%color%; +} + +.hincomingName { + color:%color%; +} + +.houtgoingName { + color:%color%; +} + +.ooutgoingName { + color:%color%; +} diff --git a/retroshare-gui/src/gui/qss/chat/compact/public/variants/Standard.css b/retroshare-gui/src/gui/qss/chat/compact/public/variants/Standard.css index e69de29bb..92fe4d80b 100644 --- a/retroshare-gui/src/gui/qss/chat/compact/public/variants/Standard.css +++ b/retroshare-gui/src/gui/qss/chat/compact/public/variants/Standard.css @@ -0,0 +1,19 @@ +.incomingName { + color:#2D84C9; +} + +.outgoingName { + color:#2D84C9; +} + +.hincomingName { + color:#1E5684; +} + +.houtgoingName { + color:#1E5684; +} + +.ooutgoingName { + color:#ff0000; +} diff --git a/retroshare-gui/src/gui/qss/chat/standard/public/main.css b/retroshare-gui/src/gui/qss/chat/standard/public/main.css index 4750522cb..1d9fdad51 100644 --- a/retroshare-gui/src/gui/qss/chat/standard/public/main.css +++ b/retroshare-gui/src/gui/qss/chat/standard/public/main.css @@ -39,5 +39,5 @@ } .ooutgoingName { - color:#2D84C9; + color:#FF0000; }