Kirigami-addons

FormPlaceholderMessageDelegate.qml
1// SPDX-FileCopyrightText: 2024 Carl Schwan <carl@carlschwan.eu>
2// SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
3
4import QtQuick
5import QtQuick.Layouts
6import org.kde.kirigami as Kirigami
7
8/**
9 * @brief A placeholder message indicating that a FormCard is empty.
10 *
11 * Example usage:
12 *
13 * import org.kde.kirigamiaddons.formcard as FormCard
14 *
15 * FormCard.FormCardPage {
16 * FormCard.FormHeader {
17 * title: i18nc("@title:group", "Items")
18 * }
19 *
20 * FormCard.FormCard {
21 * FormCard.FormPlaceholderMessageDelegate {
22 * text: i18nc("@info:placeholder", "There are no items in this list")
23 * visible: repeater.count === 0
24 * }
25 *
26 * Repeater {
27 * id: repeater
28 * model: [ ... ]
29 * delegate: [ ... ]
30 * }
31 *
32 * FormCard.FormDelegateSeparator {}
33 *
34 * FormCard.FormButtonDelegate {
35 * text: i18nc("@action:button", "Add Item")
36 * icon.name: "list-add-symbolic"
37 * }
38 * }
39 * }
40 *
41 * @since 6.9
42 */
43AbstractFormDelegate {
44 id: root
45
46 /**
47 * @brief This property holds the smaller explanatory text to show below the larger title-style text
48 *
49 * Useful for providing a user-friendly explanation on how to proceed.
50 *
51 * Optional; if not defined, the message will have no supplementary
52 * explanatory text.
53 */
54 property string explanation
55
56 /**
57 * This property holds the link embedded in the explanatory message text that
58 * the user is hovering over.
59 */
60 property alias hoveredLink: label.hoveredLink
61
62 /**
63 * This signal is emitted when a link is hovered in the explanatory message
64 * text.
65 * @param The hovered link.
66 */
67 signal linkHovered(string link)
69 /**
70 * This signal is emitted when a link is clicked or tapped in the explanatory
71 * message text.
72 * @param The clicked or tapped link.
73 */
74 signal linkActivated(string link)
75
76 topPadding: Kirigami.Units.gridUnit
77 bottomPadding: Kirigami.Units.gridUnit
78
79 icon {
80 width: Kirigami.Units.iconSizes.medium
81 height: Kirigami.Units.iconSizes.medium
82 }
83
84 Accessible.description: explanation
85
86 background: null
87 contentItem: ColumnLayout {
88 id: placeholderMessage
89
90 spacing: Kirigami.Units.smallSpacing
91
92 Kirigami.Icon {
93 visible: source !== undefined
94 opacity: 0.5
95
96 Layout.alignment: Qt.AlignHCenter
97 Layout.preferredWidth: root.icon.width
98 Layout.preferredHeight: root.icon.height
99
100 color: root.icon.color
101
102 source: {
103 if (root.icon.source.length > 0) {
104 return root.icon.source
105 } else if (root.icon.name.length > 0) {
106 return root.icon.name
107 }
108 return undefined
109 }
110 }
111
112 Kirigami.Heading {
113 text: root.text
114 visible: text.length > 0
115
116 level: 3
117 type: Kirigami.Heading.Primary
118 opacity: 0.65
119
120
121 Layout.fillWidth: true
122 horizontalAlignment: Qt.AlignHCenter
123 verticalAlignment: Qt.AlignVCenter
124
125 wrapMode: Text.WordWrap
126
127 Accessible.ignored: true
128 }
129
130 Kirigami.SelectableLabel {
131 id: label
132
133 text: root.explanation
134 visible: root.explanation.length > 0
135 opacity: 0.65
136
137 horizontalAlignment: Qt.AlignHCenter
138 wrapMode: Text.WordWrap
139
140 Layout.fillWidth: true
141
142 onLinkHovered: link => root.linkHovered(link)
143 onLinkActivated: link => root.linkActivated(link)
144
145 Accessible.ignored: true
146 }
147
148 visible: root.visible // for accessibility
149 }
150}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:03:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.