From e235a1b795567a99d67e1887a1c7151e60ebe395 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 5 Nov 2023 21:30:59 +0100 Subject: [PATCH] Sketcher: Handling of right mouse button 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/DrawSketchDefaultHandler.h | 13 +++++++++++++ src/Mod/Sketcher/Gui/DrawSketchHandler.cpp | 7 +++++++ src/Mod/Sketcher/Gui/DrawSketchHandler.h | 3 ++- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 4 ++-- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h b/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h index 62faadfeff..bf4121d58e 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchDefaultHandler.h @@ -437,6 +437,19 @@ public: } } } + + void pressRightButton(Base::Vector2d onSketchPos) override + { + Q_UNUSED(onSketchPos); + + if (this->isFirstState()) { + quit(); + } + else { + handleContinuousMode(); + } + } + //@} diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index 3464ecfbdd..50dfbe1f55 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -378,6 +378,13 @@ void DrawSketchHandler::registerPressedKey(bool pressed, int key) } } +void DrawSketchHandler::pressRightButton(Base::Vector2d /*onSketchPos*/) +{ + // the default behaviour is to quit - specific handler categories may + // override this behaviour, for example to implement a continuous mode + quit(); +} + //************************************************************************** // Helpers diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.h b/src/Mod/Sketcher/Gui/DrawSketchHandler.h index 6e508465dc..989837ff41 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.h @@ -152,7 +152,8 @@ public: { return false; } - virtual void registerPressedKey(bool /*pressed*/, int /*key*/); + virtual void registerPressedKey(bool pressed, int key); + virtual void pressRightButton(Base::Vector2d onSketchPos); virtual void quit(); diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index e47bf294e4..7fbed4f501 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -1169,8 +1169,8 @@ bool ViewProviderSketch::mouseButtonPressed(int Button, bool pressed, const SbVe if (!pressed) { switch (Mode) { case STATUS_SKETCH_UseHandler: - // make the handler quit - sketchHandler->quit(); + // delegate to handler whether to quit or do otherwise + sketchHandler->pressRightButton(Base::Vector2d(x, y)); return true; case STATUS_NONE: { // A right click shouldn't change the Edit Mode