Warning, /maui/mauikit/src/controls.6/SettingsDialog.qml is written in an unsupported language. File is not indexed.
0001 import org.mauikit.controls 1.3 as Maui
0002 import QtQuick.Controls
0003 import QtQuick.Layouts
0004 import QtQuick
0005
0006 /**
0007 * @inherit QtQuick.Loader
0008 *
0009 * @brief A popup page with a scrollable vertical layout, and support for a stack of multiple pages.
0010 * The default container fo this control is a MauiKit SettingsPage, and the popup will snap to the window full size on constrained spaces.
0011 * @see SettingsPage
0012 *
0013 * You can add multiple sub pages to this control by making use of the SettingsPage control and the `addPage` function.
0014 * By using the SettingsPage you can expect to have a way to navigate between the control sub pages.
0015 * The code snippet below shows a quick demo on how to do it.
0016 * @see addPage
0017 *
0018 * @image html Misc/settingsdialog.png
0019 *
0020 * @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.
0021 *
0022 * @code
0023 * Maui.SettingsDialog
0024 * {
0025 * id: _settingsDialog
0026 *
0027 * Maui.FlexSectionItem
0028 * {
0029 * label1.text: "SSetting Subpage"
0030 * label2.text: "Click me to add a new page"
0031 *
0032 * ToolButton
0033 * {
0034 * icon.name: "go-next"
0035 * checkable: true
0036 * onToggled: _settingsDialog.addPage(_settingsPage2)
0037 * }
0038 * }
0039 *
0040 * Maui.SectionGroup
0041 * {
0042 * title: "First Section"
0043 *
0044 * Maui.FlexSectionItem
0045 * {
0046 * label1.text: "Configuration title"
0047 * label2.text: "Description text"
0048 *
0049 * Button
0050 * {
0051 * text: "Test"
0052 * }
0053 * }
0054 *
0055 * Maui.FlexSectionItem
0056 * {
0057 * label1.text: "Configuration title"
0058 * label2.text: "Description text"
0059 *
0060 * Switch {}
0061 * }
0062 *
0063 * Maui.FlexSectionItem
0064 * {
0065 * label1.text: "Configuration title"
0066 * label2.text: "Description text"
0067 *
0068 * Switch {}
0069 * }
0070 * }
0071 *
0072 * Maui.SectionGroup
0073 * {
0074 * title: "A Second Section"
0075 *
0076 * Maui.FlexSectionItem
0077 * {
0078 * label1.text: "Configuration title"
0079 * label2.text: "Description text"
0080 *
0081 * Switch {}
0082 * }
0083 *
0084 * Maui.FlexSectionItem
0085 * {
0086 * label1.text: "Configuration title"
0087 * label2.text: "Description text"
0088 * wide: false
0089 * TextField
0090 * {
0091 * Layout.fillWidth: true
0092 * }
0093 * }
0094 *
0095 * Maui.FlexSectionItem
0096 * {
0097 * label1.text: "Configuration title"
0098 * label2.text: "Description text"
0099 *
0100 * Switch {}
0101 * }
0102 * }
0103 *
0104 * Component
0105 * {
0106 * id: _settingsPage2
0107 *
0108 * Maui.SettingsPage
0109 * {
0110 * title: "Page2"
0111 *
0112 * Maui.FlexSectionItem
0113 * {
0114 * label1.text: "Configuration title"
0115 * label2.text: "Description text"
0116 *
0117 * Switch {}
0118 * }
0119 * }
0120 * }
0121 * }
0122 * @endcode
0123 *
0124 * <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>
0125 */
0126
0127 Loader
0128 {
0129 id: control
0130
0131 /**
0132 * @brief By default all the children content will be placed into a MauiKit SettingsPage, which has a scrollable column layout.
0133 * @property list<QtObject> SettingsDialog::content
0134 */
0135 default property list<QtObject> content
0136
0137 Component
0138 {
0139 id: _appComponent
0140
0141 Maui.DialogWindow
0142 {
0143 id: _window
0144 width: 400
0145 maximumWidth: 800
0146 height: Math.max(500, Math.min(900, implicitHeight))
0147 modality: Qt.ApplicationModal
0148
0149 readonly property int implicitHeight: Math.max(_content.implicitHeight, _stackView.currentItem.implicitHeight)+_stackView.topPadding + _stackView.bottomPadding
0150
0151 title: _stackView.currentItem.title ? _stackView.currentItem.title : ""
0152 onClosing: (close) =>
0153 {
0154 _window.hide()
0155 close.accepted = true
0156 }
0157
0158 readonly property alias stackView: _stackView
0159
0160 page.headBar.forceCenterMiddleContent: true
0161 page.headBar.leftContent: ToolButton
0162 {
0163 icon.name: "go-previous"
0164 visible: _stackView.depth > 1
0165
0166 onClicked: _stackView.pop()
0167 }
0168
0169 StackView
0170 {
0171 id: _stackView
0172 anchors.fill: parent
0173
0174 initialItem: Maui.SettingsPage
0175 {
0176 id:_content
0177 content: control.content
0178 }
0179 }
0180
0181 function addPage(component, properties)
0182 {
0183 _stackView.push(component, properties)
0184 }
0185
0186 function open()
0187 {
0188 _window.show()
0189 }
0190 }
0191 }
0192
0193 Component
0194 {
0195 id: _dialogComponent
0196
0197 Maui.PopupPage
0198 {
0199 id: control
0200
0201 readonly property alias stackView: _stackView
0202
0203 maxHeight: implicitHeight
0204 maxWidth: 500
0205
0206 hint: 1
0207
0208 page.title: _stackView.currentItem.title ? _stackView.currentItem.title : ""
0209
0210 headBar.visible: true
0211
0212 headBar.leftContent: ToolButton
0213 {
0214 icon.name: "go-previous"
0215 visible: _stackView.depth > 1
0216
0217 onClicked: _stackView.pop()
0218 }
0219
0220 stack: StackView
0221 {
0222 id: _stackView
0223 Layout.fillHeight: true
0224 Layout.fillWidth: true
0225 implicitHeight: Math.max(_content.implicitHeight, currentItem.implicitHeight)+topPadding +bottomPadding
0226
0227 initialItem: Maui.SettingsPage
0228 {
0229 id: _content
0230 content: control.content
0231 }
0232 }
0233
0234 function addPage(component, properties)
0235 {
0236 _stackView.push(component, properties)
0237 }
0238 }
0239
0240 }
0241
0242 function open()
0243 {
0244 if(control.item)
0245 {
0246 control.item.open()
0247 return
0248 }
0249
0250 if(Maui.Handy.isMobile)
0251 {
0252 control.sourceComponent = _dialogComponent
0253 }else
0254 {
0255 control.sourceComponent = _appComponent
0256 }
0257 control.item.open()
0258
0259 }
0260
0261 /**
0262 * @brief Adds a new sub page to the control. Use a MauiKit SettingsPage for the component.
0263 * @param component the QQC2 Component wrapping a MauiKit SettingsPage
0264 * @param properties optional properties map for the newly added sub page component
0265 *
0266 * @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.
0267 * Checkout QT documentation on the StackView methods.
0268 */
0269 function addPage(component, properties)
0270 {
0271 control.item.addPage(component, properties)
0272 }
0273 }
0274