diff --git a/src/Gui/Icons/resource.qrc b/src/Gui/Icons/resource.qrc index 39df69cbc5..5db1668671 100644 --- a/src/Gui/Icons/resource.qrc +++ b/src/Gui/Icons/resource.qrc @@ -101,6 +101,7 @@ accessories-calculator.svg internet-web-browser.svg InTray.svg + InTray_missed_notifications.svg view-select.svg view-unselectable.svg view-refresh.svg diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 779c60b98f..7d761ef133 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -314,7 +314,6 @@ MainWindow::MainWindow(QWidget * parent, Qt::WindowFlags f) if(notificationAreaEnabled) { NotificationArea* notificationArea = new NotificationArea(statusBar()); notificationArea->setObjectName(QString::fromLatin1("notificationArea")); - notificationArea->setIcon(QIcon(QString::fromLatin1(":/icons/InTray.svg"))); notificationArea->setStyleSheet(QStringLiteral("text-align:left;")); statusBar()->addPermanentWidget(notificationArea); } diff --git a/src/Gui/NotificationArea.cpp b/src/Gui/NotificationArea.cpp index a74398d42b..687b9dc126 100644 --- a/src/Gui/NotificationArea.cpp +++ b/src/Gui/NotificationArea.cpp @@ -108,6 +108,8 @@ struct NotificationAreaP const unsigned int inhibitNotificationTime = 250; //@} + bool missedNotifications = false; + // Access control std::mutex mutexNotification; @@ -141,6 +143,8 @@ private: warning = BitmapFactory().pixmapFromSvg(":/icons/Warning.svg", QSize(16, 16)); critical = BitmapFactory().pixmapFromSvg(":/icons/critical-info.svg", QSize(16, 16)); info = BitmapFactory().pixmapFromSvg(":/icons/info.svg", QSize(16, 16)); + notificationArea = QIcon(QStringLiteral(":/icons/InTray.svg")); + notificationAreaMissedNotifications = QIcon(QStringLiteral(":/icons/InTray_missed_notifications.svg")); } inline static const auto& getResourceManager() @@ -175,11 +179,25 @@ public: return rm.info; } + inline static auto NotificationAreaIcon() + { + auto rm = getResourceManager(); + return rm.notificationArea; + } + + inline static auto notificationAreaMissedNotificationsIcon() + { + auto rm = getResourceManager(); + return rm.notificationAreaMissedNotifications; + } + private: QPixmap error; QPixmap warning; QPixmap critical; QPixmap info; + QIcon notificationArea; + QIcon notificationAreaMissedNotifications; }; /******************** Console Messages Observer (Console Interface) ************************/ @@ -723,6 +741,10 @@ NotificationArea::NotificationArea(QWidget* parent) pImp->mutexNotification);// guard to avoid modifying the notification list and indices // while creating the tooltip setText(QString::number(0)); // no unread notifications + if(pImp->missedNotifications) { + setIcon(TrayIcon::Normal); + pImp->missedNotifications = false; + } static_cast(pImp->notificationaction)->synchroniseWidget(); // the position of the action has already been calculated (for a non-synchronised widget), @@ -748,6 +770,8 @@ NotificationArea::NotificationArea(QWidget* parent) setText(QString::number(na->getUnreadCount())); showInNotificationArea(); }); + + setIcon(TrayIcon::Normal); } NotificationArea::~NotificationArea() @@ -1015,13 +1039,18 @@ void NotificationArea::showInNotificationArea() options = options | NotificationBox::Options::HideIfReferenceWidgetDeactivated; } - NotificationBox::showText(this->mapToGlobal(QPoint()), + bool isshown = NotificationBox::showText(this->mapToGlobal(QPoint()), msgw, getMainWindow(), pImp->notificationExpirationTime, pImp->minimumOnScreenTime, options, pImp->notificationWidth); + + if(!isshown && !pImp->missedNotifications) { + pImp->missedNotifications = true; + setIcon(TrayIcon::MissedNotifications); + } } } @@ -1030,3 +1059,13 @@ void NotificationArea::slotRestoreFinished(const App::Document&) // Re-arm on restore critical message modal notifications if another document is loaded pImp->requireConfirmationCriticalMessageDuringRestoring = true; } + +void NotificationArea::setIcon(TrayIcon trayIcon) +{ + if(trayIcon == TrayIcon::Normal) { + QPushButton::setIcon(ResourceManager::NotificationAreaIcon()); + } + else if(trayIcon == TrayIcon::MissedNotifications) { + QPushButton::setIcon(ResourceManager::notificationAreaMissedNotificationsIcon()); + } +} diff --git a/src/Gui/NotificationArea.h b/src/Gui/NotificationArea.h index 133cb41737..8857966b35 100644 --- a/src/Gui/NotificationArea.h +++ b/src/Gui/NotificationArea.h @@ -39,6 +39,11 @@ struct NotificationAreaP; class NotificationArea: public QPushButton { + enum class TrayIcon { + Normal, + MissedNotifications, + }; + public: class ParameterObserver: public ParameterGrp::ObserverType { @@ -68,6 +73,8 @@ private: void mousePressEvent(QMouseEvent* e) override; + void setIcon(TrayIcon trayIcon); + private: std::unique_ptr pImp; }; diff --git a/src/Gui/NotificationBox.cpp b/src/Gui/NotificationBox.cpp index 5af23eec94..44b1da08da 100644 --- a/src/Gui/NotificationBox.cpp +++ b/src/Gui/NotificationBox.cpp @@ -318,7 +318,7 @@ bool NotificationLabel::notificationLabelChanged(const QString& text) /***************************** NotificationBox **********************************/ -void NotificationBox::showText(const QPoint& pos, const QString& text, QWidget * referenceWidget, int displayTime, +bool NotificationBox::showText(const QPoint& pos, const QString& text, QWidget * referenceWidget, int displayTime, unsigned int minShowTime, Options options, int width) { @@ -327,7 +327,7 @@ void NotificationBox::showText(const QPoint& pos, const QString& text, QWidget * if(referenceWidget) { if(options & Options::OnlyIfReferenceActive) { if (!referenceWidget->isActiveWindow()) { - return; + return false; } } @@ -344,7 +344,7 @@ void NotificationBox::showText(const QPoint& pos, const QString& text, QWidget * if (NotificationLabel::instance && NotificationLabel::instance->isVisible()) { if (text.isEmpty()) {// empty text means hide current label NotificationLabel::instance->hideNotification(); - return; + return false; } else { // If the label has changed, reuse the one that is showing (removes flickering) @@ -355,7 +355,7 @@ void NotificationBox::showText(const QPoint& pos, const QString& text, QWidget * NotificationLabel::instance->reuseNotification(text, displayTime, pos, width); NotificationLabel::instance->placeNotificationLabel(pos); } - return; + return true; } } @@ -378,6 +378,8 @@ void NotificationBox::showText(const QPoint& pos, const QString& text, QWidget * NotificationLabel::instance->showNormal(); } + + return true; } bool NotificationBox::isVisible() diff --git a/src/Gui/NotificationBox.h b/src/Gui/NotificationBox.h index c34483d675..f4f4dce034 100644 --- a/src/Gui/NotificationBox.h +++ b/src/Gui/NotificationBox.h @@ -71,8 +71,10 @@ public: * @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 void showText(const QPoint& pos, const QString& text, QWidget * referenceWidget = nullptr, int displayTime = -1, + 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.