Kirigami-addons

FormTextDelegate.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 text label and a description.
16 *
17 * This component is used to create primary text with the inherited
18 * QtQuick.Controls.AbstractButton.text property, with an optional
19 * ::description that serves as secondary text/subtitle.
20 *
21 * If you need just a secondary text component, use a FormSectionText
22 * instead.
23 *
24 * @since KirigamiAddons 0.11.0
25 *
26 * @see FormSectionText
27 * @see QtQuick.Controls.AbstractButton
28 *
29 * @inherit AbstractFormDelegate
30 */
32 id: root
33
34 /**
35 * @brief A label containing secondary text that appears under the
36 * inherited text property.
37 *
38 * This provides additional information shown in a faint gray color.
39 */
40 property string description: ""
41
42 /**
43 * @brief This property allows for access to the description label item.
44 */
45 property alias descriptionItem: internalDescriptionItem
46
47 /**
48 * @brief This property holds allows for access to the text label item.
49 */
50 property alias textItem: internalTextItem
52 /**
53 * @brief This property holds an item that will be displayed before
54 * the delegate's contents.
55 */
56 property var leading: null
57
58 /**
59 * @brief This property holds the padding after the leading item.
60 */
61 property real leadingPadding: Kirigami.Units.smallSpacing
62
63 /**
64 * @brief This property holds an item that will be displayed after
65 * the delegate's contents.
66 */
67 property var trailing: null
68
69 /**
70 * @brief This property holds the padding before the trailing item.
71 */
72 property real trailingPadding: Kirigami.Units.smallSpacing
73
74 signal linkActivated(string link)
75
76 focusPolicy: Qt.NoFocus
77
78 background: null
79
80 contentItem: RowLayout {
81 spacing: 0
82
83 Private.ContentItemLoader {
84 Layout.rightMargin: visible ? root.leadingPadding : 0
85 visible: root.leading
86 implicitHeight: visible ? root.leading.implicitHeight : 0
87 implicitWidth: visible ? root.leading.implicitWidth : 0
88 contentItem: root.leading
89 }
90
91 Kirigami.Icon {
92 visible: root.icon.name !== ""
93 source: root.icon.name
94 color: root.icon.color
95 Layout.rightMargin: (root.icon.name !== "") ? Private.FormCardUnits.horizontalSpacing : 0
96 implicitWidth: (root.icon.name !== "") ? Kirigami.Units.iconSizes.smallMedium : 0
97 implicitHeight: (root.icon.name !== "") ? Kirigami.Units.iconSizes.smallMedium : 0
98 }
99
100 ColumnLayout {
101 Layout.fillWidth: true
102 spacing: 0
103
104 Label {
105 id: internalTextItem
106 Layout.fillWidth: true
107 text: root.text
108 elide: Text.ElideRight
109 onLinkActivated: root.linkActivated(link)
110 visible: root.text
111 Accessible.ignored: true // base class sets this text on root already
112 }
113
114 Label {
115 id: internalDescriptionItem
116 Layout.fillWidth: true
117 text: root.description
118 color: Kirigami.Theme.disabledTextColor
119 visible: root.description !== ""
120 onLinkActivated: root.linkActivated(link)
121 wrapMode: Text.Wrap
122 }
123 }
124
125 Private.ContentItemLoader {
126 Layout.leftMargin: visible ? root.trailingPadding : 0
127 visible: root.trailing
128 implicitHeight: visible ? root.trailing.implicitHeight : 0
129 implicitWidth: visible ? root.trailing.implicitWidth : 0
130 contentItem: root.trailing
131 }
132 }
133}
134
A base item for delegates to be used in a FormCard.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 13 2024 11:46:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.