Skip to content

Commit

Permalink
Merge pull request #1061 from ShaopengLin/Issue#967-fix-search-bar-sh…
Browse files Browse the repository at this point in the history
…ortcut

Fix #967: Search Bar Key Board Short Cut Performs the same as Mouse Click
  • Loading branch information
kelson42 authored Apr 12, 2024
2 parents 0b18cc6 + 366ab1d commit 20f32d0
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/kiwixapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,7 @@ void KiwixApp::createActions()
HIDE_ACTION(SavePageAsAction);
*/

CREATE_ACTION_SHORTCUT(SearchArticleAction, gt("search-article"), QKeySequence(Qt::CTRL | Qt::Key_L));
HIDE_ACTION(SearchArticleAction);
CREATE_ACTION_SHORTCUTS(SearchArticleAction, gt("search-article"), QList<QKeySequence>({QKeySequence(Qt::Key_F6), QKeySequence(Qt::CTRL | Qt::Key_L), QKeySequence(Qt::ALT | Qt::Key_D)}));

CREATE_ACTION_SHORTCUT(SearchLibraryAction, gt("search-in-library"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_R));
HIDE_ACTION(SearchLibraryAction);
Expand Down
12 changes: 0 additions & 12 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,6 @@ void MainWindow::when_libraryPageDisplayed(bool showed)
}
}

void MainWindow::keyPressEvent(QKeyEvent *event)
{
auto key = event->key();
auto modifier = event->modifiers();
if (key == Qt::Key_F6 ||
(key == Qt::Key_L && modifier == Qt::ControlModifier) ||
(key == Qt::Key_D && modifier == Qt::AltModifier)) {
getTopWidget()->getSearchBar().selectAll();
getTopWidget()->getSearchBar().setFocus();
}
return QWidget::keyPressEvent(event);
}
TabBar* MainWindow::getTabBar()
{
return mp_ui->tabBar;
Expand Down
1 change: 0 additions & 1 deletion src/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class MainWindow : public QMainWindow
QWidget getMainView();

protected:
void keyPressEvent(QKeyEvent *event) override;
bool eventFilter(QObject* object, QEvent* event) override;

private slots:
Expand Down
10 changes: 9 additions & 1 deletion src/searchbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ SearchBar::SearchBar(QWidget *parent) :
connect(this, &QLineEdit::returnPressed, this, [=]() {
m_returnPressed = true;
});

auto app = KiwixApp::instance();
connect(app->getAction(KiwixApp::SearchArticleAction), &QAction::triggered,
this, [=]() {
this->selectAll();
this->setFocus(Qt::ShortcutFocusReason);
});
}

void SearchBar::hideSuggestions()
Expand Down Expand Up @@ -129,7 +136,8 @@ void SearchBar::focusInEvent( QFocusEvent* event)
clear();
}
if (event->reason() == Qt::ActiveWindowFocusReason ||
event->reason() == Qt::MouseFocusReason) {
event->reason() == Qt::MouseFocusReason ||
event->reason() == Qt::ShortcutFocusReason) {
connect(&m_completer, QOverload<const QModelIndex &>::of(&QCompleter::activated),
this, QOverload<const QModelIndex &>::of(&SearchBar::openCompletion));
}
Expand Down

0 comments on commit 20f32d0

Please sign in to comment.