Favorites in the game list (#2649)

Fixed issue where background change was inconsistent while adding
favorites, unselect row when adding favorites, cleaned code, changed
right click menu options to match the game's favorite status.
This commit is contained in:
David Antunes 2025-06-16 15:01:12 +01:00
parent 6b5f472bf0
commit a8d0b0b210
4 changed files with 20 additions and 39 deletions

View File

@ -54,10 +54,6 @@ GameListFrame::GameListFrame(std::shared_ptr<gui_settings> gui_settings,
this->horizontalHeader()->setSectionResizeMode(10, QHeaderView::Fixed);
PopulateGameList();
connect(this, &QTableWidget::cellClicked, this, [=, this](int row, int column) {
ToggleFavorite(row, column);
PopulateGameList(false);
});
connect(this, &QTableWidget::currentCellChanged, this, &GameListFrame::onCurrentCellChanged);
connect(this->verticalScrollBar(), &QScrollBar::valueChanged, this,
&GameListFrame::RefreshListBackgroundImage);
@ -94,6 +90,12 @@ GameListFrame::GameListFrame(std::shared_ptr<gui_settings> gui_settings,
auto url_issues = "https://github.com/shadps4-emu/shadps4-game-compatibility/issues/";
QDesktopServices::openUrl(
QUrl(url_issues + m_game_info->m_games[row].compatibility.issue_number));
} else if (column == 10) {
QString serialStr = QString::fromStdString(m_game_info->m_games[row].serial);
bool isFavorite = m_gui_settings->GetValue(gui::favorites, serialStr, false).toBool();
m_gui_settings->SetValue(gui::favorites, serialStr, !isFavorite, true);
this->setCurrentCell(-1, -1);
PopulateGameList(false);
}
});
}
@ -455,27 +457,6 @@ void GameListFrame::SetFavoriteIcon(int row, int column) {
}
}
void GameListFrame::ToggleFavorite(int row, int column) {
if (column != 10) {
return;
}
QWidget* cellWidget = this->cellWidget(row, column);
if (!cellWidget) {
return;
}
QLabel* label = cellWidget->findChild<QLabel*>("favoriteIcon");
if (!label) {
return;
}
QString serialStr = QString::fromStdString(m_game_info->m_games[row].serial);
bool isFavorite = m_gui_settings->GetValue(gui::favorites, serialStr, false).toBool();
m_gui_settings->SetValue(gui::favorites, serialStr, !isFavorite, true);
label->setVisible(!isFavorite);
}
QString GameListFrame::GetPlayTime(const std::string& serial) {
QString playTime;
const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);

View File

@ -38,7 +38,6 @@ public Q_SLOTS:
void PlayBackgroundMusic(QTableWidgetItem* item);
void onCurrentCellChanged(int currentRow, int currentColumn, int previousRow,
int previousColumn);
void ToggleFavorite(int row, int column);
private:
void SetTableItem(int row, int column, QString itemStr);

View File

@ -66,13 +66,22 @@ public:
menu.addMenu(openFolderMenu);
QAction addToFavorites(tr("Add/Remove Favorite"), widget);
QString serialStr = QString::fromStdString(m_games[itemID].serial);
bool isFavorite = m_gui_settings->GetValue(gui::favorites, serialStr, false).toBool();
QAction* toggleFavorite;
if (isFavorite) {
toggleFavorite = new QAction(tr("Remove from Favorites"), widget);
} else {
toggleFavorite = new QAction(tr("Add to Favorites"), widget);
}
QAction createShortcut(tr("Create Shortcut"), widget);
QAction openCheats(tr("Cheats / Patches"), widget);
QAction openSfoViewer(tr("SFO Viewer"), widget);
QAction openTrophyViewer(tr("Trophy Viewer"), widget);
menu.addAction(&addToFavorites);
menu.addAction(toggleFavorite);
menu.addAction(&createShortcut);
menu.addAction(&openCheats);
menu.addAction(&openSfoViewer);
@ -306,10 +315,9 @@ public:
}
}
if (selected == &addToFavorites) {
QString serialStr = QString::fromStdString(m_games[itemID].serial);
bool isFavorite = m_gui_settings->GetValue(gui::favorites, serialStr, false).toBool();
if (selected == toggleFavorite) {
m_gui_settings->SetValue(gui::favorites, serialStr, !isFavorite, true);
widget->setCurrentCell(-1, -1);
}
if (selected == &openCheats) {

View File

@ -841,13 +841,6 @@ void MainWindow::CreateConnects() {
}
void MainWindow::StartGame() {
// Ignore favorite column
if (m_game_list_frame->currentItem()->column() == 10) {
m_game_list_frame->ToggleFavorite(m_game_list_frame->currentItem()->row(),
m_game_list_frame->currentItem()->column());
return;
}
BackgroundMusicPlayer::getInstance().stopMusic();
QString gamePath = "";
int table_mode = m_gui_settings->GetValue(gui::gl_mode).toInt();