MauiKit Controls

GridBrowserDelegate.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
21import QtQml
22
23import QtQuick.Controls
24import org.mauikit.controls as Maui
25
26/**
27 * @inherit ItemDelegate
28 * @brief A MauiKit ItemDelegate with some extra functionality and an informational column layout.
29 *
30 * This controls inherits from MauiKit ItemDelegate, to checkout its inherited properties refer to docs.
31 *
32 * @note This is essentially different from QQC2 ItemDelegate control, where the QQC2 can have a text, an icon etc; this one is only a container with some predefined behavior.
33 * @see ItemDelegate
34 *
35 * @image html Delegates/gridbrowserdelegate.png
36 * @note An example of GridBrowserDelegates in the Index -file manager - application.
37 *
38 * @section structure Structure
39 * The GridBrowserDelegate layouts the information vertically. It's composed of three main sections: the top icon header, a title label and finally an extra label message. Those sections are all handled by a MauiKit GridItemTemplate control, which is exposed by the alias property `template`.
40 * @see GridItemTemplate
41 *
42 * The top icon section is handled by default by a MauiKit IconItem, which hosts an image or icon. Those can be set via the `imageSource` or the `iconSource` properties.
43 * @see IconItem
44 *
45 * The top icon header can also be replaced by any other component using the `template.iconComponent` property. An example of a custom icon header is the Mauikit controls GalleryItem and CollageItem, both of which inherit from GridBrowserDelegate and set a custom `template.iconComponent`.
46 *
47 * @section notes Notes
48 * This control can be `checkable`, and a CheckBox element will be placed on top of it. It also supports features from the Button type, such as the `autoExclusive`, `checked` properties and the press events.
49 *
50 * By inheritance this component can be `dragable`.
51 *
52 * @note This control is usually used as the delegate component for the GridBrowser or QQC2 GridView.
53 *
54 * @subsection dnd Drag & Drop
55 * To set up the drag and drop, use the Drag attached properties.
56 * The most relevant part for this control is to set the `Drag.keys` and `Drag.mimeData`
57 *
58 * @code
59 * Drag.keys: ["text/uri-list"]
60 * Drag.mimeData: Drag.active ?
61 * {
62 * "text/uri-list": "" //here a list of file separated by a comma.
63 * } : {}
64 * @endcode
65 *
66 * @image html Delegates/gridbrowserdelegate2.png
67 *
68 * @code
69 * Maui.GridBrowser
70 * {
71 * id: _gridBrowser
72 * anchors.fill: parent
73 * model: 30
74 *
75 * itemSize: 120
76 * itemHeight: 120
77 *
78 * adaptContent: true
79 *
80 * delegate: Item
81 * {
82 * width: GridView.view.cellWidth
83 * height: GridView.view.cellHeight
84 *
85 * Maui.GridBrowserDelegate
86 * {
87 * width: _gridBrowser.itemSize
88 * height: width
89 *
90 * iconSource: "folder"
91 * iconSizeHint: Maui.Style.iconSizes.big
92 * label1.text: "Title"
93 * label2.text: "Message"
94 *
95 * anchors.centerIn: parent
96 * }
97 * }
98 * }
99 * @endcode
101 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/GridBrowserDelegate.qml">You can find a more complete example at this link.</a>
102 */
103Maui.ItemDelegate
104{
105 id: control
106
107 isCurrentItem : GridView.isCurrentItem || checked
108 flat : !Maui.Handy.isMobile
109
110 implicitHeight: _template.implicitHeight + topPadding +bottomPadding
111
112 padding: Maui.Style.defaultPadding
113 spacing: Maui.Style.space.medium
115 radius: Maui.Style.radiusV
116
117 /**
118 * @brief An alias to access the GridItemTemplate control properties. This is the template element that layouts all the information: labels and icon/image.
119 * @see GridItemTemplate
120 * @property GridItemTemplate GridBrowserDelegate::template.
121 */
122 readonly property alias template : _template
123
124 /**
125 * @see GridItemTemplate::label1
126 */
127 readonly property alias label1 : _template.label1
129 /**
130 * @see GridItemTemplate::label2
131 */
132 readonly property alias label2 : _template.label2
133
134 /**
135 * @see GridItemTemplate::iconItem
136 */
137 property alias iconItem : _template.iconItem
138
139 /**
140 * @see GridItemTemplate::iconVisible
141 */
142 property alias iconVisible : _template.iconVisible
143
144 /**
145 * @see GridItemTemplate::imageSizeHint
146 */
147 property alias imageSizeHint : _template.imageSizeHint
149 /**
150 * @see GridItemTemplate::iconSizeHint
151 */
152 property alias iconSizeHint : _template.iconSizeHint
153
154 /**
155 * @see GridItemTemplate::imageSource
156 */
157 property alias imageSource : _template.imageSource
158
159 /**
160 * @see GridItemTemplate::iconSource
161 */
162 property alias iconSource : _template.iconSource
163
164 /**
165 * @see GridItemTemplate::labelsVisible
166 */
167 property alias labelsVisible : _template.labelsVisible
168
169 /**
170 * @brief Whether the control is checked or not.
171 * By default this is set to `false`.
172 */
173 property bool checked : false
174
175 /**
176 * @see GridItemTemplate::fillMode
177 */
178 property alias fillMode : _template.fillMode
179
180 /**
181 * @see GridItemTemplate::maskRadius
182 */
183 property alias maskRadius : _template.maskRadius
184
185 /**
186 * @brief Whether the control should become checkable. If it is checkable a CheckBox element will become visible to allow to toggle between the checked states.
187 * By default this is set to `false`.
188 */
189 property bool checkable: false
190
191 /**
192 * @brief Whether the control should be auto exclusive, this means that among other related elements - sharing the same parent- only one can be selected/checked at the time.
193 * By default this is set to `false`.
194 */
195 property bool autoExclusive: false
196
197 /**
198 * @brief An alias to expose the DropArea component in charge of the drag&drop events.
199 * @see contentDropped
200 */
201 readonly property alias dropArea : _dropArea
202
203 /**
204 * @see GridItemTemplate::imageWidth
205 */
206 property alias imageWidth : _template.imageWidth
207
208 /**
209 * @see GridItemTemplate::imageHeight
210 */
211 property alias imageHeight : _template.imageHeight
212
213 /**
214 * @brief Emitted when a drop event has been triggered on this control.
215 * @param drop The object with information about the event.
216 */
217 signal contentDropped(var drop)
218
219 /**
220 * @brief Emitted when the control checked state has been changed.
221 * @param state The checked state value.
222 */
223 signal toggled(bool state)
224
225 background: Rectangle
226 {
227 color: (control.isCurrentItem || control.containsPress ? Maui.Theme.highlightColor : ( control.hovered ? Maui.Theme.hoverColor : (control.flat ? "transparent" : Maui.Theme.alternateBackgroundColor)))
228
229 radius: control.radius
230
231 Behavior on color
232 {
233 enabled: !control.flat
234 Maui.ColorTransition{}
235 }
236 }
237
238 DropArea
239 {
240 id: _dropArea
241 width: parent.width
242 height: parent.height
243 Rectangle
244 {
245 anchors.fill: parent
246 radius: control.radius
247 color: control.Maui.Theme.backgroundColor
248 border.color: control.Maui.Theme.highlightColor
249 visible: parent.containsDrag
250 }
251
252 onDropped:
253 {
254 control.contentDropped(drop)
255 }
256 }
257
258 Maui.GridItemTemplate
259 {
260 id: _template
261 anchors.fill: parent
262 iconContainer.scale: _dropArea.containsDrag || _checkboxLoader.active ? 0.8 : 1
263 hovered: control.hovered
264 maskRadius: control.radius
265 spacing: control.spacing
266 isCurrentItem: control.isCurrentItem
267 highlighted: control.containsPress
268 }
269
270 Loader
271 {
272 id: _badgeLoader
273 asynchronous: true
274 active: control.Maui.Controls.badgeText && control.Maui.Controls.badgeText.length > 0 && control.visible
275
276 anchors.horizontalCenter: parent.right
277 anchors.verticalCenter: parent.top
278 anchors.verticalCenterOffset: 10
279 anchors.horizontalCenterOffset: -5
280
281 OpacityAnimator on opacity
282 {
283 from: 0
284 to: 1
285 duration: Maui.Style.units.longDuration
286 running: _badgeLoader.status === Loader.Ready
287 }
288
289 ScaleAnimator on scale
290 {
291 from: 0.5
292 to: 1
293 duration: Maui.Style.units.longDuration
294 running: _badgeLoader.status === Loader.Ready
295 easing.type: Easing.OutInQuad
296 }
297
298 sourceComponent: Maui.Badge
299 {
300 text: control.Maui.Controls.badgeText
301
302 padding: 2
303 font.pointSize: Maui.Style.fontSizes.tiny
304
305 Maui.Theme.colorSet: Maui.Theme.View
306 Maui.Theme.backgroundColor: Maui.Theme.negativeBackgroundColor
307 Maui.Theme.textColor: Maui.Theme.negativeTextColor
308 }
309 }
310
311 Loader
312 {
313 id: _checkboxLoader
314 asynchronous: true
315 active: control.checkable || control.checked
316
317 anchors.top: parent.top
318 anchors.left: parent.left
319 anchors.margins: Maui.Style.space.medium
320
321 scale: active ? 1 : 0
322
323 Behavior on scale
324 {
325 NumberAnimation
326 {
327 duration: Maui.Style.units.longDuration*2
328 easing.type: Easing.OutBack
329 }
330 }
331
332 sourceComponent: CheckBox
333 {
334 checkable: control.checkable
335 autoExclusive: control.autoExclusive
336
337 Binding on checked
338 {
339 value: control.checked
340 restoreMode: Binding.RestoreBinding
341 delayed: true
342 }
343
344 onToggled:
345 {
346 console.log("CHECKEDDDD STATE")
347 control.toggled(checked)
348 }
349 }
350 }
351}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Apr 18 2025 12:16:12 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.