Browse Source

feat(ui): Added feature to generate colors for user names in tox groups

reviewable/pr5404/r5
Monsterovich 7 years ago
parent
commit
aaf5229ece
  1. 19
      src/chatlog/chatmessage.cpp
  2. 13
      src/persistence/settings.cpp
  3. 3
      src/persistence/settings.h
  4. 6
      src/widget/form/settings/userinterfaceform.cpp
  5. 2
      src/widget/form/settings/userinterfaceform.h
  6. 11
      src/widget/form/settings/userinterfacesettings.ui

19
src/chatlog/chatmessage.cpp

@ -29,6 +29,7 @@
#include "src/widget/style.h" #include "src/widget/style.h"
#include <QDebug> #include <QDebug>
#include <QCryptographicHash>
#include "src/persistence/settings.h" #include "src/persistence/settings.h"
#include "src/persistence/smileypack.h" #include "src/persistence/smileypack.h"
@ -36,6 +37,8 @@
#define NAME_COL_WIDTH 90.0 #define NAME_COL_WIDTH 90.0
#define TIME_COL_WIDTH 90.0 #define TIME_COL_WIDTH 90.0
QMap <QString, QColor> authorColor;
ChatMessage::ChatMessage() ChatMessage::ChatMessage()
{ {
} }
@ -86,8 +89,22 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
if (isMe) if (isMe)
authorFont.setBold(true); 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, 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)); ColumnFormat(NAME_COL_WIDTH, ColumnFormat::FixedSize, ColumnFormat::Right));
msg->addColumn(new Text(text, baseFont, false, ((type == ACTION) && isMe) msg->addColumn(new Text(text, baseFont, false, ((type == ACTION) && isMe)
? QString("%1 %2").arg(sender, rawMessage) ? QString("%1 %2").arg(sender, rawMessage)

13
src/persistence/settings.cpp

@ -242,6 +242,7 @@ void Settings::loadGlobal()
else else
style = "None"; style = "None";
} }
groupNameColors = s.value("groupNameColors", false).toBool();
} }
s.endGroup(); s.endGroup();
@ -547,6 +548,7 @@ void Settings::saveGlobal()
s.setValue("useEmoticons", useEmoticons); s.setValue("useEmoticons", useEmoticons);
s.setValue("themeColor", themeColor); s.setValue("themeColor", themeColor);
s.setValue("style", style); s.setValue("style", style);
s.setValue("groupNameColors", groupNameColors);
s.setValue("statusChangeNotificationEnabled", statusChangeNotificationEnabled); s.setValue("statusChangeNotificationEnabled", statusChangeNotificationEnabled);
s.setValue("spellCheckingEnabled", spellCheckingEnabled); 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. * @brief Write a default personal .ini settings file for a profile.
* @param basename Filename without extension to save settings. * @param basename Filename without extension to save settings.

3
src/persistence/settings.h

@ -530,6 +530,8 @@ public:
bool getAutoLogin() const; bool getAutoLogin() const;
void setAutoLogin(bool state); void setAutoLogin(bool state);
void setEnableGroupChatsColor(bool state);
bool getEnableGroupChatsColor() const;
int getCircleCount() const; int getCircleCount() const;
int addCircle(const QString& name = QString()); int addCircle(const QString& name = QString());
@ -606,6 +608,7 @@ private:
bool notifySound; bool notifySound;
bool busySound; bool busySound;
bool groupAlwaysNotify; bool groupAlwaysNotify;
bool groupNameColors;
bool forceTCP; bool forceTCP;
bool enableLanDiscovery; bool enableLanDiscovery;

6
src/widget/form/settings/userinterfaceform.cpp

@ -73,6 +73,7 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent)
bodyUI->txtChatFont->setCurrentFont(chatBaseFont); bodyUI->txtChatFont->setCurrentFont(chatBaseFont);
int index = static_cast<int>(s.getStylePreference()); int index = static_cast<int>(s.getStylePreference());
bodyUI->textStyleComboBox->setCurrentIndex(index); bodyUI->textStyleComboBox->setCurrentIndex(index);
bodyUI->gcColors->setChecked(s.getEnableGroupChatsColor());
bodyUI->notify->setChecked(s.getNotify()); bodyUI->notify->setChecked(s.getNotify());
// Note: UI is boolean inversed from settings to maintain setting file backwards compatibility // 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); s.setChatMessageFont(tmpFont);
} }
} }
void UserInterfaceForm::on_gcColors_stateChanged(int arg1)
{
Settings::getInstance().setEnableGroupChatsColor(arg1);
}

2
src/widget/form/settings/userinterfaceform.h

@ -64,6 +64,8 @@ private slots:
void on_txtChatFontSize_valueChanged(int arg1); void on_txtChatFontSize_valueChanged(int arg1);
void on_gcColors_stateChanged(int arg1);
private: private:
void retranslateUi(); void retranslateUi();
void reloadSmileys(); void reloadSmileys();

11
src/widget/form/settings/userinterfacesettings.ui

@ -39,8 +39,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>664</width> <width>650</width>
<height>796</height> <height>892</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,0,0,0,0"> <layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,0,0,0,0">
@ -149,6 +149,13 @@
</item> </item>
</widget> </widget>
</item> </item>
<item row="2" column="1">
<widget class="QCheckBox" name="gcColors">
<property name="text">
<string>Use colors in group chats</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>

Loading…
Cancel
Save