diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-04 19:19:41 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-04 19:19:41 +0200 |
commit | d9295fc8f19e4005f8454e7f193f80316550ac0c (patch) | |
tree | f27c370d54bced09212b9c4a12b827d1cebb6110 /framework/qml/Notification.qml | |
parent | d002eae7f8b443dd1bad914444c296088c2b6e85 (diff) | |
download | kube-d9295fc8f19e4005f8454e7f193f80316550ac0c.tar.gz kube-d9295fc8f19e4005f8454e7f193f80316550ac0c.zip |
One framework plugin to rule them all
Diffstat (limited to 'framework/qml/Notification.qml')
-rw-r--r-- | framework/qml/Notification.qml | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/framework/qml/Notification.qml b/framework/qml/Notification.qml new file mode 100644 index 00000000..15291c43 --- /dev/null +++ b/framework/qml/Notification.qml | |||
@@ -0,0 +1,83 @@ | |||
1 | import QtQuick 2.0 | ||
2 | import QtQuick.Controls 2.0 | ||
3 | |||
4 | import org.kde.kirigami 1.0 as Kirigami | ||
5 | import org.kube.components.theme 1.0 as KubeTheme | ||
6 | |||
7 | |||
8 | MouseArea { | ||
9 | id: popup | ||
10 | |||
11 | property alias title: message.text | ||
12 | property alias timeout: hideTimer.interval | ||
13 | property alias background: bg.color | ||
14 | |||
15 | function hide() { | ||
16 | if (hideTimer.running) | ||
17 | hideTimer.stop() | ||
18 | popup.opacity = 0.0 | ||
19 | } | ||
20 | |||
21 | function show() { | ||
22 | console.warn("Trying to show the notification", title); | ||
23 | popup.opacity = 1.0 | ||
24 | hideTimer.restart() | ||
25 | } | ||
26 | |||
27 | function notify(text) { | ||
28 | popup.title = text | ||
29 | bg.color = KubeTheme.Colors.textColor | ||
30 | show() | ||
31 | } | ||
32 | |||
33 | Timer { | ||
34 | id: hideTimer | ||
35 | triggeredOnStart: false | ||
36 | repeat: false | ||
37 | interval: 5000 | ||
38 | onTriggered: popup.hide() | ||
39 | } | ||
40 | |||
41 | width: Math.max(300, message.contentWidth + (Kirigami.Units.largeSpacing * 2)) | ||
42 | height: Math.max(50, message.contentHeight + (Kirigami.Units.largeSpacing * 2)) | ||
43 | |||
44 | visible: opacity > 0 | ||
45 | opacity: 0.0 | ||
46 | |||
47 | Behavior on opacity { | ||
48 | NumberAnimation { | ||
49 | duration: 200 | ||
50 | easing.type: Easing.InOutQuad | ||
51 | property: "opacity" | ||
52 | } | ||
53 | } | ||
54 | |||
55 | Rectangle { | ||
56 | id: bg | ||
57 | |||
58 | anchors.fill: parent | ||
59 | |||
60 | opacity: 0.6 | ||
61 | } | ||
62 | |||
63 | Label { | ||
64 | id: message | ||
65 | |||
66 | anchors { | ||
67 | verticalCenter: popup.verticalCenter | ||
68 | left: parent.left | ||
69 | leftMargin: Kirigami.Units.largeSpacing | ||
70 | right: parent.right | ||
71 | rightMargin: Kirigami.Units.largeSpacing | ||
72 | } | ||
73 | |||
74 | font.pixelSize: 16 | ||
75 | |||
76 | color: KubeTheme.Colors.highlightedTextColor | ||
77 | horizontalAlignment: Text.AlignHCenter | ||
78 | elide: Text.ElideRight | ||
79 | wrapMode: Text.Wrap | ||
80 | } | ||
81 | |||
82 | onClicked: hide() | ||
83 | } | ||