diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -376,6 +376,7 @@ mBrowseAction->setToolTip(i18nc("@info:tooltip", "Browse folders for images")); mBrowseAction->setCheckable(true); mBrowseAction->setIcon(QIcon::fromTheme("view-list-icons")); + actionCollection->setDefaultShortcut(mBrowseAction, Qt::Key_Escape); connect(mViewMainPage, SIGNAL(goToBrowseModeRequested()), mBrowseAction, SLOT(trigger())); diff --git a/app/viewmainpage.h b/app/viewmainpage.h --- a/app/viewmainpage.h +++ b/app/viewmainpage.h @@ -141,11 +141,13 @@ void slotViewFocused(DocumentView*); void slotEnterPressed(); - void slotEscapePressed(); void trashView(DocumentView*); void deselectView(DocumentView*); +protected: + bool eventFilter(QObject* watched, QEvent* event) Q_DECL_OVERRIDE; + private: friend struct ViewMainPagePrivate; ViewMainPagePrivate* const d; diff --git a/app/viewmainpage.cpp b/app/viewmainpage.cpp --- a/app/viewmainpage.cpp +++ b/app/viewmainpage.cpp @@ -406,8 +406,6 @@ QShortcut* enterKeyShortcut = new QShortcut(Qt::Key_Return, this); connect(enterKeyShortcut, &QShortcut::activated, this, &ViewMainPage::slotEnterPressed); - QShortcut* escapeKeyShortcut = new QShortcut(Qt::Key_Escape, this); - connect(escapeKeyShortcut, &QShortcut::activated, this, &ViewMainPage::slotEscapePressed); d->setupToolContainer(); d->setupStatusBar(); @@ -440,6 +438,8 @@ d->mSynchronizeCheckBox, SLOT(setChecked(bool))); connect(d->mSynchronizeCheckBox, SIGNAL(toggled(bool)), d->mSynchronizeAction, SLOT(setChecked(bool))); + + installEventFilter(this); } ViewMainPage::~ViewMainPage() @@ -756,20 +756,26 @@ emit goToBrowseModeRequested(); } -void ViewMainPage::slotEscapePressed() -{ - DocumentView *view = d->currentView(); - if (view) { - AbstractRasterImageViewTool *tool = view->currentTool(); - if (tool) { - QKeyEvent event(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier); - tool->keyPressEvent(&event); - if (event.isAccepted()) { - return; +bool ViewMainPage::eventFilter(QObject* watched, QEvent* event) +{ + if (event->type() == QEvent::ShortcutOverride) { + const QKeyEvent* keyEvent = static_cast(event); + if (keyEvent->key() == Qt::Key_Escape) { + const DocumentView* view = d->currentView(); + if (view) { + AbstractRasterImageViewTool* tool = view->currentTool(); + if (tool) { + QKeyEvent toolKeyEvent(QEvent::KeyPress, Qt::Key_Escape, Qt::NoModifier); + tool->keyPressEvent(&toolKeyEvent); + if (toolKeyEvent.isAccepted()) { + event->accept(); + } + } } } } - emit goToBrowseModeRequested(); + + return QWidget::eventFilter(watched, event); } void ViewMainPage::trashView(DocumentView* view)