This repository has been archived by the owner on Nov 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Toast.qml
91 lines (72 loc) · 1.83 KB
/
Toast.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import QtQuick 2.7
import QtQuick.Controls.Material 2.2
/**
* adapted from StackOverflow:
* http://stackoverflow.com/questions/26879266/make-toast-in-android-by-qml
*/
/**
* @brief An Android-like timed message text in a box
*/
Rectangle {
/**
* Public
*/
property real time
property string text
signal animationEnded()
/**
* Private
*/
readonly property real margin: 20
readonly property real fadeTime: 300
id: root
anchors {
left: parent.left
right: parent.right
margins: margin
}
height: message.height + margin
radius: margin / 2
opacity: 0
Text {
id: message
text: parent.text
textFormat: Text.StyledText
color: Material.background
linkColor: Material.color(Material.Cyan)
font.pixelSize: mainWindow.font.pixelSize
wrapMode: Text.Wrap
horizontalAlignment: Text.AlignHCenter
anchors {
top: parent.top
left: parent.left
right: parent.right
margins: margin / 2
}
onLinkActivated: Qt.openUrlExternally(link)
MouseArea {
anchors.fill: parent
acceptedButtons: Qt.NoButton // we don't want to eat clicks on the Text
cursorShape: parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor
}
}
SequentialAnimation on opacity {
id: animation
running: false
NumberAnimation {
to: .9
duration: fadeTime
}
PauseAnimation {
duration: time - 2 * fadeTime
}
NumberAnimation {
to: 0
duration: fadeTime
}
onRunningChanged: if (!running) { root.animationEnded() }
}
Component.onCompleted: {
animation.start()
}
}