Qt: Scale down custom icon pixmaps

Don't want it going outside of the control bounds.
This commit is contained in:
Stenzek 2024-07-14 13:03:10 +10:00
parent fd0626aa6d
commit 594962d247
No known key found for this signature in database
2 changed files with 23 additions and 2 deletions

View File

@ -260,9 +260,12 @@ const QPixmap& GameListModel::getIconPixmapForEntry(const GameList::Entry* ge) c
const std::string path = GameList::GetGameIconPath(ge->serial, ge->path);
QPixmap pm;
if (!path.empty() && pm.load(QString::fromStdString(path)))
{
fixIconPixmapSize(pm);
return *m_memcard_pixmap_cache.Insert(ge->serial, std::move(pm));
else
return *m_memcard_pixmap_cache.Insert(ge->serial, m_type_pixmaps[static_cast<u32>(ge->type)]);
}
return *m_memcard_pixmap_cache.Insert(ge->serial, m_type_pixmaps[static_cast<u32>(ge->type)]);
}
return m_type_pixmaps[static_cast<u32>(ge->type)];
@ -285,7 +288,10 @@ QIcon GameListModel::getIconForGame(const QString& path)
{
QPixmap newpm;
if (!icon_path.empty() && newpm.load(QString::fromStdString(icon_path)))
{
fixIconPixmapSize(newpm);
ret = QIcon(*m_memcard_pixmap_cache.Insert(entry->serial, std::move(newpm)));
}
}
}
}
@ -293,6 +299,20 @@ QIcon GameListModel::getIconForGame(const QString& path)
return ret;
}
void GameListModel::fixIconPixmapSize(QPixmap& pm)
{
const int width = pm.width();
const int height = pm.height();
const int max_dim = std::max(width, height);
if (max_dim == 16)
return;
const float scale = static_cast<float>(max_dim) / 16.0f;
const int new_width = static_cast<int>(static_cast<float>(width) / scale);
const int new_height = static_cast<int>(static_cast<float>(height) / scale);
pm = pm.scaled(new_width, new_height);
}
int GameListModel::getCoverArtWidth() const
{
return std::max(static_cast<int>(static_cast<float>(COVER_ART_WIDTH) * m_cover_scale), 1);

View File

@ -105,6 +105,7 @@ private:
void invalidateCoverForPath(const std::string& path);
const QPixmap& getIconPixmapForEntry(const GameList::Entry* ge) const;
static void fixIconPixmapSize(QPixmap& pm);
static QString formatTimespan(time_t timespan);