moment/src/qml/Base/HAvatar.qml

68 lines
1.6 KiB
QML
Raw Normal View History

2019-07-08 13:52:41 +10:00
// Copyright 2019 miruka
// This file is part of harmonyqml, licensed under LGPLv3.
2019-03-22 14:28:14 +11:00
import QtQuick 2.7
2019-07-10 12:48:59 +10:00
import QtQuick.Controls 2.0
import "../Base"
import "../utils.js" as Utils
2019-03-22 14:28:14 +11:00
2019-04-29 01:32:02 +10:00
Rectangle {
property string name: ""
property var imageUrl: null
2019-07-10 12:48:59 +10:00
property var toolTipImageUrl: imageUrl
property int dimension: theme.avatar.size
property bool hidden: false
onImageUrlChanged: if (imageUrl) { avatarImage.source = imageUrl }
2019-07-10 12:48:59 +10:00
onToolTipImageUrlChanged: if (imageUrl) {
avatarToolTipImage.source = toolTipImageUrl
}
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 ? Utils.avatarColor(name) : theme.avatar.background.unknown
2019-04-29 01:32:02 +10:00
HLabel {
z: 1
anchors.centerIn: parent
visible: ! hidden && ! imageUrl
2019-04-29 01:32:02 +10:00
text: name ? name.charAt(0) : "?"
color: theme.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
id: avatarImage
2019-03-22 14:28:14 +11:00
anchors.fill: parent
visible: ! hidden && imageUrl
2019-03-22 14:28:14 +11:00
fillMode: Image.PreserveAspectCrop
2019-04-29 01:32:02 +10:00
sourceSize.width: dimension
sourceSize.height: dimension
2019-07-10 12:48:59 +10:00
MouseArea {
id: imageMouseArea
anchors.fill: parent
hoverEnabled: true
}
HToolTip {
2019-07-10 12:48:59 +10:00
visible: imageMouseArea.containsMouse
HImage {
id: avatarToolTipImage
sourceSize.width: 128
sourceSize.height: 128
}
}
2019-03-22 14:28:14 +11:00
}
}