From aaf5229ece69fb694381164f10bb85eb6fd53ee3 Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Mon, 22 Oct 2018 02:01:05 +0200 Subject: [PATCH] feat(ui): Added feature to generate colors for user names in tox groups --- src/chatlog/chatmessage.cpp | 19 ++++++++++++++++++- src/persistence/settings.cpp | 13 +++++++++++++ src/persistence/settings.h | 3 +++ .../form/settings/userinterfaceform.cpp | 6 ++++++ src/widget/form/settings/userinterfaceform.h | 2 ++ .../form/settings/userinterfacesettings.ui | 11 +++++++++-- 6 files changed, 51 insertions(+), 3 deletions(-) diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp index ebb491dda..05aad0a45 100644 --- a/src/chatlog/chatmessage.cpp +++ b/src/chatlog/chatmessage.cpp @@ -29,6 +29,7 @@ #include "src/widget/style.h" #include +#include #include "src/persistence/settings.h" #include "src/persistence/smileypack.h" @@ -36,6 +37,8 @@ #define NAME_COL_WIDTH 90.0 #define TIME_COL_WIDTH 90.0 +QMap authorColor; + ChatMessage::ChatMessage() { } @@ -86,8 +89,22 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt if (isMe) authorFont.setBold(true); + QColor color = QColor(0, 0, 0); + + if (Settings::getInstance().getEnableGroupChatsColor()) + { + QByteArray hash = QCryptographicHash::hash((sender.toUtf8()), QCryptographicHash::Md5); + quint8 *data = (quint8*)hash.data(); + + if (!authorColor[sender].isValid()) + authorColor[sender] = QColor(data[0], data[1], data[2]); + + if (!isMe) + color = authorColor[sender]; + } + msg->addColumn(new Text(senderText, authorFont, true, sender, - type == ACTION ? actionColor : Qt::black), + type == ACTION ? actionColor : color), ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right)); msg->addColumn(new Text(text, baseFont, false, ((type == ACTION) && isMe) ? QString("%1 %2").arg(sender, rawMessage) diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index ba14d71c3..057f989c2 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -242,6 +242,7 @@ void Settings::loadGlobal() else style = "None"; } + groupNameColors = s.value("groupNameColors", false).toBool(); } s.endGroup(); @@ -547,6 +548,7 @@ void Settings::saveGlobal() s.setValue("useEmoticons", useEmoticons); s.setValue("themeColor", themeColor); s.setValue("style", style); + s.setValue("groupNameColors", groupNameColors); s.setValue("statusChangeNotificationEnabled", statusChangeNotificationEnabled); s.setValue("spellCheckingEnabled", spellCheckingEnabled); } @@ -2417,6 +2419,17 @@ void Settings::setAutoLogin(bool state) } } +void Settings::setEnableGroupChatsColor(bool state) +{ + QMutexLocker locker{&bigLock}; + groupNameColors = state; +} + +bool Settings::getEnableGroupChatsColor() const +{ + return groupNameColors; +} + /** * @brief Write a default personal .ini settings file for a profile. * @param basename Filename without extension to save settings. diff --git a/src/persistence/settings.h b/src/persistence/settings.h index ecbebb256..4a999adff 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -530,6 +530,8 @@ public: bool getAutoLogin() const; void setAutoLogin(bool state); + void setEnableGroupChatsColor(bool state); + bool getEnableGroupChatsColor() const; int getCircleCount() const; int addCircle(const QString& name = QString()); @@ -606,6 +608,7 @@ private: bool notifySound; bool busySound; bool groupAlwaysNotify; + bool groupNameColors; bool forceTCP; bool enableLanDiscovery; diff --git a/src/widget/form/settings/userinterfaceform.cpp b/src/widget/form/settings/userinterfaceform.cpp index 9ed593efe..71f674742 100644 --- a/src/widget/form/settings/userinterfaceform.cpp +++ b/src/widget/form/settings/userinterfaceform.cpp @@ -73,6 +73,7 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent) bodyUI->txtChatFont->setCurrentFont(chatBaseFont); int index = static_cast(s.getStylePreference()); bodyUI->textStyleComboBox->setCurrentIndex(index); + bodyUI->gcColors->setChecked(s.getEnableGroupChatsColor()); bodyUI->notify->setChecked(s.getNotify()); // Note: UI is boolean inversed from settings to maintain setting file backwards compatibility @@ -374,3 +375,8 @@ void UserInterfaceForm::on_txtChatFontSize_valueChanged(int px) s.setChatMessageFont(tmpFont); } } + +void UserInterfaceForm::on_gcColors_stateChanged(int arg1) +{ + Settings::getInstance().setEnableGroupChatsColor(arg1); +} diff --git a/src/widget/form/settings/userinterfaceform.h b/src/widget/form/settings/userinterfaceform.h index 7da4f5f21..16a179570 100644 --- a/src/widget/form/settings/userinterfaceform.h +++ b/src/widget/form/settings/userinterfaceform.h @@ -64,6 +64,8 @@ private slots: void on_txtChatFontSize_valueChanged(int arg1); + void on_gcColors_stateChanged(int arg1); + private: void retranslateUi(); void reloadSmileys(); diff --git a/src/widget/form/settings/userinterfacesettings.ui b/src/widget/form/settings/userinterfacesettings.ui index 899ccf3a0..bcdae0a77 100644 --- a/src/widget/form/settings/userinterfacesettings.ui +++ b/src/widget/form/settings/userinterfacesettings.ui @@ -39,8 +39,8 @@ 0 0 - 664 - 796 + 650 + 892 @@ -149,6 +149,13 @@ + + + + Use colors in group chats + + +