diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2019-06-25 21:19:50 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-25 21:19:50 +0900 |
commit | d3ddd394e855cfe217bf0f0d368822c9b99316bb (patch) | |
tree | 93c89f3e83291edfe88922182d4e5608a5ec62e7 /lib/user.cpp | |
parent | 93f0c8fe89f448d1d58caa757573f17102369471 (diff) | |
parent | 48ffee5fa78f44bd00d76772ad79ae4eeb6c8dc4 (diff) | |
download | libquotient-d3ddd394e855cfe217bf0f0d368822c9b99316bb.tar.gz libquotient-d3ddd394e855cfe217bf0f0d368822c9b99316bb.zip |
Merge pull request #322 from a-andreyev/aa13q-fancy-colors
Move out the logic of the hue calculation to utils
Diffstat (limited to 'lib/user.cpp')
-rw-r--r-- | lib/user.cpp | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/lib/user.cpp b/lib/user.cpp index 7f3f11f6..7b695618 100644 --- a/lib/user.cpp +++ b/lib/user.cpp @@ -33,9 +33,6 @@ #include <QtCore/QStringBuilder> #include <QtCore/QElapsedTimer> -#include <QtCore/QCryptographicHash> -#include <QtCore/QtEndian> - #include <functional> using namespace QMatrixClient; @@ -50,23 +47,8 @@ class User::Private return Avatar(move(url)); } - qreal makeHueF() - { - Q_ASSERT(!userId.isEmpty()); - QByteArray hash = QCryptographicHash::hash(userId.toUtf8(), - QCryptographicHash::Sha1); - QDataStream dataStream(qToLittleEndian(hash).left(2)); - dataStream.setByteOrder(QDataStream::LittleEndian); - quint16 hashValue; - dataStream >> hashValue; - const auto hueF = - qreal(hashValue)/std::numeric_limits<quint16>::max(); - Q_ASSERT((0 <= hueF) && (hueF <= 1)); - return hueF; - } - Private(QString userId, Connection* connection) - : userId(move(userId)), connection(connection), hueF(makeHueF()) + : userId(move(userId)), connection(connection), hueF(stringToHueF(this->userId)) { } QString userId; |