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 2.15
7import QtQuick.Templates 2.15 as T
8import QtQuick.Controls 2.15 as Controls
9import QtQuick.Layouts 1.15
10
11import org.kde.kirigami 2.19 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 topPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
79 bottomPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
80 leftPadding: parent._internal_formcard_margins ? parent._internal_formcard_margins : Kirigami.Units.gridUnit
81 rightPadding: parent._internal_formcard_margins ? parent._internal_formcard_margins : Kirigami.Units.gridUnit
82
83 implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding
84 implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding
85
86 focusPolicy: Qt.StrongFocus
87 hoverEnabled: true
88 background: FormDelegateBackground { control: root }
89
90 Layout.fillWidth: true
91
92 contentItem: RowLayout {
93 spacing: 0
94
95 Private.ContentItemLoader {
96 Layout.rightMargin: visible ? root.leadingPadding : 0
97 visible: root.leading
98 implicitHeight: visible ? root.leading.implicitHeight : 0
99 implicitWidth: visible ? root.leading.implicitWidth : 0
100 contentItem: root.leading
101 }
102
103 Controls.CheckBox {
104 id: checkBoxItem
105 Layout.rightMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
106 focusPolicy: Qt.NoFocus // provided by delegate
107
108 checkState: root.checkState
109 nextCheckState: root.nextCheckState
110 tristate: root.tristate
111
112 onToggled: {
113 root.toggle();
114 root.toggled();
115 }
116 onClicked: root.clicked()
117 onPressAndHold: root.pressAndHold()
118 onDoubleClicked: root.doubleClicked()
119
120 enabled: root.enabled
121 checked: root.checked
122
123 Accessible.ignored: true
124 }
125
126 ColumnLayout {
127 Layout.fillWidth: true
128 spacing: Kirigami.Units.smallSpacing
129 Controls.Label {
130 text: root.text
131 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
132 elide: Text.ElideRight
133 wrapMode: Text.Wrap
134 maximumLineCount: 2
135 Layout.fillWidth: true
136 Accessible.ignored: true
137 }
138
139 Controls.Label {
140 id: internalDescriptionItem
141 Layout.fillWidth: true
142 text: root.description
143 color: Kirigami.Theme.disabledTextColor
144 visible: root.description !== ""
145 wrapMode: Text.Wrap
146 }
147 }
148
149 Private.ContentItemLoader {
150 Layout.leftMargin: visible ? root.trailingPadding : 0
151 visible: root.trailing
152 implicitHeight: visible ? root.trailing.implicitHeight : 0
153 implicitWidth: visible ? root.trailing.implicitWidth : 0
154 contentItem: root.trailing
155 }
156 }
157}
158
A background for Form delegates.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 3 2024 11:46:57 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.