diff --git a/app/mainwindow.cpp b/app/mainwindow.cpp --- a/app/mainwindow.cpp +++ b/app/mainwindow.cpp @@ -374,7 +374,6 @@ 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 @@ -140,6 +140,9 @@ void slotViewFocused(DocumentView*); + void slotEnterPressed(); + void slotEscapePressed(); + void trashView(DocumentView*); void deselectView(DocumentView*); diff --git a/app/viewmainpage.cpp b/app/viewmainpage.cpp --- a/app/viewmainpage.cpp +++ b/app/viewmainpage.cpp @@ -43,6 +43,7 @@ #include "splitter.h" #include #include +#include #include #include #include @@ -403,9 +404,10 @@ d->mCompareMode = false; d->mThumbnailBarVisibleBeforeFullScreen = false; - QShortcut* goToBrowseModeShortcut = new QShortcut(this); - goToBrowseModeShortcut->setKey(Qt::Key_Return); - connect(goToBrowseModeShortcut, &QShortcut::activated, this, &ViewMainPage::goToBrowseModeRequested); + 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(); @@ -736,6 +738,38 @@ d->setCurrentView(view); } +void ViewMainPage::slotEnterPressed() +{ + DocumentView *view = d->currentView(); + if (view) { + AbstractRasterImageViewTool *tool = view->currentTool(); + if (tool) { + QKeyEvent event(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier); + tool->keyPressEvent(&event); + if (event.isAccepted()) { + return; + } + } + } + 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; + } + } + } + emit goToBrowseModeRequested(); +} + void ViewMainPage::trashView(DocumentView* view) { QUrl url = view->url(); diff --git a/lib/crop/croptool.h b/lib/crop/croptool.h --- a/lib/crop/croptool.h +++ b/lib/crop/croptool.h @@ -57,6 +57,7 @@ virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*) Q_DECL_OVERRIDE; virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*) Q_DECL_OVERRIDE; virtual void hoverMoveEvent(QGraphicsSceneHoverEvent*) Q_DECL_OVERRIDE; + virtual void keyPressEvent(QKeyEvent*) Q_DECL_OVERRIDE; virtual void toolActivated() Q_DECL_OVERRIDE; virtual void toolDeactivated() Q_DECL_OVERRIDE; diff --git a/lib/crop/croptool.cpp b/lib/crop/croptool.cpp --- a/lib/crop/croptool.cpp +++ b/lib/crop/croptool.cpp @@ -23,6 +23,7 @@ // Qt #include +#include #include #include #include @@ -388,6 +389,24 @@ d->updateCursor(handle, false /* buttonDown */); } +void CropTool::keyPressEvent(QKeyEvent* event) +{ + QDialogButtonBox *buttons = d->mCropWidget->findChild(); + switch (event->key()) { + case Qt::Key_Escape: + event->accept(); + buttons->rejected(); + break; + case Qt::Key_Return: + case Qt::Key_Enter: + event->accept(); + buttons->accepted(); + break; + default: + break; + } +} + void CropTool::toolActivated() { imageView()->setCursor(Qt::CrossCursor); diff --git a/lib/redeyereduction/redeyereductiontool.h b/lib/redeyereduction/redeyereductiontool.h --- a/lib/redeyereduction/redeyereductiontool.h +++ b/lib/redeyereduction/redeyereductiontool.h @@ -54,6 +54,7 @@ virtual void mousePressEvent(QGraphicsSceneMouseEvent*) Q_DECL_OVERRIDE; virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*) Q_DECL_OVERRIDE; virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*) Q_DECL_OVERRIDE; + virtual void keyPressEvent(QKeyEvent*) Q_DECL_OVERRIDE; virtual void toolActivated() Q_DECL_OVERRIDE; diff --git a/lib/redeyereduction/redeyereductiontool.cpp b/lib/redeyereduction/redeyereductiontool.cpp --- a/lib/redeyereduction/redeyereductiontool.cpp +++ b/lib/redeyereduction/redeyereductiontool.cpp @@ -22,6 +22,7 @@ #include "redeyereductiontool.h" // Qt +#include #include #include #include @@ -158,6 +159,24 @@ event->accept(); } +void RedEyeReductionTool::keyPressEvent(QKeyEvent* event) +{ + QDialogButtonBox *buttons = d->mToolWidget->findChild(); + switch (event->key()) { + case Qt::Key_Escape: + event->accept(); + buttons->rejected(); + break; + case Qt::Key_Return: + case Qt::Key_Enter: + event->accept(); + buttons->accepted(); + break; + default: + break; + } +} + void RedEyeReductionTool::toolActivated() { imageView()->setCursor(Qt::CrossCursor);