Skip to content

Commit

Permalink
Game List: Make Ctrl+F Focus To Search Bar
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Apr 22, 2023
1 parent 17b7f70 commit 180e0c9
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
17 changes: 16 additions & 1 deletion rpcs3/rpcs3.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@
<ClCompile Include="QTGeneratedFiles\Debug\moc_game_compatibility.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Debug\moc_game_list.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Debug\moc_game_list_frame.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</ClCompile>
Expand Down Expand Up @@ -473,6 +476,9 @@
<ClCompile Include="QTGeneratedFiles\Release\moc_game_compatibility.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Release\moc_game_list.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Release\moc_game_list_frame.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
</ClCompile>
Expand Down Expand Up @@ -1394,7 +1400,16 @@
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DWITH_DISCORD_RPC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -DQT_WINEXTRAS_LIB -DQT_CONCURRENT_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\wolfssl\wolfssl" "-I.\..\3rdparty\curl\curl\include" "-I.\..\3rdparty\libusb\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I.\..\3rdparty\XAudio2Redist\include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtCore" "-I.\release" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras" "-I$(QTDIR)\include\QtConcurrent"</Command>
</CustomBuild>
<ClInclude Include="rpcs3qt\game_list.h" />
<CustomBuild Include="rpcs3qt\game_list.h">
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Moc%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">.\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DWIN32_LEAN_AND_MEAN -DHAVE_VULKAN -DMINIUPNP_STATICLIB -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_WINEXTRAS_LIB -DQT_CONCURRENT_LIB -DQT_MULTIMEDIA_LIB -DQT_MULTIMEDIAWIDGETS_LIB -DQT_SVG_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\SoundTouch\soundtouch\include" "-I.\..\3rdparty\cubeb\extra" "-I.\..\3rdparty\cubeb\cubeb\include" "-I.\..\3rdparty\flatbuffers\include" "-I.\..\3rdparty\wolfssl\wolfssl" "-I.\..\3rdparty\curl\curl\include" "-I.\..\3rdparty\libusb\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I.\..\3rdparty\XAudio2Redist\include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtCore" "-I.\debug" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras" "-I$(QTDIR)\include\QtConcurrent" "-I$(QTDIR)\include\QtMultimedia" "-I$(QTDIR)\include\QtMultimediaWidgets" "-I$(QTDIR)\include\QtSvg"</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(QTDIR)\bin\moc.exe;%(FullPath)</AdditionalInputs>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Moc%27ing %(Identity)...</Message>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">.\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp</Outputs>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">"$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\QTGeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_WINDOWS -DUNICODE -DWIN32 -DWIN64 -DWIN32_LEAN_AND_MEAN -DHAVE_VULKAN -DMINIUPNP_STATICLIB -DHAVE_SDL2 -DWITH_DISCORD_RPC -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DNDEBUG -DQT_WINEXTRAS_LIB -DQT_CONCURRENT_LIB -DQT_MULTIMEDIA_LIB -DQT_MULTIMEDIAWIDGETS_LIB -DQT_SVG_LIB -D%(PreprocessorDefinitions) "-I.\..\3rdparty\SoundTouch\soundtouch\include" "-I.\..\3rdparty\cubeb\extra" "-I.\..\3rdparty\cubeb\cubeb\include" "-I.\..\3rdparty\flatbuffers\include" "-I.\..\3rdparty\wolfssl\wolfssl" "-I.\..\3rdparty\curl\curl\include" "-I.\..\3rdparty\libusb\libusb\libusb" "-I$(VULKAN_SDK)\Include" "-I.\..\3rdparty\libsdl-org\SDL\include" "-I.\..\3rdparty\XAudio2Redist\include" "-I$(QTDIR)\include" "-I$(QTDIR)\include\QtWidgets" "-I$(QTDIR)\include\QtGui" "-I$(QTDIR)\include\QtANGLE" "-I$(QTDIR)\include\QtCore" "-I.\release" "-I$(QTDIR)\mkspecs\win32-msvc2015" "-I.\QTGeneratedFiles\$(ConfigurationName)" "-I.\QTGeneratedFiles" "-I$(QTDIR)\include\QtWinExtras" "-I$(QTDIR)\include\QtConcurrent" "-I$(QTDIR)\include\QtMultimedia" "-I$(QTDIR)\include\QtMultimediaWidgets" "-I$(QTDIR)\include\QtSvg"</Command>
</CustomBuild>
<ClInclude Include="rpcs3qt\game_list_grid_delegate.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="rpcs3qt\gl_gs_frame.h" />
Expand Down
12 changes: 9 additions & 3 deletions rpcs3/rpcs3.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,12 @@
<ClCompile Include="QTGeneratedFiles\Release\moc_system_cmd_dialog.cpp">
<Filter>Generated Files\Release</Filter>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Debug\moc_game_list.cpp">
<Filter>Generated Files\Debug</Filter>
</ClCompile>
<ClCompile Include="QTGeneratedFiles\Release\moc_game_list.cpp">
<Filter>Generated Files\Release</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Input\ds4_pad_handler.h">
Expand Down Expand Up @@ -974,9 +980,6 @@
<ClInclude Include="rpcs3qt\gl_gs_frame.h">
<Filter>Gui\game window</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\game_list.h">
<Filter>Gui\game list</Filter>
</ClInclude>
<ClInclude Include="rpcs3qt\game_list_grid_delegate.h">
<Filter>Gui\game list</Filter>
</ClInclude>
Expand Down Expand Up @@ -1384,6 +1387,9 @@
<CustomBuild Include="rpcs3qt\system_cmd_dialog.h">
<Filter>Gui\dev tools</Filter>
</CustomBuild>
<CustomBuild Include="rpcs3qt\game_list.h">
<Filter>Gui\game list</Filter>
</CustomBuild>
</ItemGroup>
<ItemGroup>
<Image Include="rpcs3.ico" />
Expand Down
15 changes: 15 additions & 0 deletions rpcs3/rpcs3qt/game_list.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "game_list.h"
#include "movie_item.h"

