Kirigami-addons

FormCheckDelegate.qml
1/*
2 * Copyright 2022 Devin Lin <devin@kde.org>
3 * SPDX-License-Identifier: LGPL-2.0-or-later
4 */
5
6import QtQuick
7import QtQuick.Templates as T
8import QtQuick.Controls as Controls
9import QtQuick.Layouts
10
11import org.kde.kirigami as Kirigami
12
13import "private" as Private
14
15/**
16 * @brief A Form delegate that corresponds to a checkbox.
17 *
18 * This component is used for individual settings that can be toggled on, off, or tristate, typically in conjunction with multiple other checkboxes.
19 *
20 * Use the inherited QtQuick.Controls.AbstractButton.text property to define the main text of the checkbox.
21 *
22 * If you need a purely on/off toggle for a single setting, consider using a FormSwitchDelegate.
23 *
24 * If you need multiple toggles for the same setting, use a FormRadioDelegate
25 * instead.
26 *
27 * If you need multiple values for the same setting, use a
28 * FormComboBoxDelegate instead.
29 *
30 * @since KirigamiAddons 0.11.0
31 *
32 * @see QtQuick.Controls.AbstractButton
33 * @see FormSwitchDelegate
34 * @see FormComboBoxDelegate
35 * @see FormRadioDelegate
36 *
37 * @inherit QtQuick.Controls.CheckDelegate
38 */
39T.CheckDelegate {
40 id: root
41
42 /**
43 * @brief A label containing secondary text that appears under the
44 * inherited text property.
45 *
46 * This provides additional information shown in a faint gray color.
47 */
48 property string description: ""
49
50 /**
51 * @brief This property holds an item that will be displayed to the left
52 * of the delegate's contents.
53 */
54 property var leading: null
55
56 /**
57 * @brief This property holds the padding after the leading item.
58 */
59 property real leadingPadding: Kirigami.Units.smallSpacing
61 /**
62 * @brief This property holds an item that will be displayed to the right
63 * of the delegate's contents.
64 */
65 property var trailing: null
66
67 /**
68 * @brief This property holds the padding before the trailing item.
69 */
70 property real trailingPadding: Kirigami.Units.smallSpacing
71
72 /**
73 * @brief This property allows to override the internal description
74 * item (a QtQuick.Controls.Label) with a custom component.
75 */
76 property alias descriptionItem: internalDescriptionItem
77
78 icon {
79 width: Kirigami.Units.iconSizes.smallMedium
80 height: Kirigami.Units.iconSizes.smallMedium
81 }
82
83 topPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
84 bottomPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
85 leftPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
86 rightPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
87
88 implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding
89 implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding
90
91 focusPolicy: Qt.StrongFocus
92 hoverEnabled: true
93 background: FormDelegateBackground { control: root }
94
95 Layout.fillWidth: true
96
97 contentItem: ColumnLayout {
98 spacing: Kirigami.Units.smallSpacing
99
100 RowLayout {
101 id: innerRowLayout
102
103 spacing: 0
104
105 Private.ContentItemLoader {
106 Layout.rightMargin: visible ? root.leadingPadding : 0
107 visible: root.leading
108 implicitHeight: visible ? root.leading.implicitHeight : 0
109 implicitWidth: visible ? root.leading.implicitWidth : 0
110 contentItem: root.leading
111 }
112
113 Controls.CheckBox {
114 id: checkBoxItem
115 Layout.rightMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
116 focusPolicy: Qt.NoFocus // provided by delegate
117
118 checkState: root.checkState
119 nextCheckState: root.nextCheckState
120 tristate: root.tristate
121
122 topPadding: 0
123 leftPadding: 0
124 rightPadding: 0
125 bottomPadding: 0
126
127 onToggled: {
128 root.toggle();
129 root.toggled();
130 }
131 onClicked: root.clicked()
132 onPressAndHold: root.pressAndHold()
133 onDoubleClicked: root.doubleClicked()
134
135 contentItem: null // Remove right margin
136 spacing: 0
137
138 enabled: root.enabled
139 checked: root.checked
140
141 Accessible.ignored: true
142 }
143
144 Kirigami.Icon {
145 visible: root.icon.name.length > 0 || root.icon.source.toString().length > 0
146 source: root.icon.name.length > 0 ? root.icon.name : root.icon.source
147 color: root.icon.color
148 Layout.rightMargin: visible ? Kirigami.Units.largeSpacing : 0
149 implicitWidth: visible ? root.icon.width : 0
150 implicitHeight: visible ? root.icon.height : 0
151 }
152
153 Controls.Label {
154 text: root.text
155 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
156 elide: Text.ElideRight
157 wrapMode: Text.Wrap
158 maximumLineCount: 2
159 Layout.fillWidth: true
160 Accessible.ignored: true
161 }
162
163 Private.ContentItemLoader {
164 Layout.leftMargin: visible ? root.trailingPadding : 0
165 visible: root.trailing
166 implicitHeight: visible ? root.trailing.implicitHeight : 0
167 implicitWidth: visible ? root.trailing.implicitWidth : 0
168 contentItem: root.trailing
169 }
170 }
171
172 Controls.Label {
173 id: internalDescriptionItem
174
175 Layout.fillWidth: true
176 text: root.description
177 color: Kirigami.Theme.disabledTextColor
178 visible: root.description !== ""
179 wrapMode: Text.Wrap
180 }
181 }
182}
183
A background for Form delegates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:10:34 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.