2023-02-21 23:48:49 +01:00
|
|
|
// SPDX-FileCopyrightText: Nheko Contributors
|
2021-03-07 05:57:56 +01:00
|
|
|
//
|
2021-03-05 00:35:15 +01:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2021-01-11 23:50:26 +01:00
|
|
|
import "./ui"
|
2022-01-01 16:38:52 +01:00
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
2021-12-13 19:09:03 +01:00
|
|
|
import QtQuick.Window 2.15
|
2020-06-24 16:24:22 +02:00
|
|
|
import im.nheko 1.0
|
|
|
|
|
2022-02-24 03:16:39 +01:00
|
|
|
AbstractButton {
|
2020-10-08 21:11:21 +02:00
|
|
|
id: avatar
|
|
|
|
|
2023-06-02 01:45:24 +02:00
|
|
|
property alias color: bg.color
|
|
|
|
property bool crop: true
|
2020-10-08 21:11:21 +02:00
|
|
|
property string displayName
|
2023-06-02 01:45:24 +02:00
|
|
|
property string roomid
|
2021-06-11 13:12:43 +02:00
|
|
|
property alias textColor: label.color
|
2023-06-02 01:45:24 +02:00
|
|
|
property string url
|
|
|
|
property string userid
|
2021-01-12 02:02:39 +01:00
|
|
|
|
2020-10-08 21:11:21 +02:00
|
|
|
height: 48
|
2023-06-02 01:45:24 +02:00
|
|
|
width: 48
|
|
|
|
|
2022-02-24 03:16:39 +01:00
|
|
|
background: Rectangle {
|
|
|
|
id: bg
|
2023-06-02 01:45:24 +02:00
|
|
|
|
2023-06-02 01:29:05 +02:00
|
|
|
color: palette.alternateBase
|
2023-06-02 01:45:24 +02:00
|
|
|
radius: Settings.avatarCircles ? height / 2 : height / 8
|
2022-02-24 03:16:39 +01:00
|
|
|
}
|
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
|
2023-06-02 01:45:24 +02:00
|
|
|
color: palette.text
|
|
|
|
enabled: false
|
|
|
|
font.pixelSize: avatar.height / 2
|
|
|
|
horizontalAlignment: Text.AlignHCenter
|
2023-06-19 21:24:31 +02:00
|
|
|
text: TimelineManager.escapeEmoji(avatar.displayName ? String.fromCodePoint(avatar.displayName.codePointAt(0)) : "")
|
2020-10-08 21:11:21 +02:00
|
|
|
textFormat: Text.RichText
|
|
|
|
verticalAlignment: Text.AlignVCenter
|
2020-12-25 15:14:00 +01:00
|
|
|
visible: img.status != Image.Ready && !Settings.useIdenticon
|
2020-10-08 21:11:21 +02:00
|
|
|
}
|
2020-12-25 15:14:00 +01:00
|
|
|
Image {
|
|
|
|
id: identicon
|
2021-09-18 00:21:14 +02:00
|
|
|
|
2020-12-25 15:14:00 +01:00
|
|
|
anchors.fill: parent
|
2023-06-19 21:24:31 +02:00
|
|
|
source: Settings.useIdenticon ? ("image://jdenticon/" + (avatar.userid !== "" ? avatar.userid : avatar.roomid) + "?radius=" + (Settings.avatarCircles ? 100 : 25)) : ""
|
2023-06-02 01:45:24 +02:00
|
|
|
visible: Settings.useIdenticon && img.status != Image.Ready
|
2020-12-25 15:14:00 +01:00
|
|
|
}
|
2020-10-08 21:11:21 +02:00
|
|
|
Image {
|
|
|
|
id: img
|
2019-11-03 01:17:40 +01:00
|
|
|
|
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
|
2023-06-02 23:03:56 +02:00
|
|
|
source: if (avatar.url.startsWith('image://colorimage')) {
|
|
|
|
return avatar.url + "&radius=" + (Settings.avatarCircles ? 100 : 25) + ((avatar.crop) ? "" : "&scale");
|
|
|
|
} else if (avatar.url.startsWith('image://')) {
|
2023-05-25 19:07:13 +02:00
|
|
|
return avatar.url + "?radius=" + (Settings.avatarCircles ? 100 : 25) + ((avatar.crop) ? "" : "&scale");
|
|
|
|
} else if (avatar.url.startsWith(':/')) {
|
2023-06-19 21:24:31 +02:00
|
|
|
return "image://colorimage/" + avatar.url + "?" + label.color;
|
2023-05-25 19:07:13 +02:00
|
|
|
} else {
|
|
|
|
return "";
|
|
|
|
}
|
2023-06-02 01:45:24 +02:00
|
|
|
sourceSize.height: avatar.height * Screen.devicePixelRatio
|
|
|
|
sourceSize.width: avatar.width * Screen.devicePixelRatio
|
2020-10-08 21:11:21 +02:00
|
|
|
}
|
|
|
|
Rectangle {
|
2021-12-30 04:54:03 +01:00
|
|
|
id: onlineIndicator
|
|
|
|
|
|
|
|
function updatePresence() {
|
2023-06-19 21:24:31 +02:00
|
|
|
switch (Presence.userPresence(avatar.userid)) {
|
2020-10-08 21:11:21 +02:00
|
|
|
case "online":
|
2022-10-01 23:57:02 +02:00
|
|
|
return Nheko.theme.online;
|
2020-10-08 21:11:21 +02:00
|
|
|
case "unavailable":
|
2022-10-01 23:57:02 +02:00
|
|
|
return Nheko.theme.unavailable;
|
2020-10-08 21:11:21 +02:00
|
|
|
case "offline":
|
|
|
|
default:
|
|
|
|
// return "#a82353" don't show anything if offline, since it is confusing, if presence is disabled
|
2021-12-30 04:54:03 +01:00
|
|
|
return "transparent";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-02 01:45:24 +02:00
|
|
|
anchors.bottom: avatar.bottom
|
|
|
|
anchors.right: avatar.right
|
|
|
|
color: updatePresence()
|
|
|
|
height: avatar.height / 6
|
|
|
|
radius: Settings.avatarCircles ? height / 2 : height / 8
|
2023-06-19 21:24:31 +02:00
|
|
|
visible: !!avatar.userid
|
2023-06-02 01:45:24 +02:00
|
|
|
width: height
|
2021-12-30 04:54:03 +01:00
|
|
|
|
2023-06-02 01:45:24 +02:00
|
|
|
Connections {
|
2021-12-30 04:54:03 +01:00
|
|
|
function onPresenceChanged(id) {
|
2023-06-19 21:24:31 +02:00
|
|
|
if (id == avatar.userid)
|
2023-06-02 01:45:24 +02:00
|
|
|
onlineIndicator.color = onlineIndicator.updatePresence();
|
2020-10-08 21:11:21 +02:00
|
|
|
}
|
2023-06-02 01:45:24 +02:00
|
|
|
|
|
|
|
target: Presence
|
2020-10-08 21:11:21 +02:00
|
|
|
}
|
|
|
|
}
|
2023-06-19 01:38:40 +02:00
|
|
|
NhekoCursorShape {
|
2021-02-14 01:28:28 +01:00
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
}
|
2022-01-02 06:22:27 +01:00
|
|
|
Ripple {
|
2023-06-02 01:29:05 +02:00
|
|
|
color: Qt.rgba(palette.alternateBase.r, palette.alternateBase.g, palette.alternateBase.b, 0.5)
|
2022-01-02 06:22:27 +01:00
|
|
|
}
|
2019-09-07 22:22:07 +02:00
|
|
|
}
|