NotificationArea: Change Icon color to indicate missed notifications
This commit is contained in:
committed by
abdullahtahiriyo
parent
c2b48fbe91
commit
23739bc2d0
@@ -101,6 +101,7 @@
|
||||
<file>accessories-calculator.svg</file>
|
||||
<file>internet-web-browser.svg</file>
|
||||
<file>InTray.svg</file>
|
||||
<file>InTray_missed_notifications.svg</file>
|
||||
<file>view-select.svg</file>
|
||||
<file>view-unselectable.svg</file>
|
||||
<file>view-refresh.svg</file>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<NotificationsAction*>(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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<NotificationAreaP> pImp;
|
||||
};
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user