Debian Codegraph @

resources/qml/CommunitiesList.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import "./components"
6 import QtQml
7 import QtQuick
8 import QtQuick.Controls
9 import QtQuick.Layouts
10 import im.nheko
11
12 Page {
13 id: communitySidebar
14
15 //leftPadding: Nheko.paddingSmall
16 //rightPadding: Nheko.paddingSmall
17 property int avatarSize: Math.ceil(fontMetrics.lineSpacing * 1.6)
18 property bool collapsed: false
19
20 background: Rectangle {
21 color: Nheko.theme.sidebarBackground
22 }
23
24 // HACK: https://bugreports.qt.io/browse/QTBUG-83972, qtwayland cannot auto hide menu
25 Connections {
26 function onHideMenu() {
27 communityContextMenu.close();
28 }
29
30 target: MainWindow
31 }
32 ListView {
33 id: communitiesList
34
35 anchors.left: parent.left
36 anchors.right: parent.right
37 height: parent.height
38 model: Communities.filtered()
39 boundsBehavior: Flickable.StopAtBounds
40
41 ScrollBar.vertical: ScrollBar {
42 id: scrollbar
43
44 parent: !collapsed && Settings.scrollbarsInRoomlist ? communitiesList : null
45 }
46 delegate: ItemDelegate {
47 id: communityItem
48
49 property color backgroundColor: palette.window
50 property color bubbleBackground: palette.highlight
51 property color bubbleText: palette.highlightedText
52 property color importantText: palette.text
53 required property var model
54 property color unimportantText: palette.buttonText
55
56 ToolTip.delay: Nheko.tooltipDelay
57 ToolTip.text: model.tooltip
58 ToolTip.visible: hovered && collapsed
59 height: avatarSize + 2 * Nheko.paddingMedium
60 state: "normal"
61 width: ListView.view.width - ((scrollbar.interactive && scrollbar.visible && scrollbar.parent) ? scrollbar.width : 0)
62
63 topInset: 0
64 bottomInset: 0
65 leftInset: 0
66 rightInset: 0
67
68 background: Rectangle {
69 color: communityItem.backgroundColor
70 }
71 states: [
72 State {
73 name: "highlight"
74 when: (communityItem.hovered || model.hidden) && !(Communities.currentTagId === model.id)
75
76 PropertyChanges {
77 communityItem {
78 backgroundColor: palette.dark
79 bubbleBackground: palette.highlight
80 bubbleText: palette.highlightedText
81 importantText: palette.brightText
82 unimportantText: palette.brightText
83 }
84 }
85 },
86 State {
87 name: "selected"
88 when: Communities.currentTagId == model.id
89
90 PropertyChanges {
91 communityItem {
92 backgroundColor: palette.highlight
93 bubbleBackground: palette.highlightedText
94 bubbleText: palette.highlight
95 importantText: palette.highlightedText
96 unimportantText: palette.highlightedText
97 }
98 }
99 }
100 ]
101
102 onClicked: Communities.setCurrentTagId(model.id)
103 onPressAndHold: communityContextMenu.show(communityItem, model.id, model.hidden, model.muted)
104
105 Item {
106 anchors.fill: parent
107
108 TapHandler {
109 id: rth
110 acceptedButtons: Qt.RightButton
111 acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus | PointerDevice.TouchPad
112 gesturePolicy: TapHandler.ReleaseWithinBounds
113
114 onSingleTapped: communityContextMenu.show(rth, model.id, model.hidden, model.muted)
115 }
116 }
117 RowLayout {
118 id: r
119
120 anchors.fill: parent
121 anchors.leftMargin: Nheko.paddingMedium + (communitySidebar.collapsed ? 0 : (fontMetrics.lineSpacing * model.depth))
122 anchors.margins: Nheko.paddingMedium
123 spacing: Nheko.paddingMedium
124
125 ImageButton {
126 Layout.alignment: Qt.AlignVCenter
127 Layout.preferredHeight: fontMetrics.lineSpacing
128 Layout.preferredWidth: fontMetrics.lineSpacing
129 ToolTip.delay: Nheko.tooltipDelay
130 ToolTip.text: model.collapsed ? qsTr("Expand") : qsTr("Collapse")
131 ToolTip.visible: hovered
132 hoverEnabled: true
133 image: model.collapsed ? ":/icons/icons/ui/collapsed.svg" : ":/icons/icons/ui/expanded.svg"
134 visible: !communitySidebar.collapsed && model.collapsible
135
136 onClicked: model.collapsed = !model.collapsed
137 }
138 Item {
139 Layout.preferredWidth: fontMetrics.lineSpacing
140 visible: !communitySidebar.collapsed && !model.collapsible && Communities.containsSubspaces
141 }
142 Avatar {
143 id: avatar
144
145 Layout.alignment: Qt.AlignVCenter
146 color: communityItem.backgroundColor
147 displayName: model.displayName
148 enabled: false
149 Layout.preferredHeight: avatarSize
150 roomid: model.id
151 textColor: model.avatarUrl?.startsWith(":/") == true ? communityItem.unimportantText : communityItem.importantText
152 url: {
153 if (model.avatarUrl?.startsWith("mxc://") == true)
154 return model.avatarUrl.replace("mxc://", "image://MxcImage/");
155 else if ((model.avatarUrl?.length ?? 0) > 0)
156 return model.avatarUrl;
157 else
158 return "";
159 }
160 Layout.preferredWidth: avatarSize
161
162 NotificationBubble {
163 anchors.bottom: avatar.bottom
164 anchors.margins: -Nheko.paddingSmall
165 anchors.right: avatar.right
166 bubbleBackgroundColor: communityItem.bubbleBackground
167 bubbleTextColor: communityItem.bubbleText
168 font.pixelSize: fontMetrics.font.pixelSize * 0.6
169 hasLoudNotification: model.hasLoudNotification
170 mayBeVisible: communitySidebar.collapsed && !model.muted && Settings.spaceNotifications
171 notificationCount: model.unreadMessages
172 }
173 }
174 ElidedLabel {
175 Layout.alignment: Qt.AlignVCenter
176 Layout.fillWidth: true
177 color: communityItem.importantText
178 elideWidth: width
179 fullText: model.displayName
180 textFormat: Text.PlainText
181 visible: !communitySidebar.collapsed
182 }
183 Item {
184 Layout.fillWidth: true
185 }
186 NotificationBubble {
187 Layout.alignment: Qt.AlignRight
188 Layout.leftMargin: Nheko.paddingSmall
189 bubbleBackgroundColor: communityItem.bubbleBackground
190 bubbleTextColor: communityItem.bubbleText
191 hasLoudNotification: model.hasLoudNotification
192 mayBeVisible: !communitySidebar.collapsed && !model.muted && Settings.spaceNotifications
193 notificationCount: model.unreadMessages
194 }
195 }
196 }
197
198 Menu {
199 id: communityContextMenu
200
201 property bool hidden
202 property bool muted
203 property string tagId
204
205 function show(parent, id_, hidden_, muted_) {
206 tagId = id_;
207 hidden = hidden_;
208 muted = muted_;
209 popup(parent);
210 }
211
212 Component.onCompleted: {
213 if (communityContextMenu.popupType != undefined) {
214 communityContextMenu.popupType = 2; // Popup.Native with fallback on older Qt (<6.8.0)
215 }
216 }
217
218
219 MenuItem {
220 checkable: true
221 checked: communityContextMenu.muted
222 text: qsTr("Do not show notification counts for this community or tag.")
223
224 onTriggered: Communities.toggleTagMute(communityContextMenu.tagId)
225 }
226 MenuItem {
227 checkable: true
228 checked: communityContextMenu.hidden
229 text: qsTr("Hide rooms with this tag or from this community by default.")
230
231 onTriggered: Communities.toggleTagId(communityContextMenu.tagId)
232 }
233 }
234 }
235 }