From 3fa101d9ee7c8ede39f486c407fa05123f0c6722 Mon Sep 17 00:00:00 2001 From: Paul I Date: Fri, 30 Nov 2018 00:59:34 +0300 Subject: [PATCH] StringsWidget: add shortcuts for QuickFilter (#973) --- src/widgets/ComboQuickFilterView.cpp | 18 ++++++++++++++++++ src/widgets/ComboQuickFilterView.h | 6 ++++++ src/widgets/StringsWidget.cpp | 8 ++++++++ 3 files changed, 32 insertions(+) diff --git a/src/widgets/ComboQuickFilterView.cpp b/src/widgets/ComboQuickFilterView.cpp index 05d44242..1a96f260 100644 --- a/src/widgets/ComboQuickFilterView.cpp +++ b/src/widgets/ComboQuickFilterView.cpp @@ -26,3 +26,21 @@ QComboBox *ComboQuickFilterView::comboBox() { return ui->comboBox; } + +void ComboQuickFilterView::showFilter() +{ + show(); + ui->lineEdit->setFocus(); +} + +void ComboQuickFilterView::clearFilter() +{ + ui->lineEdit->setText(""); +} + +void ComboQuickFilterView::closeFilter() +{ + ui->lineEdit->setText(""); + hide(); + emit filterClosed(); +} diff --git a/src/widgets/ComboQuickFilterView.h b/src/widgets/ComboQuickFilterView.h index 244de402..d8790f9c 100644 --- a/src/widgets/ComboQuickFilterView.h +++ b/src/widgets/ComboQuickFilterView.h @@ -19,8 +19,14 @@ public: void setLabelText(const QString &text); QComboBox *comboBox(); +public slots: + void showFilter(); + void closeFilter(); + void clearFilter(); + signals: void filterTextChanged(const QString &text); + void filterClosed(); private: Ui::ComboQuickFilterView *ui; diff --git a/src/widgets/StringsWidget.cpp b/src/widgets/StringsWidget.cpp index 1f3487fe..edcf4d32 100644 --- a/src/widgets/StringsWidget.cpp +++ b/src/widgets/StringsWidget.cpp @@ -178,6 +178,14 @@ StringsWidget::StringsWidget(MainWindow *main, QAction *action) : tree->showItemsNumber(proxyModel->rowCount()); }); + QShortcut *searchShortcut = new QShortcut(QKeySequence::Find, this); + connect(searchShortcut, &QShortcut::activated, ui->quickFilterView, &ComboQuickFilterView::showFilter); + searchShortcut->setContext(Qt::WidgetWithChildrenShortcut); + + QShortcut *clearShortcut = new QShortcut(QKeySequence(Qt::Key_Escape), this); + connect(clearShortcut, &QShortcut::activated, ui->quickFilterView, &ComboQuickFilterView::clearFilter); + clearShortcut->setContext(Qt::WidgetWithChildrenShortcut); + connect(Core(), SIGNAL(refreshAll()), this, SLOT(refreshStrings())); connect(