summary refs log tree commit diff
path: root/src/Utils.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-11-24 03:42:49 +0000
committerNicolas Werner <nicolas.werner@hotmail.de>2021-11-24 03:42:49 +0000
commit5bc9d885de4683a1e2e87569ba64c4cd98a2b003 (patch)
treec9ddb5c224bd8696bb56b913ad25d537562a4c71 /src/Utils.cpp
parentFix one more wrong background color (diff)
parentFix colors of sidebar in replies (diff)
downloadnheko-5bc9d885de4683a1e2e87569ba64c4cd98a2b003.tar.xz
Merge branch 'more-random-colors' into 'master'
Use a more random hash to generate user colors

See merge request nheko-reborn/nheko!17
Diffstat (limited to 'src/Utils.cpp')
-rw-r--r--src/Utils.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp

index dda6f685..3a785ddb 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp
@@ -7,6 +7,7 @@ #include <QApplication> #include <QBuffer> #include <QComboBox> +#include <QCryptographicHash> #include <QDesktopWidget> #include <QGuiApplication> #include <QImageReader> @@ -641,13 +642,9 @@ utils::linkColor() uint32_t 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++) { - hash = input.at(i).digitValue() + ((hash << 5) - hash); - } - - return hash; + return (h[0] << 24) ^ (h[1] << 16) ^ (h[2] << 8) ^ h[3]; } QColor @@ -658,7 +655,10 @@ utils::generateContrastingHexColor(const QString &input, const QColor &backgroun // Create a color for the input auto hash = hashQString(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. auto sat = 230; auto lightness = 125;