From bde6dc0df0583a2c869612a010533bb6246ad7e2 Mon Sep 17 00:00:00 2001 From: sudden6 Date: Sat, 28 Aug 2021 01:01:45 +0200 Subject: [PATCH] fix: change color equation for groupchat names --- src/chatlog/chatmessage.cpp | 8 ++++++-- src/widget/tool/identicon.h | 6 ++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/chatlog/chatmessage.cpp b/src/chatlog/chatmessage.cpp index c6f8ff1a1..e2482b1e7 100644 --- a/src/chatlog/chatmessage.cpp +++ b/src/chatlog/chatmessage.cpp @@ -28,6 +28,7 @@ #include "content/timestamp.h" #include "content/broken.h" #include "src/widget/style.h" +#include "src/widget/tool/identicon.h" #include #include @@ -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; diff --git a/src/widget/tool/identicon.h b/src/widget/tool/identicon.h index a75a53b94..d9a97d49a 100644 --- a/src/widget/tool/identicon.h +++ b/src/widget/tool/identicon.h @@ -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;