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

Merge pull request #5404

Monsterovich (6):
      feat(ui): Added feature to generate colors for user names in tox groups
      fix(ui): groupcolors fix1
      fix(ui): groupcolors fix2
      fix(ui): fix anything
      fix(ui): oops
      fix(ui): remove useless variable
This commit is contained in:
sudden6 2018-10-29 00:04:16 +01:00
commit eae3074aa7
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
10 changed files with 66 additions and 18 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,12 +37,13 @@
#define NAME_COL_WIDTH 90.0
#define TIME_COL_WIDTH 90.0
ChatMessage::ChatMessage()
{
}
ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QString& rawMessage,
MessageType type, bool isMe, const QDateTime& date)
MessageType type, bool isMe, const QDateTime& date, bool colorizeName)
{
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
@ -86,8 +88,24 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
if (isMe)
authorFont.setBold(true);
QColor color = QColor(0, 0, 0);
QColor authorColor;
if (colorizeName && Settings::getInstance().getEnableGroupChatsColor())
{
QByteArray hash = QCryptographicHash::hash((sender.toUtf8()), QCryptographicHash::Sha256);
quint8 *data = (quint8*)hash.data();
authorColor.setHsv(data[0], 255, 196);
if (!isMe)
{
color = authorColor;
}
}
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

@ -49,7 +49,7 @@ public:
static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage,
MessageType type, bool isMe,
const QDateTime& date = QDateTime());
const QDateTime& date = QDateTime(), bool colorizeName = false);
static ChatMessage::Ptr createChatInfoMessage(const QString& rawMessage, SystemMessageType type,
const QDateTime& date);
static ChatMessage::Ptr createFileTransferMessage(const QString& sender, ToxFile file,

View File

@ -242,6 +242,7 @@ void Settings::loadGlobal()
else
style = "None";
}
nameColors = s.value("nameColors", 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("nameColors", nameColors);
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};
nameColors = state;
}
bool Settings::getEnableGroupChatsColor() const
{
return nameColors;
}
/**
* @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 nameColors;
bool forceTCP;
bool enableLanDiscovery;

View File

@ -372,7 +372,7 @@ bool GenericChatForm::needsToHideName(const ToxPk& messageAuthor, const QDateTim
* @return ChatMessage object
*/
ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QString& message,
const QDateTime& dt, bool isAction, bool isSent)
const QDateTime& dt, bool isAction, bool isSent, bool colorizeName)
{
const Core* core = Core::getInstance();
bool isSelf = author == core->getSelfId().getPublicKey();
@ -383,10 +383,10 @@ ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QStri
ChatMessage::Ptr msg;
if (isAction) {
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, isSelf);
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, isSelf, QDateTime(), colorizeName);
previousId = ToxPk{};
} else {
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf);
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf, QDateTime(), colorizeName);
const QDateTime newMsgDateTime = QDateTime::currentDateTime();
if (needsToHideName(author, newMsgDateTime)) {
msg->hideSender();
@ -418,9 +418,9 @@ ChatMessage::Ptr GenericChatForm::createSelfMessage(const QString& message, cons
* @brief Inserts message into ChatLog
*/
void GenericChatForm::addMessage(const ToxPk& author, const QString& message, const QDateTime& dt,
bool isAction)
bool isAction, bool colorizeName)
{
createMessage(author, message, dt, isAction, true);
createMessage(author, message, dt, isAction, true, colorizeName);
}
/**
@ -431,11 +431,11 @@ void GenericChatForm::addSelfMessage(const QString& message, const QDateTime& da
createSelfMessage(message, datetime, isAction, true);
}
void GenericChatForm::addAlertMessage(const ToxPk& author, const QString& msg, const QDateTime& dt)
void GenericChatForm::addAlertMessage(const ToxPk& author, const QString& msg, const QDateTime& dt, bool colorizeName)
{
QString authorStr = resolveToxPk(author);
bool isSelf = author == Core::getInstance()->getSelfId().getPublicKey();
auto chatMsg = ChatMessage::createChatMessage(authorStr, msg, ChatMessage::ALERT, isSelf, dt);
auto chatMsg = ChatMessage::createChatMessage(authorStr, msg, ChatMessage::ALERT, isSelf, dt, colorizeName);
const QDateTime newMsgDateTime = QDateTime::currentDateTime();
if (needsToHideName(author, newMsgDateTime)) {
chatMsg->hideSender();

View File

@ -75,11 +75,11 @@ public:
virtual void show(ContentLayout* contentLayout);
void addMessage(const ToxPk& author, const QString& message, const QDateTime& datetime,
bool isAction);
bool isAction, bool colorizeName = false);
void addSelfMessage(const QString& message, const QDateTime& datetime, bool isAction);
void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
const QDateTime& datetime);
void addAlertMessage(const ToxPk& author, const QString& message, const QDateTime& datetime);
void addAlertMessage(const ToxPk& author, const QString& message, const QDateTime& datetime, bool colorizeName = false);
static QString resolveToxPk(const ToxPk& pk);
QDate getLatestDate() const;
QDate getFirstDate() const;
@ -127,7 +127,7 @@ private:
protected:
ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message,
const QDateTime& datetime, bool isAction, bool isSent);
const QDateTime& datetime, bool isAction, bool isSent, bool colorizeName = false);
ChatMessage::Ptr createSelfMessage(const QString& message, const QDateTime& datetime,
bool isAction, bool isSent);
bool needsToHideName(const ToxPk& messageAuthor, const QDateTime& messageTime) const;

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->useNameColors->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_useNameColors_stateChanged(int value)
{
Settings::getInstance().setEnableGroupChatsColor(value);
}

View File

@ -62,7 +62,7 @@ private slots:
void on_txtChatFont_currentFontChanged(const QFont& f);
void on_txtChatFontSize_valueChanged(int arg1);
void on_useNameColors_stateChanged(int value);
private:
void retranslateUi();

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="useNameColors">
<property name="text">
<string>Use colored nicknames in chats</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -1750,10 +1750,11 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
const auto groupId = g->getId();
const auto date = QDateTime::currentDateTime();
auto form = groupChatForms[groupId];
if (targeted && !isAction) {
form->addAlertMessage(author, message, date);
form->addAlertMessage(author, message, date, true);
} else {
form->addMessage(author, message, date, isAction);
form->addMessage(author, message, date, isAction, true);
}
newGroupMessageAlert(groupId, targeted || Settings::getInstance().getGroupAlwaysNotify());