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.
This commit is contained in:
@@ -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<View3DInventorViewer*>(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<int>(longPressTimeout * 1000));
|
||||
longPressTimer->start();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (event->type() == QEvent::MouseButtonRelease) {
|
||||
|
||||
Reference in New Issue
Block a user