diff --git a/ApplicationCode/UserInterface/RiuCadNavigation.cpp b/ApplicationCode/UserInterface/RiuCadNavigation.cpp index ba38ba5c97..5f145436a6 100644 --- a/ApplicationCode/UserInterface/RiuCadNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuCadNavigation.cpp @@ -174,6 +174,9 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent) break; } - return isEventHandled; + if (isSupposedToConsumeEvents()) + return isEventHandled; + else + return false; } diff --git a/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp b/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp index 3bb0ed1797..95ba63030e 100644 --- a/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuGeoQuestNavigation.cpp @@ -166,5 +166,8 @@ bool RiuGeoQuestNavigation::handleInputEvent(QInputEvent* inputEvent) break; } - return false;//isEventHandled; + if (isSupposedToConsumeEvents()) + return isEventHandled; + else + return false; } diff --git a/ApplicationCode/UserInterface/RiuRmsNavigation.cpp b/ApplicationCode/UserInterface/RiuRmsNavigation.cpp index e689ed92a2..75ddf0a614 100644 --- a/ApplicationCode/UserInterface/RiuRmsNavigation.cpp +++ b/ApplicationCode/UserInterface/RiuRmsNavigation.cpp @@ -190,6 +190,9 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent) break; } - return false;//isEventHandled; + if (isSupposedToConsumeEvents()) + return isEventHandled; + else + return false; } diff --git a/ApplicationCode/UserInterface/RiuViewer.cpp b/ApplicationCode/UserInterface/RiuViewer.cpp index 8b4086b7dc..f4f7e6a7eb 100644 --- a/ApplicationCode/UserInterface/RiuViewer.cpp +++ b/ApplicationCode/UserInterface/RiuViewer.cpp @@ -228,6 +228,13 @@ void RiuViewer::mouseReleaseEvent(QMouseEvent* event) if (event->button() == Qt::LeftButton) { + QPoint diffPoint = event->pos() - m_lastMousePressPosition; + if (diffPoint.manhattanLength() > 3) + { + // We are possibly in navigation mode, only clean press event will launch + return; + } + if (!m_infoLabelOverlayArea.isNull()) { if (m_infoLabelOverlayArea.contains(event->x(), event->y())) @@ -239,7 +246,9 @@ void RiuViewer::mouseReleaseEvent(QMouseEvent* event) } m_viewerCommands->handlePickAction(event->x(), event->y(), event->modifiers()); + return; + } else if (event->button() == Qt::RightButton) { diff --git a/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp b/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp index 72a705b7d6..aa94ef46ec 100644 --- a/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafCadNavigation.cpp @@ -185,5 +185,8 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent) break; } - return isEventHandled; + if (isSupposedToConsumeEvents()) + return isEventHandled; + else + return false; } diff --git a/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp b/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp index 0ef728eef1..9e324806ef 100644 --- a/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafCeetronPlusNavigation.cpp @@ -43,6 +43,7 @@ #include "cvfManipulatorTrackball.h" #include +#include "cvfTrace.h" //-------------------------------------------------------------------------------------------------- /// @@ -208,5 +209,8 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent) break; } - return false;//isEventHandled; + if (isSupposedToConsumeEvents()) + return isEventHandled; + else + return false; } diff --git a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp index 61cef22bda..9c4591c717 100644 --- a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp +++ b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.cpp @@ -50,7 +50,7 @@ //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- -caf::TrackBallBasedNavigation::TrackBallBasedNavigation() +caf::TrackBallBasedNavigation::TrackBallBasedNavigation() : m_consumeEvents(false) { } @@ -63,8 +63,6 @@ caf::TrackBallBasedNavigation::~TrackBallBasedNavigation() } - - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- @@ -80,159 +78,6 @@ void caf::TrackBallBasedNavigation::init() m_lastPosY = 0; } -#if 0 -//-------------------------------------------------------------------------------------------------- -/// -//-------------------------------------------------------------------------------------------------- -bool caf::TrackBallBasedNavigation::handleInputEvent(QInputEvent* inputEvent) -{ - if (! inputEvent) return false; - bool isEventHandled = false; - switch (inputEvent->type()) - { - case QEvent::MouseButtonPress: - { - QMouseEvent * me = static_cast( inputEvent); - int translatedMousePosX = me->x(); - int translatedMousePosY = m_viewer->height() - me->y(); - - if (me->button() == Qt::RightButton) - { - cvf::HitItemCollection hic; - bool hitSomething = m_viewer->rayPick(me->x(), me->y(), &hic); - - if (hitSomething) - { - cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint(); - this->setPointOfInterest(pointOfInterest); - } - else - { - initializeRotationCenter(); - } - - m_trackball->startNavigation(cvf::ManipulatorTrackball::ROTATE, translatedMousePosX, translatedMousePosY); - //m_viewer->setCursor(RICursors::get(RICursors::ROTATE)); - m_isNavigating = true; - m_hasMovedMouseDuringNavigation = false; - isEventHandled = true; - } - else if (me->button() == Qt::LeftButton) - { - if (me->modifiers() == Qt::NoModifier) - { - m_trackball->startNavigation(cvf::ManipulatorTrackball::PAN, translatedMousePosX, translatedMousePosY); - m_isNavigating = true; - m_hasMovedMouseDuringNavigation = false; - isEventHandled = true; - } - } - else if (me->button() == Qt::MidButton) - { - if (me->modifiers() == Qt::NoModifier) - { - QMouseEvent* we = static_cast ( inputEvent); - m_lastPosX = we->x(); - m_lastPosY = we->y(); - - m_zoomRay = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY); - - m_isNavigating = true; - m_hasMovedMouseDuringNavigation = false; - isEventHandled = true; - m_isZooming = true; - } - } - } - break; - case QEvent::MouseButtonRelease: - { - if (m_isNavigating) - { - QMouseEvent * me = static_cast( inputEvent); - if (me->button() == Qt::RightButton || me->button() == Qt::LeftButton ) - { - m_trackball->endNavigation(); - - m_isNavigating = false; - if (m_hasMovedMouseDuringNavigation) isEventHandled = true; - m_hasMovedMouseDuringNavigation = false; - } - else if ( me->button() == Qt::MidButton ) - { - m_isZooming = false; - - m_isNavigating = false; - if (m_hasMovedMouseDuringNavigation) isEventHandled = true; - m_hasMovedMouseDuringNavigation = false; - } - } - } - break; - case QEvent::MouseMove: - { - initializeRotationCenter(); - if (m_isRotCenterInitialized) - { - QMouseEvent * me = static_cast( inputEvent); - int translatedMousePosX = me->x(); - int translatedMousePosY = m_viewer->height() - me->y(); - - if (m_isNavigating) - { - if (m_isZooming) - { - int delta = 3*(m_lastPosY - me->y()); - this->zoomAlongRay(m_zoomRay.p(), delta); - m_lastPosX = me->x(); - m_lastPosY = me->y(); - } - else - { - bool needRedraw = m_trackball->updateNavigation(translatedMousePosX, translatedMousePosY); - if (needRedraw) - { - m_viewer->navigationPolicyUpdate(); - } - } - isEventHandled = true; - m_hasMovedMouseDuringNavigation = true; - } - } - } - break; - case QEvent::Wheel: - { - if (inputEvent->modifiers() == Qt::NoModifier) - { - initializeRotationCenter(); - if (m_isRotCenterInitialized) - { - QWheelEvent* we = static_cast ( inputEvent); - int translatedMousePosX = we->x(); - int translatedMousePosY = m_viewer->height() - we->y(); - int delta = we->delta(); - - cvf::ref ray; - if (delta < 0) - ray = m_viewer->mainCamera()->rayFromWindowCoordinates(translatedMousePosX, translatedMousePosY); - else - ray = m_viewer->mainCamera()->rayFromWindowCoordinates((int)(1.0*translatedMousePosX), (int)(1.0*translatedMousePosY)); - - zoomAlongRay(ray.p(), delta); - - } - isEventHandled = true; - } - } - break; - } - - return false;//isEventHandled; -} - -#endif - //-------------------------------------------------------------------------------------------------- /// //-------------------------------------------------------------------------------------------------- diff --git a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h index d4766276c7..0083512d89 100644 --- a/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h +++ b/Fwk/AppFwk/cafViewer/cafTrackBallBasedNavigation.h @@ -44,12 +44,22 @@ namespace cvf { namespace caf { +//-------------------------------------------------------------------------------------------------- +/// This class is a work in progress to consolidate the different navigation policies that are similar. +/// It is not yet finished. We need to extract the Pan, Rotation, ... etc. codes from the +/// special input event handlers and invoke those general methods from the event handlers instead. +/// Some of the protected variables in this class is used by the +/// derived classes, and should rather be used from the general methods in this class and thus be private +/// +//-------------------------------------------------------------------------------------------------- class TrackBallBasedNavigation: public NavigationPolicy { public: TrackBallBasedNavigation(); virtual ~TrackBallBasedNavigation(); + void enableEventEating(bool enable) { m_consumeEvents = enable; } + protected: // General navigation policy overrides virtual void init(); @@ -74,6 +84,10 @@ protected: int m_lastPosX; /// Previous mouse position int m_lastPosY; + bool isSupposedToConsumeEvents() { return m_consumeEvents; } + +private: + bool m_consumeEvents; }; } // End namespace caf