From 9cb6fa0df7addf9ac757484a6e2dc8c5cc4e4033 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 5 Nov 2023 08:20:02 +0100 Subject: [PATCH] Sketcher: Handling of ESC keypress during handler execution =========================================================== Instead of terminating the handler, as mandated before this PR by ViewProviderSketch, ViewProviderSketch delegates the action to DrawSketchHandler. DrawSketchHandler implements by default this terminating behaviour, but allows to override it. DrawSketchDefaultHandler (and all tools deriving from it) implement as default behaviour to cancel if in initial state, otherwise to reset. --- src/Mod/Sketcher/Gui/DrawSketchController.h | 4 ++++ src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h | 9 +++++++++ src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 11 +++++++++++ src/Mod/Sketcher/Gui/DrawSketchHandler.h | 3 +-- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 3 +-- 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchController.h b/src/Mod/Sketcher/Gui/DrawSketchController.h index fc900f1a66..18d462be74 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchController.h +++ b/src/Mod/Sketcher/Gui/DrawSketchController.h @@ -578,6 +578,10 @@ protected: onViewIndexWithFocus = 0; configureOnViewParameters(); + + if (init) { + handler->moveCursorToSketchPoint(prevCursorPosition); + } } //@} diff --git a/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h b/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h index 52d2ce580c..62faadfeff 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h @@ -427,6 +427,15 @@ public: if (key == SoKeyboardEvent::M && pressed && !this->isLastState()) { this->iterateToNextConstructionMethod(); } + else if (key == SoKeyboardEvent::ESCAPE && pressed) { + + if (this->isFirstState()) { + quit(); + } + else { + handleContinuousMode(); + } + } } //@} diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index d5ac7d55f4..3464ecfbdd 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -26,6 +26,8 @@ #include #include + +#include #endif // #ifndef _PreComp_ #include @@ -367,6 +369,15 @@ void DrawSketchHandler::toolWidgetChanged(QWidget* newwidget) onWidgetChanged(); } +void DrawSketchHandler::registerPressedKey(bool pressed, int key) +{ + // the default behaviour is to quit - specific handler categories may + // override this behaviour, for example to implement a continuous mode + if (key == SoKeyboardEvent::ESCAPE && !pressed) { + quit(); + } +} + //************************************************************************** // Helpers diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.h b/src/Mod/Sketcher/Gui/DrawSketchHandler.h index a41880c912..6e508465dc 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.h @@ -152,8 +152,7 @@ public: { return false; } - virtual void registerPressedKey(bool /*pressed*/, int /*key*/) - {} + virtual void registerPressedKey(bool /*pressed*/, int /*key*/); virtual void quit(); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index d0910a8f58..e47bf294e4 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -690,8 +690,7 @@ bool ViewProviderSketch::keyPressed(bool pressed, int key) case SoKeyboardEvent::ESCAPE: { // make the handler quit but not the edit mode if (isInEditMode() && sketchHandler) { - if (!pressed) - sketchHandler->quit(); + sketchHandler->registerPressedKey(pressed, key); // delegate return true; } if (isInEditMode() && !drag.DragConstraintSet.empty()) {