2019-03-22 14:28:14 +11:00
|
|
|
import QtQuick 2.7
|
2019-04-29 05:18:36 +10:00
|
|
|
import "../Base"
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-29 01:32:02 +10:00
|
|
|
Rectangle {
|
2019-05-12 05:52:56 +10:00
|
|
|
property var name: null
|
|
|
|
property var imageUrl: null
|
2019-05-13 05:57:18 +10:00
|
|
|
property int dimension: HStyle.avatar.size
|
2019-05-12 05:52:56 +10:00
|
|
|
property bool hidden: false
|
2019-04-19 16:07:01 +10:00
|
|
|
|
2019-07-03 03:59:52 +10:00
|
|
|
function stripUserId(user_id) {
|
|
|
|
return user_id.substring(1) // Remove leading @
|
|
|
|
}
|
|
|
|
function stripRoomName(name) {
|
|
|
|
return name[0] == "#" ? name.substring(1) : name
|
|
|
|
}
|
|
|
|
|
|
|
|
function hueFromName(name) {
|
2019-06-29 08:31:53 +10:00
|
|
|
var hue = 0
|
|
|
|
for (var i = 0; i < name.length; i++) {
|
|
|
|
hue += name.charCodeAt(i) * 99
|
|
|
|
}
|
|
|
|
return hue % 360 / 360
|
|
|
|
}
|
|
|
|
|
2019-04-29 01:32:02 +10:00
|
|
|
width: dimension
|
|
|
|
height: hidden ? 1 : dimension
|
2019-04-29 04:20:30 +10:00
|
|
|
implicitWidth: dimension
|
|
|
|
implicitHeight: hidden ? 1 : dimension
|
|
|
|
|
2019-04-29 01:32:02 +10:00
|
|
|
opacity: hidden ? 0 : 1
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-05-12 05:52:56 +10:00
|
|
|
color: name ?
|
2019-04-29 01:32:02 +10:00
|
|
|
Qt.hsla(
|
2019-07-03 03:59:52 +10:00
|
|
|
hueFromName(name),
|
2019-04-29 05:18:36 +10:00
|
|
|
HStyle.avatar.background.saturation,
|
|
|
|
HStyle.avatar.background.lightness,
|
|
|
|
HStyle.avatar.background.alpha
|
2019-05-12 05:52:56 +10:00
|
|
|
) :
|
|
|
|
HStyle.avatar.background.unknown
|
2019-04-29 01:32:02 +10:00
|
|
|
|
|
|
|
HLabel {
|
|
|
|
z: 1
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: ! hidden
|
|
|
|
|
2019-05-12 05:52:56 +10:00
|
|
|
text: name ? name.charAt(0) : "?"
|
2019-04-29 05:18:36 +10:00
|
|
|
color: HStyle.avatar.letter
|
2019-04-29 01:32:02 +10:00
|
|
|
font.pixelSize: parent.height / 1.4
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
|
|
|
|
2019-04-29 01:32:02 +10:00
|
|
|
HImage {
|
|
|
|
z: 2
|
2019-03-22 14:28:14 +11:00
|
|
|
anchors.fill: parent
|
2019-05-12 05:52:56 +10:00
|
|
|
visible: ! hidden && imageUrl
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-05-12 05:52:56 +10:00
|
|
|
Component.onCompleted: if (imageUrl) { source = imageUrl }
|
2019-03-22 14:28:14 +11:00
|
|
|
fillMode: Image.PreserveAspectCrop
|
2019-04-29 01:32:02 +10:00
|
|
|
sourceSize.width: dimension
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
|
|
|
}
|