matrixion/qml/ui/Snackbar.qml
Nicolas Werner da96558bb9
Lint qml
2022-04-23 03:10:27 +02:00

93 lines
2.1 KiB
QML

// SPDX-FileCopyrightText: 2022 Nheko Contributors
// SPDX-License-Identifier: GPL-3.0-or-later
import QtQuick 2.15
import QtQuick.Controls 2.15
import im.nheko
Popup {
id: snackbar
property string currentMessage: ""
property var messages: []
function showNotification(msg) {
messages.push(msg);
currentMessage = messages[0];
if (!visible) {
open();
dismissTimer.start();
}
}
opacity: 0
padding: Nheko.paddingLarge
parent: Overlay.overlay
x: (parent.width - width) / 2
y: -100
background: Rectangle {
color: timelineRoot.palette.dark
opacity: 0.8
radius: Nheko.paddingLarge
}
contentItem: Label {
color: timelineRoot.palette.light
font.bold: true
text: snackbar.currentMessage
width: Math.max(Overlay.overlay ? Overlay.overlay.width / 2 : 0, 400)
}
enter: Transition {
NumberAnimation {
duration: 200
easing.type: Easing.OutCubic
from: 0.0
property: "opacity"
target: snackbar
to: 1.0
}
NumberAnimation {
duration: 1000
easing.type: Easing.OutCubic
from: -100
properties: "y"
target: snackbar
to: 100
}
}
exit: Transition {
NumberAnimation {
duration: 300
easing.type: Easing.InCubic
from: 1.0
property: "opacity"
target: snackbar
to: 0.0
}
NumberAnimation {
duration: 300
easing.type: Easing.InCubic
from: 100
properties: "y"
target: snackbar
to: -100
}
}
onAboutToHide: {
messages.shift();
}
onClosed: {
if (messages.length > 0) {
currentMessage = messages[0];
open();
dismissTimer.restart();
}
}
Timer {
id: dismissTimer
interval: 10000
onTriggered: snackbar.close()
}
}