diff --git a/src/duckstation-qt/gamelistmodel.cpp b/src/duckstation-qt/gamelistmodel.cpp index 3a369775d..403dc5aa3 100644 --- a/src/duckstation-qt/gamelistmodel.cpp +++ b/src/duckstation-qt/gamelistmodel.cpp @@ -249,7 +249,7 @@ QString GameListModel::formatTimespan(time_t timespan) return qApp->translate("GameList", "%n minutes", "", minutes); } -const QPixmap& GameListModel::getIconForEntry(const GameList::Entry* ge) const +const QPixmap& GameListModel::getPixmapForEntry(const GameList::Entry* ge) const { // We only do this for discs/disc sets for now. if (m_show_game_icons && (!ge->serial.empty() && (ge->IsDisc() || ge->IsDiscSet()))) @@ -274,6 +274,30 @@ const QPixmap& GameListModel::getIconForEntry(const GameList::Entry* ge) const return m_type_pixmaps[static_cast(ge->type)]; } +QIcon GameListModel::getIconForGame(const QString& path) +{ + QIcon ret; + + if (m_show_game_icons) + { + const auto lock = GameList::GetLock(); + const GameList::Entry* entry = GameList::GetEntryForPath(path.toStdString()); + + // See above. + if (entry && !entry->serial.empty() && (entry->IsDisc() || entry->IsDiscSet())) + { + const MemoryCardImage::IconFrame* icon = m_memcard_icon_cache.Lookup(entry->serial, entry->path); + if (icon) + { + ret = QIcon(QPixmap::fromImage(QImage(reinterpret_cast(icon->pixels), MemoryCardImage::ICON_WIDTH, + MemoryCardImage::ICON_HEIGHT, QImage::Format_RGBA8888))); + } + } + } + + return ret; +} + int GameListModel::getCoverArtWidth() const { return std::max(static_cast(static_cast(COVER_ART_WIDTH) * m_cover_scale), 1); @@ -457,7 +481,7 @@ QVariant GameListModel::data(const QModelIndex& index, int role) const { case Column_Type: { - return getIconForEntry(ge); + return getPixmapForEntry(ge); } case Column_Region: diff --git a/src/duckstation-qt/gamelistmodel.h b/src/duckstation-qt/gamelistmodel.h index 60e9b6b9a..b550596f7 100644 --- a/src/duckstation-qt/gamelistmodel.h +++ b/src/duckstation-qt/gamelistmodel.h @@ -69,6 +69,7 @@ public: bool getShowGameIcons() const { return m_show_game_icons; } void setShowGameIcons(bool enabled); + QIcon getIconForGame(const QString& path); float getCoverScale() const { return m_cover_scale; } void setCoverScale(float scale); @@ -88,7 +89,7 @@ private: void loadOrGenerateCover(const GameList::Entry* ge); void invalidateCoverForPath(const std::string& path); - const QPixmap& getIconForEntry(const GameList::Entry* ge) const; + const QPixmap& getPixmapForEntry(const GameList::Entry* ge) const; static QString formatTimespan(time_t timespan); diff --git a/src/duckstation-qt/mainwindow.cpp b/src/duckstation-qt/mainwindow.cpp index f71aa9117..2056d3555 100644 --- a/src/duckstation-qt/mainwindow.cpp +++ b/src/duckstation-qt/mainwindow.cpp @@ -9,6 +9,7 @@ #include "coverdownloaddialog.h" #include "debuggerwindow.h" #include "displaywidget.h" +#include "gamelistmodel.h" #include "gamelistsettingswidget.h" #include "gamelistwidget.h" #include "interfacesettingswidget.h" @@ -90,6 +91,7 @@ static bool s_system_paused = false; static QString s_current_game_title; static QString s_current_game_serial; static QString s_current_game_path; +static QIcon s_current_game_icon; bool QtHost::IsSystemPaused() { @@ -615,6 +617,7 @@ void MainWindow::onRunningGameChanged(const QString& filename, const QString& ga s_current_game_path = filename; s_current_game_title = game_title; s_current_game_serial = game_serial; + s_current_game_icon = m_game_list_widget->getModel()->getIconForGame(filename); updateWindowTitle(); } @@ -1883,6 +1886,7 @@ void MainWindow::updateWindowTitle() if (windowTitle() != main_title) setWindowTitle(main_title); + setWindowIcon(s_current_game_icon.isNull() ? QtHost::GetAppIcon() : s_current_game_icon); if (m_display_widget && !isRenderingToMain()) { @@ -1890,6 +1894,7 @@ void MainWindow::updateWindowTitle() m_display_container ? static_cast(m_display_container) : static_cast(m_display_widget); if (container->windowTitle() != display_title) container->setWindowTitle(display_title); + container->setWindowIcon(s_current_game_icon.isNull() ? QtHost::GetAppIcon() : s_current_game_icon); } if (g_log_window)