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:
commit
eae3074aa7
|
@ -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,12 +37,13 @@
|
||||||
#define NAME_COL_WIDTH 90.0
|
#define NAME_COL_WIDTH 90.0
|
||||||
#define TIME_COL_WIDTH 90.0
|
#define TIME_COL_WIDTH 90.0
|
||||||
|
|
||||||
|
|
||||||
ChatMessage::ChatMessage()
|
ChatMessage::ChatMessage()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QString& rawMessage,
|
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);
|
ChatMessage::Ptr msg = ChatMessage::Ptr(new ChatMessage);
|
||||||
|
|
||||||
|
@ -86,8 +88,24 @@ 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);
|
||||||
|
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,
|
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)
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
|
|
||||||
static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage,
|
static ChatMessage::Ptr createChatMessage(const QString& sender, const QString& rawMessage,
|
||||||
MessageType type, bool isMe,
|
MessageType type, bool isMe,
|
||||||
const QDateTime& date = QDateTime());
|
const QDateTime& date = QDateTime(), bool colorizeName = false);
|
||||||
static ChatMessage::Ptr createChatInfoMessage(const QString& rawMessage, SystemMessageType type,
|
static ChatMessage::Ptr createChatInfoMessage(const QString& rawMessage, SystemMessageType type,
|
||||||
const QDateTime& date);
|
const QDateTime& date);
|
||||||
static ChatMessage::Ptr createFileTransferMessage(const QString& sender, ToxFile file,
|
static ChatMessage::Ptr createFileTransferMessage(const QString& sender, ToxFile file,
|
||||||
|
|
|
@ -242,6 +242,7 @@ void Settings::loadGlobal()
|
||||||
else
|
else
|
||||||
style = "None";
|
style = "None";
|
||||||
}
|
}
|
||||||
|
nameColors = s.value("nameColors", 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("nameColors", nameColors);
|
||||||
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};
|
||||||
|
nameColors = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Settings::getEnableGroupChatsColor() const
|
||||||
|
{
|
||||||
|
return nameColors;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @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.
|
||||||
|
|
|
@ -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 nameColors;
|
||||||
|
|
||||||
bool forceTCP;
|
bool forceTCP;
|
||||||
bool enableLanDiscovery;
|
bool enableLanDiscovery;
|
||||||
|
|
|
@ -372,7 +372,7 @@ bool GenericChatForm::needsToHideName(const ToxPk& messageAuthor, const QDateTim
|
||||||
* @return ChatMessage object
|
* @return ChatMessage object
|
||||||
*/
|
*/
|
||||||
ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QString& message,
|
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();
|
const Core* core = Core::getInstance();
|
||||||
bool isSelf = author == core->getSelfId().getPublicKey();
|
bool isSelf = author == core->getSelfId().getPublicKey();
|
||||||
|
@ -383,10 +383,10 @@ ChatMessage::Ptr GenericChatForm::createMessage(const ToxPk& author, const QStri
|
||||||
|
|
||||||
ChatMessage::Ptr msg;
|
ChatMessage::Ptr msg;
|
||||||
if (isAction) {
|
if (isAction) {
|
||||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, isSelf);
|
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::ACTION, isSelf, QDateTime(), colorizeName);
|
||||||
previousId = ToxPk{};
|
previousId = ToxPk{};
|
||||||
} else {
|
} else {
|
||||||
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf);
|
msg = ChatMessage::createChatMessage(authorStr, message, ChatMessage::NORMAL, isSelf, QDateTime(), colorizeName);
|
||||||
const QDateTime newMsgDateTime = QDateTime::currentDateTime();
|
const QDateTime newMsgDateTime = QDateTime::currentDateTime();
|
||||||
if (needsToHideName(author, newMsgDateTime)) {
|
if (needsToHideName(author, newMsgDateTime)) {
|
||||||
msg->hideSender();
|
msg->hideSender();
|
||||||
|
@ -418,9 +418,9 @@ ChatMessage::Ptr GenericChatForm::createSelfMessage(const QString& message, cons
|
||||||
* @brief Inserts message into ChatLog
|
* @brief Inserts message into ChatLog
|
||||||
*/
|
*/
|
||||||
void GenericChatForm::addMessage(const ToxPk& author, const QString& message, const QDateTime& dt,
|
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);
|
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);
|
QString authorStr = resolveToxPk(author);
|
||||||
bool isSelf = author == Core::getInstance()->getSelfId().getPublicKey();
|
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();
|
const QDateTime newMsgDateTime = QDateTime::currentDateTime();
|
||||||
if (needsToHideName(author, newMsgDateTime)) {
|
if (needsToHideName(author, newMsgDateTime)) {
|
||||||
chatMsg->hideSender();
|
chatMsg->hideSender();
|
||||||
|
|
|
@ -75,11 +75,11 @@ public:
|
||||||
virtual void show(ContentLayout* contentLayout);
|
virtual void show(ContentLayout* contentLayout);
|
||||||
|
|
||||||
void addMessage(const ToxPk& author, const QString& message, const QDateTime& datetime,
|
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 addSelfMessage(const QString& message, const QDateTime& datetime, bool isAction);
|
||||||
void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
|
void addSystemInfoMessage(const QString& message, ChatMessage::SystemMessageType type,
|
||||||
const QDateTime& datetime);
|
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);
|
static QString resolveToxPk(const ToxPk& pk);
|
||||||
QDate getLatestDate() const;
|
QDate getLatestDate() const;
|
||||||
QDate getFirstDate() const;
|
QDate getFirstDate() const;
|
||||||
|
@ -127,7 +127,7 @@ private:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ChatMessage::Ptr createMessage(const ToxPk& author, const QString& message,
|
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,
|
ChatMessage::Ptr createSelfMessage(const QString& message, const QDateTime& datetime,
|
||||||
bool isAction, bool isSent);
|
bool isAction, bool isSent);
|
||||||
bool needsToHideName(const ToxPk& messageAuthor, const QDateTime& messageTime) const;
|
bool needsToHideName(const ToxPk& messageAuthor, const QDateTime& messageTime) const;
|
||||||
|
|
|
@ -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->useNameColors->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_useNameColors_stateChanged(int value)
|
||||||
|
{
|
||||||
|
Settings::getInstance().setEnableGroupChatsColor(value);
|
||||||
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ private slots:
|
||||||
|
|
||||||
void on_txtChatFont_currentFontChanged(const QFont& f);
|
void on_txtChatFont_currentFontChanged(const QFont& f);
|
||||||
void on_txtChatFontSize_valueChanged(int arg1);
|
void on_txtChatFontSize_valueChanged(int arg1);
|
||||||
|
void on_useNameColors_stateChanged(int value);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void retranslateUi();
|
void retranslateUi();
|
||||||
|
|
|
@ -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="useNameColors">
|
||||||
|
<property name="text">
|
||||||
|
<string>Use colored nicknames in chats</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
|
@ -1750,10 +1750,11 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
|
||||||
const auto groupId = g->getId();
|
const auto groupId = g->getId();
|
||||||
const auto date = QDateTime::currentDateTime();
|
const auto date = QDateTime::currentDateTime();
|
||||||
auto form = groupChatForms[groupId];
|
auto form = groupChatForms[groupId];
|
||||||
|
|
||||||
if (targeted && !isAction) {
|
if (targeted && !isAction) {
|
||||||
form->addAlertMessage(author, message, date);
|
form->addAlertMessage(author, message, date, true);
|
||||||
} else {
|
} else {
|
||||||
form->addMessage(author, message, date, isAction);
|
form->addMessage(author, message, date, isAction, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
newGroupMessageAlert(groupId, targeted || Settings::getInstance().getGroupAlwaysNotify());
|
newGroupMessageAlert(groupId, targeted || Settings::getInstance().getGroupAlwaysNotify());
|
||||||
|
|
Loading…
Reference in New Issue
Block a user