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 1.3 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 implicitHeight: _layout.implicitHeight + topPadding + bottomPadding
90 /**
91 * @brief The items declared as the children of this element will wrap into a new line on constrained spaces.
92 * @note The content is handled by a RowLayout, so to position items use the Layout attached properties.
93 * @property list<QtObject> FlexListItem::content
94 */
95 default property alias content : _layout.data
96
97 /**
98 * @brief An alias to the template element handling the information labels and image/icon.
99 * @see ListItemTemplate
100 * @property ListItemTemplate FlexListItem::template
101 */
102 property alias template: _template
104 /**
105 * @see ListItemTemplate::label1
106 */
107 property alias label1 : _template.label1
108
109 /**
110 * @see ListItemTemplate::label2
111 */
112 property alias label2 : _template.label2
113
114 /**
115 * @see ListItemTemplate::label3
116 */
117 property alias label3 : _template.label3
118
119 /**
120 * @see ListItemTemplate::label4
121 */
122 property alias label4 : _template.label4
124 /**
125 * @see ListItemTemplate::iconSource
126 */
127 property alias iconSource : _template.iconSource
128
129 /**
130 * @see ListItemTemplate::imageSource
131 */
132 property alias imageSource : _template.imageSource
133
134 /**
135 * @see ListItemTemplate::iconSizeHint
136 */
137 property alias iconSizeHint : _template.iconSizeHint
138
139 /**
140 * @brief Whether the control should be styled as flat, as in not having a background or hover/pressed visual effect hints.
141 * By default this is set to `!Handy.isMobile`
142 * @see Handy::isMobile
143 */
144 property bool flat : !Maui.Handy.isMobile
145
146 /**
147 * @brief Whether the first children element from the `content` is checkable.
148 * If it is the the control will have a hover effect to hint about the item being checkable.
149 */
150 readonly property bool childCheckable : control.content.length >= 2 && control.content[1].hasOwnProperty("checkable") ? control.content[1].checkable : false
151
152 hoverEnabled: !Maui.Handy.isMobile
153
154 background: Rectangle
155 {
156 color: control.enabled ? ( control.childCheckable && control.hovered ? Maui.Theme.hoverColor : (control.flat ? "transparent" : Maui.Theme.alternateBackgroundColor)) : "transparent"
157 radius: Maui.Style.radiusV
158
159 Behavior on color
160 {
161 enabled: !control.flat
162 Maui.ColorTransition{}
163 }
164 }
165
166 contentItem: ColumnLayout
167 {
168 id: _layout
169
170 spacing: control.spacing
171
172 Maui.ListItemTemplate
173 {
174 id: _template
175 Layout.fillWidth: true
176 iconSizeHint: Maui.Style.iconSizes.medium
177 label2.wrapMode: Text.WordWrap
178 label1.font.weight: Font.Medium
179 label1.text: control.text
180 iconSource: control.icon.name
181 }
182 }
183
184 onClicked:
185 {
186 if(control.childCheckable)
187 {
188 console.log("Trying to toggle")
189 control.content[1].toggled()
190 }
191 }
192}
The Handy class.
Definition handy.h:41
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.