diff --git a/data/data.qrc b/data/data.qrc
index cda15b8b8..b6a0a0fa3 100644
--- a/data/data.qrc
+++ b/data/data.qrc
@@ -79,5 +79,7 @@
list-add.png
document-save.png
schema-7.sql
+ tiny-pause.png
+ tiny-start.png
diff --git a/data/tiny-pause.png b/data/tiny-pause.png
new file mode 100644
index 000000000..4940bc20f
Binary files /dev/null and b/data/tiny-pause.png differ
diff --git a/data/tiny-start.png b/data/tiny-start.png
new file mode 100644
index 000000000..de56e01f8
Binary files /dev/null and b/data/tiny-start.png differ
diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp
index 82c430c93..2791e7d3d 100644
--- a/src/mainwindow.cpp
+++ b/src/mainwindow.cpp
@@ -491,6 +491,7 @@ void MainWindow::MediaStopped() {
track_slider_->SetStopped();
#ifndef Q_OS_DARWIN
tray_icon_->SetProgress(0);
+ tray_icon_->SetStopped();
#endif
}
@@ -503,6 +504,10 @@ void MainWindow::MediaPaused() {
ui_.action_play_pause->setEnabled(true);
track_position_timer_->stop();
+
+#ifndef Q_OS_DARWIN
+ tray_icon_->SetPaused();
+#endif
}
void MainWindow::MediaPlaying() {
@@ -524,6 +529,10 @@ void MainWindow::MediaPlaying() {
track_position_timer_->start();
UpdateTrackPosition();
+
+#ifndef Q_OS_DARWIN
+ tray_icon_->SetPlaying();
+#endif
}
void MainWindow::ScrobblingEnabledChanged(bool value) {
diff --git a/src/systemtrayicon.cpp b/src/systemtrayicon.cpp
index 4481f317e..7df18cb03 100644
--- a/src/systemtrayicon.cpp
+++ b/src/systemtrayicon.cpp
@@ -24,7 +24,10 @@
#include
SystemTrayIcon::SystemTrayIcon(QObject* parent)
- : QSystemTrayIcon(parent)
+ : QSystemTrayIcon(parent),
+ playing_icon_(":/tiny-start.png"),
+ paused_icon_(":/tiny-pause.png"),
+ percentage_(0)
{
}
@@ -39,6 +42,11 @@ bool SystemTrayIcon::event(QEvent* event) {
}
void SystemTrayIcon::SetProgress(int percentage) {
+ percentage_ = percentage;
+ Update();
+}
+
+void SystemTrayIcon::Update() {
if (icon_.isNull()) {
icon_ = icon().pixmap(geometry().size(), QIcon::Normal);
grey_icon_ = icon().pixmap(geometry().size(), QIcon::Disabled);
@@ -51,7 +59,7 @@ void SystemTrayIcon::SetProgress(int percentage) {
// The angle of the line that's used to cover the icon.
// Centered on rect.topRight()
- double angle = double(100 - percentage) / 100.0 * M_PI_2 + M_PI;
+ double angle = double(100 - percentage_) / 100.0 * M_PI_2 + M_PI;
double length = sqrt(pow(rect.width(), 2.0) + pow(rect.height(), 2.0));
QPolygon mask;
@@ -60,7 +68,7 @@ void SystemTrayIcon::SetProgress(int percentage) {
length * sin(angle),
- length * cos(angle));
- if (percentage > 50)
+ if (percentage_ > 50)
mask << rect.bottomLeft();
mask << rect.topLeft();
@@ -68,9 +76,37 @@ void SystemTrayIcon::SetProgress(int percentage) {
QPixmap icon(icon_);
QPainter p(&icon);
+
+ // Draw the grey bit over the orange icon
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()) {
+ int height = rect.height() / 2;
+ QPixmap scaled(current_state_icon_.scaledToHeight(height, Qt::SmoothTransformation));
+
+ QRect state_rect(rect.width() - scaled.width(), 0, scaled.width(), scaled.height());
+ p.drawPixmap(state_rect, scaled);
+ }
+
p.end();
setIcon(icon);
}
+
+void SystemTrayIcon::SetPaused() {
+ current_state_icon_ = paused_icon_;
+ Update();
+}
+
+void SystemTrayIcon::SetPlaying() {
+ current_state_icon_ = playing_icon_;
+ Update();
+}
+
+void SystemTrayIcon::SetStopped() {
+ current_state_icon_ = QPixmap();
+ Update();
+}
diff --git a/src/systemtrayicon.h b/src/systemtrayicon.h
index 91d8d37a9..47c1821e1 100644
--- a/src/systemtrayicon.h
+++ b/src/systemtrayicon.h
@@ -30,13 +30,23 @@ class SystemTrayIcon : public QSystemTrayIcon {
public slots:
void SetProgress(int percentage);
+ void SetPaused();
+ void SetPlaying();
+ void SetStopped();
signals:
void WheelEvent(int delta);
private:
+ void Update();
+
QPixmap icon_;
QPixmap grey_icon_;
+ QPixmap playing_icon_;
+ QPixmap paused_icon_;
+
+ int percentage_;
+ QPixmap current_state_icon_;
};
#endif // SYSTEMTRAYICON_H