Merge pull request #6480 from spycrab/qt_search

Qt: Implement search
This commit is contained in:
Anthony 2018-03-21 12:40:34 -07:00 committed by GitHub
commit 9cf22aec04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 133 additions and 2 deletions

View File

@ -26,6 +26,7 @@ set(SRCS
MenuBar.cpp
RenderWidget.cpp
Resources.cpp
SearchBar.cpp
Settings.cpp
ToolBar.cpp
Translation.cpp

View File

@ -122,6 +122,7 @@
<QtMoc Include="QtUtils\WrapInScrollArea.h" />
<QtMoc Include="QtUtils\AspectRatioWidget.h" />
<QtMoc Include="RenderWidget.h" />
<QtMoc Include="SearchBar.h" />
<QtMoc Include="Settings.h" />
<QtMoc Include="Settings\AdvancedPane.h" />
<QtMoc Include="Settings\GeneralPane.h" />
@ -188,6 +189,7 @@
<ClCompile Include="$(QtMocOutPrefix)DoubleClickEventFilter.cpp" />
<ClCompile Include="$(QtMocOutPrefix)RegisterWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)RenderWidget.cpp" />
<ClCompile Include="$(QtMocOutPrefix)SearchBar.cpp" />
<ClCompile Include="$(QtMocOutPrefix)Settings.cpp" />
<ClCompile Include="$(QtMocOutPrefix)SettingsWindow.cpp" />
<ClCompile Include="$(QtMocOutPrefix)SoftwareRendererWidget.cpp" />
@ -280,6 +282,7 @@
<ClCompile Include="QtUtils\AspectRatioWidget.cpp" />
<ClCompile Include="RenderWidget.cpp" />
<ClCompile Include="Resources.cpp" />
<ClCompile Include="SearchBar.cpp" />
<ClCompile Include="Settings.cpp" />
<ClCompile Include="Settings\AdvancedPane.cpp" />
<ClCompile Include="Settings\AudioPane.cpp" />

View File

@ -521,3 +521,11 @@ void GameList::OnHeaderViewChanged()
QSettings().setValue(QStringLiteral("tableheader/state"),
m_list->horizontalHeader()->saveState());
}
void GameList::SetSearchTerm(const QString& term)
{
m_model->SetSearchTerm(term);
m_list_proxy->invalidate();
m_grid_proxy->invalidate();
}

View File

@ -27,9 +27,10 @@ public:
void SetListView() { SetPreferredView(true); }
void SetGridView() { SetPreferredView(false); }
void SetViewColumn(int col, bool view) { m_list->setColumnHidden(col, !view); }
void SetSearchTerm(const QString& term);
void OnColumnVisibilityToggled(const QString& row, bool visible);
void OnGameListVisibilityChanged();
signals:
void GameSelected();
void NetPlayHost(const QString& game_id);

View File

@ -150,6 +150,10 @@ bool GameListModel::ShouldDisplayGameListItem(int index) const
{
const UICommon::GameFile& game = *m_games[index];
if (!m_term.isEmpty() &&
!QString::fromStdString(game.GetName()).contains(m_term, Qt::CaseInsensitive))
return false;
const bool show_platform = [&game] {
switch (game.GetPlatform())
{
@ -244,3 +248,8 @@ int GameListModel::FindGame(const std::string& path) const
}
return -1;
}
void GameListModel::SetSearchTerm(const QString& term)
{
m_term = term;
}

View File

@ -36,6 +36,8 @@ public:
return QString::fromStdString(m_games[index]->GetUniqueIdentifier());
}
bool ShouldDisplayGameListItem(int index) const;
void SetSearchTerm(const QString& term);
enum
{
COL_PLATFORM = 0,
@ -60,4 +62,5 @@ private:
GameTracker m_tracker;
QList<std::shared_ptr<const UICommon::GameFile>> m_games;
QString m_term;
};

View File

