Commit c31920fa authored by Michael Pyne's avatar Michael Pyne

hidpi: Mark cover art as being at native display resolution.

This lets Hi-DPI displays to show cover art (when clicking the cover in
the "Now Playing" bar) at its native resolution even when using screen
scaling.

This is probably suboptimal for smaller covers but most embedded cover
art I find in the recent few years is already more than large enough to
show up fine this way.

CHANGELOG: Show embedded music cover art at native display resolution.
parent 0ad0ee58
......@@ -54,18 +54,27 @@
struct CoverPopup : public QWidget
{
CoverPopup(const QPixmap &image, const QPoint &p) :
CoverPopup(QPixmap &image, const QPoint &p) :
QWidget(0, Qt::WindowFlags(Qt::WA_DeleteOnClose | Qt::X11BypassWindowManagerHint))
{
QHBoxLayout *layout = new QHBoxLayout(this);
QLabel *label = new QLabel(this);
layout->addWidget(label);
const auto pixRatio = this->devicePixelRatioF();
QSizeF imageSize(label->width(), label->height());
if (!qFuzzyCompare(pixRatio, 1.0)) {
imageSize /= pixRatio;
image.setDevicePixelRatio(pixRatio);
}
label->setFrameStyle(QFrame::Box | QFrame::Raised);
label->setLineWidth(1);
label->setPixmap(image);
setGeometry(p.x(), p.y(), label->width(), label->height());
setGeometry(QRect(p, imageSize.toSize()));
show();
}
virtual void leaveEvent(QEvent *) { close(); }
......
......@@ -49,11 +49,6 @@
#include "collectionlist.h"
#include "juk_debug.h"
// Anon namespace to hide symbol from outside this translation unit
namespace {
static int g_imageSize = 64;
};
////////////////////////////////////////////////////////////////////////////////
// NowPlaying
////////////////////////////////////////////////////////////////////////////////
......@@ -78,8 +73,8 @@ NowPlaying::NowPlaying(QWidget *parent, PlaylistCollection *collection) :
const QFont defaultLargeFont(QFontDatabase::systemFont(QFontDatabase::TitleFont));
const QFontMetrics fm(defaultLargeFont, this);
g_imageSize = qMax(g_imageSize, fm.lineSpacing());
setFixedHeight(g_imageSize + 2);
const int coverIconHeight = qMax(64, fm.lineSpacing());
setFixedHeight(coverIconHeight + 2);
layout->addWidget(new CoverItem(this), 0);
layout->addWidget(new TrackItem(this), 2);
......@@ -138,9 +133,19 @@ void CoverItem::update(const FileHandle &file)
if(!file.isNull() && file.coverInfo()->hasCover()) {
show();
setPixmap(
file.coverInfo()->pixmap(CoverInfo::Thumbnail)
.scaled(g_imageSize, g_imageSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
const auto pixRatio = this->devicePixelRatioF();
const QSizeF logicalSize = QSizeF(this->height(), this->height());
const QSizeF scaledSize = logicalSize * pixRatio;
QPixmap pix =
file.coverInfo()->pixmap(CoverInfo::FullSize)
.scaled(scaledSize.toSize(), Qt::KeepAspectRatio, Qt::SmoothTransformation);
if (!qFuzzyCompare(pixRatio, 1.0)) {
pix.setDevicePixelRatio(pixRatio);
}
setPixmap(pix);
}
else
hide();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment