From 528ffce5932723e56daa0f36554d64250cc26984 Mon Sep 17 00:00:00 2001 From: wmayer Date: Fri, 5 Nov 2021 14:37:18 +0100 Subject: [PATCH] Gui: add method NavigationStyle::processClickEvent() to reduce code duplication in sub-classes --- src/Gui/BlenderNavigationStyle.cpp | 26 ++------------------ src/Gui/CADNavigationStyle.cpp | 26 ++------------------ src/Gui/InventorNavigationStyle.cpp | 26 ++------------------ src/Gui/NavigationStyle.cpp | 33 ++++++++++++++++++++++++++ src/Gui/NavigationStyle.h | 20 ++-------------- src/Gui/OpenCascadeNavigationStyle.cpp | 26 ++------------------ src/Gui/OpenSCADNavigationStyle.cpp | 26 ++------------------ src/Gui/RevitNavigationStyle.cpp | 26 ++------------------ src/Gui/TinkerCADNavigationStyle.cpp | 26 ++------------------ src/Gui/TouchpadNavigationStyle.cpp | 26 ++------------------ 10 files changed, 51 insertions(+), 210 deletions(-) diff --git a/src/Gui/BlenderNavigationStyle.cpp b/src/Gui/BlenderNavigationStyle.cpp index eff5b5a43d..563b124e86 100644 --- a/src/Gui/BlenderNavigationStyle.cpp +++ b/src/Gui/BlenderNavigationStyle.cpp @@ -146,30 +146,8 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) { processed = true; } - // issue #0002433: avoid to swallow the UP event if down the - // scene graph somewhere a dialog gets opened - else if (press) { - SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime()); - float dci = (float)QApplication::doubleClickInterval()/1000.0f; - // a double-click? - if (tmp.getValue() < dci) { - mouseDownConsumedEvent = *event; - mouseDownConsumedEvent.setTime(ev->getTime()); - processed = true; - } - else { - mouseDownConsumedEvent.setTime(ev->getTime()); - // 'ANY' is used to mark that we don't know yet if it will - // be a double-click event. - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } - } - else if (!press) { - if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) { - // now handle the postponed event - inherited::processSoEvent(&mouseDownConsumedEvent); - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } + else { + processed = processClickEvent(event); } break; case SoMouseButtonEvent::BUTTON2: diff --git a/src/Gui/CADNavigationStyle.cpp b/src/Gui/CADNavigationStyle.cpp index 563b4db7f0..c9e351fb2b 100644 --- a/src/Gui/CADNavigationStyle.cpp +++ b/src/Gui/CADNavigationStyle.cpp @@ -158,30 +158,8 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev) else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) { processed = true; } - // issue #0002433: avoid to swallow the UP event if down the - // scene graph somewhere a dialog gets opened - else if (press) { - SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime()); - float dci = (float)QApplication::doubleClickInterval()/1000.0f; - // a double-click? - if (tmp.getValue() < dci) { - mouseDownConsumedEvent = *event; - mouseDownConsumedEvent.setTime(ev->getTime()); - processed = true; - } - else { - mouseDownConsumedEvent.setTime(ev->getTime()); - // 'ANY' is used to mark that we don't know yet if it will - // be a double-click event. - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } - } - else if (!press) { - if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) { - // now handle the postponed event - inherited::processSoEvent(&mouseDownConsumedEvent); - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } + else { + processed = processClickEvent(event); } break; case SoMouseButtonEvent::BUTTON2: diff --git a/src/Gui/InventorNavigationStyle.cpp b/src/Gui/InventorNavigationStyle.cpp index 543cd8c522..b9bfe2986d 100644 --- a/src/Gui/InventorNavigationStyle.cpp +++ b/src/Gui/InventorNavigationStyle.cpp @@ -179,30 +179,8 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) processed = true; this->lockrecenter = true; } - // issue #0002433: avoid to swallow the UP event if down the - // scene graph somewhere a dialog gets opened - else if (press) { - SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime()); - float dci = (float)QApplication::doubleClickInterval()/1000.0f; - // a double-click? - if (tmp.getValue() < dci) { - mouseDownConsumedEvent = *event; - mouseDownConsumedEvent.setTime(ev->getTime()); - processed = true; - } - else { - mouseDownConsumedEvent.setTime(ev->getTime()); - // 'ANY' is used to mark that we don't know yet if it will - // be a double-click event. - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } - } - else if (!press) { - if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) { - // now handle the postponed event - inherited::processSoEvent(&mouseDownConsumedEvent); - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } + else { + processed = processClickEvent(event); } break; case SoMouseButtonEvent::BUTTON2: diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index bdb8d5e111..ccfefe15ea 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -1670,6 +1670,39 @@ SbBool NavigationStyle::processKeyboardEvent(const SoKeyboardEvent * const event return processed; } +SbBool NavigationStyle::processClickEvent(const SoMouseButtonEvent * const event) +{ + // issue #0002433: avoid to swallow the UP event if down the + // scene graph somewhere a dialog gets opened + SbBool processed = false; + const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false; + if (press) { + SbTime tmp = (event->getTime() - mouseDownConsumedEvent.getTime()); + float dci = (float)QApplication::doubleClickInterval()/1000.0f; + // a double-click? + if (tmp.getValue() < dci) { + mouseDownConsumedEvent = *event; + mouseDownConsumedEvent.setTime(event->getTime()); + processed = true; + } + else { + mouseDownConsumedEvent.setTime(event->getTime()); + // 'ANY' is used to mark that we don't know yet if it will + // be a double-click event. + mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); + } + } + else if (!press) { + if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) { + // now handle the postponed event + NavigationStyle::processSoEvent(&mouseDownConsumedEvent); + mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); + } + } + + return processed; +} + void NavigationStyle::setPopupMenuEnabled(const SbBool on) { this->menuenabled = on; diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index 9a3b27cd38..a8a5f58e4f 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -153,6 +153,7 @@ public: virtual SbBool processEvent(const SoEvent * const ev); virtual SbBool processMotionEvent(const SoMotion3Event * const ev); virtual SbBool processKeyboardEvent(const SoKeyboardEvent * const event); + virtual SbBool processClickEvent(const SoMouseButtonEvent * const event); void setPopupMenuEnabled(const SbBool on); SbBool isPopupMenuEnabled(void) const; @@ -227,6 +228,7 @@ protected: View3DInventorViewer* viewer; ViewerMode currentmode; + SoMouseButtonEvent mouseDownConsumedEvent; SbVec2f lastmouseposition; SbVec2s globalPos; SbVec2s localPos; @@ -296,9 +298,6 @@ public: protected: SbBool processSoEvent(const SoEvent * const ev); - -private: - SoMouseButtonEvent mouseDownConsumedEvent; }; class GuiExport CADNavigationStyle : public UserNavigationStyle { @@ -316,7 +315,6 @@ protected: private: SbBool lockButton1; - SoMouseButtonEvent mouseDownConsumedEvent; }; class GuiExport RevitNavigationStyle : public UserNavigationStyle { @@ -334,7 +332,6 @@ protected: private: SbBool lockButton1; - SoMouseButtonEvent mouseDownConsumedEvent; }; class GuiExport BlenderNavigationStyle : public UserNavigationStyle { @@ -352,7 +349,6 @@ protected: private: SbBool lockButton1; - SoMouseButtonEvent mouseDownConsumedEvent; }; class GuiExport MayaGestureNavigationStyle : public UserNavigationStyle { @@ -391,9 +387,6 @@ public: protected: SbBool processSoEvent(const SoEvent * const ev); - -private: - SoMouseButtonEvent mouseDownConsumedEvent; }; class GuiExport OpenCascadeNavigationStyle : public UserNavigationStyle { @@ -408,9 +401,6 @@ public: protected: SbBool processSoEvent(const SoEvent * const ev); - -private: - SoMouseButtonEvent mouseDownConsumedEvent; }; class GuiExport OpenSCADNavigationStyle : public UserNavigationStyle { @@ -425,9 +415,6 @@ public: protected: SbBool processSoEvent(const SoEvent * const ev); - -private: - SoMouseButtonEvent mouseDownConsumedEvent; }; class GuiExport TinkerCADNavigationStyle : public UserNavigationStyle { @@ -442,9 +429,6 @@ public: protected: SbBool processSoEvent(const SoEvent * const ev); - -private: - SoMouseButtonEvent mouseDownConsumedEvent; }; } // namespace Gui diff --git a/src/Gui/OpenCascadeNavigationStyle.cpp b/src/Gui/OpenCascadeNavigationStyle.cpp index 0b79107ea4..1cbf7b322e 100644 --- a/src/Gui/OpenCascadeNavigationStyle.cpp +++ b/src/Gui/OpenCascadeNavigationStyle.cpp @@ -146,30 +146,8 @@ SbBool OpenCascadeNavigationStyle::processSoEvent(const SoEvent * const ev) else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) { processed = true; } - // issue #0002433: avoid to swallow the UP event if down the - // scene graph somewhere a dialog gets opened - else if (press) { - SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime()); - float dci = (float)QApplication::doubleClickInterval()/1000.0f; - // a double-click? - if (tmp.getValue() < dci) { - mouseDownConsumedEvent = *event; - mouseDownConsumedEvent.setTime(ev->getTime()); - processed = true; - } - else { - mouseDownConsumedEvent.setTime(ev->getTime()); - // 'ANY' is used to mark that we don't know yet if it will - // be a double-click event. - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } - } - else if (!press) { - if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) { - // now handle the postponed event - inherited::processSoEvent(&mouseDownConsumedEvent); - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } + else { + processed = processClickEvent(event); } break; case SoMouseButtonEvent::BUTTON2: diff --git a/src/Gui/OpenSCADNavigationStyle.cpp b/src/Gui/OpenSCADNavigationStyle.cpp index 629eb0be29..c1c1ee1e6b 100644 --- a/src/Gui/OpenSCADNavigationStyle.cpp +++ b/src/Gui/OpenSCADNavigationStyle.cpp @@ -146,30 +146,8 @@ SbBool OpenSCADNavigationStyle::processSoEvent(const SoEvent * const ev) else if (viewer->isEditing() && (curmode == NavigationStyle::SPINNING)) { processed = true; } - // issue #0002433: avoid to swallow the UP event if down the - // scene graph somewhere a dialog gets opened - else if (press) { - SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime()); - float dci = (float)QApplication::doubleClickInterval()/1000.0f; - // a double-click? - if (tmp.getValue() < dci) { - mouseDownConsumedEvent = *event; - mouseDownConsumedEvent.setTime(ev->getTime()); - processed = true; - } - else { - mouseDownConsumedEvent.setTime(ev->getTime()); - // 'ANY' is used to mark that we don't know yet if it will - // be a double-click event. - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } - } - else if (!press) { - if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) { - // now handle the postponed event - inherited::processSoEvent(&mouseDownConsumedEvent); - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } + else { + processed = processClickEvent(event); } break; case SoMouseButtonEvent::BUTTON2: diff --git a/src/Gui/RevitNavigationStyle.cpp b/src/Gui/RevitNavigationStyle.cpp index 99bf448e4c..6bc4ee8ced 100644 --- a/src/Gui/RevitNavigationStyle.cpp +++ b/src/Gui/RevitNavigationStyle.cpp @@ -146,30 +146,8 @@ SbBool RevitNavigationStyle::processSoEvent(const SoEvent * const ev) else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) { processed = true; } - // issue #0002433: avoid to swallow the UP event if down the - // scene graph somewhere a dialog gets opened - else if (press) { - SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime()); - float dci = (float)QApplication::doubleClickInterval()/1000.0f; - // a double-click? - if (tmp.getValue() < dci) { - mouseDownConsumedEvent = *event; - mouseDownConsumedEvent.setTime(ev->getTime()); - processed = true; - } - else { - mouseDownConsumedEvent.setTime(ev->getTime()); - // 'ANY' is used to mark that we don't know yet if it will - // be a double-click event. - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } - } - else if (!press) { - if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) { - // now handle the postponed event - inherited::processSoEvent(&mouseDownConsumedEvent); - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } + else { + processed = processClickEvent(event); } break; case SoMouseButtonEvent::BUTTON2: diff --git a/src/Gui/TinkerCADNavigationStyle.cpp b/src/Gui/TinkerCADNavigationStyle.cpp index 14b540dd7a..50b28e47ad 100644 --- a/src/Gui/TinkerCADNavigationStyle.cpp +++ b/src/Gui/TinkerCADNavigationStyle.cpp @@ -138,30 +138,8 @@ SbBool TinkerCADNavigationStyle::processSoEvent(const SoEvent * const ev) else if (viewer->isEditing() && (curmode == NavigationStyle::SPINNING)) { processed = true; } - // issue #0002433: avoid to swallow the UP event if down the - // scene graph somewhere a dialog gets opened - else if (press) { - SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime()); - float dci = (float)QApplication::doubleClickInterval()/1000.0f; - // a double-click? - if (tmp.getValue() < dci) { - mouseDownConsumedEvent = *event; - mouseDownConsumedEvent.setTime(ev->getTime()); - processed = true; - } - else { - mouseDownConsumedEvent.setTime(ev->getTime()); - // 'ANY' is used to mark that we don't know yet if it will - // be a double-click event. - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } - } - else if (!press) { - if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) { - // now handle the postponed event - inherited::processSoEvent(&mouseDownConsumedEvent); - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } + else { + processed = processClickEvent(event); } break; case SoMouseButtonEvent::BUTTON2: diff --git a/src/Gui/TouchpadNavigationStyle.cpp b/src/Gui/TouchpadNavigationStyle.cpp index 035aa118b0..dbb2dc8b6c 100644 --- a/src/Gui/TouchpadNavigationStyle.cpp +++ b/src/Gui/TouchpadNavigationStyle.cpp @@ -146,30 +146,8 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev) else if (viewer->isEditing() && (this->currentmode == NavigationStyle::SPINNING)) { processed = true; } - // issue #0002433: avoid to swallow the UP event if down the - // scene graph somewhere a dialog gets opened - else if (press) { - SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime()); - float dci = (float)QApplication::doubleClickInterval()/1000.0f; - // a double-click? - if (tmp.getValue() < dci) { - mouseDownConsumedEvent = *event; - mouseDownConsumedEvent.setTime(ev->getTime()); - processed = true; - } - else { - mouseDownConsumedEvent.setTime(ev->getTime()); - // 'ANY' is used to mark that we don't know yet if it will - // be a double-click event. - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } - } - else if (!press) { - if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON1) { - // now handle the postponed event - inherited::processSoEvent(&mouseDownConsumedEvent); - mouseDownConsumedEvent.setButton(SoMouseButtonEvent::ANY); - } + else { + processed = processClickEvent(event); } break; case SoMouseButtonEvent::BUTTON2: