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 1.3 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
45 /**
46 * @brief By default all children will be positioned at the right end of the row.
47 * The positioning of the elements is handled by a RowLayout, so use the attached properties.
48 * @property list<QtObject> ListItemTemplate::content
49 */
50 default property alias content: _layout.data
51
52 /**
53 * @brief The spacing size between the image/icon header and the labels columns.
54 * @property int ListItemTemplate::spacing
55 */
56 property alias spacing: _layout.spacing
57
58 /**
59 * @brief The text use for the main title text.
60 * @property string ListItemTemplate::text1
61 */
62 property alias text1 : _label1.text
63
64 /**
65 * @brief The text use for the subtitle text.
66 * @property string ListItemTemplate::text2
67 */
68 property alias text2 : _label2.text
69
70 /**
71 * @brief The text use for the left-top far side text.
72 * @property string ListItemTemplate::text3
73 */
74 property alias text3 : _label3.text
75
76 /**
77 * @brief The text use for the left-bottom far side text.
78 * @property string ListItemTemplate::text4
79 */
80 property alias text4 : _label4.text
81
82 /**
83 * @brief An alias for the QQC2 Label handling the title text. Exposed for fine tuning the label font properties.
84 * @note See the QQC2 Label documentation for more information.
85 * @property Label ListItemTemplate::label1
86 */
87 readonly property alias label1 : _label1
88
89 /**
90 * @brief An alias for the QQC2 Label handling the subtitle text. Exposed for fine tuning the label font properties.
91 * @note See the QQC2 Label documentation for more information.
92 * @property Label ListItemTemplate::label2
93 */
94 readonly property alias label2 : _label2
95
96 /**
97 * @brief An alias for the QQC2 Label handling the extra information text. Exposed for fine tuning the label font properties.
98 * @note See the QQC2 Label documentation for more information.
99 * @property Label ListItemTemplate::label3
100 */
101 readonly property alias label3 : _label3
102
103 /**
104 * @brief An alias for the QQC2 Label handling the extra information text. Exposed for fine tuning the label font properties.
105 * @note See the QQC2 Label documentation for more information.
106 * @property Label ListItemTemplate::label4
107 */
108 readonly property alias label4 : _label4
109
110 /**
111 * @brief The container for the icon header section. This is handled by a QQC2 Loader.
112 * By default the source component will be loaded asynchronous.
113 * @property Loader ListItemTemplate::iconContainer
114 */
115 readonly property alias iconContainer : _iconLoader
116
117 /**
118 * @brief The Item loaded as the icon header section.
119 * The component used as the icon header is loaded with a QQC2 Loader - this property exposes that element that was loaded.
120 * By default the loaded item will be a MauiKit IconItem, but if another component is used for `iconComponent`, that will be the resulting Item.
121 * @see structure
122 * @property Item ListItemTemplate::iconItem
123 */
124 readonly property alias iconItem : _iconLoader.item
125
126 /**
127 * @brief Whether the icon/image header section should be visible.
128 * @property bool ListItemTemplate::iconVisible
129 */
130 property alias iconVisible : _iconLoader.visible
131
132 /**
133 * @brief An alias to the column element hosting the title and message labels.
134 * @property ColumnLayout ListItemTemplate::leftLabels
135 * @see label1
136 * @see label2
137 * @property ColumnLayout ListItemTemplate::leftLabels
138 */
139 readonly property alias leftLabels : _leftLabels
140
141 /**
142 * @brief An alias to the column element hosting the far-right extra labels.
143 * @property ColumnLayout ListItemTemplate::rightLabels
144 * @see label3
145 * @see label4
146 * @property ColumnLayout ListItemTemplate::rightLabels
147 */
148 readonly property alias rightLabels : _rightLabels
149
150 /**
151 * @brief An alias to the container layout for this control.
152 * This is handled by a RowLayout.
153 * @property RowLayout ListItemTemplate::layout
154 */
155 readonly property alias layout : _layout
156
157 /**
158 * @brief A size hint for the icon to be used in the header. The final size will depend on the available space.
159 */
160 property int iconSizeHint : Maui.Style.iconSizes.big
161
162 /**
163 * @brief A size hint for the image to be used in the header. The final size will depend on the available space.
164 * By default this is set to `-1` which means that the image header will take the rest of the available space.
165 */
166 property int imageSizeHint : -1
167
168 /**
169 * @brief The size of the header section. This is the size the header container will take.
170 * 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.
171 */
172 property int headerSizeHint : -1
173
174 /**
175 * @see IconItem::imageSource
176 */
177 property string imageSource
178
179 /**
180 * @see IconItem::iconSource
181 */
182 property string iconSource
183
184 /**
185 * @brief Whether this element is currently on a selected or checked state. This is used to highlight the component accordingly.
186 * By default this is set to `false`.
187 */
188 property bool isCurrentItem: false
189
190 /**
191 * @brief Whether the two bottom labels, for title and message, should be displayed.
192 * By default this is set to `true`.
193 */
194 property bool labelsVisible: true
195
196 /**
197 * @see IconItem::fillMode
198 * By default this is set to `Image.PreserveAspectFit`.
199 * @note For more options and information review the QQC2 Image documentation.
200 */
201 property int fillMode : Image.PreserveAspectFit
202
203 /**
204 * @see IconItem::maskRadius
205 */
206 property int maskRadius: 0
207
208 /**
209 * @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.
210 * @note When using a custom component for the header section, pay attention that it has an `implicitHeight` and `implicitWidth` set.
211 */
212 property Component iconComponent : _iconComponent
213
214 /**
215 * @see IconItem::isMask
216 * By default this is set to evaluate `true` for icons equal or smaller in size then 16 pixels.
217 */
218 property bool isMask : iconSizeHint <= Maui.Style.iconSizes.medium
219
220 /**
221 * @brief Whether the control should be styled as being hovered by a cursor.
222 * By default his is set to `false`.
223 */
224 property bool hovered: false
225
226 /**
227 * @brief Whether the control should be styled as being highlighted by some external event.
228 * By default this is set to `false`.
229 */
230 property bool highlighted: false
231
232 Component
233 {
234 id: _iconComponent
235
236 Maui.IconItem
237 {
238 iconSource: control.iconSource
239 imageSource: control.imageSource
240
241 highlighted: control.isCurrentItem || control.highlighted
242 hovered: control.hovered
243
244 iconSizeHint: control.iconSizeHint
245 imageSizeHint: control.imageSizeHint
246
247 fillMode: control.fillMode
248 maskRadius: control.maskRadius
249
250 isMask: control.isMask
251 }
252 }
253
254 RowLayout
255 {
256 id: _layout
257 anchors.fill: parent
258 spacing: Maui.Style.space.small
259
260 readonly property color labelColor: control.isCurrentItem || control.highlighted? Maui.Theme.highlightedTextColor : Maui.Theme.textColor
261
262 Loader
263 {
264 id: _iconLoader
265
266 asynchronous: true
267
268 visible: (control.width > Maui.Style.units.gridUnit * 10) && (control.iconSource.length > 0 || control.imageSource.length > 0)
269
270 active: visible
271
272 Layout.alignment: Qt.AlignCenter
273 Layout.fillWidth: !control.labelsVisible
274 Layout.fillHeight: true
275 Layout.preferredWidth: Math.max(implicitWidth, control.headerSizeHint)
276 Layout.preferredHeight: Math.max(implicitHeight, control.headerSizeHint)
277
278 sourceComponent: control.iconComponent
279 }
280
281
282 ColumnLayout
283 {
284 id: _leftLabels
285 clip: true
286 visible: control.labelsVisible
287
288 Layout.fillHeight: true
289 Layout.fillWidth: true
290
291 spacing: 0
292
293 Label
294 {
295 id: _label1
296 visible: text.length
297
298 Layout.fillWidth: true
299 Layout.fillHeight: true
300
301 verticalAlignment: _label2.visible ? Qt.AlignBottom : Qt.AlignVCenter
302
303 elide: Text.ElideRight
304 // wrapMode: _label2.visible ? Text.NoWrap : Text.Wrap
305 wrapMode: Text.NoWrap
306 textFormat: Text.PlainText
307 color: _layout.labelColor
308 }
309
310 Label
311 {
312 id: _label2
313 visible: text.length
314
315 Layout.fillWidth: true
316 Layout.fillHeight: true
317 verticalAlignment: _label1.visible ? Qt.AlignTop : Qt.AlignVCenter
318
319 elide: Text.ElideRight
320 // wrapMode: Text.Wrap
321 wrapMode: Text.NoWrap
322 textFormat: Text.PlainText
323 color: _layout.labelColor
324 opacity: control.isCurrentItem ? 0.8 : 0.6
325 }
326 }
327
328 ColumnLayout
329 {
330 id: _rightLabels
331 clip: true
332 // visible: (control.width > Maui.Style.units.gridUnit * 15) && control.labelsVisible
333
334 Layout.fillHeight: true
335 Layout.fillWidth: true
336 Layout.maximumWidth: control.width/2
337 Layout.preferredWidth: implicitWidth
338 Layout.minimumWidth: 0
339 spacing: _leftLabels.spacing
340
341 Label
342 {
343 id: _label3
344 visible: text.length > 0
345
346 Layout.fillHeight: true
347 Layout.fillWidth: true
348
349 Layout.alignment: Qt.AlignRight
350
351 horizontalAlignment: Qt.AlignRight
352 verticalAlignment: _label4.visible ? Qt.AlignBottom : Qt.AlignVCenter
353
354 font.pointSize: Maui.Style.fontSizes.tiny
355
356 wrapMode: Text.NoWrap
357 elide: Text.ElideMiddle
358 textFormat: Text.PlainText
359 color: _layout.labelColor
360 opacity: control.isCurrentItem ? 0.8 : 0.6
361 }
362
363 Label
364 {
365 id: _label4
366 visible: text.length > 0
367
368 Layout.fillHeight: true
369 Layout.fillWidth: true
370
371 Layout.alignment: Qt.AlignRight
372 horizontalAlignment: Qt.AlignRight
373 verticalAlignment: _label3.visible ? Qt.AlignTop : Qt.AlignVCenter
374
375 font.pointSize: Maui.Style.fontSizes.tiny
376
377 wrapMode: Text.NoWrap
378 elide: Text.ElideMiddle
379 textFormat: Text.PlainText
380 color: _layout.labelColor
381 opacity: control.isCurrentItem ? 0.8 : 0.6
382 }
383 }
384 }
385}
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.