mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Merge branch 'more-random-colors' into 'master'
Use a more random hash to generate user colors See merge request nheko-reborn/nheko!17
This commit is contained in:
commit
5bc9d885de
2 changed files with 8 additions and 8 deletions
|
@ -48,7 +48,7 @@ Item {
|
||||||
anchors.top: replyContainer.top
|
anchors.top: replyContainer.top
|
||||||
anchors.bottom: replyContainer.bottom
|
anchors.bottom: replyContainer.bottom
|
||||||
width: 4
|
width: 4
|
||||||
color: TimelineManager.userColor(userId, Nheko.colors.window)
|
color: TimelineManager.userColor(userId, Nheko.colors.base)
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
#include <QCryptographicHash>
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
|
@ -641,13 +642,9 @@ utils::linkColor()
|
||||||
uint32_t
|
uint32_t
|
||||||
utils::hashQString(const QString &input)
|
utils::hashQString(const QString &input)
|
||||||
{
|
{
|
||||||
uint32_t hash = 0;
|
auto h = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha1);
|
||||||
|
|
||||||
for (int i = 0; i < input.length(); i++) {
|
return (h[0] << 24) ^ (h[1] << 16) ^ (h[2] << 8) ^ h[3];
|
||||||
hash = input.at(i).digitValue() + ((hash << 5) - hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor
|
QColor
|
||||||
|
@ -658,7 +655,10 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun
|
||||||
// Create a color for the input
|
// Create a color for the input
|
||||||
auto hash = hashQString(input);
|
auto hash = hashQString(input);
|
||||||
// create a hue value based on the hash of the input.
|
// create a hue value based on the hash of the input.
|
||||||
auto userHue = static_cast<int>(hash % 360);
|
// Adapted to make Nico blue
|
||||||
|
auto userHue =
|
||||||
|
static_cast<int>(static_cast<double>(hash - static_cast<uint32_t>(0x60'00'00'00)) /
|
||||||
|
std::numeric_limits<uint32_t>::max() * 360.);
|
||||||
// start with moderate saturation and lightness values.
|
// start with moderate saturation and lightness values.
|
||||||
auto sat = 230;
|
auto sat = 230;
|
||||||
auto lightness = 125;
|
auto lightness = 125;
|
||||||
|
|
Loading…
Reference in a new issue