Kirigami-addons

FormRadioDelegate.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 radio button.
17 *
18 * This component is used for creating multiple on/off toggles for the same
19 * setting. In other words, by grouping multiple radio buttons under the same
20 * parent, only one of the radio buttons should be checkable and applied to a
21 * setting.
22 *
23 * Use the inherited QtQuick.Controls.AbstractButton.text property to define
24 * the main text of the radio button.
25 *
26 * If you need multiple values for the same setting, use a
27 * FormComboBoxDelegate instead.
28 *
29 * If you need a purely on/off toggle for a single setting, use a
30 * FormSwitchDelegate instead.
31 *
32 * If you need an on/off/tristate toggle, use a FormCheckDelegate instead.
33 *
34 * @since KirigamiAddons 0.11.0
35 *
36 * @see QtQuick.Controls.AbstractButton
37 * @see FormSwitchDelegate
38 * @see FormCheckDelegate
39 * @see FormComboBoxDelegate
40 *
41 * @inherit QtQuick.Controls.RadioDelegate
42 */
43T.RadioDelegate {
44 id: root
45
46 /**
47 * @brief A label containing secondary text that appears under the
48 * inherited text property.
49 *
50 * This provides additional information shown in a faint gray color.
51 */
52 property string description: ""
53
54 /**
55 * @brief This property holds an item that will be displayed to the left of the delegate's contents.
56 */
57 property var leading: null
58
59 /**
60 * @brief This property holds the padding after the leading item.
61 */
62 property real leadingPadding: Kirigami.Units.smallSpacing
64 /**
65 * @brief This property holds an item that will be displayed after the
66 * delegate's contents.
67 */
68 property var trailing: null
69
70 /**
71 * @brief This property holds the padding before the trailing item.
72 */
73 property real trailingPadding: Kirigami.Units.smallSpacing
74
75 leftPadding: Kirigami.Units.gridUnit
76 topPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
77 bottomPadding: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
78 rightPadding: Kirigami.Units.gridUnit
79
80 implicitWidth: contentItem.implicitWidth + leftPadding + rightPadding
81 implicitHeight: contentItem.implicitHeight + topPadding + bottomPadding
82
83 focusPolicy: Qt.StrongFocus
84 hoverEnabled: true
85 background: FormDelegateBackground { control: root }
86
87 Layout.fillWidth: true
88
89 contentItem: RowLayout {
90 spacing: 0
91
92 Private.ContentItemLoader {
93 Layout.rightMargin: visible ? root.leadingPadding : 0
94 visible: root.leading
95 implicitHeight: visible ? root.leading.implicitHeight : 0
96 implicitWidth: visible ? root.leading.implicitWidth : 0
97 contentItem: root.leading
98 }
99
100 Controls.RadioButton {
101 id: radioButtonItem
102 focusPolicy: Qt.NoFocus // provided by delegate
103 Layout.rightMargin: Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing
104
105 enabled: root.enabled
106 checked: root.checked
107
108 onToggled: root.toggled()
109 onClicked: root.clicked()
110 onPressAndHold: root.pressAndHold()
111 onDoubleClicked: root.doubleClicked()
112
113 onCheckedChanged: {
114 root.checked = checked;
115 checked = Qt.binding(() => root.checked);
116 }
117 }
118
119 ColumnLayout {
120 Layout.fillWidth: true
121 spacing: Kirigami.Units.smallSpacing
122
123 Controls.Label {
124 Layout.fillWidth: true
125 text: root.text
126 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
127 elide: Text.ElideRight
128 wrapMode: Text.Wrap
129 maximumLineCount: 2
130 }
131
132 Controls.Label {
133 visible: root.description !== ""
134 Layout.fillWidth: true
135 text: root.description
136 color: Kirigami.Theme.disabledTextColor
137 wrapMode: Text.Wrap
138 }
139 }
140
141 Private.ContentItemLoader {
142 Layout.leftMargin: visible ? root.trailingPadding : 0
143 visible: root.trailing
144 implicitHeight: visible ? root.trailing.implicitHeight : 0
145 implicitWidth: visible ? root.trailing.implicitWidth : 0
146 contentItem: root.trailing
147 }
148 }
149}
150
151
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.