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 2.7
10import QtGraphicalEffects 1.0
11import org.kde.kirigami 2.5 as Kirigami
12
13import "../../private"
14import "../../templates" as T
15
16/**
17 * An inline message item with support for informational, positive,
18 * warning and error types, and with support for associated actions.
19 *
20 * InlineMessage can be used to give information to the user or
21 * interact with the user, without requiring the use of a dialog.
22 *
23 * The InlineMessage item is hidden by default. It also manages its
24 * height (and implicitHeight) during an animated reveal when shown.
25 * You should avoid setting height on an InlineMessage unless it is
26 * already visible.
27 *
28 * Optionally an icon can be set, defaulting to an icon appropriate
29 * to the message type otherwise.
30 *
31 * Optionally a close button can be shown.
32 *
33 * Actions are added from left to right. If more actions are set than
34 * can fit, an overflow menu is provided.
35 *
36 * Example:
37 * @code
38 * InlineMessage {
39 *     type: Kirigami.MessageType.Error
40 *
41 *     text: "My error message"
42 *
43 *     actions: [
44 *         Kirigami.Action {
45 *             icon.name: "edit"
46 *             text: "Action text"
47 *             onTriggered: {
48 *                 // do stuff
49 *             }
50 *         },
51 *         Kirigami.Action {
52 *             icon.name: "edit"
53 *             text: "Action text"
54 *             onTriggered: {
55 *                 // do stuff
56 *             }
57 *         }
58 *     ]
59 * }
60 * @endcode
61 *
62 * @since 5.45
63 */
64
65T.InlineMessage {
66    id: root
67
68    background: Rectangle {
69        id: bgBorderRect
70
71        color: {
72            if (root.type == Kirigami.MessageType.Positive) {
73                return Kirigami.Theme.positiveTextColor;
74            } else if (root.type == Kirigami.MessageType.Warning) {
75                return Kirigami.Theme.neutralTextColor;
76            } else if (root.type == Kirigami.MessageType.Error) {
77                return Kirigami.Theme.negativeTextColor;
78            }
79
80            return Kirigami.Theme.activeTextColor;
81        }
82
83        radius: Kirigami.Units.smallSpacing / 2
84
85        Rectangle {
86            id: bgFillRect
87
88            anchors.fill: parent
89            anchors.margins: 1
90
91            color: Kirigami.Theme.backgroundColor
92
93            radius: bgBorderRect.radius * 0.60
94        }
95
96        Rectangle {
97            anchors.fill: bgFillRect
98
99            color: bgBorderRect.color
100
101            opacity: 0.20
102
103            radius: bgFillRect.radius
104        }
105
106        layer.enabled: true
107        layer.effect: DropShadow {
108            horizontalOffset: 0
109            verticalOffset: 1
110            radius: 12
111            samples: 32
112            color: Qt.rgba(0, 0, 0, 0.5)
113        }
114    }
115}
116