moment/src/qml/Base/HAvatar.qml

77 lines
2.0 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-07-13 08:02:14 +10:00
import QtQuick 2.12
import QtQuick.Controls 2.12
import "../Base"
import "../utils.js" as Utils
2019-03-22 14:28:14 +11:00
2019-07-13 07:06:37 +10:00
HRectangle {
id: avatar
implicitWidth: theme.avatar.size
implicitHeight: theme.avatar.size
property string name: ""
2019-07-16 18:37:39 +10:00
property var imageUrl: ""
2019-07-10 12:48:59 +10:00
property var toolTipImageUrl: imageUrl
property alias fillMode: avatarImage.fillMode
readonly property alias hovered: hoverHandler.hovered
readonly property var params: Utils.thumbnailParametersFor(width, height)
2019-03-22 14:28:14 +11:00
color: imageUrl ? "transparent" :
name ? Utils.avatarColor(name) :
theme.avatar.background.unknown
2019-04-29 01:32:02 +10:00
HLabel {
z: 1
anchors.centerIn: parent
visible: ! 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 {
id: avatarImage
2019-03-22 14:28:14 +11:00
anchors.fill: parent
visible: imageUrl
z: 2
sourceSize.width: params.width
sourceSize.height: params.height
fillMode: Image.PreserveAspectCrop
2019-07-16 18:37:39 +10:00
source: Qt.resolvedUrl(imageUrl)
2019-07-10 12:48:59 +10:00
2019-07-13 08:02:14 +10:00
HoverHandler {
id: hoverHandler
2019-07-10 12:48:59 +10:00
}
HToolTip {
id: avatarToolTip
visible: toolTipImageUrl && hoverHandler.hovered
2019-07-16 06:14:08 +10:00
width: 192 + background.border.width * 2
height: width
delay: 1000
background: HRectangle {
id: background
border.color: "black"
border.width: 2
}
2019-07-10 12:48:59 +10:00
HImage {
id: avatarToolTipImage
2019-07-16 06:14:08 +10:00
anchors.centerIn: parent
sourceSize.width: parent.width - background.border.width * 2
sourceSize.height: parent.height - background.border.width * 2
width: sourceSize.width
height: sourceSize.width
fillMode: Image.PreserveAspectCrop
2019-07-16 18:37:39 +10:00
source: Qt.resolvedUrl(toolTipImageUrl)
2019-07-10 12:48:59 +10:00
}
}
2019-03-22 14:28:14 +11:00
}
}