Qt: Scale down custom icon pixmaps
Don't want it going outside of the control bounds.
This commit is contained in:
parent
fd0626aa6d
commit
594962d247
|
@ -260,9 +260,12 @@ const QPixmap& GameListModel::getIconPixmapForEntry(const GameList::Entry* ge) c
|
||||||
const std::string path = GameList::GetGameIconPath(ge->serial, ge->path);
|
const std::string path = GameList::GetGameIconPath(ge->serial, ge->path);
|
||||||
QPixmap pm;
|
QPixmap pm;
|
||||||
if (!path.empty() && pm.load(QString::fromStdString(path)))
|
if (!path.empty() && pm.load(QString::fromStdString(path)))
|
||||||
|
{
|
||||||
|
fixIconPixmapSize(pm);
|
||||||
return *m_memcard_pixmap_cache.Insert(ge->serial, std::move(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)];
|
return m_type_pixmaps[static_cast<u32>(ge->type)];
|
||||||
|
@ -285,7 +288,10 @@ QIcon GameListModel::getIconForGame(const QString& path)
|
||||||
{
|
{
|
||||||
QPixmap newpm;
|
QPixmap newpm;
|
||||||
if (!icon_path.empty() && newpm.load(QString::fromStdString(icon_path)))
|
if (!icon_path.empty() && newpm.load(QString::fromStdString(icon_path)))
|
||||||
|
{
|
||||||
|
fixIconPixmapSize(newpm);
|
||||||
ret = QIcon(*m_memcard_pixmap_cache.Insert(entry->serial, std::move(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;
|
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
|
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), 1);
|
||||||
|
|
|
@ -105,6 +105,7 @@ private:
|
||||||
void invalidateCoverForPath(const std::string& path);
|
void invalidateCoverForPath(const std::string& path);
|
||||||
|
|
||||||
const QPixmap& getIconPixmapForEntry(const GameList::Entry* ge) const;
|
const QPixmap& getIconPixmapForEntry(const GameList::Entry* ge) const;
|
||||||
|
static void fixIconPixmapSize(QPixmap& pm);
|
||||||
|
|
||||||
static QString formatTimespan(time_t timespan);
|
static QString formatTimespan(time_t timespan);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue