1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

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

This commit is contained in:
Monsterovich 2018-10-22 02:01:05 +02:00
parent dec90ad84d
commit aaf5229ece
6 changed files with 51 additions and 3 deletions

View File

@ -29,6 +29,7 @@
#include "src/widget/style.h"
#include <QDebug>
#include <QCryptographicHash>
#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 <QString, QColor> 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)

View File

@ -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.

View File

@ -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;

View File

@ -73,6 +73,7 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent)
bodyUI->txtChatFont->setCurrentFont(chatBaseFont);
int index = static_cast<int>(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);
}

View File

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

View File

@ -39,8 +39,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>664</width>
<height>796</height>
<width>650</width>
<height>892</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,0,0,0,0">
@ -149,6 +149,13 @@
</item>
</widget>
</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>
</widget>
</item>