Debian Codegraph @

resources/qml/dialogs/AllowedRoomsSettingsDialog.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 import ".."
6 import QtQuick
7 import QtQuick.Controls
8 import QtQuick.Layouts
9 import QtQuick.Window
10 import im.nheko
11
12 ApplicationWindow {
13 id: allowedDialog
14
15 property var roomSettings
16
17 minimumWidth: 340
18 minimumHeight: 450
19 width: 450
20 height: 680
21 color: palette.window
22 modality: Qt.NonModal
23 flags: Qt.Dialog | Qt.WindowCloseButtonHint | Qt.WindowTitleHint
24 title: qsTr("Allowed rooms settings")
25
26 Shortcut {
27 sequence: StandardKey.Cancel
28 onActivated: roomSettingsDialog.close()
29 }
30
31 ColumnLayout {
32 anchors.margins: Nheko.paddingMedium
33 anchors.fill: parent
34 spacing: 0
35
36
37 MatrixText {
38 text: qsTr("List of rooms that allow access to this room. Anyone who is in any of those rooms can join this room.")
39 font.pixelSize: Math.floor(fontMetrics.font.pixelSize * 1.1)
40 Layout.fillWidth: true
41 Layout.fillHeight: false
42 color: palette.text
43 Layout.bottomMargin: Nheko.paddingMedium
44 }
45
46 ListView {
47 Layout.fillWidth: true
48 Layout.fillHeight: true
49
50 id: view
51
52 clip: true
53
54
55 model: roomSettings.allowedRoomsModel
56 spacing: 4
57 cacheBuffer: 50
58
59 delegate: RowLayout {
60 anchors.left: parent.left
61 anchors.right: parent.right
62
63 ColumnLayout {
64 Layout.fillWidth: true
65 Text {
66 Layout.fillWidth: true
67 text: model.name
68 color: palette.text
69 textFormat: Text.PlainText
70 }
71
72 Text {
73 Layout.fillWidth: true
74 text: model.isParent ? qsTr("Parent community") : qsTr("Other room")
75 color: palette.buttonText
76 textFormat: Text.PlainText
77 }
78 }
79
80 ToggleButton {
81 checked: model.allowed
82 Layout.alignment: Qt.AlignRight
83 onCheckedChanged: model.allowed = checked
84 }
85 }
86 }
87
88 Column{
89 id: roomEntryCompleter
90 Layout.fillWidth: true
91
92 spacing: 1
93 z: 5
94
95 Completer {
96 id: roomCompleter
97
98 visible: roomEntry.text.length > 0
99 width: parent.width
100 roomId: allowedDialog.roomSettings.roomId
101 completerName: "room"
102 bottomToTop: true
103 fullWidth: true
104 avatarHeight: Nheko.avatarSize / 2
105 avatarWidth: Nheko.avatarSize / 2
106 centerRowContent: false
107 rowMargin: 2
108 rowSpacing: 2
109 }
110
111 MatrixTextField {
112 id: roomEntry
113
114 width: parent.width
115
116 placeholderText: qsTr("Enter additional rooms not in the list yet...")
117
118 color: palette.text
119 onTextEdited: {
120 roomCompleter.completer.searchString = text;
121 }
122 Keys.onPressed: {
123 if (event.key == Qt.Key_Up || event.key == Qt.Key_Backtab) {
124 event.accepted = true;
125 roomCompleter.up();
126 } else if (event.key == Qt.Key_Down || event.key == Qt.Key_Tab) {
127 event.accepted = true;
128 if (event.key == Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier))
129 roomCompleter.up();
130 else
131 roomCompleter.down();
132 } else if (event.matches(StandardKey.InsertParagraphSeparator)) {
133 roomCompleter.finishCompletion();
134 event.accepted = true;
135 }
136 }
137 }
138
139 }
140
141 Connections {
142 function onCompletionSelected(id) {
143 console.log("selected: " + id);
144 roomSettings.allowedRoomsModel.addRoom(id);
145 roomEntry.clear();
146 }
147
148 function onCountChanged() {
149 if (roomCompleter.count > 0 && (roomCompleter.currentIndex < 0 || roomCompleter.currentIndex >= roomCompleter.count))
150 roomCompleter.currentIndex = 0;
151
152 }
153
154 target: roomCompleter
155 }
156
157 }
158
159 footer: DialogButtonBox {
160 id: dbb
161
162 standardButtons: DialogButtonBox.Ok | DialogButtonBox.Cancel
163 onAccepted: {
164 roomSettings.applyAllowedFromModel();
165 allowedDialog.close();
166 }
167 onRejected: allowedDialog.close()
168 }
169
170 }