matrixion/resources/qml/ui/Snackbar.qml

102 lines
2.2 KiB
QML
Raw Permalink Normal View History

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