From 6a597a92779b4f0fcd2aa57f703a2ab1ae392141 Mon Sep 17 00:00:00 2001 From: tetektoza Date: Sun, 19 Oct 2025 22:52:51 +0200 Subject: [PATCH] Gui: Add additional handling for Clarify Selection's long press This patch adds handling for different contexts that Clarify Selection's long press may occur in. For example, different navigation styles, transform tool, or dragger presence. This way we are sure that the context menu for Clarify Selection won't be popping up for the user when using one of the above-mentioned contexts. Also, this adds handling for different navigation styles, to accept CTRL+LMB as the long press mouse-key combos, instead of just long-pressing LMB, as in those navigation styles LMB is mostly used as rotation. --- src/Gui/View3DInventorViewer.cpp | 50 ++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 5 deletions(-) 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) {