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
24
25import org.mauikit.controls 1.3 as Maui
26
27/**
28 * @inherit ItemDelegate
29 * @brief A MauiKit ItemDelegate with some extra functionality and an informational column layout.
30 *
31 * This controls inherits from MauiKit ItemDelegate, to checkout its inherited properties refer to docs.
32 *
33 * @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.
34 * @see ItemDelegate
35 *
36 * @image html Delegates/gridbrowserdelegate.png
37 * @note An example of GridBrowserDelegates in the Index -file manager - application.
38 *
39 * @section structure Structure
40 * 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`.
41 * @see GridItemTemplate
42 *
43 * 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.
44 * @see IconItem
45 *
46 * 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`.
47 *
48 * @section notes Notes
49 * 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.
50 *
51 * By inheritance this component can be `dragable`.
52 *
53 * @note This control is usually used as the delegate component for the GridBrowser or QQC2 GridView.
54 *
55 * @subsection dnd Drag & Drop
56 * To set up the drag and drop, use the Drag attached properties.
57 * The most relevant part for this control is to set the `Drag.keys` and `Drag.mimeData`
58 *
59 * @code
60 * Drag.keys: ["text/uri-list"]
61 * Drag.mimeData: Drag.active ?
62 * {
63 * "text/uri-list": "" //here a list of file separated by a comma.
64 * } : {}
65 * @endcode
66 *
67 * @image html Delegates/gridbrowserdelegate2.png
68 *
69 * @code
70 * Maui.GridBrowser
71 * {
72 * id: _gridBrowser
73 * anchors.fill: parent
74 * model: 30
75 *
76 * itemSize: 120
77 * itemHeight: 120
78 *
79 * adaptContent: true
80 *
81 * delegate: Item
82 * {
83 * width: GridView.view.cellWidth
84 * height: GridView.view.cellHeight
85 *
86 * Maui.GridBrowserDelegate
87 * {
88 * width: _gridBrowser.itemSize
89 * height: width
90 *
91 * iconSource: "folder"
92 * iconSizeHint: Maui.Style.iconSizes.big
93 * label1.text: "Title"
94 * label2.text: "Message"
95 *
96 * anchors.centerIn: parent
97 * }
98 * }
99 * }
100 * @endcode
101 *
102 * <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>
103 */
104Maui.ItemDelegate
105{
106 id: control
107
108 isCurrentItem : GridView.isCurrentItem || checked
109 flat : !Maui.Handy.isMobile
110
111 implicitHeight: _template.implicitHeight + topPadding +bottomPadding
112
113 padding: Maui.Style.defaultPadding
114 spacing: Maui.Style.space.medium
115
116 radius: Maui.Style.radiusV
117
118 /**
119 * @brief An alias to access the GridItemTemplate control properties. This is the template element that layouts all the information: labels and icon/image.
120 * @see GridItemTemplate
121 * @property GridItemTemplate GridBrowserDelegate::template.
122 */
123 readonly property alias template : _template
125 /**
126 * @see GridItemTemplate::label1
127 */
128 readonly property alias label1 : _template.label1
129
130 /**
131 * @see GridItemTemplate::label2
132 */
133 readonly property alias label2 : _template.label2
134
135 /**
136 * @see GridItemTemplate::iconItem
137 */
138 property alias iconItem : _template.iconItem
139
140 /**
141 * @see GridItemTemplate::iconVisible
142 */
143 property alias iconVisible : _template.iconVisible
145 /**
146 * @see GridItemTemplate::imageSizeHint
147 */
148 property alias imageSizeHint : _template.imageSizeHint
149
150 /**
151 * @see GridItemTemplate::iconSizeHint
152 */
153 property alias iconSizeHint : _template.iconSizeHint
154
155 /**
156 * @see GridItemTemplate::imageSource
157 */
158 property alias imageSource : _template.imageSource
159
160 /**
161 * @see GridItemTemplate::iconSource
162 */
163 property alias iconSource : _template.iconSource
164
165 /**
166 * @see GridItemTemplate::labelsVisible
167 */
168 property alias labelsVisible : _template.labelsVisible
169
170 /**
171 * @brief Whether the control is checked or not.
172 * By default this is set to `false`.
173 */
174 property bool checked : false
176 /**
177 * @see GridItemTemplate::fillMode
178 */
179 property alias fillMode : _template.fillMode
180
181 /**
182 * @see GridItemTemplate::maskRadius
183 */
184 property alias maskRadius : _template.maskRadius
186 /**
187 * @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.
188 * By default this is set to `false`.
189 */
190 property bool checkable: false
191
192 /**
193 * @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.
194 * By default this is set to `false`.
195 */
196 property bool autoExclusive: false
197
198 /**
199 * @brief An alias to expose the DropArea component in charge of the drag&drop events.
200 * @see contentDropped
201 */
202 readonly property alias dropArea : _dropArea
203
204 /**
205 * @see GridItemTemplate::imageWidth
206 */
207 property alias imageWidth : _template.imageWidth
208
209 /**
210 * @see GridItemTemplate::imageHeight
211 */
212 property alias imageHeight : _template.imageHeight
213
214 /**
215 * @brief Emitted when a drop event has been triggered on this control.
216 * @param drop The object with information about the event.
217 */
218 signal contentDropped(var drop)
219
220 /**
221 * @brief Emitted when the control checked state has been changed.
222 * @param state The checked state value.
223 */
224 signal toggled(bool state)
225
226 background: Rectangle
227 {
228 color: (control.isCurrentItem || control.containsPress ? Maui.Theme.highlightColor : ( control.hovered ? Maui.Theme.hoverColor : (control.flat ? "transparent" : Maui.Theme.alternateBackgroundColor)))
229
230 radius: control.radius
231
232 Behavior on color
233 {
234 enabled: !control.flat
235 Maui.ColorTransition{}
236 }
237 }
238
239 DropArea
240 {
241 id: _dropArea
242 width: parent.width
243 height: parent.height
244 Rectangle
245 {
246 anchors.fill: parent
247 radius: control.radius
248 color: control.Maui.Theme.backgroundColor
249 border.color: control.Maui.Theme.highlightColor
250 visible: parent.containsDrag
251 }
252
253 onDropped:
254 {
255 control.contentDropped(drop)
256 }
257 }
258
259 Maui.GridItemTemplate
260 {
261 id: _template
262 anchors.fill: parent
263 iconContainer.scale: _dropArea.containsDrag || _checkboxLoader.active ? 0.8 : 1
264 hovered: control.hovered
265 maskRadius: control.radius
266 spacing: control.spacing
267 isCurrentItem: control.isCurrentItem
268 highlighted: control.containsPress
269 }
270
271 Loader
272 {
273 id: _checkboxLoader
274 asynchronous: true
275 active: control.checkable || control.checked
276
277 anchors.top: parent.top
278 anchors.left: parent.left
279 anchors.margins: Maui.Style.space.medium
280
281 scale: active ? 1 : 0
282
283 Behavior on scale
284 {
285 NumberAnimation
286 {
287 duration: Maui.Style.units.longDuration*2
288 easing.type: Easing.OutBack
289 }
290 }
291
292 sourceComponent: CheckBox
293 {
294 checkable: control.checkable
295 autoExclusive: control.autoExclusive
296
297 Binding on checked
298 {
299 value: control.checked
300 restoreMode: Binding.RestoreBinding
301 }
302
303 onToggled:
304 {
305 console.log("CHECKEDDDD STATE")
306 control.toggled(checked)
307 }
308 }
309 }
310}
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.