Warning, /network/neochat/src/qml/RoomDelegate.qml is written in an unsupported language. File is not indexed.

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: GPL-3.0-or-later
0003 
0004 import QtQuick
0005 import QtQuick.Controls as QQC2
0006 import QtQuick.Layouts
0007 import QtQml.Models
0008 
0009 import org.kde.kirigami as Kirigami
0010 import org.kde.kirigamiaddons.delegates as Delegates
0011 import org.kde.kirigamiaddons.labs.components as Components
0012 import org.kde.kitemmodels
0013 
0014 import org.kde.neochat
0015 import org.kde.neochat.config
0016 
0017 Delegates.RoundedItemDelegate {
0018     id: root
0019 
0020     required property int index
0021     required property int notificationCount
0022     required property int highlightCount
0023     required property NeoChatRoom currentRoom
0024     required property NeoChatConnection connection
0025     required property bool categoryVisible
0026     required property string filterText
0027     required property string avatar
0028     required property string subtitleText
0029 
0030     required property string displayName
0031 
0032     readonly property bool hasNotifications: notificationCount > 0
0033 
0034     signal selected()
0035 
0036     Accessible.name: root.displayName
0037     Accessible.onPressAction: selected()
0038     Keys.onSpacePressed: selected()
0039     Keys.onEnterPressed: selected()
0040 
0041     onPressAndHold: createRoomListContextMenu()
0042 
0043     TapHandler {
0044         acceptedButtons: Qt.RightButton | Qt.LeftButton
0045         onTapped: (eventPoint, button) => {
0046             if (button === Qt.RightButton) {
0047                 root.createRoomListContextMenu();
0048             } else {
0049                 root.selected();
0050             }
0051         }
0052     }
0053 
0054     contentItem: RowLayout {
0055         spacing: Kirigami.Units.largeSpacing
0056 
0057         Components.Avatar {
0058             source: root.avatar ? "image://mxc/" +  root.avatar : ""
0059             name: root.displayName
0060             visible: Config.showAvatarInRoomDrawer
0061             implicitHeight: Kirigami.Units.gridUnit + (Config.compactRoomList ? 0 : Kirigami.Units.largeSpacing * 2)
0062             implicitWidth: visible ? implicitHeight : 0
0063 
0064             Layout.fillHeight: true
0065             Layout.preferredWidth: height
0066         }
0067 
0068         ColumnLayout {
0069             spacing: 0
0070 
0071             Layout.fillWidth: true
0072             Layout.alignment: Qt.AlignVCenter
0073 
0074             QQC2.Label {
0075                 id: label
0076 
0077                 text: root.displayName
0078                 elide: Text.ElideRight
0079                 font.weight: root.hasNotifications ? Font.Bold : Font.Normal
0080                 textFormat: Text.PlainText
0081 
0082                 Layout.fillWidth: true
0083                 Layout.alignment: subtitle.visible ? Qt.AlignLeft | Qt.AlignBottom : Qt.AlignLeft | Qt.AlignVCenter
0084             }
0085 
0086             QQC2.Label {
0087                 id: subtitle
0088 
0089                 text: root.subtitleText
0090                 elide: Text.ElideRight
0091                 font: Kirigami.Theme.smallFont
0092                 opacity: root.hasNotifications ? 0.9 : 0.7
0093                 visible: !Config.compactRoomList
0094                 textFormat: Text.PlainText
0095 
0096                 Layout.fillWidth: true
0097                 Layout.alignment: visible ? Qt.AlignLeft | Qt.AlignTop : Qt.AlignLeft | Qt.AlignVCenter
0098             }
0099         }
0100 
0101         Kirigami.Icon {
0102             source: "notifications-disabled"
0103             enabled: false
0104             implicitWidth: Kirigami.Units.iconSizes.smallMedium
0105             implicitHeight: Kirigami.Units.iconSizes.smallMedium
0106             visible: currentRoom.pushNotificationState === PushNotificationState.Mute && !configButton.visible && !hasNotifications
0107             Accessible.name: i18n("Muted room")
0108             Layout.rightMargin: Kirigami.Units.smallSpacing
0109         }
0110 
0111         QQC2.Label {
0112             id: notificationCountLabel
0113 
0114             text: root.notificationCount
0115             visible: root.hasNotifications
0116             color: Kirigami.Theme.textColor
0117             horizontalAlignment: Text.AlignHCenter
0118             background: Rectangle {
0119                 visible: notificationCount > 0
0120                 Kirigami.Theme.colorSet: Kirigami.Theme.Button
0121                 color: highlightCount > 0 ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.disabledTextColor
0122                 opacity: highlightCount > 0 ? 1 : 0.3
0123                 radius: height / 2
0124             }
0125 
0126             Layout.rightMargin: Kirigami.Units.smallSpacing
0127             Layout.minimumHeight: Kirigami.Units.iconSizes.smallMedium
0128             Layout.minimumWidth: Math.max(notificationCountTextMetrics.advanceWidth + Kirigami.Units.smallSpacing * 2, height)
0129 
0130             TextMetrics {
0131                 id: notificationCountTextMetrics
0132                 text: notificationCountLabel.text
0133             }
0134         }
0135 
0136         QQC2.Button {
0137             id: configButton
0138             visible: root.hovered && !Kirigami.Settings.isMobile && !Config.compactRoomList
0139             text: i18n("Configure room")
0140             display: QQC2.Button.IconOnly
0141 
0142             icon.name: "configure"
0143             onClicked: createRoomListContextMenu()
0144         }
0145     }
0146 
0147     function createRoomListContextMenu() {
0148         const component = Qt.createComponent("qrc:/org/kde/neochat/qml/ContextMenu.qml")
0149         if (component.status === Component.Error) {
0150             console.error(component.errorString());
0151         }
0152         const menu = component.createObject(root, {
0153             room: root.currentRoom,
0154             connection: root.connection
0155         });
0156         if (!Kirigami.Settings.isMobile && !Config.compactRoomList) {
0157             configButton.visible = true;
0158             configButton.down = true;
0159         }
0160         menu.closed.connect(function() {
0161             configButton.down = undefined;
0162             configButton.visible = Qt.binding(() => {
0163                 return root.hovered && !Kirigami.Settings.isMobile
0164                     && !Config.compactRoomList;
0165             });
0166         })
0167         menu.open()
0168     }
0169 }