mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-26 04:58:49 +03:00
Reimplement error notifications
This commit is contained in:
parent
b4278ffaa8
commit
2613275461
9 changed files with 111 additions and 111 deletions
|
@ -336,7 +336,6 @@ set(SRC_FILES
|
||||||
src/ui/NhekoCursorShape.cpp
|
src/ui/NhekoCursorShape.cpp
|
||||||
src/ui/NhekoDropArea.cpp
|
src/ui/NhekoDropArea.cpp
|
||||||
src/ui/NhekoGlobalObject.cpp
|
src/ui/NhekoGlobalObject.cpp
|
||||||
src/ui/OverlayWidget.cpp
|
|
||||||
src/ui/RoomSettings.cpp
|
src/ui/RoomSettings.cpp
|
||||||
src/ui/TextField.cpp
|
src/ui/TextField.cpp
|
||||||
src/ui/Theme.cpp
|
src/ui/Theme.cpp
|
||||||
|
@ -532,7 +531,6 @@ qt5_wrap_cpp(MOC_HEADERS
|
||||||
src/ui/NhekoCursorShape.h
|
src/ui/NhekoCursorShape.h
|
||||||
src/ui/NhekoDropArea.h
|
src/ui/NhekoDropArea.h
|
||||||
src/ui/NhekoGlobalObject.h
|
src/ui/NhekoGlobalObject.h
|
||||||
src/ui/OverlayWidget.h
|
|
||||||
src/ui/RoomSettings.h
|
src/ui/RoomSettings.h
|
||||||
src/ui/TextField.h
|
src/ui/TextField.h
|
||||||
src/ui/Theme.h
|
src/ui/Theme.h
|
||||||
|
|
|
@ -319,7 +319,7 @@
|
||||||
<message>
|
<message>
|
||||||
<location line="+66"/>
|
<location line="+66"/>
|
||||||
<source>Failed to kick %1 from %2: %3</source>
|
<source>Failed to kick %1 from %2: %3</source>
|
||||||
<translation>Kontte %1 nicht aus %2 entfernen: %3</translation>
|
<translation>Konnte %1 nicht aus %2 entfernen: %3</translation>
|
||||||
</message>
|
</message>
|
||||||
</context>
|
</context>
|
||||||
<context>
|
<context>
|
||||||
|
|
|
@ -9,6 +9,7 @@ import "./dialogs"
|
||||||
import "./emoji"
|
import "./emoji"
|
||||||
import "./pages"
|
import "./pages"
|
||||||
import "./voip"
|
import "./voip"
|
||||||
|
import "./ui"
|
||||||
import Qt.labs.platform 1.1 as Platform
|
import Qt.labs.platform 1.1 as Platform
|
||||||
import QtQuick 2.15
|
import QtQuick 2.15
|
||||||
import QtQuick.Controls 2.15
|
import QtQuick.Controls 2.15
|
||||||
|
@ -402,6 +403,8 @@ Pane {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Snackbar { id: snackbar }
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
function onSwitchToChatPage() {
|
function onSwitchToChatPage() {
|
||||||
mainWindow.replace(null, chatPage);
|
mainWindow.replace(null, chatPage);
|
||||||
|
@ -409,6 +412,10 @@ Pane {
|
||||||
function onSwitchToLoginPage(error) {
|
function onSwitchToLoginPage(error) {
|
||||||
mainWindow.replace(welcomePage, {}, loginPage, {"error": error}, StackView.PopTransition);
|
mainWindow.replace(welcomePage, {}, loginPage, {"error": error}, StackView.PopTransition);
|
||||||
}
|
}
|
||||||
|
function onShowNotification(msg) {
|
||||||
|
snackbar.showNotification(msg);
|
||||||
|
console.log("New snack: " + msg);
|
||||||
|
}
|
||||||
target: MainWindow
|
target: MainWindow
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
98
resources/qml/ui/Snackbar.qml
Normal file
98
resources/qml/ui/Snackbar.qml
Normal file
|
@ -0,0 +1,98 @@
|
||||||
|
// 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 1.0
|
||||||
|
|
||||||
|
Popup {
|
||||||
|
id: snackbar
|
||||||
|
|
||||||
|
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: Nheko.colors.light
|
||||||
|
width: Math.max(Overlay.overlay? Overlay.overlay.width/2 : 0, 400)
|
||||||
|
text: snackbar.currentMessage
|
||||||
|
font.bold: true
|
||||||
|
}
|
||||||
|
|
||||||
|
background: Rectangle {
|
||||||
|
radius: Nheko.paddingLarge
|
||||||
|
color: Nheko.colors.dark
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -157,6 +157,7 @@
|
||||||
<file>qml/ui/NhekoSlider.qml</file>
|
<file>qml/ui/NhekoSlider.qml</file>
|
||||||
<file>qml/ui/Ripple.qml</file>
|
<file>qml/ui/Ripple.qml</file>
|
||||||
<file>qml/ui/Spinner.qml</file>
|
<file>qml/ui/Spinner.qml</file>
|
||||||
|
<file>qml/ui/Snackbar.qml</file>
|
||||||
<file>qml/ui/animations/BlinkAnimation.qml</file>
|
<file>qml/ui/animations/BlinkAnimation.qml</file>
|
||||||
<file>qml/ui/media/MediaControls.qml</file>
|
<file>qml/ui/media/MediaControls.qml</file>
|
||||||
<file>qml/voip/ActiveCallBar.qml</file>
|
<file>qml/voip/ActiveCallBar.qml</file>
|
||||||
|
|
|
@ -84,9 +84,8 @@ MainWindow::MainWindow(QWindow *parent)
|
||||||
connect(chat_page_, &ChatPage::closing, this, [this] { switchToLoginPage(""); });
|
connect(chat_page_, &ChatPage::closing, this, [this] { switchToLoginPage(""); });
|
||||||
connect(chat_page_, &ChatPage::unreadMessages, this, &MainWindow::setWindowTitle);
|
connect(chat_page_, &ChatPage::unreadMessages, this, &MainWindow::setWindowTitle);
|
||||||
connect(chat_page_, SIGNAL(unreadMessages(int)), trayIcon_, SLOT(setUnreadCount(int)));
|
connect(chat_page_, SIGNAL(unreadMessages(int)), trayIcon_, SLOT(setUnreadCount(int)));
|
||||||
connect(chat_page_, &ChatPage::showLoginPage, this, [this](const QString &msg) {
|
connect(chat_page_, &ChatPage::showLoginPage, this, &MainWindow::switchToLoginPage);
|
||||||
switchToLoginPage(msg);
|
connect(chat_page_, &ChatPage::showNotification, this, &MainWindow::showNotification);
|
||||||
});
|
|
||||||
|
|
||||||
connect(userSettings_.get(), &UserSettings::trayChanged, trayIcon_, &TrayIcon::setVisible);
|
connect(userSettings_.get(), &UserSettings::trayChanged, trayIcon_, &TrayIcon::setVisible);
|
||||||
connect(trayIcon_,
|
connect(trayIcon_,
|
||||||
|
|
|
@ -70,6 +70,8 @@ signals:
|
||||||
void reload();
|
void reload();
|
||||||
void secretsChanged();
|
void secretsChanged();
|
||||||
|
|
||||||
|
void showNotification(QString msg);
|
||||||
|
|
||||||
void switchToChatPage();
|
void switchToChatPage();
|
||||||
void switchToWelcomePage();
|
void switchToWelcomePage();
|
||||||
void switchToLoginPage(QString error);
|
void switchToLoginPage(QString error);
|
||||||
|
|
|
@ -1,79 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
||||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
#include "OverlayWidget.h"
|
|
||||||
|
|
||||||
#include <QPainter>
|
|
||||||
#include <QStyleOption>
|
|
||||||
|
|
||||||
OverlayWidget::OverlayWidget(QWidget *parent)
|
|
||||||
: QWidget(parent)
|
|
||||||
{
|
|
||||||
if (parent) {
|
|
||||||
parent->installEventFilter(this);
|
|
||||||
setGeometry(overlayGeometry());
|
|
||||||
raise();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
OverlayWidget::event(QEvent *event)
|
|
||||||
{
|
|
||||||
if (!parent())
|
|
||||||
return QWidget::event(event);
|
|
||||||
|
|
||||||
switch (event->type()) {
|
|
||||||
case QEvent::ParentChange: {
|
|
||||||
parent()->installEventFilter(this);
|
|
||||||
setGeometry(overlayGeometry());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case QEvent::ParentAboutToChange: {
|
|
||||||
parent()->removeEventFilter(this);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QWidget::event(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool
|
|
||||||
OverlayWidget::eventFilter(QObject *obj, QEvent *event)
|
|
||||||
{
|
|
||||||
switch (event->type()) {
|
|
||||||
case QEvent::Move:
|
|
||||||
case QEvent::Resize:
|
|
||||||
setGeometry(overlayGeometry());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return QWidget::eventFilter(obj, event);
|
|
||||||
}
|
|
||||||
|
|
||||||
QRect
|
|
||||||
OverlayWidget::overlayGeometry() const
|
|
||||||
{
|
|
||||||
QWidget *widget = parentWidget();
|
|
||||||
|
|
||||||
if (!widget)
|
|
||||||
return QRect();
|
|
||||||
|
|
||||||
return widget->rect();
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
OverlayWidget::paintEvent(QPaintEvent *event)
|
|
||||||
{
|
|
||||||
Q_UNUSED(event);
|
|
||||||
|
|
||||||
QStyleOption opt;
|
|
||||||
opt.initFrom(this);
|
|
||||||
QPainter p(this);
|
|
||||||
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
||||||
// SPDX-FileCopyrightText: 2022 Nheko Contributors
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <QEvent>
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
class QPainter;
|
|
||||||
|
|
||||||
class OverlayWidget : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
explicit OverlayWidget(QWidget *parent = nullptr);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
bool event(QEvent *event) override;
|
|
||||||
bool eventFilter(QObject *obj, QEvent *event) override;
|
|
||||||
|
|
||||||
QRect overlayGeometry() const;
|
|
||||||
void paintEvent(QPaintEvent *event) override;
|
|
||||||
};
|
|
Loading…
Reference in a new issue