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/timestamp.h"
|
||||||
#include "content/broken.h"
|
#include "content/broken.h"
|
||||||
#include "src/widget/style.h"
|
#include "src/widget/style.h"
|
||||||
|
#include "src/widget/tool/identicon.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QCryptographicHash>
|
#include <QCryptographicHash>
|
||||||
|
@ -93,9 +94,12 @@ ChatMessage::Ptr ChatMessage::createChatMessage(const QString& sender, const QSt
|
||||||
QColor color = Style::getColor(Style::MainText);
|
QColor color = Style::getColor(Style::MainText);
|
||||||
if (colorizeName) {
|
if (colorizeName) {
|
||||||
QByteArray hash = QCryptographicHash::hash((sender.toUtf8()), QCryptographicHash::Sha256);
|
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) {
|
if (!isMe && textType == Text::NORMAL) {
|
||||||
textType = Text::CUSTOM;
|
textType = Text::CUSTOM;
|
||||||
|
|
|
@ -27,17 +27,15 @@ class Identicon
|
||||||
public:
|
public:
|
||||||
Identicon(const QByteArray& data);
|
Identicon(const QByteArray& data);
|
||||||
QImage toImage(int scaleFactor = 1);
|
QImage toImage(int scaleFactor = 1);
|
||||||
|
static float bytesToColor(QByteArray bytes);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static constexpr int IDENTICON_ROWS = 5;
|
static constexpr int IDENTICON_ROWS = 5;
|
||||||
|
static constexpr int IDENTICON_COLOR_BYTES = 6;
|
||||||
private:
|
|
||||||
float bytesToColor(QByteArray bytes);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static constexpr int COLORS = 2;
|
static constexpr int COLORS = 2;
|
||||||
static constexpr int ACTIVE_COLS = (IDENTICON_ROWS + 1) / 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
|
static constexpr int HASH_MIN_LEN = ACTIVE_COLS * IDENTICON_ROWS
|
||||||
+ COLORS * IDENTICON_COLOR_BYTES;
|
+ COLORS * IDENTICON_COLOR_BYTES;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user