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

fix: change color equation for groupchat names

This commit is contained in:
sudden6 2021-08-28 01:01:45 +02:00
parent c95057283e
commit bde6dc0df0
No known key found for this signature in database
GPG Key ID: 279509B499E032B9
2 changed files with 8 additions and 6 deletions

View File

@ -28,6 +28,7 @@
#include "content/timestamp.h"
#include "content/broken.h"
#include "src/widget/style.h"
#include "src/widget/tool/identicon.h"
#include <QDebug>
#include <QCryptographicHash>
@ -93,9 +94,12 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
QColor color = Style::getColor(Style::MainText);
if (colorizeName) {
QByteArray hash = QCryptographicHash::hash((sender.toUtf8()), QCryptographicHash::Sha256);
const auto* data = hash.data();
float lightness = color.lightnessF();
// Adapt as good as possible to Light/Dark themes
lightness = lightness*0.5 + 0.3;
color.setHsv(data[0], 255, 196);
// Magic values
color.setHslF(Identicon::bytesToColor(hash.left(Identicon::IDENTICON_COLOR_BYTES)), 1.0, lightness);
if (!isMe && textType == Text::NORMAL) {
textType = Text::CUSTOM;

View File

@ -27,17 +27,15 @@ class Identicon
public:
Identicon(const QByteArray& data);
QImage toImage(int scaleFactor = 1);
static float bytesToColor(QByteArray bytes);
public:
static constexpr int IDENTICON_ROWS = 5;
private:
float bytesToColor(QByteArray bytes);
static constexpr int IDENTICON_COLOR_BYTES = 6;
private:
static constexpr int COLORS = 2;
static constexpr int ACTIVE_COLS = (IDENTICON_ROWS + 1) / 2;
static constexpr int IDENTICON_COLOR_BYTES = 6;
static constexpr int HASH_MIN_LEN = ACTIVE_COLS * IDENTICON_ROWS
+ COLORS * IDENTICON_COLOR_BYTES;