From df9aa6dc367b6d65b4f4977a75a794a385843c3d Mon Sep 17 00:00:00 2001 From: thalieht Date: Sun, 25 Feb 2018 20:07:37 +0200 Subject: [PATCH 1/3] Add a name filter for search results Closes #8226 --- src/gui/search/searchjobwidget.cpp | 14 ++++++++++++++ src/gui/search/searchjobwidget.h | 3 +++ 2 files changed, 17 insertions(+) diff --git a/src/gui/search/searchjobwidget.cpp b/src/gui/search/searchjobwidget.cpp index 20385f0f2..9d140001c 100644 --- a/src/gui/search/searchjobwidget.cpp +++ b/src/gui/search/searchjobwidget.cpp @@ -49,9 +49,11 @@ #include "base/utils/misc.h" #include "addnewtorrentdialog.h" #include "guiiconprovider.h" +#include "lineedit.h" #include "searchlistdelegate.h" #include "searchsortmodel.h" #include "ui_searchjobwidget.h" +#include "utils.h" SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, QWidget *parent) : QWidget(parent) @@ -126,6 +128,12 @@ SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, QWidget *parent) updateFilter(); + m_lineEditSearchResultsFilter = new LineEdit(this); + m_lineEditSearchResultsFilter->setFixedWidth(Utils::Gui::scaledSize(this, 170)); + m_lineEditSearchResultsFilter->setPlaceholderText(tr("Filter search results...")); + m_ui->horizontalLayout->insertWidget(0, m_lineEditSearchResultsFilter); + + connect(m_lineEditSearchResultsFilter, &LineEdit::textChanged, this, &SearchJobWidget::filterSearchResults); connect(m_ui->filterMode, static_cast(&QComboBox::currentIndexChanged) , this, &SearchJobWidget::updateFilter); connect(m_ui->minSeeds, &QAbstractSpinBox::editingFinished, this, &SearchJobWidget::updateFilter); @@ -327,6 +335,12 @@ void SearchJobWidget::fillFilterComboBoxes() m_ui->filterMode->setCurrentIndex((index == -1) ? 0 : index); } +void SearchJobWidget::filterSearchResults(const QString &name) +{ + m_proxyModel->setFilterRegExp(QRegExp(name, Qt::CaseInsensitive)); + updateResultsCount(); +} + QString SearchJobWidget::statusText(SearchJobWidget::Status st) { switch (st) { diff --git a/src/gui/search/searchjobwidget.h b/src/gui/search/searchjobwidget.h index 6a9cc12b3..3b2409189 100644 --- a/src/gui/search/searchjobwidget.h +++ b/src/gui/search/searchjobwidget.h @@ -41,6 +41,7 @@ class QStandardItemModel; template class CachedSettingValue; +class LineEdit; class SearchHandler; class SearchListDelegate; class SearchSortModel; @@ -93,6 +94,7 @@ private: void loadSettings(); void saveSettings() const; void updateFilter(); + void filterSearchResults(const QString &name); void displayToggleColumnsMenu(const QPoint&); void onItemDoubleClicked(const QModelIndex &index); void searchFinished(bool cancelled); @@ -115,6 +117,7 @@ private: QStandardItemModel *m_searchListModel; SearchSortModel *m_proxyModel; SearchListDelegate *m_searchDelegate; + LineEdit *m_lineEditSearchResultsFilter; Status m_status = Status::Ongoing; bool m_noSearchResults = true; }; From 2e9c61c45241f3d27719067810a2011e0ce85999 Mon Sep 17 00:00:00 2001 From: thalieht Date: Sun, 4 Mar 2018 11:57:50 +0200 Subject: [PATCH 2/3] Limit the scope of find torrents hotkey in MainWindow To TransferListWidget because it will interfere with the SearchWidget's focus hotkey --- src/gui/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index f84641d42..3b99aaee6 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -866,7 +866,7 @@ void MainWindow::createKeyboardShortcuts() connect(switchRSSShortcut, &QShortcut::activated, this, static_cast(&MainWindow::displayRSSTab)); QShortcut *switchExecutionLogShortcut = new QShortcut(Qt::ALT + Qt::Key_4, this); connect(switchExecutionLogShortcut, &QShortcut::activated, this, &MainWindow::displayExecutionLogTab); - QShortcut *switchSearchFilterShortcut = new QShortcut(QKeySequence::Find, this); + QShortcut *switchSearchFilterShortcut = new QShortcut(QKeySequence::Find, m_transferListWidget); connect(switchSearchFilterShortcut, &QShortcut::activated, this, &MainWindow::focusSearchFilter); m_ui->actionDocumentation->setShortcut(QKeySequence::HelpContents); From ae03ecea21b9e374fc64595ac46844b87b5d83fd Mon Sep 17 00:00:00 2001 From: thalieht Date: Thu, 5 Jul 2018 11:16:14 +0300 Subject: [PATCH 3/3] Add hotkey for toggling focus between the search LineEdits --- src/gui/search/searchjobwidget.cpp | 5 +++++ src/gui/search/searchjobwidget.h | 1 + src/gui/search/searchwidget.cpp | 16 ++++++++++++++++ src/gui/search/searchwidget.h | 3 +++ 4 files changed, 25 insertions(+) diff --git a/src/gui/search/searchjobwidget.cpp b/src/gui/search/searchjobwidget.cpp index 9d140001c..8be2a611d 100644 --- a/src/gui/search/searchjobwidget.cpp +++ b/src/gui/search/searchjobwidget.cpp @@ -198,6 +198,11 @@ int SearchJobWidget::visibleResultsCount() const return m_proxyModel->rowCount(); } +LineEdit *SearchJobWidget::lineEditSearchResultsFilter() const +{ + return m_lineEditSearchResultsFilter; +} + void SearchJobWidget::cancelSearch() { m_searchHandler->cancelSearch(); diff --git a/src/gui/search/searchjobwidget.h b/src/gui/search/searchjobwidget.h index 3b2409189..6e4872f1e 100644 --- a/src/gui/search/searchjobwidget.h +++ b/src/gui/search/searchjobwidget.h @@ -79,6 +79,7 @@ public: Status status() const; int visibleResultsCount() const; + LineEdit *lineEditSearchResultsFilter() const; void cancelSearch(); diff --git a/src/gui/search/searchwidget.cpp b/src/gui/search/searchwidget.cpp index 43cac5dee..d4e3fba9f 100644 --- a/src/gui/search/searchwidget.cpp +++ b/src/gui/search/searchwidget.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -154,6 +155,9 @@ SearchWidget::SearchWidget(MainWindow *mainWindow) , this, &SearchWidget::selectMultipleBox); connect(m_ui->selectPlugin, static_cast(&QComboBox::currentIndexChanged) , this, &SearchWidget::fillCatCombobox); + + m_focusSearchHotkey = new QShortcut(QKeySequence::Find, this); + connect(m_focusSearchHotkey, &QShortcut::activated, this, &SearchWidget::toggleFocusBetweenLineEdits); } void SearchWidget::fillCatCombobox() @@ -260,6 +264,18 @@ void SearchWidget::selectMultipleBox(int index) on_pluginsButton_clicked(); } +void SearchWidget::toggleFocusBetweenLineEdits() +{ + if (m_ui->lineEditSearchPattern->hasFocus() && m_currentSearchTab) { + m_currentSearchTab->lineEditSearchResultsFilter()->setFocus(); + m_currentSearchTab->lineEditSearchResultsFilter()->selectAll(); + } + else { + m_ui->lineEditSearchPattern->setFocus(); + m_ui->lineEditSearchPattern->selectAll(); + } +} + void SearchWidget::on_pluginsButton_clicked() { new PluginSelectDialog(SearchPluginManager::instance(), this); diff --git a/src/gui/search/searchwidget.h b/src/gui/search/searchwidget.h index 4ecb46f4a..153beea15 100644 --- a/src/gui/search/searchwidget.h +++ b/src/gui/search/searchwidget.h @@ -33,6 +33,7 @@ #include #include +class QShortcut; class QSignalMapper; class QTabWidget; @@ -68,6 +69,7 @@ private: void resultsCountUpdated(); void tabStatusChanged(QWidget *tab); void selectMultipleBox(int index); + void toggleFocusBetweenLineEdits(); void fillCatCombobox(); void fillPluginComboBox(); @@ -85,4 +87,5 @@ private: QList m_allTabs; // To store all tabs MainWindow *m_mainWindow; bool m_isNewQueryString; + QShortcut *m_focusSearchHotkey; };