Qt World Summit Conference App
import QtQuick 2.0
import Felgo 3.0
NotificationBar {
z: 1
y: -height
width: parent.width
height: Theme.statusBarHeight + dp(60)
enabled: visible
visible: false
property int duration: 3000
property color tintColor: "#f05352"
property color backgroundColor: Qt.rgba(tintColor.r, tintColor.g, tintColor.b, 0.75)
property color textColor: "white"
property string lastNotificationMessage: ""
property var lastNotificationData: []
property bool lastNotificationIsActive: false
signal dismiss(string message, var additionalData, bool isActive)
onDisplay: {
console.debug("Display notification "+message+"; data: "+JSON.stringify(additionalData)+"; isActive: "+isActive)
lastNotificationMessage = message
lastNotificationData = additionalData
lastNotificationIsActive = isActive
notificationMessage.text = message
notificationTitle.text = additionalData.title
y = 0
visible = true
hideAfterDelay.start()
}
Rectangle {
anchors.fill: parent
color: parent.backgroundColor
}
Text {
id: notificationTitle
font.pixelSize: sp(18)
font.bold: true
color: parent.textColor
text: ""
y: dp(8) + Theme.statusBarHeight
x: dp(8)
}
Text {
id: notificationMessage
font.pixelSize: sp(15)
x: dp(8)
color: parent.textColor
text: ""
anchors.top: notificationTitle.bottom
}
MouseArea {
anchors.fill: parent
onClicked: {
hide()
dismiss(lastNotificationMessage, lastNotificationData, lastNotificationIsActive)
}
}
Timer {
id: hideAfterDelay
interval: duration
onTriggered: {
hide()
}
}
Behavior on y {
SequentialAnimation {
NumberAnimation {
duration: 600
easing.type: Easing.InOutCubic
}
ScriptAction {
script: {
if(y <= -height) {
notificationMessage.text = ""
notificationTitle.text = ""
visible = false
}
}
}
}
}
function hide() {
hideAfterDelay.stop()