Debian Codegraph @

resources/qml/pages/UserSettingsPage.qml

raw
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 pragma ComponentBehavior: Bound
6 import ".."
7 import "../dialogs"
8 import QtQuick
9 import QtQuick.Controls
10 import QtQuick.Layouts
11 import QtQuick.Window
12 import im.nheko
13
14 Rectangle {
15 id: userSettingsDialog
16
17 property int collapsePoint: 600
18 property bool collapsed: width < collapsePoint
19 color: palette.window
20
21 ScrollView {
22 id: scroll
23
24 ScrollBar.horizontal.visible: false
25 anchors.fill: parent
26 anchors.topMargin: (collapsed? backButton.height : 0)+Nheko.paddingLarge
27 leftPadding: collapsed? Nheko.paddingMedium : Nheko.paddingLarge
28 bottomPadding: Nheko.paddingLarge
29 contentWidth: availableWidth
30
31 ColumnLayout {
32 id: grid
33
34 spacing: Nheko.paddingMedium
35
36 width: scroll.availableWidth
37 anchors.fill: parent
38 anchors.leftMargin: userSettingsDialog.collapsed ? 0 : (userSettingsDialog.width-userSettingsDialog.collapsePoint) * 0.4 + Nheko.paddingLarge
39 anchors.rightMargin: anchors.leftMargin
40
41
42 Repeater {
43 model: UserSettingsModel
44
45 delegate: GridLayout {
46 Layout.preferredWidth: scroll.availableWidth
47 columns: collapsed? 1 : 2
48 rows: collapsed? 2: 1
49 required property var model
50 id: r
51
52 Label {
53 Layout.alignment: Qt.AlignLeft
54 Layout.fillWidth: true
55 color: palette.text
56 text: model.name
57 //Layout.column: 0
58 Layout.columnSpan: (model.type == UserSettingsModel.SectionTitle && !userSettingsDialog.collapsed) ? 2 : 1
59 //Layout.row: model.index
60 //Layout.minimumWidth: implicitWidth
61 Layout.leftMargin: model.type == UserSettingsModel.SectionTitle ? 0 : Nheko.paddingMedium
62 Layout.topMargin: model.type == UserSettingsModel.SectionTitle ? Nheko.paddingLarge : 0
63 font.pointSize: 1.1 * fontMetrics.font.pointSize
64
65 HoverHandler {
66 id: hovered
67 enabled: model.description ?? false
68 }
69 ToolTip.visible: hovered.hovered && model.description
70 ToolTip.text: model.description ?? ""
71 ToolTip.delay: Nheko.tooltipDelay
72 wrapMode: Text.Wrap
73 }
74
75 DelegateChooser {
76 id: chooser
77
78 roleValue: model.type
79 Layout.alignment: Qt.AlignRight
80
81 Layout.columnSpan: (model.type == UserSettingsModel.SectionTitle && !userSettingsDialog.collapsed) ? 2 : 1
82 Layout.preferredHeight: child.height
83 Layout.preferredWidth: child.implicitWidth
84 Layout.maximumWidth: model.type == UserSettingsModel.SectionTitle ? Number.POSITIVE_INFINITY : 400
85 Layout.fillWidth: model.type == UserSettingsModel.SectionTitle || model.type == UserSettingsModel.Options || model.type == UserSettingsModel.Number
86 Layout.rightMargin: model.type == UserSettingsModel.SectionTitle ? 0 : Nheko.paddingMedium
87
88 DelegateChoice {
89 roleValue: UserSettingsModel.Toggle
90 ToggleButton {
91 checked: model.value
92 onCheckedChanged: model.value = checked
93 enabled: model.enabled
94 }
95 }
96 DelegateChoice {
97 roleValue: UserSettingsModel.Options
98 ComboBox {
99 anchors.right: parent.right
100 model: r.model.values
101 currentIndex: r.model.value
102 width: Math.min(implicitWidth, scroll.availableWidth - Nheko.paddingMedium)
103 onCurrentIndexChanged: r.model.value = currentIndex
104 implicitContentWidthPolicy: ComboBox.WidestTextWhenCompleted
105
106 WheelHandler{} // suppress scrolling changing values
107 }
108 }
109 DelegateChoice {
110 roleValue: UserSettingsModel.Integer
111
112 SpinBox {
113 anchors.right: parent.right
114 from: model.valueLowerBound
115 to: model.valueUpperBound
116 stepSize: model.valueStep
117 value: model.value
118 onValueChanged: model.value = value
119 editable: true
120
121 WheelHandler{} // suppress scrolling changing values
122 }
123 }
124 DelegateChoice {
125 roleValue: UserSettingsModel.Double
126
127 SpinBox {
128 id: spinbox
129
130 readonly property double div: 100
131 readonly property int decimals: 2
132
133 anchors.right: parent.right
134 from: model.valueLowerBound * div
135 to: model.valueUpperBound * div
136 stepSize: model.valueStep * div
137 value: model.value * div
138 onValueChanged: model.value = value/div
139 editable: true
140
141 property real realValue: value / div
142
143 validator: DoubleValidator {
144 bottom: Math.min(spinbox.from/spinbox.div, spinbox.to/spinbox.div)
145 top: Math.max(spinbox.from/spinbox.div, spinbox.to/spinbox.div)
146 }
147
148 textFromValue: function(value, locale) {
149 return Number(value / spinbox.div).toLocaleString(locale, 'f', spinbox.decimals)
150 }
151
152 valueFromText: function(text, locale) {
153 return Number.fromLocaleString(locale, text) * spinbox.div
154 }
155
156 WheelHandler{} // suppress scrolling changing values
157 }
158 }
159 DelegateChoice {
160 roleValue: UserSettingsModel.ReadOnlyText
161 TextEdit {
162 color: palette.text
163 text: model.value
164 readOnly: true
165 textFormat: Text.PlainText
166 }
167 }
168 DelegateChoice {
169 roleValue: UserSettingsModel.SectionTitle
170 Item {
171 width: grid.width
172 height: fontMetrics.lineSpacing
173 Rectangle {
174 anchors.topMargin: Nheko.paddingSmall
175 anchors.top: parent.top
176 anchors.left: parent.left
177 anchors.right: parent.right
178 color: palette.buttonText
179 height: 1
180 }
181 }
182 }
183 DelegateChoice {
184 roleValue: UserSettingsModel.KeyStatus
185 Text {
186 color: model.good ? "green" : Nheko.theme.error
187 text: model.value ? qsTr("CACHED") : qsTr("NOT CACHED")
188 }
189 }
190 DelegateChoice {
191 roleValue: UserSettingsModel.SessionKeyImportExport
192 RowLayout {
193 Button {
194 text: qsTr("IMPORT")
195 onClicked: UserSettingsModel.importSessionKeys()
196 }
197 Button {
198 text: qsTr("EXPORT")
199 onClicked: UserSettingsModel.exportSessionKeys()
200 }
201 }
202 }
203 DelegateChoice {
204 roleValue: UserSettingsModel.XSignKeysRequestDownload
205 RowLayout {
206 Button {
207 text: qsTr("DOWNLOAD")
208 onClicked: UserSettingsModel.downloadCrossSigningSecrets()
209 }
210 Button {
211 text: qsTr("REQUEST")
212 onClicked: UserSettingsModel.requestCrossSigningSecrets()
213 }
214 }
215 }
216 DelegateChoice {
217 roleValue: UserSettingsModel.ConfigureHiddenEvents
218 Button {
219 text: qsTr("CONFIGURE")
220 onClicked: {
221 var dialog = hiddenEventsDialog.createObject();
222 dialog.show();
223 destroyOnClose(dialog);
224 }
225
226 Component {
227 id: hiddenEventsDialog
228
229 HiddenEventsDialog {}
230 }
231 }
232 }
233
234 DelegateChoice {
235 roleValue: UserSettingsModel.ManageIgnoredUsers
236 Button {
237 text: qsTr("MANAGE")
238 onClicked: {
239 var dialog = ignoredUsersDialog.createObject();
240 dialog.show();
241 destroyOnClose(dialog);
242 }
243
244 Component {
245 id: ignoredUsersDialog
246
247 IgnoredUsers {}
248 }
249 }
250 }
251
252 DelegateChoice {
253 Text {
254 text: model.value
255 }
256 }
257 }
258 }
259 }
260 }
261 }
262
263 ImageButton {
264 id: backButton
265 anchors.top: parent.top
266 anchors.left: parent.left
267 anchors.margins: Nheko.paddingMedium
268 width: Nheko.avatarSize
269 height: Nheko.avatarSize
270 image: ":/icons/icons/ui/angle-arrow-left.svg"
271 ToolTip.visible: hovered
272 ToolTip.text: qsTr("Back")
273 onClicked: mainWindow.pop()
274 }
275
276 }
277