@ -15,6 +15,7 @@
#include <QMessageBox>
#include <QMimeData>
#include <QProgressDialog>
#include <QVBoxLayout>
#include <future>
#include <optional>
@ -65,6 +66,7 @@
#include "DolphinQt2/QtUtils/RunOnObject.h"
#include "DolphinQt2/QtUtils/WindowActivationEventFilter.h"
#include "DolphinQt2/Resources.h"
#include "DolphinQt2/SearchBar.h"
#include "DolphinQt2/Settings.h"
#include "DolphinQt2/TAS/GCTASInputWindow.h"
#include "DolphinQt2/TAS/WiiTASInputWindow.h"
@ -164,6 +166,7 @@ void MainWindow::CreateComponents()
{
m_menu_bar = new MenuBar(this);
m_tool_bar = new ToolBar(this);
m_search_bar = new SearchBar(this);
m_game_list = new GameList(this);
m_render_widget = new RenderWidget;
m_stack = new QStackedWidget(this);
@ -275,6 +278,8 @@ void MainWindow::ConnectMenuBar()
// View
connect(m_menu_bar, &MenuBar::ShowList, m_game_list, &GameList::SetListView);
connect(m_menu_bar, &MenuBar::ShowGrid, m_game_list, &GameList::SetGridView);
connect(m_menu_bar, &MenuBar::ToggleSearch, m_search_bar, &SearchBar::Toggle);
connect(m_menu_bar, &MenuBar::ColumnVisibilityToggled, m_game_list,
&GameList::OnColumnVisibilityToggled);
@ -372,7 +377,16 @@ void MainWindow::ConnectRenderWidget()
void MainWindow::ConnectStack()
{
m_stack->addWidget(m_game_list);
auto* widget = new QWidget;
auto* layout = new QVBoxLayout;
widget->setLayout(layout);
layout->addWidget(m_game_list);
layout->addWidget(m_search_bar);
connect(m_search_bar, &SearchBar::Search, m_game_list, &GameList::SetSearchTerm);
m_stack->addWidget(widget);
setCentralWidget(m_stack);

View File

@ -30,6 +30,7 @@ class NetPlayClient;
class NetPlayDialog;
class NetPlayServer;
class NetPlaySetupDialog;
class SearchBar;
class SettingsWindow;
class ControllersWindow;
class DragEnterEvent;
@ -137,6 +138,7 @@ private:
QStackedWidget* m_stack;
ToolBar* m_tool_bar;
MenuBar* m_menu_bar;
SearchBar* m_search_bar;
GameList* m_game_list;
RenderWidget* m_render_widget;
bool m_rendering_to_main;

View File

@ -357,6 +357,10 @@ void MenuBar::AddViewMenu()
view_menu->addSeparator();
AddShowPlatformsMenu(view_menu);
AddShowRegionsMenu(view_menu);
view_menu->addSeparator();
AddAction(view_menu, tr("Search"), this, &MenuBar::ToggleSearch,
QKeySequence(QStringLiteral("Ctrl+F")));
}
void MenuBar::AddOptionsMenu()

View File

@ -82,6 +82,7 @@ signals:
// View
void ShowList();
void ShowGrid();
void ToggleSearch();
void ColumnVisibilityToggled(const QString& row, bool visible);
void GameListPlatformVisibilityToggled(const QString& row, bool visible);
void GameListRegionVisibilityToggled(const QString& row, bool visible);

View File

@ -0,0 +1,54 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#include "DolphinQt2/SearchBar.h"
#include <QCheckBox>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
SearchBar::SearchBar(QWidget* parent) : QWidget(parent)
{
CreateWidgets();
ConnectWidgets();
setFixedHeight(32);
setHidden(true);
}
void SearchBar::CreateWidgets()
{
m_search_edit = new QLineEdit;
m_close_button = new QPushButton(tr("Close"));
m_search_edit->setPlaceholderText(tr("Type your search term here"));
auto* layout = new QHBoxLayout;
layout->addWidget(m_search_edit);
layout->addWidget(m_close_button);
layout->setMargin(0);
setLayout(layout);
}
void SearchBar::Toggle()
{
m_search_edit->clear();
setHidden(isVisible());
if (isVisible())
m_search_edit->setFocus();
else
m_search_edit->clearFocus();
}
void SearchBar::ConnectWidgets()
{
connect(m_search_edit, &QLineEdit::textChanged, this, &SearchBar::Search);
connect(m_close_button, &QPushButton::pressed, this, &SearchBar::Toggle);
}

View File

@ -0,0 +1,31 @@
// Copyright 2018 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.
#pragma once
#include <QWidget>
class QCheckBox;
class QLineEdit;
class QPushButton;
class SearchBar : public QWidget
{
Q_OBJECT
public:
explicit SearchBar(QWidget* parent = nullptr);
void Toggle();
signals:
void Search(const QString& serach);
private:
void CreateWidgets();
void ConnectWidgets();
QLineEdit* m_search_edit;
QCheckBox* m_wii_check;
QCheckBox* m_gc_check;
QPushButton* m_close_button;
};