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