MauiKit Controls

ListItemTemplate.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 QtQuick.Layouts
22import QtQuick.Controls
23
24import org.mauikit.controls as Maui
25
26/**
27 * @inherit QtQuick.Item
28 * @brief A template for an horizontal layout of information.
29 *
30 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-item.html">This controls inherits from QQC2 Item, to checkout its inherited properties refer to the Qt Docs.</a>
31 *
32 * The structure of this control is divided into a left side header for the image/icon and a four [4] labels for the title, message at the right side of the header, and at the far right side another two labels for complementary information.
33 *
34 * The icon header section can be modified and assigned to any custom control.
35 * @see iconComponent
36 *
37 * For extra information checkout the ListBrowserDelegate documentation, since this template element is used as its base.
38 */
39Item
40{
41 id: control
42
43 implicitHeight: _layout.implicitHeight
44 implicitWidth: _layout.implicitWidth
45
46 /**
47 * @brief By default all children will be positioned at the right end of the row.
48 * The positioning of the elements is handled by a RowLayout, so use the attached properties.
49 * @property list<QtObject> ListItemTemplate::content
50 */
51 default property alias content: _layout.data
52
53 /**
54 * @brief The spacing size between the image/icon header and the labels columns.
55 * @property int ListItemTemplate::spacing
56 */
57 property alias spacing: _layout.spacing
58
59 /**
60 * @brief The text use for the main title text.
61 * @property string ListItemTemplate::text1
62 */
63 property alias text1 : _label1.text
64
65 /**
66 * @brief The text use for the subtitle text.
67 * @property string ListItemTemplate::text2
68 */
69 property alias text2 : _label2.text
70
71 /**
72 * @brief The text use for the left-top far side text.
73 * @property string ListItemTemplate::text3
74 */
75 property alias text3 : _label3.text
76
77 /**
78 * @brief The text use for the left-bottom far side text.
79 * @property string ListItemTemplate::text4
80 */
81 property alias text4 : _label4.text
82
83 /**
84 * @brief An alias for the QQC2 Label handling the title text. Exposed for fine tuning the label font properties.
85 * @note See the QQC2 Label documentation for more information.
86 * @property Label ListItemTemplate::label1
87 */
88 readonly property alias label1 : _label1
89
90 /**
91 * @brief An alias for the QQC2 Label handling the subtitle text. Exposed for fine tuning the label font properties.
92 * @note See the QQC2 Label documentation for more information.
93 * @property Label ListItemTemplate::label2
94 */
95 readonly property alias label2 : _label2
96
97 /**
98 * @brief An alias for the QQC2 Label handling the extra information text. Exposed for fine tuning the label font properties.
99 * @note See the QQC2 Label documentation for more information.
100 * @property Label ListItemTemplate::label3
101 */
102 readonly property alias label3 : _label3
103
104 /**
105 * @brief An alias for the QQC2 Label handling the extra information text. Exposed for fine tuning the label font properties.
106 * @note See the QQC2 Label documentation for more information.
107 * @property Label ListItemTemplate::label4
108 */
109 readonly property alias label4 : _label4
110
111 /**
112 * @brief The container for the icon header section. This is handled by a QQC2 Loader.
113 * By default the source component will be loaded asynchronous.
114 * @property Loader ListItemTemplate::iconContainer
115 */
116 readonly property alias iconContainer : _iconLoader
117
118 /**
119 * @brief The Item loaded as the icon header section.
120 * The component used as the icon header is loaded with a QQC2 Loader - this property exposes that element that was loaded.
121 * By default the loaded item will be a MauiKit IconItem, but if another component is used for `iconComponent`, that will be the resulting Item.
122 * @see structure
123 * @property Item ListItemTemplate::iconItem
124 */
125 readonly property alias iconItem : _iconLoader.item
126
127 /**
128 * @brief Whether the icon/image header section should be visible.
129 * @property bool ListItemTemplate::iconVisible
130 */
131 property alias iconVisible : _iconLoader.visible
132
133 /**
134 * @brief An alias to the column element hosting the title and message labels.
135 * @property ColumnLayout ListItemTemplate::leftLabels
136 * @see label1
137 * @see label2
138 * @property ColumnLayout ListItemTemplate::leftLabels
139 */
140 readonly property alias leftLabels : _leftLabels
141
142 /**
143 * @brief An alias to the column element hosting the far-right extra labels.
144 * @property ColumnLayout ListItemTemplate::rightLabels
145 * @see label3
146 * @see label4
147 * @property ColumnLayout ListItemTemplate::rightLabels
148 */
149 readonly property alias rightLabels : _rightLabels
150
151 /**
152 * @brief An alias to the container layout for this control.
153 * This is handled by a RowLayout.
154 * @property RowLayout ListItemTemplate::layout
155 */
156 readonly property alias layout : _layout
157
158 /**
159 * @brief A size hint for the icon to be used in the header. The final size will depend on the available space.
160 */
161 property int iconSizeHint : Maui.Style.iconSizes.big
162
163 /**
164 * @brief A size hint for the image to be used in the header. The final size will depend on the available space.
165 * By default this is set to `-1` which means that image will fill the available space.
166 */
167 property int imageSizeHint : -1
168
169 /**
170 * @brief The size of the header section. This is the size the header container will take.
171 * By default this is set to `-1` which means that the size of the header will be determined by the child implicit height and width.
172 */
173 property int headerSizeHint : -1
174
175 /**
176 * @see IconItem::imageSource
177 */
178 property string imageSource
179
180 /**
181 * @see IconItem::iconSource
182 */
183 property string iconSource
184
185 /**
186 * @brief Whether this element is currently on a selected or checked state. This is used to highlight the component accordingly.
187 * By default this is set to `false`.
188 */
189 property bool isCurrentItem: false
190
191 /**
192 * @brief Whether the two bottom labels, for title and message, should be displayed.
193 * By default this is set to `true`.
194 */
195 property bool labelsVisible: true
196
197 /**
198 * @see IconItem::fillMode
199 * By default this is set to `Image.PreserveAspectFit`.
200 * @note For more options and information review the QQC2 Image documentation.
201 */
202 property int fillMode : Image.PreserveAspectFit
203
204 /**
205 * @see IconItem::maskRadius
206 */
207 property int maskRadius: 0
208
209 /**
210 * @brief The header section can be modified by changing its component to a custom one. By default the component used for the `iconComponent` is a MauiKit IconItem element.
211 * @note When using a custom component for the header section, pay attention that it has an `implicitHeight` and `implicitWidth` set.
212 */
213 property Component iconComponent : _iconComponent
214
215 /**
216 * @see IconItem::isMask
217 * By default this is set to evaluate `true` for icons equal or smaller in size then 16 pixels.
218 */
219 property bool isMask : iconSizeHint <= Maui.Style.iconSizes.medium
220
221 /**
222 * @brief Whether the control should be styled as being hovered by a cursor.
223 * By default his is set to `false`.
224 */
225 property bool hovered: false
226
227 /**
228 * @brief Whether the control should be styled as being highlighted by some external event.
229 * By default this is set to `false`.
230 */
231 property bool highlighted: false
232
233 Component
234 {
235 id: _iconComponent
236
237 Maui.IconItem
238 {
239 width: visible ? implicitWidth : -control.spacing
240 iconSource: control.iconSource
241 imageSource: control.imageSource
242
243 highlighted: control.isCurrentItem || control.highlighted
244 hovered: control.hovered
245
246 iconSizeHint: control.iconSizeHint
247 imageSizeHint: control.imageSizeHint
248
249 fillMode: control.fillMode
250 maskRadius: control.maskRadius
251
252 isMask: control.isMask
253 }
254 }
255
256 RowLayout
257 {
258 id: _layout
259 anchors.fill: parent
260 spacing: Maui.Style.space.small
261
262 readonly property color labelColor: control.isCurrentItem || control.highlighted? Maui.Theme.highlightedTextColor : Maui.Theme.textColor
263
264 Loader
265 {
266 id: _iconLoader
267 visible: (control.width > Maui.Style.units.gridUnit * 10) && (control.iconSource.length > 0 || control.imageSource.length > 0)
268
269 // Layout.fillWidth: !control.labelsVisible
270 // Layout.fillHeight: true
271 Layout.preferredWidth: visible ? Math.max(implicitWidth, control.headerSizeHint, 0) :-_layout.spacing
272 Layout.preferredHeight: visible ? Math.max(implicitHeight, control.headerSizeHint, 0) : 0
273
274 asynchronous: true
275 active: visible || item
276
277 sourceComponent: control.iconComponent
278/*
279 OpacityAnimator on opacity
280 {
281 from: 0
282 to: 1
283 duration: Maui.Style.units.longDuration
284 running: _iconLoader.status === Loader.Ready
285 }*/
286 }
287
288
289 ColumnLayout
290 {
291 id: _leftLabels
292 clip: true
293 visible: control.labelsVisible
294
295 Layout.fillHeight: true
296 Layout.fillWidth: true
297
298 spacing: 0
299
300 Label
301 {
302 id: _label1
303 visible: text.length
304
305 Layout.fillWidth: true
306 Layout.fillHeight: true
307
308 verticalAlignment: _label2.visible ? Qt.AlignBottom : Qt.AlignVCenter
309
310 elide: Text.ElideRight
311 // wrapMode: _label2.visible ? Text.NoWrap : Text.Wrap
312 wrapMode: Text.NoWrap
313 textFormat: Text.PlainText
314 color: _layout.labelColor
315 }
316
317 Label
318 {
319 id: _label2
320 visible: text.length
321
322 Layout.fillWidth: true
323 Layout.fillHeight: true
324 verticalAlignment: _label1.visible ? Qt.AlignTop : Qt.AlignVCenter
325
326 elide: Text.ElideRight
327 // wrapMode: Text.Wrap
328 wrapMode: Text.NoWrap
329 textFormat: Text.PlainText
330 color: _layout.labelColor
331 opacity: control.isCurrentItem ? 0.8 : 0.6
332 }
333 }
334
335 ColumnLayout
336 {
337 id: _rightLabels
338 clip: true
339 // visible: (control.width > Maui.Style.units.gridUnit * 15) && control.labelsVisible
340 Layout.fillHeight: true
341 Layout.fillWidth: true
342 Layout.maximumWidth: control.width/2
343 Layout.preferredWidth: visible ? implicitWidth : -_layout.spacing
344 Layout.minimumWidth: 0
345 spacing: _leftLabels.spacing
346 visible: _label3.text.length > 0 || _label4.text.length > 0
347
348 Label
349 {
350 id: _label3
351 visible: text.length > 0
352
353 Layout.fillHeight: true
354 Layout.fillWidth: true
355
356 Layout.alignment: Qt.AlignRight
357
358 horizontalAlignment: Qt.AlignRight
359 verticalAlignment: _label4.visible ? Qt.AlignBottom : Qt.AlignVCenter
360
361 font.pointSize: Maui.Style.fontSizes.tiny
362
363 wrapMode: Text.NoWrap
364 elide: Text.ElideMiddle
365 textFormat: Text.PlainText
366 color: _layout.labelColor
367 opacity: control.isCurrentItem ? 0.8 : 0.6
368 }
369
370 Label
371 {
372 id: _label4
373 visible: text.length > 0
374
375 Layout.fillHeight: true
376 Layout.fillWidth: true
377
378 Layout.alignment: Qt.AlignRight
379 horizontalAlignment: Qt.AlignRight
380 verticalAlignment: _label3.visible ? Qt.AlignTop : Qt.AlignVCenter
381
382 font.pointSize: Maui.Style.fontSizes.tiny
383
384 wrapMode: Text.NoWrap
385 elide: Text.ElideMiddle
386 textFormat: Text.PlainText
387 color: _layout.labelColor
388 opacity: control.isCurrentItem ? 0.8 : 0.6
389 }
390 }
391
392 Loader
393 {
394 id: _loader
395 asynchronous: true
396 active: control.Maui.Controls.badgeText && control.Maui.Controls.badgeText.length > 0 && control.visible
397 visible: active
398 width: visible ? implicitWidth : -_layout.spacing
399
400 OpacityAnimator on opacity
401 {
402 from: 0
403 to: 1
404 duration: Maui.Style.units.longDuration
405 running: _loader.status === Loader.Ready
406 }
407
408 ScaleAnimator on scale
409 {
410 from: 0.5
411 to: 1
412 duration: Maui.Style.units.longDuration
413 running: _loader.status === Loader.Ready
414 easing.type: Easing.OutInQuad
415 }
416
417 sourceComponent: Maui.Badge
418 {
419 text: control.Maui.Controls.badgeText
420
421 padding: 2
422 font.pointSize: Maui.Style.fontSizes.tiny
423
424 Maui.Theme.colorSet: Maui.Theme.View
425 Maui.Theme.backgroundColor: Maui.Theme.negativeBackgroundColor
426 Maui.Theme.textColor: Maui.Theme.negativeTextColor
427 }
428 }
429 }
430}
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 11:57:11 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.