diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index 56568ef78e..0ca79ddc8e 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -115,6 +115,8 @@ #include "Multisample.h" #include "NaviCube.h" #include "Navigation/NavigationStyle.h" +#include "Navigation/GestureNavigationStyle.h" +#include "Navigation/SiemensNXNavigationStyle.h" #include "Selection.h" #include "SoDevicePixelRatioElement.h" #include "SoFCDB.h" @@ -171,6 +173,41 @@ private: Gui::Command::runCommand(Gui::Command::Gui, "Gui.runCommand('Std_ClarifySelection')"); } + bool shouldEnableLongPress(View3DInventorViewer* viewer, const QPoint& pos, bool ctrlPressed) const { + bool enabled = App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetBool("EnableLongPressClarifySelection", true); + if (!enabled) { + return false; + } + + // check edit mode and view provider editing (for example transform manipulator) + if (viewer->isEditing() || viewer->isEditingViewProvider()) { + return false; + } + + // for navigation styles that use primarily LMB for rotation, we require + // to get CTRL+LMB combo to toggle long press + auto* navStyle = viewer->navigationStyle(); + if (navStyle) { + Base::Type navType = navStyle->getTypeId(); + if (navType == InventorNavigationStyle::getClassTypeId() || + navType == GestureNavigationStyle::getClassTypeId() || + navType == OpenSCADNavigationStyle::getClassTypeId()) { + if (!ctrlPressed) { + return false; + } + } + } + + // finally, discard long press if we are under a dragger + if (navStyle && navStyle->isDraggerUnderCursor(SbVec2s(pos.x(), pos.y()))) { + return false; + } + + return true; + } + QTimer* longPressTimer; QPoint pressPosition; View3DInventorViewer* currentViewer = nullptr; @@ -223,12 +260,15 @@ public: if (mouseEvent->button() == Qt::LeftButton) { currentViewer = static_cast(obj); pressPosition = mouseEvent->pos(); + bool ctrlPressed = (mouseEvent->modifiers() & Qt::ControlModifier) != 0; - int longPressTimeout = App::GetApplication() - .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") - ->GetInt("LongPressTimeout", 1000); - longPressTimer->setInterval(longPressTimeout); - longPressTimer->start(); + if (shouldEnableLongPress(currentViewer, pressPosition, ctrlPressed)) { + double longPressTimeout = App::GetApplication() + .GetParameterGroupByPath("User parameter:BaseApp/Preferences/View") + ->GetFloat("LongPressTimeout", 1.0); + longPressTimer->setInterval(static_cast(longPressTimeout * 1000)); + longPressTimer->start(); + } } } else if (event->type() == QEvent::MouseButtonRelease) {