MauiKit Controls

AltBrowser.qml
1import QtQuick
2import QtQml
3import QtQuick.Controls
4
5import org.mauikit.controls 1.3 as Maui
6
7/**
8 * @inherit Page
9 * @since org.mauikit.controls 1.0
10 *
11 * @brief A convinient way of switching between a grid an a list view.
12 *
13 * This controls inherits from MauiKit Page, to checkout its inherited properties refer to the docs.
14 * @see Page
15 *
16 * @note This control supports the attached `Controls.showCSD` property to display the window control buttons when using CSD.
17 *
18 * The AltBrowser makes use of the GridView and ListBrowser components, there is a property to dinamically switch between the two.
19 *
20 * For some navigation patterns is a good idea to provide a grid view when the application screen size is wide enough to fit numerous items and a list view when the space is contrained - since the list is much more compact - and makes navigation quicker.
21 * @see viewType
22 *
23 * @image html AltBrowser/views.gif "Switching between the list and grid view"
24 *
25 * @section notes Notes
26 * The data model is shared by both of the view types, but the delagates to be used have to be assigment for each one.
27 * @see listDelegate
28 * @see gridDelegate
29 *
30 * There is a MauiKit Holder element that can be used to display a placeholder message, for example, when the views are empty.
31 * @see holder
32 *
33 * @code
34 * Maui.AltBrowser
35 * {
36 * id: _altBrowser
37 * anchors.fill: parent
38 *
39 * Maui.Controls.showCSD: true
40 * viewType: Maui.AltBrowser.ViewType.Grid
41 *
42 * gridView.itemSize: 120
43 *
44 * headBar.leftContent: ToolButton
45 * {
46 * icon.name: _altBrowser.viewType === Maui.AltBrowser.ViewType.Grid ? "view-list-details" : "view-list-icons"
47 * onClicked: _altBrowser.toggle()
48 * }
49 *
50 * model: 20
51 *
52 * listDelegate: Maui.ListBrowserDelegate
53 * {
54 * width:ListView.view.width
55 * label1.text: index
56 * label2.text: "Example"
57 * iconSource: "folder"
58 * }
59 *
60 * gridDelegate: Maui.GridBrowserDelegate
61 * {
62 * height: GridView.view.cellHeight
63 * width: GridView.view.itemSize
64 *
65 * iconSource: "folder"
66 * label1.text: index
67 * label2.text: "Example"
68 * }
69 * }
70 * @endcode
71 *
72 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/AltBrowser.qml">You can find a more complete example at this link.</a>
73 */
74Maui.Page
75{
76 id: control
77
78 Maui.Theme.colorSet: Maui.Theme.View
79 Maui.Theme.inherit: false
80
81 focus: true
82 clip: false
83
84 /**
85 * @brief The current view being used, the GridView or the ListBrowser.
86 * To access the precise view use the aliases for the GridView or ListView.
87 * @see listView
88 * @see gridView
89 */
90 readonly property Item currentView : control.viewType === AltBrowser.ViewType.List ? _listView : _gridView
91
92 onCurrentViewChanged: control.currentView.forceActiveFocus()
93
94 /**
95 * @brief The two different view types possible.
96 * @enum Grid AltBrowser.Grid handled by the GridBrowser control.
97 * @enum List AltBrowser.List hanlded by the ListBrowser control.
98 */
99 enum ViewType
100 {
101 Grid,
102 List
103 }
104
105 /**
106 * @brief Sets the view type that's going to be in use.
107 *
108 * The type can be one of:
109 * - ViewType.Grid
110 * - ViewType.List The default
111 *
112 * @see ViewType
113 */
114 property int viewType: AltBrowser.ViewType.List
115
116 /**
117 * @brief The index of the current item selected in either view type.
118 * This value is synced to both view types.
119 */
120 property int currentIndex : -1
121 Binding on currentIndex
122 {
123 when: control.currentView
124 value: control.currentView.currentIndex
125 }
126
127 /**
128 * @brief The delegate to be used by the ListBrowser.
129 */
130 property Component listDelegate : null
131
132 /**
133 * @brief The delegate to be used by the GridView.
134 */
135 property Component gridDelegate : null
136
137 /**
138 * @brief The shared data model to be used by both view types.
139 */
140 property var model : null
141
142 /**
143 * @brief Allow the lasso selection for multiple items with mouse or track based input methods.
144 */
145 property bool enableLassoSelection: false
147 /**
148 * @brief Allow the selection mode, which sets the views in the mode to accept to select multiple items.
149 */
150 property bool selectionMode: false
151
152 /**
153 * @brief Item to set a place holder emoji and message.
154 * For more details on its properties check the Holder component.
155 * @property Holder AltBrowser::holder
156 *
157 * @see Holder
158 */
159 property alias holder : _holder
160
161 /**
162 * @brief The GridBrowser used as the grid view alternative.
163 * @property GridBrowser AltBrowser::gridView
164 */
165 readonly property alias gridView : _gridView
166
167 /**
168 * The ListBrowser used as the list view alternative.
169 * @property ListBrowser AltBrowser::listView
170 */
171 readonly property alias listView : _listView
172
173 /**
174 * @brief The total amount of items in the current view.
175 */
176 readonly property int count : currentView.count
177
178 flickable: currentView.flickable
179
180 Maui.GridBrowser
181 {
182 id: _gridView
183 focus: control.focus
184 anchors.fill: parent
185 visible: control.viewType === AltBrowser.ViewType.Grid
186 currentIndex: control.currentIndex
187 model: control.model
188 delegate: control.gridDelegate
189 enableLassoSelection: control.enableLassoSelection
190 selectionMode: control.selectionMode
191 adaptContent: true
192 clip: control.clip
193 }
194
195 Maui.ListBrowser
196 {
197 anchors.fill: parent
198 focus: control.focus
199 id: _listView
200 visible: control.viewType === AltBrowser.ViewType.List
201 currentIndex: control.currentIndex
202 model: control.model
203 delegate: control.listDelegate
204 enableLassoSelection: control.enableLassoSelection
205 selectionMode: control.selectionMode
206 clip: control.clip
207 }
208
209 Maui.Holder
210 {
211 id: _holder
212 anchors.fill: parent
213 visible: false
214 }
215
216 /**
217 * @brief Toggle between the two views. If in list view then switches to grid, and from grid to list.
218 */
219 function toggle()
220 {
221 control.viewType = (control.viewType == Maui.AltBrowser.ViewType.Grid ? Maui.AltBrowser.ViewType.List : Maui.AltBrowser.ViewType.Grid)
222 }
223}
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.