mirror of
https://github.com/kiwix/kiwix-desktop.git
synced 2025-09-23 03:58:56 -04:00
Merge pull request #1061 from ShaopengLin/Issue#967-fix-search-bar-shortcut
Fix #967: Search Bar Key Board Short Cut Performs the same as Mouse Click
This commit is contained in:
commit
20f32d03b5
@ -439,8 +439,7 @@ void KiwixApp::createActions()
|
|||||||
HIDE_ACTION(SavePageAsAction);
|
HIDE_ACTION(SavePageAsAction);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
CREATE_ACTION_SHORTCUT(SearchArticleAction, gt("search-article"), QKeySequence(Qt::CTRL | Qt::Key_L));
|
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)}));
|
||||||
HIDE_ACTION(SearchArticleAction);
|
|
||||||
|
|
||||||
CREATE_ACTION_SHORTCUT(SearchLibraryAction, gt("search-in-library"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_R));
|
CREATE_ACTION_SHORTCUT(SearchLibraryAction, gt("search-in-library"), QKeySequence(Qt::CTRL | Qt::SHIFT | Qt::Key_R));
|
||||||
HIDE_ACTION(SearchLibraryAction);
|
HIDE_ACTION(SearchLibraryAction);
|
||||||
|
@ -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()
|
TabBar* MainWindow::getTabBar()
|
||||||
{
|
{
|
||||||
return mp_ui->tabBar;
|
return mp_ui->tabBar;
|
||||||
|
@ -27,7 +27,6 @@ public:
|
|||||||
QWidget getMainView();
|
QWidget getMainView();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *event) override;
|
|
||||||
bool eventFilter(QObject* object, QEvent* event) override;
|
bool eventFilter(QObject* object, QEvent* event) override;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -94,6 +94,13 @@ SearchBar::SearchBar(QWidget *parent) :
|
|||||||
connect(this, &QLineEdit::returnPressed, this, [=]() {
|
connect(this, &QLineEdit::returnPressed, this, [=]() {
|
||||||
m_returnPressed = true;
|
m_returnPressed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
auto app = KiwixApp::instance();
|
||||||
|
connect(app->getAction(KiwixApp::SearchArticleAction), &QAction::triggered,
|
||||||
|
this, [=]() {
|
||||||
|
this->selectAll();
|
||||||
|
this->setFocus(Qt::ShortcutFocusReason);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchBar::hideSuggestions()
|
void SearchBar::hideSuggestions()
|
||||||
@ -129,7 +136,8 @@ void SearchBar::focusInEvent( QFocusEvent* event)
|
|||||||
clear();
|
clear();
|
||||||
}
|
}
|
||||||
if (event->reason() == Qt::ActiveWindowFocusReason ||
|
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),
|
connect(&m_completer, QOverload<const QModelIndex &>::of(&QCompleter::activated),
|
||||||
this, QOverload<const QModelIndex &>::of(&SearchBar::openCompletion));
|
this, QOverload<const QModelIndex &>::of(&SearchBar::openCompletion));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user