diff options
-rw-r--r-- | CHANGELOG.md | 4 | ||||
-rw-r--r-- | src/mainwindow.cpp | 11 | ||||
-rw-r--r-- | src/notificationpopup.h | 34 |
3 files changed, 23 insertions, 26 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3626e5c..e5d1792 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# Change log: +## Change log: ### 4.3 - feat: IPC; restore window directly when another instance is launched @@ -21,7 +21,7 @@ example: `whatsie whatsapp://whatsie` will restore the primary instance of whatsie process -## 4.0 +### 4.0 - fix(SystemTray) tray icon uses png rather than SVG - feat(SystemTray) added settings to lets users change the system tray icon click behavior(minimize/maximize on right-click) - feat(Download) added setting that lets the user set default download directory, avoid asking while saving files diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8b00d80..13b01eb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -190,9 +190,7 @@ void MainWindow::updateWindowTheme() { } QList<QWidget *> widgets = this->findChildren<QWidget *>(); - foreach (QWidget *w, widgets) { - w->setPalette(qApp->palette()); - } + foreach (QWidget *w, widgets) { w->setPalette(qApp->palette()); } setNotificationPresenter(webEngine->page()->profile()); if (lockWidget != nullptr) { @@ -505,7 +503,9 @@ void MainWindow::notify(QString title, QString message) { popup->style()->polish(qApp); popup->setMinimumWidth(300); popup->adjustSize(); - popup->present(title, message, QPixmap(":/icons/app/icon-64.png")); + int screenNumber = qApp->desktop()->screenNumber(this); + popup->present(screenNumber < 0 ? 0 : screenNumber, title, message, + QPixmap(":/icons/app/icon-64.png")); } } @@ -844,7 +844,8 @@ void MainWindow::setNotificationPresenter(QWebEngineProfile *profile) { } else { popup->setMinimumWidth(300); - popup->present(notification); + int screenNumber = qApp->desktop()->screenNumber(this); + popup->present(screenNumber, notification); } }); } diff --git a/src/notificationpopup.h b/src/notificationpopup.h index 07a63f1..81d4d7b 100644 --- a/src/notificationpopup.h +++ b/src/notificationpopup.h @@ -12,6 +12,7 @@ #include <QMouseEvent> #include <QPropertyAnimation> #include <QPushButton> +#include <QScreen> #include <QSettings> #include <QSpacerItem> #include <QTimer> @@ -52,27 +53,25 @@ public: adjustSize(); } - void present(QString title, QString message, const QPixmap image) { + void present(int screenNumber, QString title, QString message, + const QPixmap image) { m_title.setText("<b>" + title + "</b>"); m_message.setText(message); m_icon.setPixmap( image.scaledToHeight(m_icon.height(), Qt::SmoothTransformation)); - this->adjustSize(); - qApp->processEvents(); - - int x = QApplication::desktop()->geometry().width() - (this->width() + 10); - int y = 40; - - this->update(); QTimer::singleShot(settings.value("notificationTimeOut", 9000).toInt(), this, [=]() { onClosed(); }); + this->adjustSize(); + QRect screenRect = QGuiApplication::screens().at(screenNumber)->geometry(); + int x = (screenRect.x() + screenRect.width() - 30) - this->width(); + int y = 40; + QPropertyAnimation *a = new QPropertyAnimation(this, "pos"); a->setDuration(200); - a->setStartValue( - QApplication::desktop()->mapToGlobal(QPoint(x + this->width(), y))); + a->setStartValue(QApplication::desktop()->mapToGlobal(QPoint(x - 20, y))); a->setEndValue(QApplication::desktop()->mapToGlobal(QPoint(x, y))); a->setEasingCurve(QEasingCurve::Linear); a->start(QPropertyAnimation::DeleteWhenStopped); @@ -80,7 +79,8 @@ public: this->show(); } - void present(std::unique_ptr<QWebEngineNotification> &newNotification) { + void present(int screenNumber, + std::unique_ptr<QWebEngineNotification> &newNotification) { if (notification) { notification->close(); notification.reset(); @@ -99,22 +99,18 @@ public: &NotificationPopup::onClosed); QTimer::singleShot(settings.value("notificationTimeOut", 9000).toInt(), notification.get(), [&]() { onClosed(); }); - this->adjustSize(); - qApp->processEvents(); - - int x = QApplication::desktop()->geometry().width() - (this->width() + 10); + QRect screenRect = QGuiApplication::screens().at(screenNumber)->geometry(); + int x = (screenRect.x() + screenRect.width() - 30) - this->width(); int y = 40; - this->update(); - QPropertyAnimation *a = new QPropertyAnimation(this, "pos"); a->setDuration(200); - a->setStartValue( - QApplication::desktop()->mapToGlobal(QPoint(x + this->width(), y))); + a->setStartValue(QApplication::desktop()->mapToGlobal(QPoint(x - 20, y))); a->setEndValue(QApplication::desktop()->mapToGlobal(QPoint(x, y))); a->setEasingCurve(QEasingCurve::Linear); a->start(QPropertyAnimation::DeleteWhenStopped); + this->show(); } |