SystemTrayIcon: Simply icon loading

This commit is contained in:
Jonas Kvinge 2023-04-22 15:27:34 +02:00
parent bdf6844b74
commit 3145433099
2 changed files with 19 additions and 17 deletions

View File

@ -38,11 +38,8 @@ SystemTrayIcon::SystemTrayIcon(QObject *parent)
: QSystemTrayIcon(parent), : QSystemTrayIcon(parent),
menu_(new QMenu), menu_(new QMenu),
app_name_(QCoreApplication::applicationName()), app_name_(QCoreApplication::applicationName()),
icon_(IconLoader::Load("strawberry")), pixmap_playing_(":/pictures/tiny-play.png"),
normal_icon_(icon_.pixmap(48, QIcon::Normal)), pixmap_paused_(":/pictures/tiny-pause.png"),
grey_icon_(icon_.pixmap(48, QIcon::Disabled)),
playing_icon_(":/pictures/tiny-play.png"),
paused_icon_(":/pictures/tiny-pause.png"),
action_play_pause_(nullptr), action_play_pause_(nullptr),
action_stop_(nullptr), action_stop_(nullptr),
action_stop_after_this_track_(nullptr), action_stop_after_this_track_(nullptr),
@ -53,14 +50,20 @@ SystemTrayIcon::SystemTrayIcon(QObject *parent)
song_progress_(0) { song_progress_(0) {
app_name_[0] = app_name_[0].toUpper(); app_name_[0] = app_name_[0].toUpper();
QIcon theme_icon_grey = IconLoader::Load("strawberry-grey");
if (!theme_icon_grey.isNull()) { const QIcon icon = IconLoader::Load("strawberry");
grey_icon_ = theme_icon_grey.pixmap(48, QIcon::Disabled); const QIcon icon_grey = IconLoader::Load("strawberry-grey");
pixmap_normal_ = icon.pixmap(48, QIcon::Normal);
if (icon_grey.isNull()) {
pixmap_grey_ = icon.pixmap(48, QIcon::Disabled);
}
else {
pixmap_grey_ = icon_grey.pixmap(48, QIcon::Disabled);
} }
if (isSystemTrayAvailable()) { if (isSystemTrayAvailable()) {
available_ = true; available_ = true;
setIcon(normal_icon_); setIcon(icon);
setToolTip(app_name_); setToolTip(app_name_);
} }
@ -129,13 +132,13 @@ void SystemTrayIcon::ShowPopup(const QString &summary, const QString &message, c
void SystemTrayIcon::UpdateIcon() { void SystemTrayIcon::UpdateIcon() {
if (available_) setIcon(CreateIcon(normal_icon_, grey_icon_)); if (available_) setIcon(CreateIcon(pixmap_normal_, pixmap_grey_));
} }
void SystemTrayIcon::SetPlaying(bool enable_play_pause) { void SystemTrayIcon::SetPlaying(bool enable_play_pause) {
current_state_icon_ = playing_icon_; current_state_icon_ = pixmap_playing_;
UpdateIcon(); UpdateIcon();
action_stop_->setEnabled(true); action_stop_->setEnabled(true);
@ -148,7 +151,7 @@ void SystemTrayIcon::SetPlaying(bool enable_play_pause) {
void SystemTrayIcon::SetPaused() { void SystemTrayIcon::SetPaused() {
current_state_icon_ = paused_icon_; current_state_icon_ = pixmap_paused_;
UpdateIcon(); UpdateIcon();
action_stop_->setEnabled(true); action_stop_->setEnabled(true);

View File

@ -83,11 +83,10 @@ class SystemTrayIcon : public QSystemTrayIcon {
private: private:
QMenu *menu_; QMenu *menu_;
QString app_name_; QString app_name_;
QIcon icon_; QPixmap pixmap_normal_;
QPixmap normal_icon_; QPixmap pixmap_grey_;
QPixmap grey_icon_; QPixmap pixmap_playing_;
QPixmap playing_icon_; QPixmap pixmap_paused_;
QPixmap paused_icon_;
QAction *action_play_pause_; QAction *action_play_pause_;
QAction *action_stop_; QAction *action_stop_;