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
|
2019-07-13 19:39:01 +10:00
|
|
|
import QtQuick.Controls 2.12
|
2019-04-29 05:18:36 +10:00
|
|
|
import "../Base"
|
2019-07-04 12:31:29 +10:00
|
|
|
import "../utils.js" as Utils
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-13 07:06:37 +10:00
|
|
|
HRectangle {
|
2019-07-14 10:15:20 +10:00
|
|
|
id: avatar
|
2019-07-24 16:14:34 +10:00
|
|
|
implicitWidth: theme.controls.avatar.size
|
|
|
|
implicitHeight: theme.controls.avatar.size
|
2019-07-14 10:15:20 +10:00
|
|
|
|
2019-07-07 14:24:23 +10:00
|
|
|
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
|
2019-07-14 10:15:20 +10:00
|
|
|
property alias fillMode: avatarImage.fillMode
|
2019-04-19 16:07:01 +10:00
|
|
|
|
2019-07-16 10:10:43 +10:00
|
|
|
readonly property alias hovered: hoverHandler.hovered
|
|
|
|
|
2019-07-14 10:15:20 +10:00
|
|
|
readonly property var params: Utils.thumbnailParametersFor(width, height)
|
2019-03-22 14:28:14 +11:00
|
|
|
|
2019-07-24 16:14:34 +10:00
|
|
|
color: avatarImage.visible ? "transparent" : Utils.hsla(
|
|
|
|
name ? Utils.hueFrom(name) : 0,
|
|
|
|
name ? theme.controls.avatar.background.saturation : 0,
|
|
|
|
theme.controls.avatar.background.lightness,
|
|
|
|
theme.controls.avatar.background.opacity
|
|
|
|
)
|
2019-04-29 01:32:02 +10:00
|
|
|
|
|
|
|
HLabel {
|
|
|
|
z: 1
|
|
|
|
anchors.centerIn: parent
|
2019-07-24 16:14:34 +10:00
|
|
|
visible: ! avatarImage.visible
|
2019-04-29 01:32:02 +10:00
|
|
|
|
2019-05-12 05:52:56 +10:00
|
|
|
text: name ? name.charAt(0) : "?"
|
2019-04-29 01:32:02 +10:00
|
|
|
font.pixelSize: parent.height / 1.4
|
2019-07-24 16:14:34 +10:00
|
|
|
|
|
|
|
color: Utils.hsla(
|
|
|
|
name ? Utils.hueFrom(name) : 0,
|
|
|
|
name ? theme.controls.avatar.letter.saturation : 0,
|
|
|
|
theme.controls.avatar.letter.lightness,
|
|
|
|
theme.controls.avatar.letter.opacity
|
|
|
|
)
|
2019-03-22 14:28:14 +11:00
|
|
|
}
|
|
|
|
|
2019-04-29 01:32:02 +10:00
|
|
|
HImage {
|
2019-07-10 11:46:21 +10:00
|
|
|
id: avatarImage
|
2019-03-22 14:28:14 +11:00
|
|
|
anchors.fill: parent
|
2019-07-14 10:15:20 +10:00
|
|
|
visible: imageUrl
|
|
|
|
z: 2
|
|
|
|
sourceSize.width: params.width
|
|
|
|
sourceSize.height: params.height
|
2019-07-16 10:10:43 +10:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-07-10 12:51:52 +10:00
|
|
|
HToolTip {
|
2019-07-10 13:42:03 +10:00
|
|
|
id: avatarToolTip
|
2019-07-14 10:15:20 +10:00
|
|
|
visible: toolTipImageUrl && hoverHandler.hovered
|
2019-07-16 22:10:37 +10:00
|
|
|
width: Math.min(
|
|
|
|
mainUI.width / 1.25,
|
|
|
|
mainUI.height / 1.25,
|
|
|
|
192 + background.border.width * 2
|
|
|
|
)
|
2019-07-16 06:14:08 +10:00
|
|
|
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
|
2019-07-14 10:15:20 +10:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|