mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-19 04:52:30 +01:00
Show a tiny play or pause icon in the system tray
This commit is contained in:
parent
1dc8cca6e1
commit
b418141aa0
@ -79,5 +79,7 @@
|
|||||||
<file>list-add.png</file>
|
<file>list-add.png</file>
|
||||||
<file>document-save.png</file>
|
<file>document-save.png</file>
|
||||||
<file>schema-7.sql</file>
|
<file>schema-7.sql</file>
|
||||||
|
<file>tiny-pause.png</file>
|
||||||
|
<file>tiny-start.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
BIN
data/tiny-pause.png
Normal file
BIN
data/tiny-pause.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 367 B |
BIN
data/tiny-start.png
Normal file
BIN
data/tiny-start.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 429 B |
@ -491,6 +491,7 @@ void MainWindow::MediaStopped() {
|
|||||||
track_slider_->SetStopped();
|
track_slider_->SetStopped();
|
||||||
#ifndef Q_OS_DARWIN
|
#ifndef Q_OS_DARWIN
|
||||||
tray_icon_->SetProgress(0);
|
tray_icon_->SetProgress(0);
|
||||||
|
tray_icon_->SetStopped();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -503,6 +504,10 @@ void MainWindow::MediaPaused() {
|
|||||||
ui_.action_play_pause->setEnabled(true);
|
ui_.action_play_pause->setEnabled(true);
|
||||||
|
|
||||||
track_position_timer_->stop();
|
track_position_timer_->stop();
|
||||||
|
|
||||||
|
#ifndef Q_OS_DARWIN
|
||||||
|
tray_icon_->SetPaused();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::MediaPlaying() {
|
void MainWindow::MediaPlaying() {
|
||||||
@ -524,6 +529,10 @@ void MainWindow::MediaPlaying() {
|
|||||||
|
|
||||||
track_position_timer_->start();
|
track_position_timer_->start();
|
||||||
UpdateTrackPosition();
|
UpdateTrackPosition();
|
||||||
|
|
||||||
|
#ifndef Q_OS_DARWIN
|
||||||
|
tray_icon_->SetPlaying();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::ScrobblingEnabledChanged(bool value) {
|
void MainWindow::ScrobblingEnabledChanged(bool value) {
|
||||||
|
@ -24,7 +24,10 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
SystemTrayIcon::SystemTrayIcon(QObject* parent)
|
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) {
|
void SystemTrayIcon::SetProgress(int percentage) {
|
||||||
|
percentage_ = percentage;
|
||||||
|
Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SystemTrayIcon::Update() {
|
||||||
if (icon_.isNull()) {
|
if (icon_.isNull()) {
|
||||||
icon_ = icon().pixmap(geometry().size(), QIcon::Normal);
|
icon_ = icon().pixmap(geometry().size(), QIcon::Normal);
|
||||||
grey_icon_ = icon().pixmap(geometry().size(), QIcon::Disabled);
|
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.
|
// The angle of the line that's used to cover the icon.
|
||||||
// Centered on rect.topRight()
|
// 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));
|
double length = sqrt(pow(rect.width(), 2.0) + pow(rect.height(), 2.0));
|
||||||
|
|
||||||
QPolygon mask;
|
QPolygon mask;
|
||||||
@ -60,7 +68,7 @@ void SystemTrayIcon::SetProgress(int percentage) {
|
|||||||
length * sin(angle),
|
length * sin(angle),
|
||||||
- length * cos(angle));
|
- length * cos(angle));
|
||||||
|
|
||||||
if (percentage > 50)
|
if (percentage_ > 50)
|
||||||
mask << rect.bottomLeft();
|
mask << rect.bottomLeft();
|
||||||
|
|
||||||
mask << rect.topLeft();
|
mask << rect.topLeft();
|
||||||
@ -68,9 +76,37 @@ void SystemTrayIcon::SetProgress(int percentage) {
|
|||||||
|
|
||||||
QPixmap icon(icon_);
|
QPixmap icon(icon_);
|
||||||
QPainter p(&icon);
|
QPainter p(&icon);
|
||||||
|
|
||||||
|
// Draw the grey bit over the orange icon
|
||||||
p.setClipRegion(mask);
|
p.setClipRegion(mask);
|
||||||
p.drawPixmap(0, 0, grey_icon_);
|
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();
|
p.end();
|
||||||
|
|
||||||
setIcon(icon);
|
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();
|
||||||
|
}
|
||||||
|
@ -30,13 +30,23 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
|||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void SetProgress(int percentage);
|
void SetProgress(int percentage);
|
||||||
|
void SetPaused();
|
||||||
|
void SetPlaying();
|
||||||
|
void SetStopped();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void WheelEvent(int delta);
|
void WheelEvent(int delta);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void Update();
|
||||||
|
|
||||||
QPixmap icon_;
|
QPixmap icon_;
|
||||||
QPixmap grey_icon_;
|
QPixmap grey_icon_;
|
||||||
|
QPixmap playing_icon_;
|
||||||
|
QPixmap paused_icon_;
|
||||||
|
|
||||||
|
int percentage_;
|
||||||
|
QPixmap current_state_icon_;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SYSTEMTRAYICON_H
|
#endif // SYSTEMTRAYICON_H
|
||||||
|
Loading…
Reference in New Issue
Block a user