diff options
| author | isanae <14251494+isanae@users.noreply.github.com> | 2019-06-12 18:04:42 -0400 |
|---|---|---|
| committer | isanae <14251494+isanae@users.noreply.github.com> | 2019-06-12 18:04:42 -0400 |
| commit | 16d6a4c528fd226ac5bf9a2ff54911c567d5bca0 (patch) | |
| tree | 4eb5011470de5b0ed5a935b069c2523a8d0cae64 | |
| parent | dc08c12fe8cde84c7cf507954d090d572ac865d5 (diff) | |
added a StatusBarNotifications class to handle icon, text and double click
| -rw-r--r-- | src/mainwindow.cpp | 2 | ||||
| -rw-r--r-- | src/statusbar.cpp | 46 | ||||
| -rw-r--r-- | src/statusbar.h | 24 |
3 files changed, 58 insertions, 14 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c39ac749..6d65d64c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -902,7 +902,7 @@ void MainWindow::updateProblemsButton() // updating the status bar, may be null very early when MO is starting if (m_statusBar) { - m_statusBar->setHasNotifications(numProblems > 0); + m_statusBar->updateNotifications(numProblems > 0); } } diff --git a/src/statusbar.cpp b/src/statusbar.cpp index 1c62b38e..9ff1c476 100644 --- a/src/statusbar.cpp +++ b/src/statusbar.cpp @@ -2,9 +2,9 @@ #include "nexusinterface.h" #include "settings.h" -StatusBar::StatusBar(QStatusBar* bar, QAction* notifications) : - m_bar(bar), m_progress(new QProgressBar), m_notifications(new QToolButton), - m_api(new QLabel) +StatusBar::StatusBar(QStatusBar* bar, QAction* actionNotifications) : + m_bar(bar), m_notifications(new StatusBarNotifications(actionNotifications)), + m_progress(new QProgressBar), m_api(new QLabel) { m_bar->addPermanentWidget(m_progress); m_bar->addPermanentWidget(m_notifications); @@ -12,13 +12,11 @@ StatusBar::StatusBar(QStatusBar* bar, QAction* notifications) : m_progress->setTextVisible(true); m_progress->setRange(0, 100); - m_progress->setMaximumWidth(100); - - m_notifications->setDefaultAction(notifications); - m_notifications->setAutoRaise(true); + m_progress->setMaximumWidth(150); + m_progress->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding); m_api->setObjectName("apistats"); - m_api->setStyleSheet("QLabel{ padding-left: 0.1em; padding-right: 0.1em; }"); + m_api->setStyleSheet("QLabel{ padding: 0.1em 0 0.1em 0; }"); m_bar->clearMessage(); setProgress(-1); @@ -28,6 +26,7 @@ StatusBar::StatusBar(QStatusBar* bar, QAction* notifications) : void StatusBar::setProgress(int percent) { if (percent < 0 || percent >= 100) { + m_bar->clearMessage(); m_progress->setVisible(false); } else { m_bar->showMessage(QObject::tr("Loading...")); @@ -36,9 +35,9 @@ void StatusBar::setProgress(int percent) } } -void StatusBar::setHasNotifications(bool b) +void StatusBar::updateNotifications(bool hasNotifications) { - m_notifications->setVisible(b); + m_notifications->update(hasNotifications); } void StatusBar::updateAPI(const APIStats& stats, const APIUserAccount& user) @@ -78,3 +77,30 @@ void StatusBar::checkSettings(const Settings& settings) { m_api->setVisible(!settings.hideAPICounter()); } + + +StatusBarNotifications::StatusBarNotifications(QAction* action) + : m_action(action), m_icon(new QLabel), m_text(new QLabel) +{ + setLayout(new QHBoxLayout); + layout()->setContentsMargins(0, 0, 0, 0); + layout()->addWidget(m_icon); + layout()->addWidget(m_text); +} + +void StatusBarNotifications::update(bool hasNotifications) +{ + if (hasNotifications) { + m_icon->setPixmap(m_action->icon().pixmap(16, 16)); + m_text->setText(QObject::tr("Notifications")); + } + + setVisible(hasNotifications); +} + +void StatusBarNotifications::mouseDoubleClickEvent(QMouseEvent* e) +{ + if (m_action->isEnabled()) { + m_action->trigger(); + } +} diff --git a/src/statusbar.h b/src/statusbar.h index bf14ba57..8edfd037 100644 --- a/src/statusbar.h +++ b/src/statusbar.h @@ -8,20 +8,38 @@ struct APIStats; class APIUserAccount; class Settings; + +class StatusBarNotifications : public QWidget +{ +public: + StatusBarNotifications(QAction* action); + + void update(bool hasNotifications); + +protected: + void mouseDoubleClickEvent(QMouseEvent* e) override; + +private: + QAction* m_action; + QLabel* m_icon; + QLabel* m_text; +}; + + class StatusBar { public: - StatusBar(QStatusBar* bar, QAction* notifications); + StatusBar(QStatusBar* bar, QAction* actionNotifications); void setProgress(int percent); - void setHasNotifications(bool b); + void updateNotifications(bool hasNotifications); void updateAPI(const APIStats& stats, const APIUserAccount& user); void checkSettings(const Settings& settings); private: QStatusBar* m_bar; + StatusBarNotifications* m_notifications; QProgressBar* m_progress; - QToolButton* m_notifications; QLabel* m_api; }; |
