PlaylistView: Fix scaling mid bar for currently playing track

Fixes #1051
This commit is contained in:
Jonas Kvinge 2022-10-09 21:41:16 +02:00
parent 5c8e49296c
commit 143f72cf6b
2 changed files with 16 additions and 10 deletions

View File

@ -445,26 +445,32 @@ void PlaylistView::RestoreHeaderState() {
void PlaylistView::ReloadBarPixmaps() { void PlaylistView::ReloadBarPixmaps() {
currenttrack_bar_left_ = LoadBarPixmap(":/pictures/currenttrack_bar_left.png"); currenttrack_bar_left_ = LoadBarPixmap(":/pictures/currenttrack_bar_left.png", true);
currenttrack_bar_mid_ = LoadBarPixmap(":/pictures/currenttrack_bar_mid.png"); currenttrack_bar_mid_ = LoadBarPixmap(":/pictures/currenttrack_bar_mid.png", false);
currenttrack_bar_right_ = LoadBarPixmap(":/pictures/currenttrack_bar_right.png"); currenttrack_bar_right_ = LoadBarPixmap(":/pictures/currenttrack_bar_right.png", true);
} }
QList<QPixmap> PlaylistView::LoadBarPixmap(const QString &filename) { QList<QPixmap> PlaylistView::LoadBarPixmap(const QString &filename, const bool keep_aspect_ratio) {
QImage image(filename); QImage image(filename);
image = image.scaledToHeight(row_height_, Qt::SmoothTransformation); QImage image_scaled;
if (keep_aspect_ratio) {
image_scaled = image.scaledToHeight(row_height_, Qt::SmoothTransformation);
}
else {
image_scaled = image.scaled(image.width(), row_height_, Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
}
// Colour the bar with the palette colour // Colour the bar with the palette colour
QPainter p(&image); QPainter p(&image_scaled);
p.setCompositionMode(QPainter::CompositionMode_SourceAtop); p.setCompositionMode(QPainter::CompositionMode_SourceAtop);
p.setOpacity(0.7); p.setOpacity(0.7);
if (playlist_playing_song_color_.isValid()) { if (playlist_playing_song_color_.isValid()) {
p.fillRect(image.rect(), playlist_playing_song_color_); p.fillRect(image_scaled.rect(), playlist_playing_song_color_);
} }
else { else {
p.fillRect(image.rect(), QApplication::palette().color(QPalette::Highlight)); p.fillRect(image_scaled.rect(), QApplication::palette().color(QPalette::Highlight));
} }
p.end(); p.end();
@ -472,7 +478,7 @@ QList<QPixmap> PlaylistView::LoadBarPixmap(const QString &filename) {
QList<QPixmap> ret; QList<QPixmap> ret;
ret.reserve(kGlowIntensitySteps); ret.reserve(kGlowIntensitySteps);
for (int i = 0; i < kGlowIntensitySteps; ++i) { for (int i = 0; i < kGlowIntensitySteps; ++i) {
QImage step(image.copy()); QImage step(image_scaled.copy());
p.begin(&step); p.begin(&step);
p.setCompositionMode(QPainter::CompositionMode_SourceAtop); p.setCompositionMode(QPainter::CompositionMode_SourceAtop);
p.setOpacity(0.4 - 0.6 * sin(static_cast<float>(i) / kGlowIntensitySteps * (M_PI / 2))); p.setOpacity(0.4 - 0.6 * sin(static_cast<float>(i) / kGlowIntensitySteps * (M_PI / 2)));

View File

@ -194,7 +194,7 @@ class PlaylistView : public QTreeView {
void RestoreHeaderState(); void RestoreHeaderState();
void ReloadBarPixmaps(); void ReloadBarPixmaps();
QList<QPixmap> LoadBarPixmap(const QString &filename); QList<QPixmap> LoadBarPixmap(const QString &filename, const bool keep_aspect_ratio);
void LoadTinyPlayPausePixmaps(const int desired_size); void LoadTinyPlayPausePixmaps(const int desired_size);
void UpdateCachedCurrentRowPixmap(QStyleOptionViewItem option, const QModelIndex &idx); void UpdateCachedCurrentRowPixmap(QStyleOptionViewItem option, const QModelIndex &idx);