moment/src/gui/Base/HAvatar.qml

117 lines
3.6 KiB
QML
Raw Normal View History

// Copyright Mirage authors & contributors <https://github.com/mirukana/mirage>
2019-12-19 22:46:16 +11:00
// SPDX-License-Identifier: LGPL-3.0-or-later
2019-07-13 08:02:14 +10:00
import QtQuick 2.12
import QtQuick.Controls 2.12
2019-03-22 14:28:14 +11:00
2019-08-28 12:46:31 +10:00
Rectangle {
id: avatar
2020-03-16 05:14:05 +11:00
property bool compact: false
property string name
property alias clientUserId: avatarImage.clientUserId
property alias mxc: avatarImage.mxc
property alias title: avatarImage.title
property alias sourceOverride: avatarImage.sourceOverride
property alias fillMode: avatarImage.fillMode
property alias animate: avatarImage.animate
property string toolTipMxc: mxc
property string toolTipSourceOverride: ""
readonly property alias hovered: hoverHandler.hovered
2020-03-16 05:14:05 +11:00
readonly property alias circleRadius: avatarImage.circleRadius
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-22 05:47:43 +11:00
Behavior on color { HColorAnimation {} }
2019-04-29 01:32:02 +10:00
HLabel {
z: 1
anchors.centerIn: parent
visible: ! avatarImage.visible
2019-04-29 01:32:02 +10:00
text: name ? name.charAt(0) : "?"
2019-04-29 01:32:02 +10:00
font.pixelSize: parent.height / 1.4
color: utils.hsluv(
name ? utils.hueFrom(name) : 0,
name ? theme.controls.avatar.letter.saturation : 0,
theme.controls.avatar.letter.lightness,
theme.controls.avatar.letter.opacity
)
2020-03-22 05:47:43 +11:00
Behavior on color { HColorAnimation {} }
2019-03-22 14:28:14 +11:00
}
HMxcImage {
id: avatarImage
2019-03-22 14:28:14 +11:00
anchors.fill: parent
visible: Boolean(sourceOverride || mxc)
z: 2
sourceSize.width: parent.width
sourceSize.height: parent.height
showProgressBar: false
fillMode: Image.PreserveAspectCrop
2020-07-17 21:26:31 +10:00
animatedFillMode: AnimatedImage.PreserveAspectCrop
2019-09-13 06:16:35 +10:00
animate: false
2020-03-16 05:14:05 +11:00
radius: parent.radius
2019-07-10 12:48:59 +10:00
HoverHandler { id: hoverHandler }
2019-07-10 12:48:59 +10:00
HToolTip {
id: avatarToolTip
2019-09-13 09:54:31 +10:00
readonly property int dimension: Math.min(
2019-07-16 22:10:37 +10:00
mainUI.width / 1.25,
mainUI.height / 1.25,
theme.controls.avatar.hoveredImage.size +
background.border.width * 2,
2019-07-16 22:10:37 +10:00
)
2019-07-16 06:14:08 +10:00
visible:
! avatarImage.broken &&
! window.anyMenu &&
avatarImage.width < dimension * 0.75 &&
(toolTipSourceOverride || toolTipMxc) &&
hoverHandler.hovered
delay: 1000
backgroundColor: theme.controls.avatar.hoveredImage.background
contentItem: HLoader {
active: avatarToolTip.visible
sourceComponent: HMxcImage {
id: avatarToolTipImage
fillMode: Image.PreserveAspectCrop
animatedFillMode: AnimatedImage.PreserveAspectCrop
clientUserId: avatarImage.clientUserId
title: avatarImage.title
mxc: avatar.toolTipMxc
sourceOverride: avatar.toolTipSourceOverride
sourceSize.width: avatarToolTip.dimension
sourceSize.height: avatarToolTip.dimension
width: avatarToolTip.dimension
height: avatarToolTip.dimension
}
2019-07-10 12:48:59 +10:00
}
}
2019-03-22 14:28:14 +11:00
}
}