MauiKit Controls

Holder.qml
1/*
2 * Copyright 2018 Camilo Higuita <milo.h@aol.com>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Library General Public License as
6 * published by the Free Software Foundation; either version 2, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details
13 *
14 * You should have received a copy of the GNU Library General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19
20import QtQuick
21import QtQuick.Controls
22
23import org.mauikit.controls 1.3 as Maui
24
25/**
26 * @inherit QtQuick.Item
27 * @brief Holder
28 * A component meant to be used as a placeholder element with support for a title, message body, icon image - animated or not -, and a set of contextual actions.
29 *
30 * <a href="https://doc.qt.io/qt-6/qml-qtquick-controls-item.html">This controls inherits from QQC2 Item, to checkout its inherited properties refer to the Qt Docs.</a>
31 *
32 * This control is meant to display messages, such as warning messages with a title and icon, and with a set of possible actions.
33 * The default content children of this component are QQC2 Actions.
34 *
35 * @image html Holder/holder_actions.png "Placeholder message using a colorful icon image"
36 *
37 * @section notes Notes
38 * By default the icon is supossed to be symbolic and will be colored - if a colorful icon is to be used, the coloring mask should toggle off.
39 * @see isMask
40 * @see emoji
41 *
42 * It is possible to add an animated image source as the icon. To enable the animation toggle on the animation property.
43 * @see isGif
44 *
45 * @code
46 * Holder
47 * {
48 * title: "Holder"
49 * body: "Placeholder message."
50 *
51 * emoji: "dialog-warning"
52 * isMask: false
53 *
54 * QQC2.Action
55 * {
56 * text: "Action1"
57 * }
58 *
59 * QQC2.Action
60 * {
61 * text: "Action2"
62 * }
63 *
64 * QQC2.Action
65 * {
66 * text: "Action3"
67 * }
68 * }
69 * @endcode
70 *
71 * <a href="https://invent.kde.org/maui/mauikit/-/blob/qt6-2/examples/Holder.qml">You can find a more complete example at this link.</a>
72 *
73 */
74Item
75{
76 id: control
77 implicitHeight: _layout.implicitHeight
78
79 /**
80 * @brief A list of contextual actions. By default this control takes a list of QQC2 Actions as the children.
81 * The actions will be represented as a column of button under the title and message.
82 */
83 default property list<Action> actions
84
85 /**
86 * @brief An alias to add children elements to the bottom of the default layout container.
87 * @property list<QtObject> Holder::content
88 *
89 * @code
90 * Holder
91 * {
92 * title: "Example"
93 * emoji: "actor"
94 * body: "Test of the holder"
95 *
96 * content: Chip
97 * {
98 * text: "Hello World!"
99 * }
100 * }
101 * @endcode
102 */
103 property alias content : _layout.data
104
105 /**
106 * @brief The icon source to be used as the heading.
107 */
108 property string emoji
109
110 /**
111 * @brief The image to be used as the heading.
112 */
113 property string imageSource
114
115 /**
116 * @brief The title of the place holder element.
117 * @property string Holder::title
118 */
119 property alias title : _template.text1
121 /**
122 * @brief The body message of the place holder element.
123 * @property string Holder::body
124 */
125 property alias body : _template.text2
126
127 /**
128 * @brief Whether the image/icon should be masked and tinted with the text color. If the `emoji` is set to a colorful source, then this should be set to `false`.
129 */
130 property bool isMask : true
131
132 /**
133 * @brief Whether the `emoji` source is an animated image file.
134 * By default this is set to `false`.
135 */
136 property bool isGif : false
138 /**
139 * @brief The size of the icon/image used as the emoji.
140 * By default this value is set to `Style.iconSizes.big`.
141 */
142 property int emojiSize : Maui.Style.iconSizes.big
143
144 /**
145 * @brief The Label element used as the title.
146 * This is exposed so the title label properties can be tweaked, such as making the font bolder, lighter or changing its color or size.
147 * @property Label Holder::label1
148 * @see title
149 */
150 property alias label1 : _template.label1
151
152 /**
153 * @brief The Label element used as the message body.
154 * This is exposed so the body message label properties can be tweaked, such as making the font bolder, lighter or changing its color or size.
155 * @property Label Holder::label2
156 * @see body
157 */
158 property alias label2 : _template.label2
159
160 /**
161 * @brief Alias to the DropArea exposed to tweak its properties.
162 */
163 readonly property alias dropArea: _dropArea
164
165 /**
166 * @brief Emitted when a drop event has occurred
167 * @param drop the drop object with the event information
168 */
169 signal contentDropped(var drop)
170
171 Component
172 {
173 id: imgComponent
174
175 Maui.IconItem
176 {
177 id: imageHolder
178
179 isMask: control.isMask
180 opacity: isMask ? _template.opacity : 1
181 iconSource: control.emoji
182 imageSource: control.imageSource
183 fillMode: Image.PreserveAspectFit
184 }
185 }
186
187 Component
188 {
189 id: animComponent
190 AnimatedImage
191 {
192 id: animation
193 source: control.emoji
194 }
195 }
196
197 Rectangle
198 {
199 anchors.fill: parent
200 opacity: _dropArea.containsDrag ? 0.4 : 0
201 color: Maui.Theme.textColor
202 DropArea
203 {
204 id: _dropArea
205 anchors.fill: parent
206 onDropped: (drop) =>
207 {
208 control.contentDropped(drop)
209 }
210 }
211 }
212
213 Column
214 {
215 id: _layout
216 anchors.centerIn: parent
217 spacing: Maui.Style.defaultSpacing
218
219 Loader
220 {
221 visible: active && (control.emoji || control.imageSource)
222 active: control.height > (_template.implicitHeight + control.emojiSize)
223 height: visible ? control.emojiSize : 0
224 width: height
225 asynchronous: true
226 sourceComponent: control.isGif ? animComponent : imgComponent
227 }
228
230 {
231 id: _template
232 width: Math.min(control.width * 0.7, layout.implicitWidth)
233
234 label1.font: Maui.Style.h1Font
235 label1.wrapMode: Text.Wrap
236 label2.wrapMode: Text.Wrap
237 }
238
239 Item
240 {
241 height: Maui.Style.space.medium;
242 width: height
243 }
244
245 Repeater
246 {
247 model: control.actions
248
249 Button
250 {
251 id: _button
252 width: Math.max(120, implicitWidth)
253 action: modelData
254 }
255 }
256 }
257}
A template for an horizontal layout of information.
KIOWIDGETS_EXPORT DropJob * drop(const QDropEvent *dropEvent, const QUrl &destUrl, DropJobFlags dropjobFlags, JobFlags flags=DefaultFlags)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 17 2024 11:56:16 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.