summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-06-09 09:42:22 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-06-09 09:42:22 -0400
commitc31f8b7e314d08022d1d8e50cc77e727eb4bcb5c (patch)
treee8debea965e0159ba8900f9261c5a154c784dc06 /src
parent4f240ddb7f8fa2cb2211105756202daca010b008 (diff)
fixed notification icon not respecting the stylesheet on startup
Diffstat (limited to 'src')
-rw-r--r--src/mainwindow.cpp57
-rw-r--r--src/mainwindow.h4
2 files changed, 55 insertions, 6 deletions
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 62846da8..a20f49f8 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -490,6 +490,10 @@ void MainWindow::resetActionIcons()
// sort of button, which typically happens on the toolbar) _and_ to the
// QAction itself, which is used in the menu bar
+ // clearing the notification, will be set below if the stylesheet has set
+ // anything for it
+ m_originalNotificationIcon = {};
+
// QActions created from the .ui file are children of the main window
for (QAction* action : findChildren<QAction*>()) {
// creating a dummy button
@@ -519,7 +523,16 @@ void MainWindow::resetActionIcons()
// the action's icon is used by the menu bar
action->setIcon(icon);
+
+ if (action == ui->actionNotifications) {
+ // if the stylesheet has set a notification icon, remember it here so it
+ // can be used in updateProblemsButton()
+ m_originalNotificationIcon = icon;
+ }
}
+
+ // update the button for the potentially new icon
+ updateProblemsButton();
}
@@ -831,20 +844,52 @@ void MainWindow::scheduleUpdateButton()
void MainWindow::updateProblemsButton()
{
- size_t numProblems = checkForProblems();
+ // if the current stylesheet doesn't provide an icon, this is used instead
+ const char* DefaultIconName = ":/MO/gui/warning";
+
+ const std::size_t numProblems = checkForProblems();
+
+ // starting icon
+ const QIcon original = m_originalNotificationIcon.isNull() ?
+ QIcon(DefaultIconName) : m_originalNotificationIcon;
+
+ // final icon
+ QIcon final;
+
if (numProblems > 0) {
ui->actionNotifications->setToolTip(tr("There are notifications to read"));
- QPixmap mergedIcon = QPixmap(":/MO/gui/warning").scaled(64, 64);
+ // will contain the original icon, plus a notification count; this also
+ // makes sure the pixmap is exactly 64x64 by 1) requesting the icon that's
+ // as close to 64x64 as possible, then scaling it up if it's too small
+ QPixmap merged = original.pixmap(64, 64).scaled(64, 64);
+
{
- QPainter painter(&mergedIcon);
- std::string badgeName = std::string(":/MO/gui/badge_") + (numProblems < 10 ? std::to_string(static_cast<long long>(numProblems)) : "more");
+ QPainter painter(&merged);
+
+ const std::string badgeName =
+ std::string(":/MO/gui/badge_") +
+ (numProblems < 10 ? std::to_string(static_cast<long long>(numProblems)) : "more");
+
painter.drawPixmap(32, 32, 32, 32, QPixmap(badgeName.c_str()));
}
- ui->actionNotifications->setIcon(QIcon(mergedIcon));
+
+ final = QIcon(merged);
} else {
ui->actionNotifications->setToolTip(tr("There are no notifications"));
- ui->actionNotifications->setIcon(QIcon(":/MO/gui/warning"));
+
+ // no change
+ final = original;
+ }
+
+ // setting the icon on the action (shown on the menu)
+ ui->actionNotifications->setIcon(final);
+
+ // setting the icon on the toolbar button
+ if (auto* actionWidget=ui->toolBar->widgetForAction(ui->actionNotifications)) {
+ if (auto* button=dynamic_cast<QAbstractButton*>(actionWidget)) {
+ button->setIcon(final);
+ }
}
}
diff --git a/src/mainwindow.h b/src/mainwindow.h
index 07a580c3..b8d9f49f 100644
--- a/src/mainwindow.h
+++ b/src/mainwindow.h
@@ -398,6 +398,10 @@ private:
MOBase::DelayedFileWriter m_ArchiveListWriter;
+ // icon set by the stylesheet, used to remember its original appearance
+ // when painting the count
+ QIcon m_originalNotificationIcon;
+
enum class ShortcutType {
Toolbar,
Desktop,