mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-05-09 14:45:43 -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 "core/system.h"
|
||||||
#include <QtCore/QDate>
|
#include <QtCore/QDate>
|
||||||
#include <QtCore/QDateTime>
|
#include <QtCore/QDateTime>
|
||||||
|
#include <QtGui/QGuiApplication>
|
||||||
#include <QtGui/QIcon>
|
#include <QtGui/QIcon>
|
||||||
#include <QtGui/QPainter>
|
#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)
|
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"));
|
QPixmap pm(QStringLiteral(":/icons/cover-placeholder.png"));
|
||||||
|
pm.setDevicePixelRatio(dpr);
|
||||||
if (pm.isNull())
|
if (pm.isNull())
|
||||||
return QPixmap(width, height);
|
return QPixmap(width, height);
|
||||||
|
|
||||||
@ -61,7 +64,9 @@ static QPixmap createPlaceholderImage(int width, int height, float scale, const
|
|||||||
painter.setFont(font);
|
painter.setFont(font);
|
||||||
painter.setPen(Qt::white);
|
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();
|
painter.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,12 +114,12 @@ void GameListModel::refreshCovers()
|
|||||||
|
|
||||||
int GameListModel::getCoverArtWidth() const
|
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
|
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
|
int GameListModel::getCoverArtSpacing() const
|
||||||
@ -317,8 +322,11 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const
|
|||||||
{
|
{
|
||||||
image = QPixmap(QString::fromStdString(path));
|
image = QPixmap(QString::fromStdString(path));
|
||||||
if (!image.isNull())
|
if (!image.isNull())
|
||||||
|
{
|
||||||
|
image.setDevicePixelRatio(qApp->devicePixelRatio());
|
||||||
resizeAndPadPixmap(&image, getCoverArtWidth(), getCoverArtHeight());
|
resizeAndPadPixmap(&image, getCoverArtWidth(), getCoverArtHeight());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (image.isNull())
|
if (image.isNull())
|
||||||
image = createPlaceholderImage(getCoverArtWidth(), getCoverArtHeight(), m_cover_scale, ge.title);
|
image = createPlaceholderImage(getCoverArtWidth(), getCoverArtHeight(), m_cover_scale, ge.title);
|
||||||
@ -477,8 +485,8 @@ bool GameListModel::lessThan(const QModelIndex& left_index, const QModelIndex& r
|
|||||||
|
|
||||||
case Column_Players:
|
case Column_Players:
|
||||||
{
|
{
|
||||||
u8 left_players = (left.min_players << 4 ) + left.max_players;
|
u8 left_players = (left.min_players << 4) + left.max_players;
|
||||||
u8 right_players = (right.min_players << 4 ) + right.max_players;
|
u8 right_players = (right.min_players << 4) + right.max_players;
|
||||||
if (left_players == right_players)
|
if (left_players == right_players)
|
||||||
return titlesLessThan(left_row, right_row, ascending);
|
return titlesLessThan(left_row, right_row, ascending);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user