SearchBar shortcuts work now

Refactored shortcut to search bar and removed redundant code. Fix #967
This commit is contained in:
ShaopengLin 2024-03-15 02:26:53 -04:00 committed by Kelson
parent 0b18cc6a32
commit 366ab1d173
4 changed files with 10 additions and 16 deletions

View File

@ -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);

View File

@ -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;

View File

@ -27,7 +27,6 @@ public:
QWidget getMainView();
protected:
void keyPressEvent(QKeyEvent *event) override;
bool eventFilter(QObject* object, QEvent* event) override;
private slots:

View File

@ -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()
@ -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));
}