MauiKit Controls

PopupPage.qml
1/*
2 * Copyright 2018 Camilo Higuita <milo.h@aol.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20import QtQuick
21
22import QtQuick.Controls
23import QtQuick.Layouts
24
25import org.mauikit.controls as Maui
26
27import Qt5Compat.GraphicalEffects
28
29/**
30 * @inherit QtQuick.Controls.Popup
31 * @since org.mauikit.controls 1.0
32 * @brief A QQC2 Popup with extra built-in features, such as a snapping surface, scrollable contents, and action buttons.
33 *
34 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-popup.html">This control inherits from QQC2 Popup, to checkout its inherited properties refer to the Qt Docs.</a>
35 *
36 * @image html Misc/popuppage.png "The image depicts the control a floating VS snapped surface"
37 *
38 * @section structure Structure
39 *
40 * The inner container is handled by a MauiKit Page, and this can be accessed via the alias property `page` - which means this control can have a header and footer bar, and all the other Page features.
41 * @see page
42 *
43 * By default the children content is positioned into a MauiKit ScrollColumn, that's scrollable. If it's desired, this can be avoided by placing the children manually, using the property `stack`. This way any other element can be positioned manually using the Layout attached properties.
44 * @see stack
45 *
46 * @note The `stack` children are positioned using a ColumnLayout.
47 *
48 * @section features Features
49 *
50 * @subsection snapping Snapping
51 * The Popup can snap to the full window area on constrained spaces. To allow this behavior there a few steps to look after, first make `hint: 1`and set `persistent: true`.
52 * @ref ScrollColumn#notes Notes
53 * @see persistent
54 *
55 * @subsection scrollable Scrollable Layout
56 * By default the children content of this element will be placed on a MauiKit ScrollColumn, which allows the content to be scrollable/flickable when its implicit height is bigger than the actual popup area.
57 * To position the children content use the `implicitHeight` and the Layout attached properties, such as `Layout.fillWidth`.
58 * @see content
59 * @see ScrollColumn
60 *
61 * @subsection actions Action Buttons
62 * The regular QQC2 Popup control does not have support for setting standard action buttons like the Dialog controls does; but this control allows it. The action buttons will be styled in the same manner as the Dialog buttons, but the actions here are added differently.
63 * To set the actions, use the `actions` property.
64 * @see actions
65 *
66 * @code
67 * Maui.PopupPage
68 * {
69 * id: _popupPage
70 *
71 * title: "Title"
72 *
73 * persistent: true
74 * hint: 1
75 *
76 * Rectangle
77 * {
78 * implicitHeight: 200
79 * Layout.fillWidth: true
80 * color: "purple"
81 * }
82 *
83 * Rectangle
84 * {
85 * implicitHeight: 200
86 * Layout.fillWidth: true
87 * color: "orange"
88 * }
89 *
90 * Rectangle
91 * {
92 * implicitHeight: 200
93 * Layout.fillWidth: true
94 * color: "yellow"
95 * }
96 *
97 * actions: [
98 * Action
99 * {
100 * text: "Action1"
101 * },
102 *
103 * Action
104 * {
105 * text: "Action2"
106 * }
107 * ]
108 * }
109 * @endcode
110 *
111 * @section notes Notes
112 * Some properties have been obscure by the Maui Style layer.
113 * The style layer adds some extra properties to the Popup control:
114 * - `filling : bool` Whether the popup area should be style as if filling the whole window area.
115 * - `maxWidth : int` The maximum width the popup area can have. If the window width space becomes smaller then the popup area, then it will be resized to fit. Or if the `hint: 1` then it will snap to fill the whole window area.
116 * - `maxHeight : int` The maximum height the popup area can have. If the window height space becomes smaller then the popup area, then it will be resized to fit. Or if the `hint: 1` then it will snap to fill the whole window area.
117 * -` hint : double` Determines the resizing final size of the popup area when it reaches the `maxWidth` or `maxHeight` constrains. For example a `1` value means the popup area will be resize to fill the window available space, but a `0.5` value means it will be conserving a margin when resized of 25% at left and right sides.
118 * - `heightHint : double` By default this is bind to the `hint` value.
119 * - `widthHint : double` By default this is bind to the `hint` value.
120 *
121 *
122 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/PopupPage.qml">You can find a more complete example at this link.</a>
123 */
124Popup
125{
126 id: control
127
128 focus: true
129
130 Maui.Theme.colorSet: Maui.Theme.Window
131 Maui.Theme.inherit: false
132
133 closePolicy: control.persistent ? Popup.NoAutoClose | Popup.CloseOnEscape : Popup.CloseOnEscape | Popup.CloseOnPressOutside
134
135 maxWidth: 300
136 maxHeight: implicitHeight
137 implicitHeight: _layout.implicitHeight + topPadding + bottomPadding + topMargin + bottomMargin
138
139 hint: 0.9
140 heightHint: 0.9
141 spacing: Maui.Style.space.big
142
143 margins: 0
144
145 filling: persistent && mWidth === control.parent.width
146
147 /**
148 * @brief Default children content will be added to a scrollable ColumnLayout.
149 * When adding a item keep on mind that to correctly have the scrollable behavior the item must have an implicit height set. And the positioning should be handled via the Layout attached properties.
150 * @property list<Item> PopupPage::scrollable
151 */
152 default property alias scrollable : _scrollView.content
153
154 /**
155 * @brief To skip the default scrollable-layout behavior, there is a `stack` overlay component to which items can be added, this is also controlled by a ColumnLayout, but it is not scrollable.
156 * @code
157 * Maui.PopupPage
158 * {
159 * stack: Rectangle
160 * {
161 * Layout.fillWidth: true
162 * Layout.fillHeight: true
163 * Layout.preferredHeight: 800
164 * }
165 * }
166 * @endcode
167 * @property list<QtObject> PopupPage::stack
168 */
169 property alias stack : _stack.data
170
171 /**
172 * @see Page::title
173 */
174 property alias title : _page.title
175
176 /**
177 * @brief Whether the dialog should be closed when it loses focus or not.
178 * If it is marked as persistent a close button is shown in the header bar, other wise the header bar is hidden if there is not more elements on it.
179 * By default this is set to `true`.
180 */
181 property bool persistent : true
182
183 /**
184 * @brief An alias to the MauiKit Page, which is the main container of this control.
185 * It is exposed to allow access to the Page properties.
186 * @see Page
187 * @property Page PopupPage::page
188 */
189 readonly property alias page : _page
190
191 /**
192 * @see Page::footBar
193 */
194 property alias footBar : _page.footBar
195
196 /**
197 * @see Page::headBar
198 */
199 property alias headBar: _page.headBar
200
201 /**
202 * @brief Whether the close button is visible.
203 * By default this is bind to the `persistent` value.
204 * @see persistent.
205 */
206 property bool closeButtonVisible: control.persistent
207
208 /**
209 * @see ScrollColumn::flickable
210 */
211 readonly property alias flickable : _scrollView.flickable
212
213 /**
214 * @brief An alias to the MauiKit ScrollColumn handling the scrollable content.
215 * @property ScrollView PopupPage::scrollView
216 */
217 readonly property alias scrollView : _scrollView
218
219 /**
220 * @brief The policy for the scroll view vertical scroll bar.
221 * By default this is set to `ScrollBar.AsNeeded`.
222 */
223 property int verticalScrollBarPolicy: ScrollBar.AsNeeded
224
225 /**
226 * @brief The policy for the scroll view horizontal scroll bar.
227 * By default this is set to `ScrollBar.AlwaysOff`.
228 */
229 property int horizontalScrollBarPolicy: ScrollBar.AlwaysOff
230
231 /**
232 * @brief Whether the control should be closed automatically after the close button is pressed.
233 * If this is set to `false`, then the `closeTriggered` will be emitted instead.
234 * This is useful if a conformation action needs to take place before closing the control.
235 * By default this is set to `true`.
236 */
237 property bool autoClose : true
238
239 /**
240 * @brief List of actions to be added to the bottom section as buttons.
241 */
242 property list<Action> actions
243
244 /**
245 * @brief The GridLayout handling the bottom part of action buttons added via the `actions` property.
246 * @property GridLayout PopupPage:: actionBar
247 */
248 readonly property alias actionBar : _defaultButtonsLayout
249
250 /**
251 * @brief Emitted when the close button has been clicked and the `autoClose` property has been disabled.
252 * @see autoClose
253 * @see closeButtonVisible
254 */
255 signal closeTriggered()
256
257 ColumnLayout
258 {
259 id: _layout
260 anchors.fill: parent
261 spacing: 0
262
263 Maui.Page
264 {
265 id: _page
266
267 clip: true
268
269 Maui.Theme.colorSet: control.Maui.Theme.colorSet
270
271 Layout.fillWidth: true
272 Layout.fillHeight: true
273
274 implicitHeight: Math.max(_scrollView.contentHeight + _scrollView.topPadding + _scrollView.bottomPadding, _stack.implicitHeight) + _page.footerContainer.implicitHeight + (_page.topPadding + _page.bottomPadding) + _page.headerContainer.implicitHeight + (_page.topMargin + _page.bottomMargin)
275
276 headerPositioning: ListView.InlineHeader
277
278 padding: 0
279 margins: 0
280
281 headBar.visible: control.persistent
282 headBar.borderVisible: false
283
284 background: null
285
286 headBar.farRightContent: Loader
287 {
288 asynchronous: true
289 visible: active
290 active: control.persistent && closeButtonVisible
291
292 sourceComponent: Maui.CloseButton
293 {
294 onClicked:
295 {
296 if(control.autoClose)
297 {
298 control.close()
299 }else
300 {
301 control.closeTriggered()
302 }
303 }
304 }
305 }
306
307 ColumnLayout
308 {
309 id: _stack
310
311 anchors.fill: parent
312 spacing: control.spacing
313 }
314
315 Maui.ScrollColumn
316 {
317 id: _scrollView
318
319 anchors.fill: parent
320
321 visible: _stack.children.length === 0
322
323 spacing: control.spacing
324 padding: Maui.Style.space.big
325
326 ScrollBar.horizontal.policy: control.horizontalScrollBarPolicy
327 ScrollBar.vertical.policy: control.verticalScrollBarPolicy
328 }
329 }
330
331 GridLayout
332 {
333 id: _defaultButtonsLayout
334
335 rowSpacing: Maui.Style.space.small
336 columnSpacing: Maui.Style.space.small
337
338 Layout.fillWidth: true
339 Layout.margins: Maui.Style.contentMargins
340
341 property bool isWide : control.width > Maui.Style.units.gridUnit*10
342
343 visible: control.actions.length
344
345 rows: isWide? 1 : _defaultButtonsLayout.children.length
346 columns: isWide ? _defaultButtonsLayout.children.length : 1
347
348 Repeater
349 {
350 model: control.actions
351
352 Button
353 {
354 id: _actionButton
355 focus: true
356 Layout.fillWidth: true
357
358 action: modelData
359 }
360 }
361 }
362 }
363}
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.