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{.qml}
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  * @see <a href="https://develop.kde.org/docs/getting-started/kirigami/components-inlinemessages">Inline Messages in Kirigami</a>
59  * @see <a href="https://develop.kde.org/hig/components/assistance/inline">KDE Human Interface Guidelines on Inline Messages</a>
60  * @since KDE Frameworks 5.45
61  * @inherit kirigami::templates::InlineMessage
62  */
63 T.InlineMessage {
64  id: root
65 
66  // a rectangle padded with anchors.margins is used to simulate a border
67  padding: bgFillRect.anchors.margins + Kirigami.Units.smallSpacing
68 
69  background: Rectangle {
70  id: bgBorderRect
71 
72  color: switch (root.type) {
73  case Kirigami.MessageType.Positive: return Kirigami.Theme.positiveTextColor;
74  case Kirigami.MessageType.Warning: return Kirigami.Theme.neutralTextColor;
75  case Kirigami.MessageType.Error: return Kirigami.Theme.negativeTextColor;
76  default: return Kirigami.Theme.activeTextColor;
77  }
78 
79  radius: Kirigami.Units.smallSpacing / 2
80 
81  Rectangle {
82  id: bgFillRect
83 
84  anchors.fill: parent
85  anchors.margins: 1
86 
87  color: Kirigami.Theme.backgroundColor
88 
89  radius: bgBorderRect.radius * 0.60
90  }
91 
92  Rectangle {
93  anchors.fill: bgFillRect
94 
95  color: bgBorderRect.color
96 
97  opacity: 0.20
98 
99  radius: bgFillRect.radius
100  }
101  }
102 }
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Oct 3 2023 03:58:35 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.