mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
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
This commit is contained in:
parent
a1806bb04f
commit
d3e2eb1f54
@ -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);
|
||||
|
@ -99,6 +99,7 @@
|
||||
*/
|
||||
|
||||
#include <QApplication>
|
||||
#include <QColor>
|
||||
|
||||
#include "ChatStyle.h"
|
||||
#include "gui/settings/rsharesettings.h"
|
||||
@ -107,6 +108,8 @@
|
||||
|
||||
#include <retroshare/rsinit.h>
|
||||
|
||||
//#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 <a href> 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) + "<a href=\"" + rx.cap(count) + "\">" + rx.cap(count) + "</a>" + 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<QString, QString> i(smileys);
|
||||
// while(i.hasNext())
|
||||
// {
|
||||
// i.next();
|
||||
// foreach(QString code, i.key().split("|"))
|
||||
// message.replace(code, "<img src=\"" + i.value() + "\">");
|
||||
// }
|
||||
// }
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -506,6 +506,7 @@
|
||||
<file>qss/chat/compact/private/ooutgoing.htm</file>
|
||||
<file>qss/chat/compact/private/main.css</file>
|
||||
<file>qss/chat/compact/private/variants/Standard.css</file>
|
||||
<file>qss/chat/compact/private/variants/Colored.css</file>
|
||||
<file>qss/chat/compact/public/info.xml</file>
|
||||
<file>qss/chat/compact/public/incoming.htm</file>
|
||||
<file>qss/chat/compact/public/outgoing.htm</file>
|
||||
@ -514,6 +515,7 @@
|
||||
<file>qss/chat/compact/public/ooutgoing.htm</file>
|
||||
<file>qss/chat/compact/public/main.css</file>
|
||||
<file>qss/chat/compact/public/variants/Standard.css</file>
|
||||
<file>qss/chat/compact/public/variants/Colored.css</file>
|
||||
<file>qss/chat/compact/history/info.xml</file>
|
||||
<file>qss/chat/compact/history/incoming.htm</file>
|
||||
<file>qss/chat/compact/history/outgoing.htm</file>
|
||||
|
@ -0,0 +1,19 @@
|
||||
.incomingName {
|
||||
color:#2D84C9;
|
||||
}
|
||||
|
||||
.outgoingName {
|
||||
color:#2D84C9;
|
||||
}
|
||||
|
||||
.hincomingName {
|
||||
color:#1E5684;
|
||||
}
|
||||
|
||||
.houtgoingName {
|
||||
color:#1E5684;
|
||||
}
|
||||
|
||||
.ooutgoingName {
|
||||
color:#ff0000;
|
||||
}
|
@ -5,23 +5,3 @@
|
||||
.time {
|
||||
color:#808080;
|
||||
}
|
||||
|
||||
.incomingName {
|
||||
color:#42940C;
|
||||
}
|
||||
|
||||
.outgoingName {
|
||||
color:#2F5A9B;
|
||||
}
|
||||
|
||||
.hincomingName {
|
||||
color:#88f042;
|
||||
}
|
||||
|
||||
.houtgoingName {
|
||||
color:#6491d2;
|
||||
}
|
||||
|
||||
.ooutgoingName {
|
||||
color:#ff0000;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
.incomingName {
|
||||
color:%color%;
|
||||
}
|
||||
|
||||
.outgoingName {
|
||||
color:%color%;
|
||||
}
|
||||
|
||||
.hincomingName {
|
||||
color:%color%;
|
||||
}
|
||||
|
||||
.houtgoingName {
|
||||
color:%color%;
|
||||
}
|
||||
|
||||
.ooutgoingName {
|
||||
color:%color%;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
.incomingName {
|
||||
color:#42940C;
|
||||
}
|
||||
|
||||
.outgoingName {
|
||||
color:#2F5A9B;
|
||||
}
|
||||
|
||||
.hincomingName {
|
||||
color:#88f042;
|
||||
}
|
||||
|
||||
.houtgoingName {
|
||||
color:#6491d2;
|
||||
}
|
||||
|
||||
.ooutgoingName {
|
||||
color:#ff0000;
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
.incomingName {
|
||||
color:%color%;
|
||||
}
|
||||
|
||||
.outgoingName {
|
||||
color:%color%;
|
||||
}
|
||||
|
||||
.hincomingName {
|
||||
color:%color%;
|
||||
}
|
||||
|
||||
.houtgoingName {
|
||||
color:%color%;
|
||||
}
|
||||
|
||||
.ooutgoingName {
|
||||
color:%color%;
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
.incomingName {
|
||||
color:#2D84C9;
|
||||
}
|
||||
|
||||
.outgoingName {
|
||||
color:#2D84C9;
|
||||
}
|
||||
|
||||
.hincomingName {
|
||||
color:#1E5684;
|
||||
}
|
||||
|
||||
.houtgoingName {
|
||||
color:#1E5684;
|
||||
}
|
||||
|
||||
.ooutgoingName {
|
||||
color:#ff0000;
|
||||
}
|
@ -39,5 +39,5 @@
|
||||
}
|
||||
|
||||
.ooutgoingName {
|
||||
color:#2D84C9;
|
||||
color:#FF0000;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user