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