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: currentRoom.pushNotificationState === PushNotificationState.MentionKeyword || currentRoom.isLowPriority ? highlightCount > 0 : notificationCount > 0 0033 0034 signal selected 0035 0036 Accessible.name: root.displayName 0037 Accessible.onPressAction: select() 0038 0039 onPressAndHold: createRoomListContextMenu() 0040 0041 Keys.onSpacePressed: select() 0042 Keys.onEnterPressed: select() 0043 Keys.onReturnPressed: select() 0044 0045 TapHandler { 0046 acceptedButtons: Qt.RightButton | Qt.LeftButton 0047 onTapped: (eventPoint, button) => { 0048 if (button === Qt.RightButton) { 0049 root.createRoomListContextMenu(); 0050 } else { 0051 select(); 0052 } 0053 } 0054 } 0055 0056 contentItem: RowLayout { 0057 spacing: Kirigami.Units.largeSpacing 0058 0059 Components.Avatar { 0060 source: root.avatar ? "image://mxc/" + root.avatar : "" 0061 name: root.displayName 0062 visible: Config.showAvatarInRoomDrawer 0063 implicitHeight: Kirigami.Units.gridUnit + (Config.compactRoomList ? 0 : Kirigami.Units.largeSpacing * 2) 0064 implicitWidth: visible ? implicitHeight : 0 0065 0066 Layout.fillHeight: true 0067 Layout.preferredWidth: height 0068 } 0069 0070 ColumnLayout { 0071 spacing: 0 0072 0073 Layout.fillWidth: true 0074 Layout.alignment: Qt.AlignVCenter 0075 0076 QQC2.Label { 0077 id: label 0078 0079 text: root.displayName 0080 elide: Text.ElideRight 0081 font.weight: root.hasNotifications ? Font.Bold : Font.Normal 0082 textFormat: Text.PlainText 0083 0084 Layout.fillWidth: true 0085 Layout.alignment: subtitle.visible ? Qt.AlignLeft | Qt.AlignBottom : Qt.AlignLeft | Qt.AlignVCenter 0086 } 0087 0088 QQC2.Label { 0089 id: subtitle 0090 0091 text: root.subtitleText 0092 elide: Text.ElideRight 0093 font: Kirigami.Theme.smallFont 0094 opacity: root.hasNotifications ? 0.9 : 0.7 0095 visible: !Config.compactRoomList && text.length > 0 0096 textFormat: Text.PlainText 0097 0098 Layout.fillWidth: true 0099 Layout.alignment: visible ? Qt.AlignLeft | Qt.AlignTop : Qt.AlignLeft | Qt.AlignVCenter 0100 } 0101 } 0102 0103 Kirigami.Icon { 0104 source: "notifications-disabled" 0105 enabled: false 0106 implicitWidth: Kirigami.Units.iconSizes.smallMedium 0107 implicitHeight: Kirigami.Units.iconSizes.smallMedium 0108 visible: currentRoom.pushNotificationState === PushNotificationState.Mute && !configButton.visible 0109 Accessible.name: i18n("Muted room") 0110 Layout.rightMargin: Kirigami.Units.smallSpacing 0111 } 0112 0113 QQC2.Label { 0114 id: notificationCountLabel 0115 0116 text: currentRoom.pushNotificationState === PushNotificationState.MentionKeyword || currentRoom.isLowPriority ? root.highlightCount : root.notificationCount 0117 visible: root.hasNotifications && currentRoom.pushNotificationState !== PushNotificationState.Mute 0118 color: Kirigami.Theme.textColor 0119 horizontalAlignment: Text.AlignHCenter 0120 verticalAlignment: Text.AlignVCenter 0121 background: Rectangle { 0122 visible: root.hasNotifications 0123 Kirigami.Theme.colorSet: Kirigami.Theme.Button 0124 color: highlightCount > 0 ? Kirigami.Theme.positiveTextColor : Kirigami.Theme.disabledTextColor 0125 opacity: highlightCount > 0 ? 1 : 0.3 0126 radius: height / 2 0127 } 0128 0129 Layout.rightMargin: Kirigami.Units.smallSpacing 0130 Layout.minimumHeight: Kirigami.Units.iconSizes.smallMedium 0131 Layout.minimumWidth: Math.max(notificationCountTextMetrics.advanceWidth + Kirigami.Units.smallSpacing * 2, height) 0132 0133 TextMetrics { 0134 id: notificationCountTextMetrics 0135 text: notificationCountLabel.text 0136 } 0137 } 0138 0139 QQC2.Button { 0140 id: configButton 0141 visible: root.hovered && !Kirigami.Settings.isMobile && !Config.compactRoomList 0142 text: i18n("Configure room") 0143 display: QQC2.Button.IconOnly 0144 0145 icon.name: "configure" 0146 onClicked: createRoomListContextMenu() 0147 } 0148 } 0149 0150 function select() { 0151 RoomManager.resolveResource(currentRoom.id); 0152 root.selected(); 0153 } 0154 0155 function createRoomListContextMenu() { 0156 const component = Qt.createComponent("qrc:/org/kde/neochat/qml/ContextMenu.qml"); 0157 if (component.status === Component.Error) { 0158 console.error(component.errorString()); 0159 } 0160 const menu = component.createObject(root, { 0161 room: root.currentRoom, 0162 connection: root.connection 0163 }); 0164 if (!Kirigami.Settings.isMobile && !Config.compactRoomList) { 0165 configButton.visible = true; 0166 configButton.down = true; 0167 } 0168 menu.closed.connect(function () { 0169 configButton.down = undefined; 0170 configButton.visible = Qt.binding(() => { 0171 return root.hovered && !Kirigami.Settings.isMobile && !Config.compactRoomList; 0172 }); 0173 }); 0174 menu.open(); 0175 } 0176 }