Skip to content

Commit

Permalink
User Interface: Focus to game searchbar on load
Browse files Browse the repository at this point in the history
Make return key press focus to game list's first entry.
  • Loading branch information
elad335 committed Apr 21, 2023
1 parent 500f790 commit 717e7fb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions rpcs3/rpcs3qt/game_list.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,13 @@ void game_list::leaveEvent(QEvent */*event*/)
m_last_hover_item = nullptr;
}
}

void game_list::FocusAndSelectFirstEntryIfNoneIs()
{
if (QTableWidgetItem* item = itemAt(0, 0); item && selectedIndexes().isEmpty())
{
setCurrentItem(item);
}

setFocus();
}
3 changes: 3 additions & 0 deletions rpcs3/rpcs3qt/game_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class game_list : public QTableWidget
public:
void clear_list(); // Use this instead of clearContents

public Q_SLOTS:
void FocusAndSelectFirstEntryIfNoneIs();

protected:
movie_item* m_last_hover_item = nullptr;

Expand Down
22 changes: 22 additions & 0 deletions rpcs3/rpcs3qt/game_list_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2477,6 +2477,28 @@ void game_list_frame::SetSearchText(const QString& text)
Refresh();
}

void game_list_frame::FocusAndSelectFirstEntryIfNoneIs()
{
if (m_is_list_layout)
{
if (!m_game_list)
{
return;
}

m_game_list->FocusAndSelectFirstEntryIfNoneIs();
}
else
{
if (!m_game_grid)
{
return;
}

m_game_grid->FocusAndSelectFirstEntryIfNoneIs();
}
}

void game_list_frame::closeEvent(QCloseEvent *event)
{
QDockWidget::closeEvent(event);
Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/game_list_frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public Q_SLOTS:
void SetShowCompatibilityInGrid(bool show);
void SetShowCustomIcons(bool show);
void SetPlayHoverGifs(bool play);
void FocusAndSelectFirstEntryIfNoneIs();

private Q_SLOTS:
void OnRefreshFinished();
Expand Down
4 changes: 4 additions & 0 deletions rpcs3/rpcs3qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ bool main_window::Init([[maybe_unused]] bool with_cli_boot)
// Disable vsh if not present.
ui->bootVSHAct->setEnabled(fs::is_file(g_cfg_vfs.get_dev_flash() + "vsh/module/vsh.self"));

// Focus to search bar by default
ui->mw_searchbar->setFocus();

return true;
}

Expand Down Expand Up @@ -2784,6 +2787,7 @@ void main_window::CreateConnects()
});

connect(ui->mw_searchbar, &QLineEdit::textChanged, m_game_list_frame, &game_list_frame::SetSearchText);
connect(ui->mw_searchbar, &QLineEdit::returnPressed, m_game_list_frame, &game_list_frame::FocusAndSelectFirstEntryIfNoneIs);
}

void main_window::CreateDockWindows()
Expand Down

0 comments on commit 717e7fb

Please sign in to comment.