mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-05-09 07:55:41 -04:00
Qt/GameList: Use device pixel ratio for cover pixmaps
This commit is contained in:
parent
2bde6d8e10
commit
5f2a340953
@ -4,6 +4,7 @@
|
||||
#include "core/system.h"
|
||||
#include <QtCore/QDate>
|
||||
#include <QtCore/QDateTime>
|
||||
#include <QtGui/QGuiApplication>
|
||||
#include <QtGui/QIcon>
|
||||
#include <QtGui/QPainter>
|
||||
|
||||
@ -48,7 +49,9 @@ static void resizeAndPadPixmap(QPixmap* pm, int expected_width, int expected_hei
|
||||
|
||||
static QPixmap createPlaceholderImage(int width, int height, float scale, const std::string& title)
|
||||
{
|
||||
const float dpr = qApp->devicePixelRatio();
|
||||
QPixmap pm(QStringLiteral(":/icons/cover-placeholder.png"));
|
||||
pm.setDevicePixelRatio(dpr);
|
||||
if (pm.isNull())
|
||||
return QPixmap(width, height);
|
||||
|
||||
@ -61,7 +64,9 @@ static QPixmap createPlaceholderImage(int width, int height, float scale, const
|
||||
painter.setFont(font);
|
||||
painter.setPen(Qt::white);
|
||||
|
||||
painter.drawText(QRect(0, 0, width, height), Qt::AlignCenter | Qt::TextWordWrap, QString::fromStdString(title));
|
||||
const QRect text_rc(0, 0, static_cast<int>(static_cast<float>(width) / dpr),
|
||||
static_cast<int>(static_cast<float>(height) / dpr));
|
||||
painter.drawText(text_rc, Qt::AlignCenter | Qt::TextWordWrap, QString::fromStdString(title));
|
||||
painter.end();
|
||||
}
|
||||
|
||||
@ -109,12 +114,12 @@ void GameListModel::refreshCovers()
|
||||
|
||||
int GameListModel::getCoverArtWidth() const
|
||||
{
|
||||
return std::max(static_cast<int>(static_cast<float>(COVER_ART_WIDTH) * m_cover_scale), 1);
|
||||
return std::max(static_cast<int>(static_cast<float>(COVER_ART_WIDTH) * m_cover_scale * qApp->devicePixelRatio()), 1);
|
||||
}
|
||||
|
||||
int GameListModel::getCoverArtHeight() const
|
||||
{
|
||||
return std::max(static_cast<int>(static_cast<float>(COVER_ART_HEIGHT) * m_cover_scale), 1);
|
||||
return std::max(static_cast<int>(static_cast<float>(COVER_ART_HEIGHT) * m_cover_scale * qApp->devicePixelRatio()), 1);
|
||||
}
|
||||
|
||||
int GameListModel::getCoverArtSpacing() const
|
||||
@ -317,8 +322,11 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
image = QPixmap(QString::fromStdString(path));
|
||||
if (!image.isNull())
|
||||
{
|
||||
image.setDevicePixelRatio(qApp->devicePixelRatio());
|
||||
resizeAndPadPixmap(&image, getCoverArtWidth(), getCoverArtHeight());
|
||||
}
|
||||
}
|
||||
|
||||
if (image.isNull())
|
||||
image = createPlaceholderImage(getCoverArtWidth(), getCoverArtHeight(), m_cover_scale, ge.title);
|
||||
|
Loading…
x
Reference in New Issue
Block a user