MauiKit Controls

LabelDelegate.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
22
23import org.mauikit.controls 1.3 as Maui
24
25/**
26 * @inherit QtQuick.Controls.Control
27 * @brief A basic MauiKit delegate for displaying a text label with an icon in a horizontal layout.
28 *
29 * @warning This item is not interactive and is meant to be use as an information label. Not press events are handled.
30 * For a similar interactive delegate checkout ListDelegate.
31 * @see ListDelegate
32 *
33 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-itemdelegate.html">This controls inherits from QQC2 ItemDelegate, to checkout its inherited properties refer to the Qt Docs.</a>
34 *
35 * @image html Misc/labeldelegate.png
36 *
37 * @code
38 * Column
39 * {
40 * width: Math.min(600, parent.width)
41 * anchors.centerIn: parent
42 *
43 * Maui.LabelDelegate
44 * {
45 * width: parent.width
46 * text: "Hola!"
47 * icon.name: "love"
48 * }
49 *
50 * Maui.LabelDelegate
51 * {
52 * width: parent.width
53 * text: "Section Header"
54 * icon.name: "anchor"
55 * isSection: true
56 * }
57 *
58 *
59 * Maui.LabelDelegate
60 * {
61 * width: parent.width
62 * text: "Regular label thingy."
63 * }
64 *
65 * Maui.LabelDelegate
66 * {
67 * width: parent.width
68 * text: "Hola!"
69 * icon.name: "folder"
70 * }
71 * }
72 * @endcode
73 *
74 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/LabelDelegate.qml">You can find a more complete example at this link.</a>
75 *
76 */
77Control
78{
79 id: control
80
81 implicitHeight: Maui.Style.rowHeight + topPadding + bottomPadding
82
83 focusPolicy: Qt.NoFocus
84 hoverEnabled: false
85
86 padding: Maui.Style.defaultPadding
87 spacing: Maui.Style.defaultSpacing
88
89 /**
90 * @brief Whether the label should be styled as a section header.
91 * @see SectionHeader
92 * By default this is set to `false`.
93 */
94 property bool isSection : false
95
96 /**
97 * @see IconLabel::label
98 */
99 property alias label: _labelTxt.label
100
101 /**
102 * @see IconLabel::color
103 */
104 property alias color: _labelTxt.color
105
106 /**
107 * @brief The group icon properties, to set the icon name, source, and size.
108 */
109 property alias icon : _dummyButton.icon
110
111 /**
112 * @see IconLabel::text
113 */
114 property alias text : _labelTxt.text
115
116 /**
117 * @brief An alias to the IconLabel control handling the information.
118 * @see IconLabel for properties.
119 * @property IconLabel LabelDelegate::template
120 */
121 property alias template : _labelTxt
122
123 background: Item{}
124
125 AbstractButton
126 {
127 id: _dummyButton
128 visible: false
129 icon.height: Maui.Style.iconSize
130 icon.width: Maui.Style.iconSize
131 icon.color: control.color
132 }
133
134 contentItem: MouseArea
135 {
136 propagateComposedEvents: true
137 preventStealing: false
138 // onPressed: mouse.accepted= false
139
140 Maui.IconLabel
141 {
142 id: _labelTxt
143
144 anchors.fill: parent
145
146 display: ToolButton.TextBesideIcon
147 icon: control.icon
148 font: control.isSection ? Maui.Style.h2Font : Maui.Style.defaultFont
149
150 alignment: Qt.AlignLeft
151
152 text: control.text
153 color: control.isCurrentListItem ? control.Maui.Theme.highlightedTextColor : control.Maui.Theme.textColor
154 }
155 }
156}
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.