mirror of
https://github.com/clementine-player/Clementine
synced 2024-12-14 18:35:16 +01:00
Tray icon gets dimmer when you play more of a track
This commit is contained in:
parent
0d4e1e0bdf
commit
f950701620
4
TODO
4
TODO
@ -5,6 +5,10 @@
|
||||
- Copy to library, move to library
|
||||
- Global shortcut keys
|
||||
- Clicking play plays selected item
|
||||
- Configuration for:
|
||||
- crossfading
|
||||
- osd
|
||||
- If there's only one node in a library item then expand it when expanding the parent
|
||||
|
||||
- Edit tags in playlist view
|
||||
- Disabled fields in tag editor
|
||||
|
@ -281,6 +281,7 @@ void MainWindow::MediaStopped() {
|
||||
|
||||
track_position_timer_->stop();
|
||||
track_slider_->SetStopped();
|
||||
tray_icon_->SetProgress(0);
|
||||
}
|
||||
|
||||
void MainWindow::MediaPaused() {
|
||||
@ -403,8 +404,11 @@ void MainWindow::FilePathChanged(const QString& path) {
|
||||
}
|
||||
|
||||
void MainWindow::UpdateTrackPosition() {
|
||||
int position = std::floor(float(player_->GetEngine()->position()) / 1000.0 + 0.5);
|
||||
// Track position in seconds
|
||||
const int position = std::floor(float(player_->GetEngine()->position()) / 1000.0 + 0.5);
|
||||
const int length = playlist_->current_item()->Metadata().length();
|
||||
|
||||
// Time to scrobble?
|
||||
LastFMService* lastfm = radio_model_->GetLastFMService();
|
||||
|
||||
if (!playlist_->has_scrobbled() &&
|
||||
@ -413,7 +417,13 @@ void MainWindow::UpdateTrackPosition() {
|
||||
playlist_->set_scrobbled(true);
|
||||
}
|
||||
|
||||
track_slider_->SetValue(position, playlist_->current_item()->Metadata().length());
|
||||
// Update the slider
|
||||
track_slider_->SetValue(position, length);
|
||||
|
||||
// Update the tray icon every 10 seconds
|
||||
if (position % 10 == 1) {
|
||||
tray_icon_->SetProgress(double(position) / length * 100);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::Love() {
|
||||
|
@ -2,6 +2,10 @@
|
||||
|
||||
#include <QEvent>
|
||||
#include <QWheelEvent>
|
||||
#include <QPainter>
|
||||
#include <QtDebug>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
SystemTrayIcon::SystemTrayIcon(QObject* parent)
|
||||
: QSystemTrayIcon(parent)
|
||||
@ -15,3 +19,40 @@ bool SystemTrayIcon::event(QEvent* event) {
|
||||
}
|
||||
return QSystemTrayIcon::event(event);
|
||||
}
|
||||
|
||||
void SystemTrayIcon::SetProgress(int percentage) {
|
||||
if (icon_.isNull()) {
|
||||
icon_ = icon().pixmap(geometry().size(), QIcon::Normal);
|
||||
grey_icon_ = icon().pixmap(geometry().size(), QIcon::Disabled);
|
||||
|
||||
if (icon_.isNull())
|
||||
return;
|
||||
}
|
||||
|
||||
QRect rect(icon_.rect());
|
||||
|
||||
// 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 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 (percentage > 50)
|
||||
mask << rect.bottomLeft();
|
||||
|
||||
mask << rect.topLeft();
|
||||
mask << rect.topRight();
|
||||
|
||||
QPixmap icon(icon_);
|
||||
QPainter p(&icon);
|
||||
p.setClipRegion(mask);
|
||||
p.drawPixmap(0, 0, grey_icon_);
|
||||
p.end();
|
||||
|
||||
setIcon(icon);
|
||||
}
|
||||
|
@ -11,8 +11,15 @@ class SystemTrayIcon : public QSystemTrayIcon {
|
||||
|
||||
bool event(QEvent* event);
|
||||
|
||||
public slots:
|
||||
void SetProgress(int percentage);
|
||||
|
||||
signals:
|
||||
void WheelEvent(int delta);
|
||||
|
||||
private:
|
||||
QPixmap icon_;
|
||||
QPixmap grey_icon_;
|
||||
};
|
||||
|
||||
#endif // SYSTEMTRAYICON_H
|
||||
|
Loading…
Reference in New Issue
Block a user