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 2.15
7import QtQuick.Controls 2.15
8import QtQuick.Layouts 1.15
9
10import org.kde.kirigami 2.19 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 icon {
67 width: Kirigami.Units.iconSizes.small
68 height: Kirigami.Units.iconSizes.small
69 }
70
71 contentItem: RowLayout {
72 spacing: 0
73
74 Private.ContentItemLoader {
75 Layout.rightMargin: visible ? root.leadingPadding : 0
76 visible: root.leading
77 implicitHeight: visible ? root.leading.implicitHeight : 0
78 implicitWidth: visible ? root.leading.implicitWidth : 0
79 contentItem: root.leading
80 }
81
82 Kirigami.Icon {
83 visible: root.icon.name !== ""
84 source: root.icon.name
85 color: root.icon.color
86 Layout.rightMargin: (root.icon.name !== "") ? Kirigami.Units.largeSpacing + Kirigami.Units.smallSpacing : 0
87 implicitWidth: (root.icon.name !== "") ? root.icon.width : 0
88 implicitHeight: (root.icon.name !== "") ? root.icon.height : 0
89 }
90
91 ColumnLayout {
92 Layout.fillWidth: true
93 spacing: Kirigami.Units.smallSpacing
94
95 Label {
96 Layout.fillWidth: true
97 text: root.text
98 elide: Text.ElideRight
99 wrapMode: Text.Wrap
100 maximumLineCount: 2
101 color: root.enabled ? Kirigami.Theme.textColor : Kirigami.Theme.disabledTextColor
102 Accessible.ignored: true // base class sets this text on root already
103 }
104
105 Label {
106 id: internalDescriptionItem
107 Layout.fillWidth: true
108 text: root.description
109 color: Kirigami.Theme.disabledTextColor
110 elide: Text.ElideRight
111 visible: root.description !== ""
112 wrapMode: Text.Wrap
113 Accessible.ignored: !visible
114 }
115 }
116
117 FormArrow {
118 Layout.leftMargin: Kirigami.Units.smallSpacing
119 Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
120 direction: Qt.RightArrow
121 visible: root.background.visible
122 }
123 }
124
125 Accessible.onPressAction: action ? action.trigger() : root.clicked()
126}
A base item for delegates to be used in a FormCard.
An arrow UI component used in Form delegates.
Definition FormArrow.qml:22
QString name(StandardShortcut id)
AlignRight
RightArrow
ElideRight
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.