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:
parent
c95057283e
commit
bde6dc0df0
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user