MauiKit Controls

SectionItem.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.Controls
22import QtQuick.Layouts
23
24import org.mauikit.controls as Maui
25
26/**
27 * @inherit QtQuick.Controls.ItemDelegate
28 * @since org.mauikit.controls
29 * @brief An item used for holding information in a vertical column layout.
30 *
31 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-itemdelegate.html">This control inherits from QQC2 ItemDelegate, to checkout its inherited properties refer to the Qt Docs.</a>
32 *
33 * Although it is similar to the SectionGroup (an information header with the children in a vertical layout) this control has some functionality differences, like being interactive and a different styling of the information labels. It is commonly use as the children elements of the SectionGroup.
34 *
35 * @note There is also the FlexSectionItem, which uses a dynamic layout for wrapping the content that does not fit.
36 * @see FlexSectionItem
37 *
38 * @image html Misc/sectionitem.png "Three types of sections inside a SectionGroup"
39 *
40 * If the first and single child element of this control is `checkable`, then the state of such control will be toggled by clicking on the area of the SectionItem.
41 *
42 * @code
43 * Maui.SectionGroup
44 * {
45 * title: "Section with Children"
46 * description: "The description label can be a bit longer explaining something important. Maybe?"
47 *
48 * Maui.SectionItem
49 * {
50 * label1.text: "Checkable section item"
51 * iconSource: "folder"
52 *
53 * Switch
54 * {
55 * onToggled: checked = !checked
56 * }
57 * }
58 *
59 * Maui.SectionItem
60 * {
61 * label1.text: "Single section item"
62 * iconSource: "anchor"
63 * }
64 *
65 * Maui.SectionItem
66 * {
67 * label1.text: "Hello this is a two line section item"
68 * label2.text : "Subtitle text"
69 *
70 * TextArea
71 * {
72 * Layout.fillWidth: true
73 * }
74 * }
75 * }
76 * @endcode
77 *
78 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/SectionItem.qml">You can find a more complete example at this link.</a>
79 */
80ItemDelegate
81{
82 id: control
83
84 padding: Maui.Style.defaultPadding
85 spacing: Maui.Style.space.small
86
87 Layout.fillWidth: true
88 implicitWidth: _layout.implicitWidth + leftPadding + rightPadding
89 implicitHeight: _layout.implicitHeight + topPadding + bottomPadding
91 /**
92 * @brief The items declared as the children of this element will wrap into a new line on constrained spaces.
93 * @note The content is handled by a RowLayout, so to position items use the Layout attached properties.
94 * @property list<QtObject> FlexListItem::content
95 */
96 default property alias content : _layout.data
97
98 /**
99 * @brief An alias to the template element handling the information labels and image/icon.
100 * @see ListItemTemplate
101 * @property ListItemTemplate FlexListItem::template
102 */
103 property alias template: _template
105 /**
106 * @see ListItemTemplate::label1
107 */
108 property alias label1 : _template.label1
109
110 /**
111 * @see ListItemTemplate::label2
112 */
113 property alias label2 : _template.label2
114
115 /**
116 * @see ListItemTemplate::label3
117 */
118 property alias label3 : _template.label3
119
120 /**
121 * @see ListItemTemplate::label4
122 */
123 property alias label4 : _template.label4
125 /**
126 * @see ListItemTemplate::iconSource
127 */
128 property alias iconSource : _template.iconSource
129
130 /**
131 * @see ListItemTemplate::imageSource
132 */
133 property alias imageSource : _template.imageSource
134
135 /**
136 * @see ListItemTemplate::iconSizeHint
137 */
138 property alias iconSizeHint : _template.iconSizeHint
139
140 /**
141 * @brief Whether the control should be styled as flat, as in not having a background or hover/pressed visual effect hints.
142 * By default this is set to `!Handy.isMobile`
143 * @see Handy::isMobile
144 */
145 property bool flat : !Maui.Handy.isMobile
146
147 /**
148 * @brief Whether the first children element from the `content` is checkable.
149 * If it is the the control will have a hover effect to hint about the item being checkable.
150 */
151 readonly property bool childCheckable : control.content.length >= 2 && control.content[1].hasOwnProperty("checkable") ? control.content[1].checkable : false
152
153 hoverEnabled: !Maui.Handy.isMobile
154
155 background: Rectangle
156 {
157 color: control.enabled ? ( control.childCheckable && control.hovered ? Maui.Theme.hoverColor : (control.flat ? "transparent" : Maui.Theme.alternateBackgroundColor)) : "transparent"
158 radius: Maui.Style.radiusV
159
160 Behavior on color
161 {
162 enabled: !control.flat
163 Maui.ColorTransition{}
164 }
165 }
166
167 contentItem: ColumnLayout
168 {
169 id: _layout
170
171 spacing: control.spacing
172
173 Maui.ListItemTemplate
174 {
175 id: _template
176 Layout.fillWidth: true
177 iconSizeHint: Maui.Style.iconSizes.medium
178 label2.wrapMode: Text.WordWrap
179 label1.text: control.text
180 label2.font.pointSize: Maui.Style.fontSizes.small
181 iconSource: control.icon.name
182 }
183 }
184
185 onClicked:
186 {
187 if(control.childCheckable)
188 {
189 console.log("Trying to toggle")
190 control.content[1].toggled()
191 }
192 }
193}
The Handy class.
Definition handy.h:41
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.