diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index faedc77b9..7bb893e2a 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -890,7 +890,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); diff --git a/src/gui/search/searchjobwidget.cpp b/src/gui/search/searchjobwidget.cpp index 20385f0f2..8be2a611d 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); @@ -190,6 +198,11 @@ int SearchJobWidget::visibleResultsCount() const return m_proxyModel->rowCount(); } +LineEdit *SearchJobWidget::lineEditSearchResultsFilter() const +{ + return m_lineEditSearchResultsFilter; +} + void SearchJobWidget::cancelSearch() { m_searchHandler->cancelSearch(); @@ -327,6 +340,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..6e4872f1e 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; @@ -78,6 +79,7 @@ public: Status status() const; int visibleResultsCount() const; + LineEdit *lineEditSearchResultsFilter() const; void cancelSearch(); @@ -93,6 +95,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 +118,7 @@ private: QStandardItemModel *m_searchListModel; SearchSortModel *m_proxyModel; SearchListDelegate *m_searchDelegate; + LineEdit *m_lineEditSearchResultsFilter; Status m_status = Status::Ongoing; bool m_noSearchResults = true; }; 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; };