Kirigami2

controls/InlineMessage.qml
1/*
2 * SPDX-FileCopyrightText: 2018 Eike Hein <hein@kde.org>
3 * SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org>
4 * SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <kde@privat.broulik.de>
5 *
6 * SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8
9import QtQuick
10import org.kde.kirigami as Kirigami
11import org.kde.kirigami.templates as KT
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 * import org.kde.kirigami as Kirigami
36 *
37 * Kirigami.InlineMessage {
38 * type: Kirigami.MessageType.Error
39 *
40 * text: i18n("My error message")
41 *
42 * actions: [
43 * Kirigami.Action {
44 * icon.name: "list-add"
45 * text: i18n("Add")
46 * onTriggered: source => {
47 * // do stuff
48 * }
49 * },
50 * Kirigami.Action {
51 * icon.name: "edit"
52 * text: i18n("Edit")
53 * onTriggered: source => {
54 * // do stuff
55 * }
56 * }
57 * ]
58 * }
59 * @endcode
60 * @inherit org::kde::kirigami::templates::InlineMessage
61 * @since 5.45
62 */
63KT.InlineMessage {
64 id: root
65
66 // a rectangle padded with anchors.margins is used to simulate a border
67 leftPadding: bgFillRect.anchors.leftMargin + Kirigami.Units.smallSpacing
68 topPadding: bgFillRect.anchors.topMargin + Kirigami.Units.smallSpacing
69 rightPadding: bgFillRect.anchors.rightMargin + Kirigami.Units.smallSpacing
70 bottomPadding: bgFillRect.anchors.bottomMargin + Kirigami.Units.smallSpacing
71
72 background: Rectangle {
73 id: bgBorderRect
74
75 color: switch (root.type) {
76 case Kirigami.MessageType.Positive: return Kirigami.Theme.positiveTextColor;
77 case Kirigami.MessageType.Warning: return Kirigami.Theme.neutralTextColor;
78 case Kirigami.MessageType.Error: return Kirigami.Theme.negativeTextColor;
79 default: return Kirigami.Theme.activeTextColor;
80 }
81
82 radius: root.position === KT.InlineMessage.Position.Inline ? Kirigami.Units.cornerRadius : 0
83
84 Rectangle {
85 id: bgFillRect
86
87 anchors.fill: parent
88 anchors {
89 leftMargin: root.position === KT.InlineMessage.Position.Inline ? 1 : 0
90 topMargin: root.position === KT.InlineMessage.Position.Header ? 0 : 1
91 rightMargin: root.position === KT.InlineMessage.Position.Inline ? 1 : 0
92 bottomMargin: root.position === KT.InlineMessage.Position.Footer ? 0 : 1
93 }
94
95 color: Kirigami.Theme.backgroundColor
96
97 radius: bgBorderRect.radius * 0.60
98 }
99
100 Rectangle {
101 anchors.fill: bgFillRect
102
103 color: bgBorderRect.color
104
105 opacity: 0.20
106
107 radius: bgFillRect.radius
108 }
109 }
110}
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:09:31 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.