2023-02-22 01:48:49 +03:00
|
|
|
// 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
|
|
|
|
|
|
|
|
property string currentMessage: ""
|
2023-10-31 05:11:03 +03:00
|
|
|
property var messages: []
|
2022-01-30 21:14:33 +03:00
|
|
|
|
|
|
|
function showNotification(msg) {
|
|
|
|
messages.push(msg);
|
|
|
|
currentMessage = messages[0];
|
|
|
|
if (!visible) {
|
|
|
|
open();
|
|
|
|
dismissTimer.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
opacity: 0
|
|
|
|
padding: Nheko.paddingLarge
|
|
|
|
|
2023-10-31 05:11:03 +03:00
|
|
|
// Workaround palettes not inheriting for popups
|
|
|
|
palette: timelineRoot.palette
|
|
|
|
parent: Overlay.overlay
|
|
|
|
x: (parent.width - width) / 2
|
|
|
|
y: -100
|
2022-01-30 21:14:33 +03:00
|
|
|
|
|
|
|
background: Rectangle {
|
2023-06-02 02:29:05 +03:00
|
|
|
color: palette.dark
|
2022-01-30 21:14:33 +03:00
|
|
|
opacity: 0.8
|
2023-10-31 05:11:03 +03:00
|
|
|
radius: Nheko.paddingLarge
|
|
|
|
}
|
|
|
|
contentItem: Label {
|
|
|
|
color: palette.light
|
|
|
|
font.bold: true
|
|
|
|
text: snackbar.currentMessage
|
|
|
|
width: Math.max(snackbar.Overlay.overlay ? snackbar.Overlay.overlay.width / 2 : 0, 400)
|
2022-01-30 21:14:33 +03:00
|
|
|
}
|
|
|
|
enter: Transition {
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 200
|
|
|
|
easing.type: Easing.OutCubic
|
2023-10-31 05:11:03 +03:00
|
|
|
from: 0.0
|
|
|
|
property: "opacity"
|
|
|
|
target: snackbar
|
|
|
|
to: 1.0
|
2022-01-30 21:14:33 +03:00
|
|
|
}
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 1000
|
|
|
|
easing.type: Easing.OutCubic
|
2023-10-31 05:11:03 +03:00
|
|
|
from: -100
|
|
|
|
properties: "y"
|
|
|
|
target: snackbar
|
|
|
|
to: 100
|
2022-01-30 21:14:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exit: Transition {
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 300
|
|
|
|
easing.type: Easing.InCubic
|
2023-10-31 05:11:03 +03:00
|
|
|
from: 1.0
|
|
|
|
property: "opacity"
|
|
|
|
target: snackbar
|
|
|
|
to: 0.0
|
2022-01-30 21:14:33 +03:00
|
|
|
}
|
|
|
|
NumberAnimation {
|
|
|
|
duration: 300
|
|
|
|
easing.type: Easing.InCubic
|
2023-10-31 05:11:03 +03:00
|
|
|
from: 100
|
|
|
|
properties: "y"
|
|
|
|
target: snackbar
|
|
|
|
to: -100
|
2022-01-30 21:14:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-31 05:11:03 +03:00
|
|
|
onAboutToHide: {
|
|
|
|
messages.shift();
|
|
|
|
}
|
|
|
|
onClosed: {
|
|
|
|
if (messages.length > 0) {
|
|
|
|
currentMessage = messages[0];
|
|
|
|
open();
|
|
|
|
dismissTimer.restart();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Timer {
|
|
|
|
id: dismissTimer
|
2022-01-30 21:14:33 +03:00
|
|
|
|
2023-10-31 05:11:03 +03:00
|
|
|
interval: 10000
|
|
|
|
|
|
|
|
onTriggered: snackbar.close()
|
|
|
|
}
|
|
|
|
}
|