Kirigami2

controls/InlineMessage.qml
1 /*
2  * SPDX-FileCopyrightText: 2018 Eike Hein <[email protected]>
3  * SPDX-FileCopyrightText: 2018 Marco Martin <[email protected]>
4  * SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <[email protected]>
5  *
6  * SPDX-License-Identifier: LGPL-2.0-or-later
7  */
8 
9 import QtQuick 2.7
10 import org.kde.kirigami 2.5 as Kirigami
11 import "templates" as T
12 
13 /**
14  * An inline message item with support for informational, positive,
15  * warning and error types, and with support for associated actions.
16  *
17  * InlineMessage can be used to give information to the user or
18  * interact with the user, without requiring the use of a dialog.
19  *
20  * The InlineMessage item is hidden by default. It also manages its
21  * height (and implicitHeight) during an animated reveal when shown.
22  * You should avoid setting height on an InlineMessage unless it is
23  * already visible.
24  *
25  * Optionally an icon can be set, defaulting to an icon appropriate
26  * to the message type otherwise.
27  *
28  * Optionally a close button can be shown.
29  *
30  * Actions are added from left to right. If more actions are set than
31  * can fit, an overflow menu is provided.
32  *
33  * Example usage:
34  * @code
35  * InlineMessage {
36  * type: Kirigami.MessageType.Error
37  *
38  * text: "My error message"
39  *
40  * actions: [
41  * Kirigami.Action {
42  * icon.name: "edit"
43  * text: "Action text"
44  * onTriggered: {
45  * // do stuff
46  * }
47  * },
48  * Kirigami.Action {
49  * icon.name: "edit"
50  * text: "Action text"
51  * onTriggered: {
52  * // do stuff
53  * }
54  * }
55  * ]
56  * }
57  * @endcode
58  * @inherit org::kde::kirigami::templates::InlineMessage
59  * @since 5.45
60  */
61 T.InlineMessage {
62  id: root
63 
64  // a rectangle padded with anchors.margins is used to simulate a border
65  padding: bgFillRect.anchors.margins + Kirigami.Units.smallSpacing
66 
67  background: Rectangle {
68  id: bgBorderRect
69 
70  color: switch (root.type) {
71  case Kirigami.MessageType.Positive: return Kirigami.Theme.positiveTextColor;
72  case Kirigami.MessageType.Warning: return Kirigami.Theme.neutralTextColor;
73  case Kirigami.MessageType.Error: return Kirigami.Theme.negativeTextColor;
74  default: return Kirigami.Theme.activeTextColor;
75  }
76 
77  radius: Kirigami.Units.smallSpacing / 2
78 
79  Rectangle {
80  id: bgFillRect
81 
82  anchors.fill: parent
83  anchors.margins: 1
84 
85  color: Kirigami.Theme.backgroundColor
86 
87  radius: bgBorderRect.radius * 0.60
88  }
89 
90  Rectangle {
91  anchors.fill: bgFillRect
92 
93  color: bgBorderRect.color
94 
95  opacity: 0.20
96 
97  radius: bgFillRect.radius
98  }
99  }
100 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Jan 29 2023 04:11:03 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.