Kirigami-addons

FormButtonDelegate.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.Controls
8import QtQuick.Layouts
9
10import org.kde.kirigami as Kirigami
11
12import "private" as Private
13
14/**
15 * @brief A Form delegate that corresponds to a clickable button.
16 *
17 * Use the inherited QtQuick.Controls.AbstractButton.text property to define
18 * the main text of the button.
19 *
20 * The trailing property (right-most side of the button) includes an arrow
21 * pointing to the right by default and cannot be overridden.
22 *
23 * @since KirigamiAddons 0.11.0
24 *
25 * @inherit AbstractFormDelegate
26 */
28 id: root
29
30 /**
31 * @brief A label containing secondary text that appears under the
32 * inherited text property.
33 *
34 * This provides additional information shown in a faint gray color.
35 *
36 * This is supposed to be a short text and the API user should avoid
37 * making it longer than two lines.
38 */
39 property string description: ""
40
41 /**
42 * @brief This property allows to override the internal description
43 * item (a QtQuick.Controls.Label) with a custom component.
44 */
45 property alias descriptionItem: internalDescriptionItem
46
47 /**
48 * @brief This property holds an item that will be displayed to the
49 * left of the delegate's contents.
50 *
51 * default: `null`
52 */
53 property var leading: null
54
55 /**
56 * @brief This property holds the padding after the leading item.
57 *
58 * It is recommended to use Kirigami.Units here instead of direct values.
59 *
60 * @see Kirigami.Units
61 */
62 property real leadingPadding: Kirigami.Units.largeSpacing
64 /**
65 * @brief This property holds an alias to the internal FormCard.FormArrow.
66 *
67 * This allow to hide it completely or change the direction (e.g. to
68 * implement a collapsible section).
69 *
70 * @since 1.7.0
71 */
72 readonly property alias trailingLogo: formArrow
73
74 focusPolicy: Qt.StrongFocus
75
76 contentItem: RowLayout {
77 spacing: 0
78
79 Private.ContentItemLoader {
80 readonly property bool _visible: root.leading && root.leading.visible
81 Layout.rightMargin: _visible ? root.leadingPadding : 0
82 implicitHeight: _visible ? root.leading.implicitHeight : 0
83 implicitWidth: _visible ? root.leading.implicitWidth : 0
84 contentItem: root.leading
85 }
86
87 Kirigami.Icon {
88 visible: root.icon.name !== ""
89 source: root.icon.name
90 color: root.icon.color
91 Layout.rightMargin: (root.icon.name !== "") ? Private.FormCardUnits.horizontalSpacing : 0
92 implicitWidth: (root.icon.name !== "") ? root.icon.width : 0
93 implicitHeight: (root.icon.name !== "") ? root.icon.height : 0
94 }
95
96 ColumnLayout {
97 Layout.fillWidth: true
98 spacing: 0
99
100 Label {
101 Layout.fillWidth: true
102 text: root.text
103 elide: Text.ElideRight
104 wrapMode: Text.Wrap
105 maximumLineCount: 2
106 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
107 Accessible.ignored: true // base class sets this text on root already
108 }
109
110 Label {
111 id: internalDescriptionItem
112 Layout.fillWidth: true
113 text: root.description
114 color: Kirigami.Theme.disabledTextColor
115 elide: Text.ElideRight
116 visible: root.description !== ""
117 wrapMode: Text.Wrap
118 Accessible.ignored: !visible
119 }
120 }
121
122 FormArrow {
123 id: formArrow
124
125 Layout.leftMargin: Kirigami.Units.smallSpacing
126 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
127 direction: Qt.RightArrow
128 visible: root.background.visible
129 }
130 }
131
132 Accessible.onPressAction: action ? action.trigger() : root.clicked()
133}
A base item for delegates to be used in a FormCard.
An arrow UI component used in Form delegates.
Definition FormArrow.qml:22
alias trailingLogo
This property holds an alias to the internal FormCard.FormArrow.
var leading
This property holds an item that will be displayed to the left of the delegate's contents.
real leadingPadding
This property holds the padding after the leading item.
alias descriptionItem
This property allows to override the internal description item (a QtQuick.Controls....
string description
A label containing secondary text that appears under the inherited text property.
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri Jan 24 2025 11:49:11 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.