2019-03-22 14:28:14 +11:00
|
|
|
import QtQuick 2.7
|
|
|
|
import QtQuick.Controls 2.0
|
|
|
|
import QtQuick.Layouts 1.4
|
2019-04-29 02:45:12 +10:00
|
|
|
import "../Base" as Base
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-29 01:32:02 +10:00
|
|
|
Rectangle {
|
|
|
|
property bool hidden: false
|
2019-04-19 16:07:01 +10:00
|
|
|
property var name: null // null, string or PyQtFuture
|
2019-03-22 14:28:14 +11:00
|
|
|
property var imageSource: null
|
2019-04-29 01:32:02 +10:00
|
|
|
property int dimension: 48
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-04-29 04:20:30 +10:00
|
|
|
|
2019-04-21 07:36:21 +10:00
|
|
|
readonly property string resolvedName:
|
2019-04-19 16:07:01 +10:00
|
|
|
! name ? "?" :
|
|
|
|
typeof(name) == "string" ? name :
|
|
|
|
(name.value ? name.value : "?")
|
|
|
|
|
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-04-29 01:32:02 +10:00
|
|
|
color: resolvedName === "?" ?
|
|
|
|
Base.HStyle.avatar.background.unknown :
|
|
|
|
Qt.hsla(
|
|
|
|
Backend.hueFromString(resolvedName),
|
|
|
|
Base.HStyle.avatar.background.saturation,
|
|
|
|
Base.HStyle.avatar.background.lightness,
|
|
|
|
Base.HStyle.avatar.background.alpha
|
|
|
|
)
|
|
|
|
|
|
|
|
HLabel {
|
|
|
|
z: 1
|
|
|
|
anchors.centerIn: parent
|
|
|
|
visible: ! hidden
|
|
|
|
|
|
|
|
text: resolvedName.charAt(0)
|
|
|
|
color: Base.HStyle.avatar.letter
|
|
|
|
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-04-29 01:32:02 +10:00
|
|
|
visible: ! hidden && imageSource !== null
|
2019-03-22 14:28:14 +11:00
|
|
|
|
|
|
|
Component.onCompleted: if (imageSource) {source = imageSource}
|
|
|
|
fillMode: Image.PreserveAspectCrop
|
2019-04-29 01:32:02 +10:00
|
|
|
sourceSize.width: dimension
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
|
|
|
}
|