feat: now-playing album art scales to full dock width

Stores the raw downloaded pixmap and rescales it (smooth, aspect-ratio
preserved) whenever the dock is resized, so the image always fills
the available width.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
joren
2026-03-24 11:46:43 +01:00
parent 7b0e5dcfa8
commit 9ca17b4406
2 changed files with 27 additions and 8 deletions

View File

@@ -7,8 +7,6 @@
namespace Context
{
static constexpr int ArtSize = 96;
View::View(QobuzBackend *backend, QWidget *parent)
: QDockWidget(tr("Now Playing"), parent)
, m_backend(backend)
@@ -25,12 +23,11 @@ View::View(QobuzBackend *backend, QWidget *parent)
layout->setSpacing(6);
m_albumArt = new QLabel(container);
m_albumArt->setFixedSize(ArtSize, ArtSize);
m_albumArt->setScaledContents(true);
m_albumArt->setAlignment(Qt::AlignCenter);
m_albumArt->setStyleSheet(QStringLiteral(
"background: #1a1a1a; border-radius: 4px;"));
layout->addWidget(m_albumArt, 0, Qt::AlignCenter);
m_albumArt->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
layout->addWidget(m_albumArt);
m_title = new QLabel(tr("Not playing"), container);
m_title->setAlignment(Qt::AlignCenter);
@@ -80,9 +77,23 @@ void View::onArtReady(QNetworkReply *reply)
reply->deleteLater();
if (reply->error() != QNetworkReply::NoError)
return;
QPixmap pix;
if (pix.loadFromData(reply->readAll()))
m_albumArt->setPixmap(pix);
if (m_artPixmap.loadFromData(reply->readAll()))
scaleArtToWidth();
}
void View::resizeEvent(QResizeEvent *event)
{
QDockWidget::resizeEvent(event);
scaleArtToWidth();
}
void View::scaleArtToWidth()
{
if (m_artPixmap.isNull()) return;
// Available width = dock width minus the 8px margins on each side
const int side = qMax(32, widget() ? widget()->width() - 16 : width() - 16);
m_albumArt->setFixedSize(side, side);
m_albumArt->setPixmap(m_artPixmap.scaled(side, side, Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
} // namespace Context