MauiKit Controls

ListBrowserDelegate.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 QtQuick.Layouts
25
26import org.mauikit.controls 1.3 as Maui
27
28/**
29 * @inherit ItemDelegate
30 * @brief A MauiKit ItemDelegate with an informational row layout.
31 * This controls inherits from MauiKit ItemDelegate, to checkout its inherited properties refer to docs.
32 *
33 * @image html Delegates/listbrowserdelegate.png
34 * @note An example of ListBrowserDelegate in the Index -f ile manager - application.
35 *
36 * @section structure Structure
37 * The ListBrowserDelegate layouts its information horizontally. It's composed of two main sections: the far left icon header, and the text labels at the right side - there are four [4] possible labels. Those sections are all handled by a MauiKit ListItemTemplate control, which is exposed by the alias property `template`.
38 * @see ListItemTemplate
39 * @see template
40 *
41 * The far left icon section is handled by default by a MauiKit IconItem, which can have an image or icon. Those can be set via the `imageSource` or the `iconSource` properties.
42 * @see IconItem
43 *
44 * The said icon header can also be replaced by any other component using the `template.iconComponent` property.
45 *
46 * @section notes Notes
47 * This control can be `checkable`, and a CheckBox element will be placed on the left side. It also supports features from the Button type, such as the `autoExclusive`, `checked` properties and the press events.
48 *
49 * By inheritance this component can be `dragable`.
50 *
51 * @note This control is usually used as the delegate component for the ListBrowser or QQC2 ListView.
52 *
53 * @subsection dnd Drag & Drop
54 * To set up the drag and drop, use the Drag attached properties.
55 * The most relevant part for this control is to set the `Drag.keys` and `Drag.mimeData`
56 *
57 * @code
58 * Drag.keys: ["text/uri-list"]
59 * Drag.mimeData: Drag.active ?
60 * {
61 * "text/uri-list": "" //here a list of file separated by a comma.
62 * } : {}
63 * @endcode
64 *
65 * @code
66 * Maui.ListBrowserDelegate
67 * {
68 * width: ListView.view.width
69 * label1.text: "An example delegate."
70 * label2.text: "Using the MauiKit ListBrowser."
71 *
72 * iconSource: "folder"
73 * }
74 * @endcode
75 *
76 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/ListBrowser.qml">You can find a more complete example at this link.</a>
77 */
78Maui.ItemDelegate
79{
80 id: control
81
82 focus: true
83
84 radius: Maui.Style.radiusV
85
86 flat : !Maui.Handy.isMobile
88 implicitHeight: _layout.implicitHeight + topPadding + bottomPadding
89
90 isCurrentItem : ListView.isCurrentItem || checked
91
92 padding: Maui.Style.defaultPadding
93 spacing: Maui.Style.space.small
94
95 /**
96 * @see ListItemTemplate::content
97 */
98 default property alias content : _template.content
99
100 /**
101 * @see ListItemTemplate::label1
102 */
103 readonly property alias label1 : _template.label1
104
105 /**
106 * @see ListItemTemplate::label2
107 */
108 readonly property alias label2 : _template.label2
109
110 /**
111 * @see ListItemTemplate::label3
112 */
113 readonly property alias label3 : _template.label3
114
115 /**
116 * @see ListItemTemplate::label4
117 */
118 readonly property alias label4 : _template.label4
120 /**
121 * @see ListItemTemplate::iconItem
122 */
123 property alias iconItem : _template.iconItem
124
125 /**
126 * @see ListItemTemplate::iconVisible
127 */
128 property alias iconVisible : _template.iconVisible
129
130 /**
131 * @see ListItemTemplate::iconSizeHint
132 */
133 property alias iconSizeHint : _template.iconSizeHint
134
135 /**
136 * @see ListItemTemplate::imageSource
137 */
138 property alias imageSource : _template.imageSource
139
140 /**
141 * @see ListItemTemplate::iconSource
142 */
143 property alias iconSource : _template.iconSource
144
145 /**
146 * @see ListItemTemplate::labelsVisible
147 */
148 property alias showLabel : _template.labelsVisible
149
150 /**
151 * @brief Whether the control is checked or not.
152 * By default this is set to `false`.
153 */
154 property bool checked : false
155
156 /**
157 * @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.
158 * By default this is set to `false`.
159 */
160 property bool checkable: false
161
162 /**
163 * @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.
164 * By default this is set to `false`.
165 */
166 property bool autoExclusive: false
168 /**
169 * @see ListItemTemplate::leftLabels
170 */
171 readonly property alias leftLabels: _template.leftLabels
172
173 /**
174 * @see ListItemTemplate::rightLabels
175 */
176 readonly property alias rightLabels: _template.rightLabels
177
178 /**
179 * @brief An alias to access the ListItemTemplate control properties. This is the template element that layouts all the information: labels and icon/image.
180 * @see ListItemTemplate
181 * @property GridItemTemplate ListBrowserDelegate::template.
182 */
183 readonly property alias template : _template
184
185 /**
186 * @see ListItemTemplate::maskRadius
187 */
188 property alias maskRadius : _template.maskRadius
189
190 /**
191 * @brief Whether this element currently contains any item being dragged on top of it.
192 * @property bool ListBrowserDelegate::containsDrag
193 */
194 readonly property alias containsDrag : _dropArea.containsDrag
196 /**
197 * @brief An alias to expose the DropArea component in charge of the drag&drop events.
198 * @see contentDropped
199 */
200 readonly property alias dropArea : _dropArea
201
202 /**
203 * @brief An alias to access the layout fo this control handled by a RowLayout.
204 * @property RowLayout ListBrowserDelegate::layout
205 */
206 readonly property alias layout : _layout
207
208 /**
209 * @brief Emitted when a drop event has been triggered on this control.
210 * @param drop The object with information about the event.
211 */
212 signal contentDropped(var drop)
213
214 /**
215 * @brief Emitted when a drop event has entered the area of this control.
216 * @param drop The object with information about the event.
217 */
218 signal contentEntered(var drag)
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
227 background: Rectangle
228 {
229 color: (control.isCurrentItem || control.containsPress ? Maui.Theme.highlightColor : ( control.hovered ? Maui.Theme.hoverColor : (control.flat ? "transparent" : Maui.Theme.alternateBackgroundColor)))
230
231 radius: control.radius
232
233 Rectangle
234 {
235 width: parent.width
236 height: parent.height
237 radius: control.radius
238 visible: control.containsDrag
239 color: control.Maui.Theme.backgroundColor
240 border.color: control.Maui.Theme.highlightColor
241
242 Behavior on color
243 {
244 Maui.ColorTransition{}
245 }
246 }
247
248 Behavior on color
249 {
250 enabled: !control.flat
251 Maui.ColorTransition{}
252 }
253 }
254
255 DropArea
256 {
257 id: _dropArea
258 width: parent.width
259 height: parent.height
260 enabled: control.draggable
261
262 onDropped: (drop) =>
263 {
264 control.contentDropped(drop)
265 }
266
267 onEntered: (drop) =>
268 {
269 control.contentEntered(drag)
270 }
271 }
272
273 RowLayout
274 {
275 id: _layout
276 anchors.fill: parent
277 spacing: _template.spacing
278
279 Loader
280 {
281 asynchronous: true
282 active: control.checkable || control.checked
283 visible: active
284
285 Layout.alignment: Qt.AlignCenter
286
287 scale: active? 1 : 0
288
289 Behavior on scale
290 {
291 NumberAnimation
292 {
293 duration: Maui.Style.units.longDuration
294 easing.type: Easing.InOutQuad
295 }
296 }
297
298 sourceComponent: CheckBox
299 {
300 checkable: control.checkable
301 autoExclusive: control.autoExclusive
302
303 Binding on checked
304 {
305 value: control.checked
306 restoreMode: Binding.RestoreBinding
307 }
308
309 onToggled: control.toggled(checked)
310 }
311 }
312
313 Maui.ListItemTemplate
314 {
315 id: _template
316 Layout.fillHeight: true
317 Layout.fillWidth: true
318
319 spacing: control.spacing
320
321 hovered: control.hovered
322 isCurrentItem : control.isCurrentItem
323 highlighted: control.containsPress
324 }
325 }
326}
KIOWIDGETS_EXPORT DropJob * drop(const QDropEvent *dropEvent, const QUrl &destUrl, DropJobFlags dropjobFlags, JobFlags flags=DefaultFlags)
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.