From 49966ac84dc761a70d1367212657a050025334a9 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Tue, 21 Mar 2023 08:36:16 +0100 Subject: [PATCH] NotificationBox: Add option to hide notification if reference widget is deactivated --- src/Gui/NotificationArea.cpp | 3 ++- src/Gui/NotificationBox.cpp | 15 ++++++++++++++- src/Gui/NotificationBox.h | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Gui/NotificationArea.cpp b/src/Gui/NotificationArea.cpp index 6e4d6fd8c8..93fbe07fd2 100644 --- a/src/Gui/NotificationArea.cpp +++ b/src/Gui/NotificationArea.cpp @@ -997,7 +997,8 @@ void NotificationArea::showInNotificationArea() pImp->notificationExpirationTime, pImp->minimumOnScreenTime, NotificationBox::OnlyIfReferenceActive | - NotificationBox::RestrictAreaToReference, + NotificationBox::RestrictAreaToReference | + NotificationBox::HideIfReferenceWidgetDeactivated, pImp->notificationWidth); } } diff --git a/src/Gui/NotificationBox.cpp b/src/Gui/NotificationBox.cpp index ff07a9646a..5af23eec94 100644 --- a/src/Gui/NotificationBox.cpp +++ b/src/Gui/NotificationBox.cpp @@ -76,6 +76,8 @@ public: /// Set the windowrect defining an area to which the label should be constrained void setTipRect(const QRect &restrictionarea); + void setHideIfReferenceWidgetDeactivated(bool on); + /// The instance static qobject_delete_later_unique_ptr instance; @@ -95,6 +97,7 @@ private: QTimer expireTimer; QRect restrictionArea; + bool hideIfReferenceWidgetDeactivated; }; qobject_delete_later_unique_ptr NotificationLabel::instance = nullptr; @@ -248,7 +251,8 @@ bool NotificationLabel::eventFilter(QObject* o, QEvent* e) } break; case QEvent::WindowDeactivate: - hideNotificationImmediately(); + if(hideIfReferenceWidgetDeactivated) + hideNotificationImmediately(); break; default: @@ -302,6 +306,11 @@ void NotificationLabel::setTipRect(const QRect &restrictionarea) restrictionArea = restrictionarea; } +void NotificationLabel::setHideIfReferenceWidgetDeactivated(bool on) +{ + hideIfReferenceWidgetDeactivated = on; +} + bool NotificationLabel::notificationLabelChanged(const QString& text) { return NotificationLabel::instance->text() != text; @@ -341,6 +350,8 @@ void NotificationBox::showText(const QPoint& pos, const QString& text, QWidget * // If the label has changed, reuse the one that is showing (removes flickering) if (NotificationLabel::instance->notificationLabelChanged(text)) { NotificationLabel::instance->setTipRect(restrictionarea); + NotificationLabel::instance->setHideIfReferenceWidgetDeactivated(options & + Options::HideIfReferenceWidgetDeactivated); NotificationLabel::instance->reuseNotification(text, displayTime, pos, width); NotificationLabel::instance->placeNotificationLabel(pos); } @@ -360,6 +371,8 @@ void NotificationBox::showText(const QPoint& pos, const QString& text, QWidget * width);// sets NotificationLabel::instance to itself NotificationLabel::instance->setTipRect(restrictionarea); + NotificationLabel::instance->setHideIfReferenceWidgetDeactivated(options & + Options::HideIfReferenceWidgetDeactivated); NotificationLabel::instance->placeNotificationLabel(pos); NotificationLabel::instance->setObjectName(QLatin1String("NotificationBox_label")); diff --git a/src/Gui/NotificationBox.h b/src/Gui/NotificationBox.h index dca3cd9bf6..323f7ad448 100644 --- a/src/Gui/NotificationBox.h +++ b/src/Gui/NotificationBox.h @@ -53,6 +53,7 @@ public: None = 0x0, RestrictAreaToReference = 0x1, OnlyIfReferenceActive = 0x2, + HideIfReferenceWidgetDeactivated = 0x4, }; /** Shows a non-intrusive notification.