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 horizontalPadding: Private.FormCardUnits.horizontalPadding
84 verticalPadding: Private.FormCardUnits.verticalPadding
85
86 implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding
87 implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding
88
89 focusPolicy: Qt.StrongFocus
90 hoverEnabled: true
91 background: FormDelegateBackground { control: root }
92
93 Layout.fillWidth: true
94
95 contentItem: ColumnLayout {
96 spacing: Private.FormCardUnits.verticalSpacing
97
98 RowLayout {
99 id: innerRowLayout
100
101 spacing: 0
102
103 Private.ContentItemLoader {
104 Layout.rightMargin: visible ? root.leadingPadding : 0
105 visible: root.leading
106 implicitHeight: visible ? root.leading.implicitHeight : 0
107 implicitWidth: visible ? root.leading.implicitWidth : 0
108 contentItem: root.leading
109 }
110
111 Controls.CheckBox {
112 id: checkBoxItem
113 Layout.rightMargin: Private.FormCardUnits.horizontalSpacing
114 focusPolicy: Qt.NoFocus // provided by delegate
115
116 checkState: root.checkState
117 nextCheckState: root.nextCheckState
118 tristate: root.tristate
119
120 topPadding: 0
121 leftPadding: 0
122 rightPadding: 0
123 bottomPadding: 0
124
125 onToggled: {
126 root.toggle();
127 root.toggled();
128 }
129 onClicked: root.clicked()
130 onPressAndHold: root.pressAndHold()
131 onDoubleClicked: root.doubleClicked()
132
133 contentItem: null // Remove right margin
134 spacing: 0
135
136 enabled: root.enabled
137 checked: root.checked
138
139 Accessible.ignored: true
140 }
141
142 Kirigami.Icon {
143 visible: root.icon.name.length > 0 || root.icon.source.toString().length > 0
144 source: root.icon.name.length > 0 ? root.icon.name : root.icon.source
145 color: root.icon.color
146 Layout.rightMargin: visible ? Private.FormCardUnits.horizonalSpacing : 0
147 implicitWidth: visible ? root.icon.width : 0
148 implicitHeight: visible ? root.icon.height : 0
149 }
150
151 Controls.Label {
152 text: root.text
153 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
154 elide: Text.ElideRight
155 wrapMode: Text.Wrap
156 maximumLineCount: 2
157 Layout.fillWidth: true
158 Accessible.ignored: true
159 }
160
161 Private.ContentItemLoader {
162 Layout.leftMargin: visible ? root.trailingPadding : 0
163 visible: root.trailing
164 implicitHeight: visible ? root.trailing.implicitHeight : 0
165 implicitWidth: visible ? root.trailing.implicitWidth : 0
166 contentItem: root.trailing
167 }
168 }
169
170 Controls.Label {
171 id: internalDescriptionItem
172
173 Layout.fillWidth: true
174 text: root.description
175 color: Kirigami.Theme.disabledTextColor
176 visible: root.description !== ""
177 wrapMode: Text.Wrap
178 }
179 }
180}
181
A background for Form delegates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:33:45 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.