| 916 | } |
| 917 | |
| 918 | void MainWindow::updateProblemsButton() |
| 919 | { |
| 920 | // if the current stylesheet doesn't provide an icon, this is used instead |
| 921 | const char* DefaultIconName = ":/MO/gui/warning"; |
| 922 | |
| 923 | const std::size_t numProblems = m_NumberOfProblems; |
| 924 | |
| 925 | // original icon without a count painted on it |
| 926 | const QIcon original = m_originalNotificationIcon.isNull() |
| 927 | ? QIcon(DefaultIconName) |
| 928 | : m_originalNotificationIcon; |
| 929 | |
| 930 | // final icon |
| 931 | QIcon final; |
| 932 | |
| 933 | if (numProblems > 0) { |
| 934 | ui->actionNotifications->setToolTip(tr("There are notifications to read")); |
| 935 | |
| 936 | // will contain the original icon, plus a notification count; this also |
| 937 | // makes sure the pixmap is exactly 64x64 by requesting the icon that's |
| 938 | // as close to 64x64 as possible, and then scaling it up if it's too small |
| 939 | QPixmap merged = original.pixmap(64, 64).scaled(64, 64); |
| 940 | |
| 941 | { |
| 942 | QPainter painter(&merged); |
| 943 | |
| 944 | const std::string badgeName = |
| 945 | std::string(":/MO/gui/badge_") + |
| 946 | (numProblems < 10 ? std::to_string(static_cast<long long>(numProblems)) |
| 947 | : "more"); |
| 948 | |
| 949 | painter.drawPixmap(32, 32, 32, 32, QPixmap(badgeName.c_str())); |
| 950 | } |
| 951 | |
| 952 | final = QIcon(merged); |
| 953 | } else { |
| 954 | ui->actionNotifications->setToolTip(tr("There are no notifications")); |
| 955 | |
| 956 | // no change |
| 957 | final = original; |
| 958 | } |
| 959 | |
| 960 | ui->actionNotifications->setEnabled(numProblems > 0); |
| 961 | |
| 962 | // setting the icon on the action (shown on the menu) |
| 963 | ui->actionNotifications->setIcon(final); |
| 964 | |
| 965 | // setting the icon on the toolbar button |
| 966 | if (auto* actionWidget = ui->toolBar->widgetForAction(ui->actionNotifications)) { |
| 967 | if (auto* button = dynamic_cast<QAbstractButton*>(actionWidget)) { |
| 968 | button->setIcon(final); |
| 969 | } |
| 970 | } |
| 971 | |
| 972 | // updating the status bar, may be null very early when MO is starting |
| 973 | if (ui->statusBar) { |
| 974 | ui->statusBar->setNotifications(numProblems > 0); |
| 975 | } |
nothing calls this directly
no test coverage detected