From c3d84e9bf8b9cd56256e7b930fdb91316ca0fb77 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 7 Jul 2012 00:28:03 +0200 Subject: [PATCH] 0000772: Navigation style suggestion - do not change cursor location when you are controling view --- src/Gui/BlenderNavigationStyle.cpp | 6 ++++++ src/Gui/CADNavigationStyle.cpp | 6 ++++++ src/Gui/InventorNavigationStyle.cpp | 4 ++++ src/Gui/NavigationStyle.cpp | 31 +++++++++++++++++++++++++++++ src/Gui/NavigationStyle.h | 7 +++++++ src/Gui/TouchpadNavigationStyle.cpp | 6 ++++++ src/Gui/View3DInventor.cpp | 5 +++++ 7 files changed, 65 insertions(+) diff --git a/src/Gui/BlenderNavigationStyle.cpp b/src/Gui/BlenderNavigationStyle.cpp index 154180072..a33763596 100644 --- a/src/Gui/BlenderNavigationStyle.cpp +++ b/src/Gui/BlenderNavigationStyle.cpp @@ -181,6 +181,7 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) else if (press && (this->currentmode == NavigationStyle::PANNING || this->currentmode == NavigationStyle::ZOOMING)) { newmode = NavigationStyle::DRAGGING; + saveCursorPosition(ev); this->centerTime = ev->getTime(); processed = TRUE; } @@ -221,6 +222,7 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) if (press && (this->currentmode == NavigationStyle::PANNING || this->currentmode == NavigationStyle::ZOOMING)) { newmode = NavigationStyle::DRAGGING; + saveCursorPosition(ev); this->centerTime = ev->getTime(); processed = TRUE; } @@ -285,6 +287,7 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) else if (this->currentmode == NavigationStyle::DRAGGING) { this->addToLog(event->getPosition(), event->getTime()); this->spin(posn); + moveCursorPosition(); processed = TRUE; } } @@ -338,6 +341,9 @@ SbBool BlenderNavigationStyle::processSoEvent(const SoEvent * const ev) newmode = NavigationStyle::PANNING; break; case BUTTON3DOWN: + if (newmode != NavigationStyle::DRAGGING) { + saveCursorPosition(ev); + } newmode = NavigationStyle::DRAGGING; break; case CTRLDOWN|SHIFTDOWN|BUTTON2DOWN: diff --git a/src/Gui/CADNavigationStyle.cpp b/src/Gui/CADNavigationStyle.cpp index a85124a02..b6e49d632 100644 --- a/src/Gui/CADNavigationStyle.cpp +++ b/src/Gui/CADNavigationStyle.cpp @@ -210,6 +210,7 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev) else if (press && (this->currentmode == NavigationStyle::PANNING || this->currentmode == NavigationStyle::ZOOMING)) { newmode = NavigationStyle::DRAGGING; + saveCursorPosition(ev); this->centerTime = ev->getTime(); processed = TRUE; } @@ -250,6 +251,7 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev) if (press && (this->currentmode == NavigationStyle::PANNING || this->currentmode == NavigationStyle::ZOOMING)) { newmode = NavigationStyle::DRAGGING; + saveCursorPosition(ev); this->centerTime = ev->getTime(); processed = TRUE; } @@ -314,6 +316,7 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev) else if (this->currentmode == NavigationStyle::DRAGGING) { this->addToLog(event->getPosition(), event->getTime()); this->spin(posn); + moveCursorPosition(); processed = TRUE; } } @@ -379,6 +382,9 @@ SbBool CADNavigationStyle::processSoEvent(const SoEvent * const ev) newmode = NavigationStyle::PANNING; break; case SHIFTDOWN|BUTTON2DOWN: + if (newmode != NavigationStyle::DRAGGING) { + saveCursorPosition(ev); + } newmode = NavigationStyle::DRAGGING; break; case CTRLDOWN|SHIFTDOWN|BUTTON2DOWN: diff --git a/src/Gui/InventorNavigationStyle.cpp b/src/Gui/InventorNavigationStyle.cpp index e1e6f4755..2ebc53371 100644 --- a/src/Gui/InventorNavigationStyle.cpp +++ b/src/Gui/InventorNavigationStyle.cpp @@ -279,6 +279,7 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) else if (this->currentmode == NavigationStyle::DRAGGING) { this->addToLog(event->getPosition(), event->getTime()); this->spin(posn); + moveCursorPosition(); processed = TRUE; } } @@ -316,6 +317,9 @@ SbBool InventorNavigationStyle::processSoEvent(const SoEvent * const ev) } break; case BUTTON1DOWN: + if (newmode != NavigationStyle::DRAGGING) { + saveCursorPosition(ev); + } newmode = NavigationStyle::DRAGGING; break; case BUTTON3DOWN: diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index cd70bf0ba..c533e8e76 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -55,11 +55,13 @@ struct NavigationStyleP { SbRotation endRotation; SoTimerSensor * animsensor; float sensitivity; + SbBool resetcursorpos; NavigationStyleP() { this->animationsteps = 0; this->sensitivity = 2.0f; + this->resetcursorpos = FALSE; } static void viewAnimationCB(void * data, SoSensor * sensor); }; @@ -844,6 +846,25 @@ SbBool NavigationStyle::doSpin() return FALSE; } +void NavigationStyle::saveCursorPosition(const SoEvent * const ev) +{ + this->globalPos.setValue(QCursor::pos().x(), QCursor::pos().y()); + this->localPos = ev->getPosition(); +} + +void NavigationStyle::moveCursorPosition() +{ + if (!isResetCursorPosition()) + return; + + QPoint cpos = QCursor::pos(); + if (abs(cpos.x()-globalPos[0]) > 10 || + abs(cpos.y()-globalPos[1]) > 10) { + QCursor::setPos(globalPos[0], globalPos[1]-1); + this->log.position[0] = localPos; + } +} + void NavigationStyle::updateAnimation() { SbTime now = SbTime::getTimeOfDay(); @@ -943,6 +964,16 @@ float NavigationStyle::getSensitivity() const return PRIVATE(this)->sensitivity; } +void NavigationStyle::setResetCursorPosition(SbBool on) +{ + PRIVATE(this)->resetcursorpos = on; +} + +SbBool NavigationStyle::isResetCursorPosition() const +{ + return PRIVATE(this)->resetcursorpos; +} + void NavigationStyle::setZoomInverted(SbBool on) { this->invertZoom = on; diff --git a/src/Gui/NavigationStyle.h b/src/Gui/NavigationStyle.h index 760ff5399..be0200dcb 100644 --- a/src/Gui/NavigationStyle.h +++ b/src/Gui/NavigationStyle.h @@ -113,6 +113,9 @@ public: void setSensitivity(float); float getSensitivity() const; + void setResetCursorPosition(SbBool); + SbBool isResetCursorPosition() const; + void setZoomInverted(SbBool); SbBool isZoomInverted() const; void setZoomStep(float); @@ -175,6 +178,8 @@ protected: void doZoom(SoCamera * camera, SbBool forward, const SbVec2f& pos); void spin(const SbVec2f & pointerpos); SbBool doSpin(); + void moveCursorPosition(); + void saveCursorPosition(const SoEvent * const ev); SbBool handleEventInForeground(const SoEvent* const e); virtual SbBool processSoEvent(const SoEvent * const ev); @@ -195,6 +200,8 @@ protected: View3DInventorViewer* viewer; ViewerMode currentmode; SbVec2f lastmouseposition; + SbVec2s globalPos; + SbVec2s localPos; SbPlane panningplane; SbTime prevRedrawTime; SbTime centerTime; diff --git a/src/Gui/TouchpadNavigationStyle.cpp b/src/Gui/TouchpadNavigationStyle.cpp index e33323c33..9eca5aafc 100644 --- a/src/Gui/TouchpadNavigationStyle.cpp +++ b/src/Gui/TouchpadNavigationStyle.cpp @@ -185,6 +185,7 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev) else if (press && (this->currentmode == NavigationStyle::PANNING || this->currentmode == NavigationStyle::ZOOMING)) { newmode = NavigationStyle::DRAGGING; + saveCursorPosition(ev); this->centerTime = ev->getTime(); processed = TRUE; } @@ -225,6 +226,7 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev) if (press && (this->currentmode == NavigationStyle::PANNING || this->currentmode == NavigationStyle::ZOOMING)) { newmode = NavigationStyle::DRAGGING; + saveCursorPosition(ev); this->centerTime = ev->getTime(); processed = TRUE; } @@ -259,6 +261,7 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev) else if (this->currentmode == NavigationStyle::DRAGGING) { this->addToLog(event->getPosition(), event->getTime()); this->spin(posn); + moveCursorPosition(); processed = TRUE; } } @@ -305,6 +308,9 @@ SbBool TouchpadNavigationStyle::processSoEvent(const SoEvent * const ev) break; case ALTDOWN: case CTRLDOWN|SHIFTDOWN: + if (newmode != NavigationStyle::DRAGGING) { + saveCursorPosition(ev); + } newmode = NavigationStyle::DRAGGING; break; case CTRLDOWN|SHIFTDOWN|BUTTON1DOWN: diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index 86f83fd08..735ab91bc 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -141,6 +141,7 @@ View3DInventor::View3DInventor(Gui::Document* pcDocument, QWidget* parent, Qt::W OnChange(*hGrp,"NavigationStyle"); OnChange(*hGrp,"OrbitStyle"); OnChange(*hGrp,"Sensitivity"); + OnChange(*hGrp,"ResetCursorPosition"); stopSpinTimer = new QTimer(this); connect(stopSpinTimer, SIGNAL(timeout()), this, SLOT(stopAnimating())); @@ -279,6 +280,10 @@ void View3DInventor::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M float val = rGrp.GetFloat("Sensitivity",2.0f); _viewer->navigationStyle()->setSensitivity(val); } + else if (strcmp(Reason,"ResetCursorPosition") == 0) { + bool on = rGrp.GetBool("ResetCursorPosition",false); + _viewer->navigationStyle()->setResetCursorPosition(on); + } else if (strcmp(Reason,"InvertZoom") == 0) { bool on = rGrp.GetBool("InvertZoom", false); _viewer->navigationStyle()->setZoomInverted(on);