diff --git a/src/Gui/NotificationBox.cpp b/src/Gui/NotificationBox.cpp index 44b1da08da..f96f58e70d 100644 --- a/src/Gui/NotificationBox.cpp +++ b/src/Gui/NotificationBox.cpp @@ -60,7 +60,8 @@ class NotificationLabel: public QLabel { Q_OBJECT public: - NotificationLabel(const QString& text, const QPoint& pos, int displayTime, int minShowTime = 0, int width = 0); + NotificationLabel(const QString& text, const QPoint& pos, int displayTime, int minShowTime = 0, + int width = 0); /// Reuse existing notification to show a new notification (with a new text) void reuseNotification(const QString& text, int displayTime, const QPoint& pos, int width); /// Hide notification after a hiding timer. @@ -74,7 +75,7 @@ public: /// Place the notification at the given position void placeNotificationLabel(const QPoint& pos); /// Set the windowrect defining an area to which the label should be constrained - void setTipRect(const QRect &restrictionarea); + void setTipRect(const QRect& restrictionarea); void setHideIfReferenceWidgetDeactivated(bool on); @@ -150,9 +151,10 @@ void NotificationLabel::restartExpireTimer(int displayTime) hideTimer.stop(); } -void NotificationLabel::reuseNotification(const QString& text, int displayTime, const QPoint& pos, int width) +void NotificationLabel::reuseNotification(const QString& text, int displayTime, const QPoint& pos, + int width) { - if(width > 0) + if (width > 0) setFixedWidth(width); setText(text); @@ -248,10 +250,9 @@ bool NotificationLabel::eventFilter(QObject* o, QEvent* e) return insideclick; } - } - break; + } break; case QEvent::WindowDeactivate: - if(hideIfReferenceWidgetDeactivated) + if (hideIfReferenceWidgetDeactivated) hideNotificationImmediately(); break; @@ -278,7 +279,7 @@ void NotificationLabel::placeNotificationLabel(const QPoint& pos) QRect actinglimit = screen->geometry(); - if(!restrictionArea.isNull()) + if (!restrictionArea.isNull()) actinglimit = restrictionArea; const int standard_x_padding = 4; @@ -301,7 +302,7 @@ void NotificationLabel::placeNotificationLabel(const QPoint& pos) this->move(p); } -void NotificationLabel::setTipRect(const QRect &restrictionarea) +void NotificationLabel::setTipRect(const QRect& restrictionarea) { restrictionArea = restrictionarea; } @@ -318,25 +319,25 @@ bool NotificationLabel::notificationLabelChanged(const QString& text) /***************************** NotificationBox **********************************/ -bool NotificationBox::showText(const QPoint& pos, const QString& text, QWidget * referenceWidget, int displayTime, - unsigned int minShowTime, Options options, - int width) +bool NotificationBox::showText(const QPoint& pos, const QString& text, QWidget* referenceWidget, + int displayTime, unsigned int minShowTime, Options options, + int width) { QRect restrictionarea = {}; - if(referenceWidget) { - if(options & Options::OnlyIfReferenceActive) { + if (referenceWidget) { + if (options & Options::OnlyIfReferenceActive) { if (!referenceWidget->isActiveWindow()) { return false; } } - if(options & Options::RestrictAreaToReference) { + if (options & Options::RestrictAreaToReference) { // Calculate the main window QRect in global screen coordinates. auto mainwindowrect = referenceWidget->rect(); - restrictionarea = - QRect(referenceWidget->mapToGlobal(mainwindowrect.topLeft()), mainwindowrect.size()); + restrictionarea = QRect(referenceWidget->mapToGlobal(mainwindowrect.topLeft()), + mainwindowrect.size()); } } @@ -350,8 +351,8 @@ bool 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->setHideIfReferenceWidgetDeactivated( + options & Options::HideIfReferenceWidgetDeactivated); NotificationLabel::instance->reuseNotification(text, displayTime, pos, width); NotificationLabel::instance->placeNotificationLabel(pos); } @@ -371,8 +372,8 @@ bool 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->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 f4f4dce034..f25cae4c44 100644 --- a/src/Gui/NotificationBox.h +++ b/src/Gui/NotificationBox.h @@ -49,34 +49,40 @@ class NotificationBox NotificationBox() = delete; public: - enum class Options { - None = 0x0, - RestrictAreaToReference = 0x1, - OnlyIfReferenceActive = 0x2, - HideIfReferenceWidgetDeactivated = 0x4, + enum class Options + { + None = 0x0, + RestrictAreaToReference = 0x1, + OnlyIfReferenceActive = 0x2, + HideIfReferenceWidgetDeactivated = 0x4, }; /** Shows a non-intrusive notification. * @param pos Position at which the notification will be shown * @param text Message to be shown - * @param referenceWidget If provided, will set the reference to calculate a restrictionarea (see below restrictAreaToReference) and - * to prevent notifications for being shown if not active. + * @param referenceWidget If provided, will set the reference to calculate a restrictionarea + * (see below options) and to prevent notifications for being shown if not active. * @param displayTime Time after which the notification will auto-close (unless it is closed by * an event, see class documentation above) * @param minShowTime Time during which the notification can only be made disappear by popping * it out (clicking inside it). - * @param restrictAreaToReference Try to keep the NotificationBox within the QRect of the referenceWidget. if false or referenceWidget is - * nullptr, the whole screen is used as restriction area. - * @param onlyIfReferenceActive Show only if the reference window is active. + * @param options Different flag options: + * - HideIfReferenceWidgetDeactivated - Hides a notification if the main window becomes + * inactive. + * - RestrictAreaToReference - Try to keep the NotificationBox within the QRect of the + * referenceWidget. if false or referenceWidget is nullptr, the whole screen is used as + * restriction area. + * - OnlyIfReferenceActive - Show only if the reference window is active. + * * @param width Fixes the width of the notification. Default value makes the width to be system * determined (dependent on the text). If a fixed width is provided it is enforced over the * restrictionarea. * * @return returns whether the notification was shown or not */ - static bool showText(const QPoint& pos, const QString& text, QWidget * referenceWidget = nullptr, int displayTime = -1, - unsigned int minShowTime = 0, Options options = Options::None, - int width = 0); + static bool showText(const QPoint& pos, const QString& text, QWidget* referenceWidget = nullptr, + int displayTime = -1, unsigned int minShowTime = 0, + Options options = Options::None, int width = 0); /// Hides a notification. static inline void hideText() { @@ -96,16 +102,18 @@ public: static void setFont(const QFont&); }; -inline NotificationBox::Options operator|(NotificationBox::Options lhs, NotificationBox::Options rhs) { +inline NotificationBox::Options operator|(NotificationBox::Options lhs, + NotificationBox::Options rhs) +{ return static_cast( - static_cast::type>(lhs) | - static_cast::type>(rhs)); + static_cast::type>(lhs) + | static_cast::type>(rhs)); } -inline bool operator&(NotificationBox::Options lhs, NotificationBox::Options rhs) { - return ( - static_cast::type>(lhs) & - static_cast::type>(rhs)); +inline bool operator&(NotificationBox::Options lhs, NotificationBox::Options rhs) +{ + return (static_cast::type>(lhs) + & static_cast::type>(rhs)); } }// namespace Gui