MauiKit Controls

SettingsDialog.qml
1import org.mauikit.controls 1.3 as Maui
2import QtQuick.Controls
3import QtQuick.Layouts
4import QtQuick
5
6/**
7 * @inherit QtQuick.Loader
8 *
9 * @brief A popup page with a scrollable vertical layout, and support for a stack of multiple pages.
10 * The default container fo this control is a MauiKit SettingsPage, and the popup will snap to the window full size on constrained spaces.
11 * @see SettingsPage
12 *
13 * You can add multiple sub pages to this control by making use of the SettingsPage control and the `addPage` function.
14 * By using the SettingsPage you can expect to have a way to navigate between the control sub pages.
15 * The code snippet below shows a quick demo on how to do it.
16 * @see addPage
17 *
18 * @image html Misc/settingsdialog.png
19 *
20 * @note This control is mostly use for presenting a group of configuration settings to the user. Usually it is populated with sections SectionGroup containing FlexSectionItem.
21 *
22 * @code
23 * Maui.SettingsDialog
24 * {
25 * id: _settingsDialog
26 *
27 * Maui.FlexSectionItem
28 * {
29 * label1.text: "SSetting Subpage"
30 * label2.text: "Click me to add a new page"
31 *
32 * ToolButton
33 * {
34 * icon.name: "go-next"
35 * checkable: true
36 * onToggled: _settingsDialog.addPage(_settingsPage2)
37 * }
38 * }
39 *
40 * Maui.SectionGroup
41 * {
42 * title: "First Section"
43 *
44 * Maui.FlexSectionItem
45 * {
46 * label1.text: "Configuration title"
47 * label2.text: "Description text"
48 *
49 * Button
50 * {
51 * text: "Test"
52 * }
53 * }
54 *
55 * Maui.FlexSectionItem
56 * {
57 * label1.text: "Configuration title"
58 * label2.text: "Description text"
59 *
60 * Switch {}
61 * }
62 *
63 * Maui.FlexSectionItem
64 * {
65 * label1.text: "Configuration title"
66 * label2.text: "Description text"
67 *
68 * Switch {}
69 * }
70 * }
71 *
72 * Maui.SectionGroup
73 * {
74 * title: "A Second Section"
75 *
76 * Maui.FlexSectionItem
77 * {
78 * label1.text: "Configuration title"
79 * label2.text: "Description text"
80 *
81 * Switch {}
82 * }
83 *
84 * Maui.FlexSectionItem
85 * {
86 * label1.text: "Configuration title"
87 * label2.text: "Description text"
88 * wide: false
89 * TextField
90 * {
91 * Layout.fillWidth: true
92 * }
93 * }
94 *
95 * Maui.FlexSectionItem
96 * {
97 * label1.text: "Configuration title"
98 * label2.text: "Description text"
99 *
100 * Switch {}
101 * }
102 * }
103 *
104 * Component
105 * {
106 * id: _settingsPage2
107 *
108 * Maui.SettingsPage
109 * {
110 * title: "Page2"
111 *
112 * Maui.FlexSectionItem
113 * {
114 * label1.text: "Configuration title"
115 * label2.text: "Description text"
116 *
117 * Switch {}
118 * }
119 * }
120 * }
121 * }
122 * @endcode
123 *
124 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/SettingsDialog.qml">You can find a more complete example at this link.</a>
125 */
126
127Loader
128{
129 id: control
130
131 /**
132 * @brief By default all the children content will be placed into a MauiKit SettingsPage, which has a scrollable column layout.
133 * @property list<QtObject> SettingsDialog::content
134 */
135 default property list<QtObject> content
136 Maui.Controls.title: i18n("Settings")
137
138 Component
139 {
140 id: _appComponent
141
142 Maui.DialogWindow
143 {
144 id: _window
145 width: 400
146 maximumWidth: 800
147 height: Math.max(500, Math.min(900, implicitHeight))
148 modality: Qt.ApplicationModal
149
150 readonly property int implicitHeight: Math.max(_content.implicitHeight, _stackView.currentItem.implicitHeight)+_stackView.topPadding + _stackView.bottomPadding
152 title: _stackView.currentItem.title ? _stackView.currentItem.title : ""
153 onClosing: (close) =>
154 {
155 _window.hide()
156 close.accepted = true
157 }
158
159 readonly property alias stackView: _stackView
160
161 page.headBar.forceCenterMiddleContent: true
162 page.headBar.leftContent: ToolButton
163 {
164 icon.name: "go-previous"
165 visible: _stackView.depth > 1
166
167 onClicked: _stackView.pop()
168 }
169
170 StackView
171 {
172 id: _stackView
173 anchors.fill: parent
174
175 initialItem: Maui.SettingsPage
176 {
177 id:_content
178 content: control.content
179 title: control.Maui.Controls.title
180 }
181 }
182
183 function addPage(component, properties)
184 {
185 _stackView.push(component, properties)
186 }
187
188 function open()
189 {
190 _window.show()
191 }
192 }
193 }
194
195 Component
196 {
197 id: _dialogComponent
198
199 Maui.PopupPage
200 {
201 id: control
202
203 readonly property alias stackView: _stackView
204
205 maxHeight: implicitHeight
206 maxWidth: 500
207
208 hint: 1
209
210 page.title: _stackView.currentItem.title ? _stackView.currentItem.title : ""
211
212 headBar.visible: true
213
214 headBar.leftContent: ToolButton
215 {
216 icon.name: "go-previous"
217 visible: _stackView.depth > 1
218
219 onClicked: _stackView.pop()
220 }
221
222 stack: StackView
223 {
224 id: _stackView
225 Layout.fillHeight: true
226 Layout.fillWidth: true
227 implicitHeight: Math.max(_content.implicitHeight, currentItem.implicitHeight)+topPadding +bottomPadding
228
229 initialItem: Maui.SettingsPage
230 {
231 id: _content
232 content: control.content
233 title: control.Maui.Controls.title
234 }
235 }
236
237 function addPage(component, properties)
238 {
239 _stackView.push(component, properties)
240 }
241 }
242
243 }
244
245 function open()
246 {
247 if(control.item)
248 {
249 control.item.open()
250 return
251 }
252
253 if(Maui.Handy.isMobile)
254 {
255 control.sourceComponent = _dialogComponent
256 }else
257 {
258 control.sourceComponent = _appComponent
259 }
260 control.item.open()
261
262 }
263
264 /**
265 * @brief Adds a new sub page to the control. Use a MauiKit SettingsPage for the component.
266 * @param component the QQC2 Component wrapping a MauiKit SettingsPage
267 * @param properties optional properties map for the newly added sub page component
268 *
269 * @note The optional properties argument specifies a map of initial property values for the pushed item. For dynamically created items, these values are applied before the creation is finalized. This is more efficient than setting property values after creation, particularly where large sets of property values are defined, and also allows property bindings to be set up (using Qt.binding()) before the item is created.
270 * Checkout QT documentation on the StackView methods.
271 */
272 function addPage(component, properties)
273 {
274 control.item.addPage(component, properties)
275 }
276}
277
QString i18n(const char *text, const TYPE &arg...)
QAction * hint(const QObject *recvr, const char *slot, QObject *parent)
QAction * open(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.