Skip to content

Commit

Permalink
Merge pull request FreeCAD#11841 from Rexbas/navigation-context-menu-…
Browse files Browse the repository at this point in the history
…fixes

Right click context menu fixes
  • Loading branch information
chennes authored Jan 5, 2024
2 parents 7074d59 + 96a60a5 commit b2e4e03
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 20 deletions.
12 changes: 12 additions & 0 deletions src/Gui/NavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ void NavigationStyle::initialize()
setRotationCenterMode(NavigationStyle::RotationCenterMode::ScenePointAtCursor |
NavigationStyle::RotationCenterMode::BoundingBoxCenter);
}

this->hasDragged = false;
this->hasPanned = false;
}

void NavigationStyle::finalize()
Expand Down Expand Up @@ -583,6 +586,7 @@ void NavigationStyle::panCamera(SoCamera * cam, float aspectratio, const SbPlane
// Reposition camera according to the vector difference between the
// projected points.
cam->position = cam->position.getValue() - (current_planept - old_planept);
hasPanned = true;
}

void NavigationStyle::pan(SoCamera* camera)
Expand Down Expand Up @@ -895,6 +899,8 @@ void NavigationStyle::spin(const SbVec2f & pointerpos)
// when the user quickly trigger (as in "click-drag-release") a spin
// animation.
if (this->spinsamplecounter > 3) this->spinsamplecounter = 3;

hasDragged = true;
}

/*!
Expand Down Expand Up @@ -929,6 +935,7 @@ void NavigationStyle::spin_simplified(SoCamera* cam, SbVec2f curpos, SbVec2f pre
r.invert();
this->reorientCamera(cam, r);

hasDragged = true;
}

SbBool NavigationStyle::doSpin()
Expand Down Expand Up @@ -1345,6 +1352,11 @@ void NavigationStyle::setViewingMode(const ViewerMode newmode)
return;
}

if (newmode != NavigationStyle::IDLE) {
hasPanned = false;
hasDragged = false;
}

switch (newmode) {
case DRAGGING:
// Set up initial projection point for the projector object when
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/NavigationStyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ class GuiExport NavigationStyle : public Base::BaseClass
SbBool invertZoom;
SbBool zoomAtCursor;
float zoomStep;
SbBool hasDragged;
SbBool hasPanned;

/** @name Mouse model */
//@{
Expand Down
8 changes: 6 additions & 2 deletions src/Gui/OpenSCADNavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ SbBool OpenSCADNavigationStyle::processSoEvent(const SoEvent * const ev)
if (!viewer->isEditing()) {
// If we are in zoom or pan mode ignore RMB events otherwise
// the canvas doesn't get any release events
if (curmode != NavigationStyle::ZOOMING &&
if ((curmode != NavigationStyle::ZOOMING &&
curmode != NavigationStyle::PANNING &&
curmode != NavigationStyle::DRAGGING) {
curmode != NavigationStyle::DRAGGING) ||
(curmode == NavigationStyle::PANNING && !hasPanned)) {
if (this->isPopupMenuEnabled()) {
if (!press) { // release right mouse button
this->openPopupMenu(event->getPosition());
Expand All @@ -165,6 +166,9 @@ SbBool OpenSCADNavigationStyle::processSoEvent(const SoEvent * const ev)
newmode = NavigationStyle::IDLE;
processed = true;
}
else if (!press && curmode == NavigationStyle::PANNING && hasPanned) {
processed = true;
}
break;
case SoMouseButtonEvent::BUTTON3:
this->button3down = press;
Expand Down
28 changes: 10 additions & 18 deletions src/Gui/TinkerCADNavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ SbBool TinkerCADNavigationStyle::processSoEvent(const SoEvent * const ev)
const auto event = (const SoMouseButtonEvent *) ev;
const int button = event->getButton();
const SbBool press = event->getState() == SoButtonEvent::DOWN ? true : false;
SbBool shortRMBclick = false;

switch (button) {
case SoMouseButtonEvent::BUTTON1:
Expand All @@ -135,14 +134,6 @@ SbBool TinkerCADNavigationStyle::processSoEvent(const SoEvent * const ev)
mouseDownConsumedEvent = *event;
mouseDownConsumedEvent.setTime(ev->getTime());
}
else if (mouseDownConsumedEvent.getButton() == SoMouseButtonEvent::BUTTON2) {
SbTime tmp = (ev->getTime() - mouseDownConsumedEvent.getTime());
float dci = float(QApplication::doubleClickInterval())/1000.0f;
// time between press and release event
if (tmp.getValue() < dci) {
shortRMBclick = true;
}
}

// About to start rotating
if (press && (curmode == NavigationStyle::IDLE)) {
Expand All @@ -151,16 +142,17 @@ SbBool TinkerCADNavigationStyle::processSoEvent(const SoEvent * const ev)
this->centerTime = ev->getTime();
processed = true;
}
else if (!press && (curmode == NavigationStyle::DRAGGING)) {
if (shortRMBclick) {
newmode = NavigationStyle::IDLE;
if (!viewer->isEditing()) {
// If we are in drag mode but mouse hasn't been moved open the context-menu
if (this->isPopupMenuEnabled()) {
this->openPopupMenu(event->getPosition());
}
processed = true;
else if (!press && curmode == NavigationStyle::DRAGGING && hasDragged) {
processed = true;
}
else if (!press && curmode == NavigationStyle::DRAGGING && !hasDragged) {
newmode = NavigationStyle::IDLE;
if (!viewer->isEditing()) {
// If we are in drag mode but mouse hasn't been moved open the context-menu
if (this->isPopupMenuEnabled()) {
this->openPopupMenu(event->getPosition());
}
processed = true;
}
}
break;
Expand Down

0 comments on commit b2e4e03

Please sign in to comment.