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.smallSpacing
63
64 focusPolicy: Qt.StrongFocus
65
66 contentItem: RowLayout {
67 spacing: 0
68
69 Private.ContentItemLoader {
70 Layout.rightMargin: visible ? root.leadingPadding : 0
71 visible: root.leading
72 implicitHeight: visible ? root.leading.implicitHeight : 0
73 implicitWidth: visible ? root.leading.implicitWidth : 0
74 contentItem: root.leading
75 }
76
77 Kirigami.Icon {
78 visible: root.icon.name !== ""
79 source: root.icon.name
80 color: root.icon.color
81 Layout.rightMargin: (root.icon.name !== "") ? Private.FormCardUnits.horizontalSpacing : 0
82 implicitWidth: (root.icon.name !== "") ? root.icon.width : 0
83 implicitHeight: (root.icon.name !== "") ? root.icon.height : 0
84 }
85
86 ColumnLayout {
87 Layout.fillWidth: true
88 spacing: 0
89
90 Label {
91 Layout.fillWidth: true
92 text: root.text
93 elide: Text.ElideRight
94 wrapMode: Text.Wrap
95 maximumLineCount: 2
96 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
97 Accessible.ignored: true // base class sets this text on root already
98 }
99
100 Label {
101 id: internalDescriptionItem
102 Layout.fillWidth: true
103 text: root.description
104 color: Kirigami.Theme.disabledTextColor
105 elide: Text.ElideRight
106 visible: root.description !== ""
107 wrapMode: Text.Wrap
108 Accessible.ignored: !visible
109 }
110 }
111
112 FormArrow {
113 Layout.leftMargin: Kirigami.Units.smallSpacing
114 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
115 direction: Qt.RightArrow
116 visible: root.background.visible
117 }
118 }
119
120 Accessible.onPressAction: action ? action.trigger() : root.clicked()
121}
A base item for delegates to be used in a FormCard.
An arrow UI component used in Form delegates.
Definition FormArrow.qml:22
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:49:32 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.