| 1 |
// SPDX-FileCopyrightText: Nheko Contributors |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: GPL-3.0-or-later |
| 4 |
|
| 5 |
import QtQuick 2.15 |
| 6 |
import QtQuick.Controls 2.15 |
| 7 |
import im.nheko 1.0 |
| 8 |
|
| 9 |
Popup { |
| 10 |
id: snackbar |
| 11 |
|
| 12 |
// Workaround palettes not inheriting for popups |
| 13 |
palette: timelineRoot.palette |
| 14 |
|
| 15 |
property var messages: [] |
| 16 |
property string currentMessage: "" |
| 17 |
|
| 18 |
function showNotification(msg) { |
| 19 |
messages.push(msg); |
| 20 |
currentMessage = messages[0]; |
| 21 |
if (!visible) { |
| 22 |
open(); |
| 23 |
dismissTimer.start(); |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
Timer { |
| 28 |
id: dismissTimer |
| 29 |
interval: 10000 |
| 30 |
onTriggered: snackbar.close() |
| 31 |
} |
| 32 |
|
| 33 |
onAboutToHide: { |
| 34 |
messages.shift(); |
| 35 |
} |
| 36 |
onClosed: { |
| 37 |
if (messages.length > 0) { |
| 38 |
currentMessage = messages[0]; |
| 39 |
open(); |
| 40 |
dismissTimer.restart(); |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
parent: Overlay.overlay |
| 45 |
opacity: 0 |
| 46 |
y: -100 |
| 47 |
x: (parent.width - width)/2 |
| 48 |
padding: Nheko.paddingLarge |
| 49 |
|
| 50 |
contentItem: Label { |
| 51 |
color: palette.light |
| 52 |
width: Math.max(snackbar.Overlay.overlay? snackbar.Overlay.overlay.width/2 : 0, 400) |
| 53 |
text: snackbar.currentMessage |
| 54 |
font.bold: true |
| 55 |
} |
| 56 |
|
| 57 |
background: Rectangle { |
| 58 |
radius: Nheko.paddingLarge |
| 59 |
color: palette.dark |
| 60 |
opacity: 0.8 |
| 61 |
} |
| 62 |
|
| 63 |
enter: Transition { |
| 64 |
NumberAnimation { |
| 65 |
target: snackbar |
| 66 |
property: "opacity" |
| 67 |
from: 0.0 |
| 68 |
to: 1.0 |
| 69 |
duration: 200 |
| 70 |
easing.type: Easing.OutCubic |
| 71 |
} |
| 72 |
NumberAnimation { |
| 73 |
target: snackbar |
| 74 |
properties: "y" |
| 75 |
from: -100 |
| 76 |
to: 100 |
| 77 |
duration: 1000 |
| 78 |
easing.type: Easing.OutCubic |
| 79 |
} |
| 80 |
} |
| 81 |
exit: Transition { |
| 82 |
NumberAnimation { |
| 83 |
target: snackbar |
| 84 |
property: "opacity" |
| 85 |
from: 1.0 |
| 86 |
to: 0.0 |
| 87 |
duration: 300 |
| 88 |
easing.type: Easing.InCubic |
| 89 |
} |
| 90 |
NumberAnimation { |
| 91 |
target: snackbar |
| 92 |
properties: "y" |
| 93 |
to: -100 |
| 94 |
from: 100 |
| 95 |
duration: 300 |
| 96 |
easing.type: Easing.InCubic |
| 97 |
} |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|