From 933341b7e66fc6fe53e3e54b5abe66b0ac47ab19 Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 28 Jun 2019 18:31:53 -0400 Subject: [PATCH] Implement avatar hue from name --- src/qml/Base/HAvatar.qml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/qml/Base/HAvatar.qml b/src/qml/Base/HAvatar.qml index 01480627..be97d8cd 100644 --- a/src/qml/Base/HAvatar.qml +++ b/src/qml/Base/HAvatar.qml @@ -7,6 +7,14 @@ Rectangle { property int dimension: HStyle.avatar.size property bool hidden: false + function hue_from_name(name) { + var hue = 0 + for (var i = 0; i < name.length; i++) { + hue += name.charCodeAt(i) * 99 + } + return hue % 360 / 360 + } + width: dimension height: hidden ? 1 : dimension implicitWidth: dimension @@ -16,7 +24,7 @@ Rectangle { color: name ? Qt.hsla( - Backend.hueFromString(name), + hue_from_name(name), HStyle.avatar.background.saturation, HStyle.avatar.background.lightness, HStyle.avatar.background.alpha