Qt: Fix CurrentSelectionIconPath for game grid

Fixes deselection issue when booting a game in the game grid
This commit is contained in:
Megamouse 2020-03-07 02:01:28 +01:00
parent 0c45457101
commit 7dd36ff829
2 changed files with 25 additions and 12 deletions

View file

@ -789,8 +789,7 @@ void game_list_frame::Refresh(const bool fromDrive, const bool scrollAfter)
if (m_isListLayout) if (m_isListLayout)
{ {
const int scroll_position = m_gameList->verticalScrollBar()->value(); const int scroll_position = m_gameList->verticalScrollBar()->value();
const int row = PopulateGameList(); PopulateGameList();
m_gameList->selectRow(row);
SortGameList(); SortGameList();
if (scrollAfter) if (scrollAfter)
@ -1950,9 +1949,9 @@ bool game_list_frame::eventFilter(QObject *object, QEvent *event)
/** /**
Cleans and readds entries to table widget in UI. Cleans and readds entries to table widget in UI.
*/ */
int game_list_frame::PopulateGameList() void game_list_frame::PopulateGameList()
{ {
int result = -1; int selected_row = -1;
std::string selected_item = CurrentSelectionIconPath(); std::string selected_item = CurrentSelectionIconPath();
@ -2073,15 +2072,14 @@ int game_list_frame::PopulateGameList()
if (selected_item == game->info.icon_path) if (selected_item == game->info.icon_path)
{ {
result = row; selected_row = row;
} }
row++; row++;
} }
m_gameList->setRowCount(row); m_gameList->setRowCount(row);
m_gameList->selectRow(selected_row);
return result;
} }
void game_list_frame::PopulateGameGrid(int maxCols, const QSize& image_size, const QColor& image_color) void game_list_frame::PopulateGameGrid(int maxCols, const QSize& image_size, const QColor& image_color)
@ -2150,7 +2148,7 @@ void game_list_frame::PopulateGameGrid(int maxCols, const QSize& image_size, con
if (selected_item == app->info.icon_path) if (selected_item == app->info.icon_path)
{ {
m_xgrid->setCurrentItem(m_xgrid->item(r, c)); m_xgrid->setCurrentCell(r, c);
} }
if (++c >= maxCols) if (++c >= maxCols)
@ -2193,9 +2191,25 @@ std::string game_list_frame::CurrentSelectionIconPath()
{ {
std::string selection; std::string selection;
if (m_gameList->selectedItems().count()) QTableWidgetItem* item = nullptr;
if (m_oldLayoutIsList)
{
if (!m_gameList->selectedItems().isEmpty())
{
item = m_gameList->item(m_gameList->currentRow(), 0);
}
}
else
{
if (!m_xgrid->selectedItems().isEmpty())
{
item = m_xgrid->currentItem();
}
}
if (item)
{ {
QTableWidgetItem* item = m_oldLayoutIsList ? m_gameList->item(m_gameList->currentRow(), 0) : m_xgrid->currentItem();
QVariant var = item->data(gui::game_role); QVariant var = item->data(gui::game_role);
if (var.canConvert<game_info>()) if (var.canConvert<game_info>())

View file

@ -97,11 +97,10 @@ private:
QPixmap PaintedPixmap(const QPixmap& icon, bool paint_config_icon = false, bool paint_pad_config_icon = false, const QColor& color = QColor()); QPixmap PaintedPixmap(const QPixmap& icon, bool paint_config_icon = false, bool paint_pad_config_icon = false, const QColor& color = QColor());
QColor getGridCompatibilityColor(const QString& string); QColor getGridCompatibilityColor(const QString& string);
void ShowCustomConfigIcon(game_info game); void ShowCustomConfigIcon(game_info game);
void PopulateGameList();
void PopulateGameGrid(int maxCols, const QSize& image_size, const QColor& image_color); void PopulateGameGrid(int maxCols, const QSize& image_size, const QColor& image_color);
bool IsEntryVisible(const game_info& game); bool IsEntryVisible(const game_info& game);
void SortGameList(); void SortGameList();
int PopulateGameList();
bool SearchMatchesApp(const QString& name, const QString& serial) const; bool SearchMatchesApp(const QString& name, const QString& serial) const;
bool RemoveCustomConfiguration(const std::string& title_id, game_info game = nullptr, bool is_interactive = false); bool RemoveCustomConfiguration(const std::string& title_id, game_info game = nullptr, bool is_interactive = false);