Re-enable progress on system tray icon (#578)
* Re-enable progress on system tray icon * fix copy-paste typo in mac sources * Make tray icon progress optional * Move tray icon progress setting control to MainWindow * Move trayicon settings to behavioursettings Co-authored-by: Yavuz Mert <yavuz.mert@darkbluesystems.net>
This commit is contained in:
@@ -58,6 +58,7 @@ protected:
|
||||
|
||||
private:
|
||||
QPixmap normal_icon_;
|
||||
QPixmap grey_icon_;
|
||||
std::unique_ptr<MacSystemTrayIconPrivate> p_;
|
||||
Q_DISABLE_COPY(MacSystemTrayIcon);
|
||||
};
|
||||
|
||||
@@ -165,7 +165,8 @@ class MacSystemTrayIconPrivate {
|
||||
|
||||
MacSystemTrayIcon::MacSystemTrayIcon(QObject* parent)
|
||||
: SystemTrayIcon(parent),
|
||||
normal_icon_(QPixmap(":/pictures/strawberry.png").scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)) {
|
||||
normal_icon_(QPixmap(":/pictures/strawberry.png").scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)),
|
||||
grey_icon_(QPixmap(":/pictures/strawberry-grey.png").scaled(128, 128, Qt::KeepAspectRatio, Qt::SmoothTransformation)) {
|
||||
QApplication::setWindowIcon(normal_icon_);
|
||||
}
|
||||
|
||||
|
||||
@@ -1023,6 +1023,7 @@ void MainWindow::ReloadSettings() {
|
||||
s.beginGroup(BehaviourSettingsPage::kSettingsGroup);
|
||||
keep_running_ = s.value("keeprunning", false).toBool();
|
||||
playing_widget_ = s.value("playing_widget", true).toBool();
|
||||
bool trayicon_progress = s.value("trayicon_progress", false).toBool();
|
||||
if (playing_widget_ != ui_->widget_playing->IsEnabled()) TabSwitched();
|
||||
doubleclick_addmode_ = BehaviourSettingsPage::AddBehaviour(s.value("doubleclick_addmode", BehaviourSettingsPage::AddBehaviour_Append).toInt());
|
||||
doubleclick_playmode_ = BehaviourSettingsPage::PlayBehaviour(s.value("doubleclick_playmode", BehaviourSettingsPage::PlayBehaviour_Never).toInt());
|
||||
@@ -1034,6 +1035,8 @@ void MainWindow::ReloadSettings() {
|
||||
int iconsize = s.value(AppearanceSettingsPage::kIconSizePlayControlButtons, 32).toInt();
|
||||
s.endGroup();
|
||||
|
||||
if (tray_icon_) tray_icon_->SetTrayiconProgress(trayicon_progress);
|
||||
|
||||
ui_->back_button->setIconSize(QSize(iconsize, iconsize));
|
||||
ui_->pause_play_button->setIconSize(QSize(iconsize, iconsize));
|
||||
ui_->stop_button->setIconSize(QSize(iconsize, iconsize));
|
||||
@@ -2960,7 +2963,7 @@ void MainWindow::SetToggleScrobblingIcon(const bool value) {
|
||||
if (value) {
|
||||
if (app_->playlist_manager()->active() && app_->playlist_manager()->active()->scrobbled())
|
||||
ui_->action_toggle_scrobbling->setIcon(IconLoader::Load("scrobble", 22));
|
||||
else
|
||||
else
|
||||
ui_->action_toggle_scrobbling->setIcon(IconLoader::Load("scrobble", 22)); // TODO: Create a faint version of the icon
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -54,7 +54,10 @@ QtSystemTrayIcon::QtSystemTrayIcon(QObject *parent)
|
||||
action_mute_(nullptr) {
|
||||
|
||||
app_name_[0] = app_name_[0].toUpper();
|
||||
|
||||
QIcon theme_icon_grey = IconLoader::Load("strawberry-grey");
|
||||
if (! theme_icon_grey.isNull()) {
|
||||
grey_icon_ = theme_icon_grey.pixmap(48, QIcon::Disabled);
|
||||
}
|
||||
tray_->setIcon(normal_icon_);
|
||||
tray_->installEventFilter(this);
|
||||
ClearNowPlaying();
|
||||
|
||||
@@ -47,31 +47,31 @@ SystemTrayIcon::SystemTrayIcon(QObject *parent)
|
||||
|
||||
QPixmap SystemTrayIcon::CreateIcon(const QPixmap &icon, const QPixmap &grey_icon) {
|
||||
|
||||
Q_UNUSED(grey_icon);
|
||||
|
||||
QRect rect(icon.rect());
|
||||
|
||||
// The angle of the line that's used to cover the icon.
|
||||
// Centered on rect.topRight()
|
||||
double angle = double(100 - song_progress()) / 100.0 * M_PI_2 + M_PI;
|
||||
double length = sqrt(pow(rect.width(), 2.0) + pow(rect.height(), 2.0));
|
||||
|
||||
QPolygon mask;
|
||||
mask << rect.topRight();
|
||||
mask << rect.topRight() + QPoint(length * sin(angle), -length * cos(angle));
|
||||
|
||||
if (song_progress() > 50) mask << rect.bottomLeft();
|
||||
|
||||
mask << rect.topLeft();
|
||||
mask << rect.topRight();
|
||||
|
||||
QPixmap ret(icon);
|
||||
QPainter p(&ret);
|
||||
|
||||
// Draw the grey bit
|
||||
//p.setClipRegion(mask);
|
||||
//p.drawPixmap(0, 0, grey_icon);
|
||||
//p.setClipping(false);
|
||||
if (trayicon_progress_) {
|
||||
// The angle of the line that's used to cover the icon.
|
||||
// Centered on rect.topLeft()
|
||||
double angle = double(100 - song_progress()) / 100.0 * M_PI_2;
|
||||
double length = sqrt(pow(rect.width(), 2.0) + pow(rect.height(), 2.0));
|
||||
|
||||
QPolygon mask;
|
||||
mask << rect.topLeft();
|
||||
mask << rect.topLeft() + QPoint(length * sin(angle), length * cos(angle));
|
||||
|
||||
if (song_progress() > 50) mask << rect.bottomRight();
|
||||
|
||||
mask << rect.topRight();
|
||||
mask << rect.topLeft();
|
||||
|
||||
// Draw the grey bit
|
||||
p.setClipRegion(mask);
|
||||
p.drawPixmap(0, 0, grey_icon);
|
||||
p.setClipping(false);
|
||||
}
|
||||
|
||||
// Draw the playing or paused icon in the top-right
|
||||
if (!current_state_icon().isNull()) {
|
||||
|
||||
@@ -57,6 +57,7 @@ class SystemTrayIcon : public QObject {
|
||||
|
||||
public slots:
|
||||
void SetProgress(int percentage);
|
||||
void SetTrayiconProgress(bool enabled) { trayicon_progress_ = enabled; }
|
||||
virtual void SetPaused();
|
||||
virtual void SetPlaying(bool enable_play_pause = false);
|
||||
virtual void SetStopped();
|
||||
@@ -85,6 +86,7 @@ class SystemTrayIcon : public QObject {
|
||||
QPixmap playing_icon_;
|
||||
QPixmap paused_icon_;
|
||||
QPixmap current_state_icon_;
|
||||
bool trayicon_progress_;
|
||||
};
|
||||
|
||||
#endif // SYSTEMTRAYICON_H
|
||||
|
||||
Reference in New Issue
Block a user