moment/harmonyqml/components/Base/HAvatar.qml

46 lines
1.1 KiB
QML
Raw Normal View History

2019-03-22 14:28:14 +11:00
import QtQuick 2.7
import "../Base"
2019-03-22 14:28:14 +11:00
2019-04-29 01:32:02 +10:00
Rectangle {
property var name: null
property var imageUrl: null
property int dimension: 36
property bool hidden: false
2019-04-29 01:32:02 +10:00
width: dimension
height: hidden ? 1 : dimension
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
color: name ?
2019-04-29 01:32:02 +10:00
Qt.hsla(
Backend.hueFromString(name),
HStyle.avatar.background.saturation,
HStyle.avatar.background.lightness,
HStyle.avatar.background.alpha
) :
HStyle.avatar.background.unknown
2019-04-29 01:32:02 +10:00
HLabel {
z: 1
anchors.centerIn: parent
visible: ! hidden
text: name ? name.charAt(0) : "?"
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
visible: ! hidden && imageUrl
2019-03-22 14:28:14 +11: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
}
}