#include <QApplication>

void game_list::clear_list()
{
m_last_hover_item = nullptr;
Expand Down Expand Up @@ -37,6 +39,19 @@ void game_list::mouseMoveEvent(QMouseEvent *event)
m_last_hover_item = new_item;
}

void game_list::keyPressEvent(QKeyEvent* event)
{
const auto modifiers = QApplication::keyboardModifiers();

if (modifiers == Qt::ControlModifier && event->key() == Qt::Key_F && !event->isAutoRepeat())
{
Q_EMIT FocusToSearchBar();
return;
}

QTableWidget::keyPressEvent(event);
}

void game_list::leaveEvent(QEvent */*event*/)
{
if (m_last_hover_item)
Expand Down
7 changes: 7 additions & 0 deletions rpcs3/rpcs3qt/game_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <QTableWidget>
#include <QMouseEvent>
#include <QKeyEvent>
#include <QPixmap>

#include "game_compatibility.h"
Expand Down Expand Up @@ -32,16 +33,22 @@ Q_DECLARE_METATYPE(game_info)
*/
class game_list : public QTableWidget
{
Q_OBJECT

public:
void clear_list(); // Use this instead of clearContents

public Q_SLOTS:
void FocusAndSelectFirstEntryIfNoneIs();

Q_SIGNALS:
void FocusToSearchBar();

protected:
movie_item* m_last_hover_item = nullptr;

void mousePressEvent(QMouseEvent *event) override;
void mouseMoveEvent(QMouseEvent *event) override;
void keyPressEvent(QKeyEvent *event) override;
void leaveEvent(QEvent *event) override;
};
20 changes: 16 additions & 4 deletions rpcs3/rpcs3qt/game_list_frame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ game_list_frame::game_list_frame(std::shared_ptr<gui_settings> gui_settings, std
QMessageBox::warning(this, tr("Warning!"), tr("Failed to retrieve the online compatibility database!\nFalling back to local database.\n\n%0").arg(error));
});

connect(m_game_grid, &game_list_grid::FocusToSearchBar, this, [this]() { Q_EMIT FocusToSearchBar(); });
connect(m_game_list, &game_list::FocusToSearchBar, this, [this]() { Q_EMIT FocusToSearchBar(); });

for (int col = 0; col < m_columnActs.count(); ++col)
{
m_columnActs[col]->setCheckable(true);
Expand Down Expand Up @@ -2751,17 +2754,26 @@ void game_list_frame::PopulateGameGrid(int maxCols, const QSize& image_size, con
// Get list of matching apps
QList<game_info> matching_apps;

// Fallback is not needed when at least one entry is visible
const bool use_search_fallback = std::none_of(m_game_data.begin(), m_game_data.end(), [this](auto& game){ return IsEntryVisible(game); });

for (const auto& app : m_game_data)
{
if (IsEntryVisible(app, use_search_fallback))
if (IsEntryVisible(app))
{
matching_apps.push_back(app);
}
}

// Fallback is not needed when at least one entry is visible
if (matching_apps.isEmpty())
{
for (const auto& app : m_game_data)
{
if (IsEntryVisible(app, true))
{
matching_apps.push_back(app);
}
}
}

const int entries = matching_apps.count();

// Edge cases!
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 @@ -92,6 +92,7 @@ private Q_SLOTS:
void RequestBoot(const game_info& game, cfg_mode config_mode = cfg_mode::custom, const std::string& config_path = "", const std::string& savestate = "");
void RequestIconSizeChange(const int& val);
void NotifyEmuSettingsChange();
void FocusToSearchBar();
protected:
/** Override inherited method from Qt to allow signalling when close happened.*/
void closeEvent(QCloseEvent* event) override;
Expand Down
1 change: 1 addition & 0 deletions rpcs3/rpcs3qt/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2788,6 +2788,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);
connect(m_game_list_frame, &game_list_frame::FocusToSearchBar, this, [this]() { ui->mw_searchbar->setFocus(); });
}

void main_window::CreateDockWindows()
Expand Down

0 comments on commit 180e0c9

Please sign in to comment.