2019-12-19 07:46:16 -04:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-07-12 18:02:14 -04:00
|
|
|
import QtQuick 2.12
|
2019-07-13 05:39:01 -04:00
|
|
|
import QtQuick.Controls 2.12
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-08-27 22:46:31 -04:00
|
|
|
Rectangle {
|
2019-07-13 20:15:20 -04:00
|
|
|
id: avatar
|
2020-03-15 14:14:05 -04:00
|
|
|
|
2020-03-22 12:50:10 -04:00
|
|
|
property bool compact: false
|
|
|
|
|
2019-11-03 13:48:12 -04:00
|
|
|
property string name
|
|
|
|
property alias mxc: avatarImage.mxc
|
2020-03-09 11:46:08 -04:00
|
|
|
property alias title: avatarImage.title
|
2019-11-03 13:48:12 -04:00
|
|
|
|
|
|
|
property alias toolTipMxc: avatarToolTipImage.mxc
|
|
|
|
property alias sourceOverride: avatarImage.sourceOverride
|
|
|
|
property alias toolTipSourceOverride: avatarToolTipImage.sourceOverride
|
|
|
|
property alias fillMode: avatarImage.fillMode
|
|
|
|
property alias animate: avatarImage.animate
|
|
|
|
|
|
|
|
readonly property alias hovered: hoverHandler.hovered
|
2020-03-15 14:14:05 -04:00
|
|
|
readonly property alias circleRadius: avatarImage.circleRadius
|
|
|
|
|
2019-11-03 13:48:12 -04:00
|
|
|
|
2020-07-12 00:25:57 -04:00
|
|
|
implicitWidth: implicitHeight
|
|
|
|
implicitHeight:
|
|
|
|
compact ?
|
|
|
|
theme.controls.avatar.compactSize :
|
|
|
|
theme.controls.avatar.size
|
|
|
|
|
|
|
|
radius: theme.controls.avatar.radius
|
|
|
|
|
|
|
|
color: avatarImage.visible ? "transparent" : utils.hsluv(
|
|
|
|
name ? utils.hueFrom(name) : 0,
|
|
|
|
name ? theme.controls.avatar.background.saturation : 0,
|
|
|
|
theme.controls.avatar.background.lightness,
|
|
|
|
theme.controls.avatar.background.opacity
|
|
|
|
)
|
|
|
|
|
2020-03-21 14:47:43 -04:00
|
|
|
Behavior on color { HColorAnimation {} }
|
|
|
|
|
2019-04-28 11:32:02 -04:00
|
|
|
HLabel {
|
|
|
|
z: 1
|
|
|
|
anchors.centerIn: parent
|
2019-07-24 02:14:34 -04:00
|
|
|
visible: ! avatarImage.visible
|
2019-04-28 11:32:02 -04:00
|
|
|
|
2019-05-11 15:52:56 -04:00
|
|
|
text: name ? name.charAt(0) : "?"
|
2019-04-28 11:32:02 -04:00
|
|
|
font.pixelSize: parent.height / 1.4
|
2019-07-24 02:14:34 -04:00
|
|
|
|
2019-12-17 17:59:53 -04:00
|
|
|
color: utils.hsluv(
|
|
|
|
name ? utils.hueFrom(name) : 0,
|
2019-07-24 02:14:34 -04:00
|
|
|
name ? theme.controls.avatar.letter.saturation : 0,
|
|
|
|
theme.controls.avatar.letter.lightness,
|
|
|
|
theme.controls.avatar.letter.opacity
|
|
|
|
)
|
2020-03-21 14:47:43 -04:00
|
|
|
|
|
|
|
Behavior on color { HColorAnimation {} }
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|
|
|
|
|
2019-11-03 13:48:12 -04:00
|
|
|
HMxcImage {
|
2019-07-09 21:46:21 -04:00
|
|
|
id: avatarImage
|
2019-03-21 23:28:14 -04:00
|
|
|
anchors.fill: parent
|
2019-12-15 13:02:40 -04:00
|
|
|
showProgressBar: false
|
2019-11-03 13:48:12 -04:00
|
|
|
visible: Boolean(sourceOverride || mxc)
|
2019-07-13 20:15:20 -04:00
|
|
|
z: 2
|
2019-11-03 13:48:12 -04:00
|
|
|
sourceSize.width: parent.width
|
|
|
|
sourceSize.height: parent.height
|
2019-07-15 20:10:43 -04:00
|
|
|
fillMode: Image.PreserveAspectCrop
|
2020-07-17 07:26:31 -04:00
|
|
|
animatedFillMode: AnimatedImage.PreserveAspectCrop
|
2019-09-12 16:16:35 -04:00
|
|
|
animate: false
|
2020-03-15 14:14:05 -04:00
|
|
|
radius: parent.radius
|
2019-07-09 22:48:59 -04:00
|
|
|
|
2019-08-22 09:27:26 -04:00
|
|
|
HoverHandler { id: hoverHandler }
|
2019-07-09 22:48:59 -04:00
|
|
|
|
2019-07-09 22:51:52 -04:00
|
|
|
HToolTip {
|
2019-07-09 23:42:03 -04:00
|
|
|
id: avatarToolTip
|
2019-09-12 19:54:31 -04:00
|
|
|
|
|
|
|
readonly property int dimension: Math.min(
|
2019-07-16 08:10:37 -04:00
|
|
|
mainUI.width / 1.25,
|
|
|
|
mainUI.height / 1.25,
|
2019-09-12 20:04:46 -04:00
|
|
|
theme.controls.avatar.hoveredImage.size +
|
|
|
|
background.border.width * 2,
|
2019-07-16 08:10:37 -04:00
|
|
|
)
|
2019-07-15 16:14:08 -04:00
|
|
|
|
2020-07-12 00:25:57 -04:00
|
|
|
visible: ! avatarImage.broken &&
|
|
|
|
avatarImage.width < dimension * 0.75 &&
|
|
|
|
(toolTipSourceOverride || toolTipMxc) &&
|
|
|
|
hoverHandler.hovered
|
|
|
|
delay: 1000
|
|
|
|
backgroundColor: theme.controls.avatar.hoveredImage.background
|
|
|
|
|
2019-11-03 13:48:12 -04:00
|
|
|
contentItem: HMxcImage {
|
2019-07-09 22:48:59 -04:00
|
|
|
id: avatarToolTipImage
|
2019-07-13 20:15:20 -04:00
|
|
|
fillMode: Image.PreserveAspectCrop
|
2020-07-17 07:26:31 -04:00
|
|
|
animatedFillMode: AnimatedImage.PreserveAspectCrop
|
2019-11-03 13:48:12 -04:00
|
|
|
mxc: avatarImage.mxc
|
2020-03-09 11:46:08 -04:00
|
|
|
title: avatarImage.title
|
2019-09-12 19:54:31 -04:00
|
|
|
|
|
|
|
sourceSize.width: avatarToolTip.dimension
|
|
|
|
sourceSize.height: avatarToolTip.dimension
|
|
|
|
width: avatarToolTip.dimension
|
|
|
|
height: avatarToolTip.dimension
|
2019-07-09 22:48:59 -04:00
|
|
|
}
|
|
|
|
}
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|
|
|
|
}
|