From d2c94992e51c783d5c455196a1948ac70defdb0b Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 10 Nov 2023 10:06:55 +0100 Subject: [PATCH] opacity support for notifications --- .../notifications/basetoastnotification.cpp | 3 +- .../toastnotificationsmanager.cpp | 11 +-- .../notifications/toastnotificationsmanager.h | 2 + .../gui/settings/settingsnotifications.cpp | 3 + .../gui/settings/settingsnotifications.ui | 84 +++++++++++++------ src/librssguard/miscellaneous/settings.cpp | 3 + src/librssguard/miscellaneous/settings.h | 3 + 7 files changed, 78 insertions(+), 31 deletions(-) diff --git a/src/librssguard/gui/notifications/basetoastnotification.cpp b/src/librssguard/gui/notifications/basetoastnotification.cpp index 2538a11ea..29cc3a4df 100644 --- a/src/librssguard/gui/notifications/basetoastnotification.cpp +++ b/src/librssguard/gui/notifications/basetoastnotification.cpp @@ -15,9 +15,8 @@ using namespace std::chrono_literals; BaseToastNotification::BaseToastNotification(QWidget* parent) : QDialog(parent), m_timerId(-1) { setAttribute(Qt::WidgetAttribute::WA_ShowWithoutActivating); - setFixedWidth(qApp->settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsWidth)).toInt()); + // setFixedWidth(qApp->settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsWidth)).toInt()); setFocusPolicy(Qt::FocusPolicy::NoFocus); - setAttribute(Qt::WidgetAttribute::WA_DeleteOnClose, false); setWindowFlags( diff --git a/src/librssguard/gui/notifications/toastnotificationsmanager.cpp b/src/librssguard/gui/notifications/toastnotificationsmanager.cpp index 64bbe2cd3..72ff3f999 100644 --- a/src/librssguard/gui/notifications/toastnotificationsmanager.cpp +++ b/src/librssguard/gui/notifications/toastnotificationsmanager.cpp @@ -31,7 +31,7 @@ QString ToastNotificationsManager::textForPosition(ToastNotificationsManager::No ToastNotificationsManager::ToastNotificationsManager(QObject* parent) : QObject(parent), m_position(ToastNotificationsManager::NotificationPosition::TopRight), m_screen(0), m_margins(0), - m_articleListNotification(nullptr) { + m_width(0), m_opacity(0.0), m_articleListNotification(nullptr) { resetNotifications(false); } @@ -65,8 +65,8 @@ void ToastNotificationsManager::resetNotifications(bool reload_existing_notifica .value(); m_screen = qApp->settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsScreen)).toInt(); m_margins = qApp->settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsMargin)).toInt(); - - auto notif_width = qApp->settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsWidth)).toInt(); + m_opacity = qApp->settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsOpacity)).toDouble(); + m_width = qApp->settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsWidth)).toInt(); if (reload_existing_notifications) { auto notif = m_activeNotifications; @@ -76,8 +76,6 @@ void ToastNotificationsManager::resetNotifications(bool reload_existing_notifica while (!notif.isEmpty()) { BaseToastNotification* one_notif = notif.takeLast(); - one_notif->setFixedWidth(notif_width); - processNotification(one_notif); } } @@ -92,6 +90,9 @@ void ToastNotificationsManager::clear(bool delete_from_memory) { } void ToastNotificationsManager::processNotification(BaseToastNotification* notif) { + notif->setWindowOpacity(m_opacity); + notif->setFixedWidth(m_width); + notif->show(); auto* screen = moveToProperScreen(notif); diff --git a/src/librssguard/gui/notifications/toastnotificationsmanager.h b/src/librssguard/gui/notifications/toastnotificationsmanager.h index e80d6b53f..6634290eb 100644 --- a/src/librssguard/gui/notifications/toastnotificationsmanager.h +++ b/src/librssguard/gui/notifications/toastnotificationsmanager.h @@ -69,6 +69,8 @@ class ToastNotificationsManager : public QObject { NotificationPosition m_position; int m_screen; int m_margins; + int m_width; + double m_opacity; // List of all displayed notifications, newest notifications are in the beginning of the list // and oldest at the end. diff --git a/src/librssguard/gui/settings/settingsnotifications.cpp b/src/librssguard/gui/settings/settingsnotifications.cpp index 7e3fd8090..3ffed29e0 100644 --- a/src/librssguard/gui/settings/settingsnotifications.cpp +++ b/src/librssguard/gui/settings/settingsnotifications.cpp @@ -30,6 +30,7 @@ SettingsNotifications::SettingsNotifications(Settings* settings, QWidget* parent connect(m_ui.m_sbScreen, QOverload::of(&QSpinBox::valueChanged), this, &SettingsNotifications::dirtifySettings); connect(m_ui.m_sbMargin, QOverload::of(&QSpinBox::valueChanged), this, &SettingsNotifications::dirtifySettings); connect(m_ui.m_sbWidth, QOverload::of(&QSpinBox::valueChanged), this, &SettingsNotifications::dirtifySettings); + connect(m_ui.m_sbOpacity, QOverload::of(&QSpinBox::valueChanged), this, &SettingsNotifications::dirtifySettings); connect(m_ui.m_sbScreen, QOverload::of(&QSpinBox::valueChanged), this, &SettingsNotifications::showScreenInfo); @@ -64,6 +65,7 @@ void SettingsNotifications::loadSettings() { m_ui.m_sbScreen->setValue(settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsScreen)).toInt()); m_ui.m_sbWidth->setValue(settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsWidth)).toInt()); m_ui.m_sbMargin->setValue(settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsMargin)).toInt()); + m_ui.m_sbOpacity->setValue(settings()->value(GROUP(GUI), SETTING(GUI::ToastNotificationsOpacity)).toDouble() * 100); m_ui.m_cbCustomNotificationsPosition ->setCurrentIndex(m_ui.m_cbCustomNotificationsPosition @@ -85,6 +87,7 @@ void SettingsNotifications::saveSettings() { settings()->setValue(GROUP(GUI), GUI::ToastNotificationsScreen, m_ui.m_sbScreen->value()); settings()->setValue(GROUP(GUI), GUI::ToastNotificationsWidth, m_ui.m_sbWidth->value()); settings()->setValue(GROUP(GUI), GUI::ToastNotificationsMargin, m_ui.m_sbMargin->value()); + settings()->setValue(GROUP(GUI), GUI::ToastNotificationsOpacity, m_ui.m_sbOpacity->value() / 100.0); settings()->setValue(GROUP(GUI), GUI::ToastNotificationsPosition, diff --git a/src/librssguard/gui/settings/settingsnotifications.ui b/src/librssguard/gui/settings/settingsnotifications.ui index 49f58bc46..ec51b5f81 100644 --- a/src/librssguard/gui/settings/settingsnotifications.ui +++ b/src/librssguard/gui/settings/settingsnotifications.ui @@ -76,31 +76,20 @@ - - - - 99 - - - - - + + - Screen + Width - - - - - - + + m_sbWidth - px + px 50 @@ -110,27 +99,67 @@ - - + + - Width + Margins + + + m_sbMargin - px + px 100 - - + + - Margins + Screen + + + m_sbScreen + + + + + + + 99 + + + + + + + + + + + + + + % + + + 100 + + + + + + + Opacity + + + m_sbOpacity @@ -158,6 +187,13 @@ m_checkEnableNotifications + m_rbNativeNotifications + m_rbCustomNotifications + m_cbCustomNotificationsPosition + m_sbWidth + m_sbMargin + m_sbScreen + m_sbOpacity diff --git a/src/librssguard/miscellaneous/settings.cpp b/src/librssguard/miscellaneous/settings.cpp index 5514ec581..3143aab0a 100644 --- a/src/librssguard/miscellaneous/settings.cpp +++ b/src/librssguard/miscellaneous/settings.cpp @@ -298,6 +298,9 @@ DVALUE(int) GUI::ToastNotificationsScreenDef = -1; DKEY GUI::ToastNotificationsMargin = "toast_notifications_margin"; DVALUE(int) GUI::ToastNotificationsMarginDef = NOTIFICATIONS_MARGIN; +DKEY GUI::ToastNotificationsOpacity = "toast_notifications_opacity"; +DVALUE(double) GUI::ToastNotificationsOpacityDef = 0.9; + DKEY GUI::ToastNotificationsWidth = "toast_notifications_width"; DVALUE(int) GUI::ToastNotificationsWidthDef = NOTIFICATIONS_WIDTH; diff --git a/src/librssguard/miscellaneous/settings.h b/src/librssguard/miscellaneous/settings.h index fb6076906..5ce9fa908 100644 --- a/src/librssguard/miscellaneous/settings.h +++ b/src/librssguard/miscellaneous/settings.h @@ -231,6 +231,9 @@ namespace GUI { KEY ToastNotificationsMargin; VALUE(int) ToastNotificationsMarginDef; + KEY ToastNotificationsOpacity; + VALUE(double) ToastNotificationsOpacityDef; + KEY ToastNotificationsWidth; VALUE(int) ToastNotificationsWidthDef;