2019-07-07 23:52:41 -04:00
|
|
|
// Copyright 2019 miruka
|
|
|
|
// This file is part of harmonyqml, licensed under LGPLv3.
|
|
|
|
|
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-04-28 15:18:36 -04:00
|
|
|
import "../Base"
|
2019-07-03 22:31:29 -04:00
|
|
|
import "../utils.js" as Utils
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-07-12 17:06:37 -04:00
|
|
|
HRectangle {
|
2019-07-13 20:15:20 -04:00
|
|
|
id: avatar
|
|
|
|
implicitWidth: theme.avatar.size
|
|
|
|
implicitHeight: theme.avatar.size
|
|
|
|
|
2019-07-07 00:24:23 -04:00
|
|
|
property string name: ""
|
2019-07-16 04:37:39 -04:00
|
|
|
property var imageUrl: ""
|
2019-07-09 22:48:59 -04:00
|
|
|
property var toolTipImageUrl: imageUrl
|
2019-07-13 20:15:20 -04:00
|
|
|
property alias fillMode: avatarImage.fillMode
|
2019-04-19 02:07:01 -04:00
|
|
|
|
2019-07-15 20:10:43 -04:00
|
|
|
readonly property alias hovered: hoverHandler.hovered
|
|
|
|
|
2019-07-13 20:15:20 -04:00
|
|
|
readonly property var params: Utils.thumbnailParametersFor(width, height)
|
2019-03-21 23:28:14 -04:00
|
|
|
|
2019-07-13 20:15:20 -04:00
|
|
|
color: imageUrl ? "transparent" :
|
|
|
|
name ? Utils.avatarColor(name) :
|
|
|
|
theme.avatar.background.unknown
|
2019-04-28 11:32:02 -04:00
|
|
|
|
|
|
|
HLabel {
|
|
|
|
z: 1
|
|
|
|
anchors.centerIn: parent
|
2019-07-13 20:15:20 -04:00
|
|
|
visible: ! imageUrl
|
2019-04-28 11:32:02 -04:00
|
|
|
|
2019-05-11 15:52:56 -04:00
|
|
|
text: name ? name.charAt(0) : "?"
|
2019-07-06 17:50:55 -04:00
|
|
|
color: theme.avatar.letter
|
2019-04-28 11:32:02 -04:00
|
|
|
font.pixelSize: parent.height / 1.4
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|
|
|
|
|
2019-04-28 11:32:02 -04:00
|
|
|
HImage {
|
2019-07-09 21:46:21 -04:00
|
|
|
id: avatarImage
|
2019-03-21 23:28:14 -04:00
|
|
|
anchors.fill: parent
|
2019-07-13 20:15:20 -04:00
|
|
|
visible: imageUrl
|
|
|
|
z: 2
|
|
|
|
sourceSize.width: params.width
|
|
|
|
sourceSize.height: params.height
|
2019-07-15 20:10:43 -04:00
|
|
|
fillMode: Image.PreserveAspectCrop
|
2019-07-16 04:37:39 -04:00
|
|
|
source: Qt.resolvedUrl(imageUrl)
|
2019-07-09 22:48:59 -04:00
|
|
|
|
2019-07-12 18:02:14 -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-07-13 20:15:20 -04:00
|
|
|
visible: toolTipImageUrl && hoverHandler.hovered
|
2019-07-15 16:14:08 -04:00
|
|
|
width: 192 + background.border.width * 2
|
|
|
|
height: width
|
|
|
|
delay: 1000
|
|
|
|
|
|
|
|
background: HRectangle {
|
|
|
|
id: background
|
|
|
|
border.color: "black"
|
|
|
|
border.width: 2
|
|
|
|
}
|
2019-07-09 22:48:59 -04:00
|
|
|
|
|
|
|
HImage {
|
|
|
|
id: avatarToolTipImage
|
2019-07-15 16:14:08 -04: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-13 20:15:20 -04:00
|
|
|
fillMode: Image.PreserveAspectCrop
|
2019-07-16 04:37:39 -04:00
|
|
|
source: Qt.resolvedUrl(toolTipImageUrl)
|
2019-07-09 22:48:59 -04:00
|
|
|
}
|
|
|
|
}
|
2019-03-21 23:28:14 -04:00
|
|
|
}
|
|
|
|
}
|