matrixion/qml/Avatar.qml

99 lines
3.1 KiB
QML
Raw Normal View History

2021-03-05 02:35:15 +03:00
// SPDX-FileCopyrightText: 2021 Nheko Contributors
// SPDX-FileCopyrightText: 2022 Nheko Contributors
2021-03-05 02:35:15 +03:00
// SPDX-License-Identifier: GPL-3.0-or-later
2022-04-16 03:13:01 +03:00
import "ui"
import QtQuick 2.15
import QtQuick.Controls 2.15
import QtQuick.Window 2.15
import im.nheko
2020-06-24 17:24:22 +03:00
AbstractButton {
2020-10-08 22:11:21 +03:00
id: avatar
2022-04-16 03:13:01 +03:00
property alias color: bg.color
property bool crop: true
2020-10-08 22:11:21 +03:00
property string displayName
2022-04-16 03:13:01 +03:00
property string roomid
2021-06-11 14:12:43 +03:00
property alias textColor: label.color
2022-04-16 03:13:01 +03:00
property string url
property string userid
2021-01-12 04:02:39 +03:00
2020-10-08 22:11:21 +03:00
height: 48
2022-04-16 03:13:01 +03:00
width: 48
background: Rectangle {
id: bg
2022-04-11 05:18:16 +03:00
color: timelineRoot.palette.alternateBase
2022-04-16 03:13:01 +03:00
radius: Settings.avatarCircles ? height / 2 : height / 8
}
2019-09-07 23:22:07 +03:00
2020-10-08 22:11:21 +03:00
Label {
2021-06-11 14:12:43 +03:00
id: label
2020-10-08 22:11:21 +03:00
anchors.fill: parent
2022-04-16 03:13:01 +03:00
color: timelineRoot.palette.text
enabled: false
font.pixelSize: avatar.height / 2
horizontalAlignment: Text.AlignHCenter
2020-10-08 22:11:21 +03:00
text: TimelineManager.escapeEmoji(displayName ? String.fromCodePoint(displayName.codePointAt(0)) : "")
textFormat: Text.RichText
verticalAlignment: Text.AlignVCenter
2020-12-25 17:14:00 +03:00
visible: img.status != Image.Ready && !Settings.useIdenticon
2020-10-08 22:11:21 +03:00
}
2020-12-25 17:14:00 +03:00
Image {
id: identicon
anchors.fill: parent
2021-09-07 04:11:37 +03:00
source: Settings.useIdenticon ? ("image://jdenticon/" + (userid !== "" ? userid : roomid) + "?radius=" + (Settings.avatarCircles ? 100 : 25)) : ""
2022-04-16 03:13:01 +03:00
visible: Settings.useIdenticon && img.status != Image.Ready
2020-12-25 17:14:00 +03:00
}
2020-10-08 22:11:21 +03:00
Image {
id: img
anchors.fill: parent
asynchronous: true
2021-08-06 02:45:47 +03:00
fillMode: avatar.crop ? Image.PreserveAspectCrop : Image.PreserveAspectFit
2020-10-08 22:11:21 +03:00
mipmap: true
smooth: true
source: avatar.url ? (avatar.url + "?radius=" + (Settings.avatarCircles ? 100 : 25) + ((avatar.crop) ? "" : "&scale")) : ""
2022-04-16 03:13:01 +03:00
sourceSize.height: avatar.height * Screen.devicePixelRatio
sourceSize.width: avatar.width * Screen.devicePixelRatio
2020-10-08 22:11:21 +03:00
}
Rectangle {
id: onlineIndicator
function updatePresence() {
switch (Presence.userPresence(userid)) {
2020-10-08 22:11:21 +03:00
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
return "transparent";
}
}
2022-04-16 03:13:01 +03:00
anchors.bottom: avatar.bottom
anchors.right: avatar.right
color: updatePresence()
height: avatar.height / 6
radius: Settings.avatarCircles ? height / 2 : height / 8
visible: !!userid
width: height
2022-04-16 03:13:01 +03:00
Connections {
function onPresenceChanged(id) {
2022-04-16 03:13:01 +03:00
if (id == userid)
onlineIndicator.color = onlineIndicator.updatePresence();
2020-10-08 22:11:21 +03:00
}
2022-04-16 03:13:01 +03:00
target: Presence
2020-10-08 22:11:21 +03:00
}
}
NhekoCursorShape {
2021-02-14 03:28:28 +03:00
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
}
Ripple {
2022-04-11 05:18:16 +03:00
color: Qt.rgba(timelineRoot.palette.alternateBase.r, timelineRoot.palette.alternateBase.g, timelineRoot.palette.alternateBase.b, 0.5)
}
2019-09-07 23:22:07 +03:00
}