Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(ui): Added feature to generate colors for user names in tox groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed Oct 25, 2018
1 parent dec90ad commit aaf5229
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/chatlog/chatmessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@
#include "src/widget/style.h"

#include <QDebug>
#include <QCryptographicHash>

#include "src/persistence/settings.h"
#include "src/persistence/smileypack.h"

#define NAME_COL_WIDTH 90.0
#define TIME_COL_WIDTH 90.0

QMap <QString, QColor> authorColor;

ChatMessage::ChatMessage()
{
}
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ void Settings::loadGlobal()
else
style = "None";
}
groupNameColors = s.value("groupNameColors", false).toBool();
}
s.endGroup();

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,8 @@ public slots:

bool getAutoLogin() const;
void setAutoLogin(bool state);
void setEnableGroupChatsColor(bool state);
bool getEnableGroupChatsColor() const;

int getCircleCount() const;
int addCircle(const QString& name = QString());
Expand Down Expand Up @@ -606,6 +608,7 @@ public slots:
bool notifySound;
bool busySound;
bool groupAlwaysNotify;
bool groupNameColors;

bool forceTCP;
bool enableLanDiscovery;
Expand Down
6 changes: 6 additions & 0 deletions src/widget/form/settings/userinterfaceform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
2 changes: 2 additions & 0 deletions src/widget/form/settings/userinterfaceform.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private slots:
void on_txtChatFontSize_valueChanged(int arg1);


void on_gcColors_stateChanged(int arg1);

private:
void retranslateUi();
void reloadSmileys();
Expand Down
11 changes: 9 additions & 2 deletions src/widget/form/settings/userinterfacesettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down

0 comments on commit aaf5229

Please sign in to comment.