opacity support for notifications

This commit is contained in:
Martin Rotter 2023-11-10 10:06:55 +01:00
parent 700b932cd8
commit d2c94992e5
7 changed files with 78 additions and 31 deletions

View File

@ -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(

View File

@ -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<ToastNotificationsManager::NotificationPosition>();
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);

View File

@ -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.

View File

@ -30,6 +30,7 @@ SettingsNotifications::SettingsNotifications(Settings* settings, QWidget* parent
connect(m_ui.m_sbScreen, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingsNotifications::dirtifySettings);
connect(m_ui.m_sbMargin, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingsNotifications::dirtifySettings);
connect(m_ui.m_sbWidth, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingsNotifications::dirtifySettings);
connect(m_ui.m_sbOpacity, QOverload<int>::of(&QSpinBox::valueChanged), this, &SettingsNotifications::dirtifySettings);
connect(m_ui.m_sbScreen, QOverload<int>::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,

View File

@ -76,31 +76,20 @@
<item row="0" column="1">
<widget class="QComboBox" name="m_cbCustomNotificationsPosition"/>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="m_sbScreen">
<property name="value">
<number>99</number>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Screen</string>
<string>Width</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="m_lblScreenInfo">
<property name="text">
<string/>
<property name="buddy">
<cstring>m_sbWidth</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="m_sbWidth">
<property name="suffix">
<string> px</string>
<string notr="true"> px</string>
</property>
<property name="minimum">
<number>50</number>
@ -110,27 +99,67 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Width</string>
<string>Margins</string>
</property>
<property name="buddy">
<cstring>m_sbMargin</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="m_sbMargin">
<property name="suffix">
<string> px</string>
<string notr="true"> px</string>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<item row="3" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Margins</string>
<string>Screen</string>
</property>
<property name="buddy">
<cstring>m_sbScreen</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="m_sbScreen">
<property name="value">
<number>99</number>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="m_lblScreenInfo">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QSpinBox" name="m_sbOpacity">
<property name="suffix">
<string notr="true"> %</string>
</property>
<property name="maximum">
<number>100</number>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Opacity</string>
</property>
<property name="buddy">
<cstring>m_sbOpacity</cstring>
</property>
</widget>
</item>
@ -158,6 +187,13 @@
</customwidgets>
<tabstops>
<tabstop>m_checkEnableNotifications</tabstop>
<tabstop>m_rbNativeNotifications</tabstop>
<tabstop>m_rbCustomNotifications</tabstop>
<tabstop>m_cbCustomNotificationsPosition</tabstop>
<tabstop>m_sbWidth</tabstop>
<tabstop>m_sbMargin</tabstop>
<tabstop>m_sbScreen</tabstop>
<tabstop>m_sbOpacity</tabstop>
</tabstops>
<resources/>
<connections>

View File

@ -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;

View File

@ -231,6 +231,9 @@ namespace GUI {
KEY ToastNotificationsMargin;
VALUE(int) ToastNotificationsMarginDef;
KEY ToastNotificationsOpacity;
VALUE(double) ToastNotificationsOpacityDef;
KEY ToastNotificationsWidth;
VALUE(int) ToastNotificationsWidthDef;