nheko/resources/qml/Avatar.qml

115 lines
3.1 KiB
QML
Raw Normal View History

2021-03-05 00:35:15 +01:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
//
2021-03-05 00:35:15 +01:00
// SPDX-License-Identifier: GPL-3.0-or-later
import "./ui"
import QtQuick 2.6
import QtQuick.Controls 2.3
2020-06-24 16:24:22 +02:00
import im.nheko 1.0
2019-09-07 22:22:07 +02:00
Rectangle {
2020-10-08 21:11:21 +02:00
id: avatar
2021-08-06 01:45:47 +02:00
property string url
2020-10-08 21:11:21 +02:00
property string userid
2021-08-31 02:08:47 +02:00
property string roomid
2020-10-08 21:11:21 +02:00
property string displayName
2021-06-11 13:12:43 +02:00
property alias textColor: label.color
2021-08-06 01:45:47 +02:00
property bool crop: true
2019-09-07 22:22:07 +02:00
2021-01-12 02:02:39 +01:00
signal clicked(var mouse)
2020-10-08 21:11:21 +02:00
width: 48
height: 48
2021-08-16 12:47:44 +02:00
radius: Settings.avatarCircles ? height / 2 : height / 8
2021-05-13 08:23:56 +02:00
color: Nheko.colors.alternateBase
2021-01-12 02:02:39 +01:00
Component.onCompleted: {
mouseArea.clicked.connect(clicked);
}
2019-09-07 22:22:07 +02:00
2020-10-08 21:11:21 +02:00
Label {
2021-06-11 13:12:43 +02:00
id: label
2021-06-11 14:51:29 +02:00
2020-10-08 21:11:21 +02:00
anchors.fill: parent
text: TimelineManager.escapeEmoji(displayName ? String.fromCodePoint(displayName.codePointAt(0)) : "")
textFormat: Text.RichText
font.pixelSize: avatar.height / 2
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
2020-12-25 15:14:00 +01:00
visible: img.status != Image.Ready && !Settings.useIdenticon
2021-05-13 08:23:56 +02:00
color: Nheko.colors.text
2020-10-08 21:11:21 +02:00
}
2019-09-07 22:22:07 +02:00
2020-12-25 15:14:00 +01:00
Image {
id: identicon
2020-12-25 15:14:00 +01:00
anchors.fill: parent
2021-09-07 03:11:49 +02:00
visible: Settings.useIdenticon && img.status != Image.Ready
2021-09-07 03:11:37 +02:00
source: Settings.useIdenticon ? ("image://jdenticon/" + (userid !== "" ? userid : roomid) + "?radius=" + (Settings.avatarCircles ? 100 : 25)) : ""
2021-08-14 02:05:51 +02:00
MouseArea {
anchors.fill: parent
Ripple {
rippleTarget: parent
color: Qt.rgba(Nheko.colors.alternateBase.r, Nheko.colors.alternateBase.g, Nheko.colors.alternateBase.b, 0.5)
}
}
2020-12-25 15:14:00 +01:00
}
2020-10-08 21:11:21 +02:00
Image {
id: img
2020-10-08 21:11:21 +02:00
anchors.fill: parent
asynchronous: true
2021-08-06 01:45:47 +02:00
fillMode: avatar.crop ? Image.PreserveAspectCrop : Image.PreserveAspectFit
2020-10-08 21:11:21 +02:00
mipmap: true
smooth: true
2020-10-08 21:11:21 +02:00
sourceSize.width: avatar.width
sourceSize.height: avatar.height
source: avatar.url ? (avatar.url + "?radius=" + (Settings.avatarCircles ? 100 : 25) + ((avatar.crop) ? "" : "&scale")) : ""
2019-09-07 22:22:07 +02:00
MouseArea {
id: mouseArea
anchors.fill: parent
Ripple {
rippleTarget: mouseArea
2021-05-13 08:23:56 +02:00
color: Qt.rgba(Nheko.colors.alternateBase.r, Nheko.colors.alternateBase.g, Nheko.colors.alternateBase.b, 0.5)
}
}
2020-10-08 21:11:21 +02:00
}
2020-10-08 21:11:21 +02:00
Rectangle {
anchors.bottom: avatar.bottom
anchors.right: avatar.right
visible: !!userid
height: avatar.height / 6
width: height
2021-08-16 12:47:44 +02:00
radius: Settings.avatarCircles ? height / 2 : height / 8
2020-10-08 21:11:21 +02:00
color: {
switch (TimelineManager.userPresence(userid)) {
case "online":
return "#00cc66";
case "unavailable":
return "#ff9933";
case "offline":
default:
// return "#a82353" don't show anything if offline, since it is confusing, if presence is disabled
"transparent";
}
}
}
2021-02-14 01:28:28 +01:00
CursorShape {
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
}
2019-09-07 22:22:07 +02:00
}