-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNotificationSystem.qml
More file actions
executable file
·103 lines (100 loc) · 3.52 KB
/
NotificationSystem.qml
File metadata and controls
executable file
·103 lines (100 loc) · 3.52 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
import QtQuick 2.5
import QtQuick.Window 2.0
Item {
id:notificationRoot
property var notificationColor : "#333"
property bool isOnTheTop : false
property bool centralized : false
property var defaultH: parent.height/10
property var defaultW: parent.width/2
property alias timeInterval: timer.interval
function show() { notificationRoot.state = isOnTheTop?"showT":"showB" }
function hide() { notificationRoot.state = isOnTheTop?"hideT":"hideB" }
function notify(msg) { coloredNotify(msg,"#333") }
function coloredNotify(msg, color) {
show(); timer.restart()
notificationColor = color
notificationLabel.text = msg
notificationRect.color = notificationColor
}
state:isOnTheTop?"hideT":"hideB"
height:defaultH; width:defaultW
anchors{
margins:parent.height/50
right:centralized?undefined:parent.right
horizontalCenter: centralized?parent.horizontalCenter:undefined
}
Timer {
id:timer
interval: 2000; repeat: false
onTriggered: notificationRoot.hide()
}
Rectangle {
id:notificationRect
anchors.fill:parent
radius: height/6; color: notificationColor
MouseArea {
anchors.fill: parent; hoverEnabled: true
onEntered: { notificationRect.color = Qt.lighter(notificationColor,1.2) ; timer.stop() }
onExited: { notificationRect.color = notificationColor ; timer.start() }
onClicked: { timer.stop(); notificationRoot.state = isOnTheTop?"hideT":"hideB" }
}
}
Text {
id:notificationLabel
anchors.centerIn: parent
height:parent.height*0.8; width:parent.width*0.9
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
wrapMode: Text.WrapAtWordBoundaryOrAnywhere
font.pixelSize: height*0.5; fontSizeMode: Text.Fit
text:"Oi"; color:Qt.lighter(notificationColor,3.5)
onTextChanged: {
notificationRoot.height=defaultH
notificationRoot.width=defaultW
while(notificationRoot.height < notificationLabel.contentHeight) {
notificationRoot.height *= 1.2
}
}
}
states: [
State {
name: "showT";
AnchorChanges {
target:notificationRoot
anchors.top:parent.top
anchors.bottom:undefined
}
},
State {
name: "hideT";
AnchorChanges {
target:notificationRoot
anchors.bottom:parent.top
anchors.top:undefined
}
},
State {
name: "showB";
AnchorChanges {
target:notificationRoot
anchors.top:undefined
anchors.bottom:parent.bottom
}
},
State {
name: "hideB";
AnchorChanges {
target:notificationRoot
anchors.bottom:undefined
anchors.top:parent.bottom
}
}
]
transitions: [
Transition { from:"hideT"; to: "showT"; AnchorAnimation { duration:400; easing.type: "OutBack" } },
Transition { from:"showT"; to: "hideT"; AnchorAnimation { duration:400; easing.type: "InBack" } },
Transition { from:"hideB"; to: "showB"; AnchorAnimation { duration:400; easing.type: "OutBack" } },
Transition { from:"showB"; to: "hideB"; AnchorAnimation { duration:400; easing.type: "InBack" } }
]
}