mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
(#695) Unintentional picking fixed.
Fixed in viewer, keeping the concept of the navigation policies to not flag the the events as handled. Made this clearer by adding an interface to turn event consumption on or off on the navigation policies.
This commit is contained in:
parent
f1574bc774
commit
1d9481f09b
@ -174,6 +174,9 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
break;
|
||||
}
|
||||
|
||||
return isEventHandled;
|
||||
if (isSupposedToConsumeEvents())
|
||||
return isEventHandled;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -166,5 +166,8 @@ bool RiuGeoQuestNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
break;
|
||||
}
|
||||
|
||||
return false;//isEventHandled;
|
||||
if (isSupposedToConsumeEvents())
|
||||
return isEventHandled;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
@ -190,6 +190,9 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
break;
|
||||
}
|
||||
|
||||
return false;//isEventHandled;
|
||||
if (isSupposedToConsumeEvents())
|
||||
return isEventHandled;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -185,5 +185,8 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
break;
|
||||
}
|
||||
|
||||
return isEventHandled;
|
||||
if (isSupposedToConsumeEvents())
|
||||
return isEventHandled;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
@ -43,6 +43,7 @@
|
||||
#include "cvfManipulatorTrackball.h"
|
||||
|
||||
#include <QInputEvent>
|
||||
#include "cvfTrace.h"
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
@ -208,5 +209,8 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent)
|
||||
break;
|
||||
}
|
||||
|
||||
return false;//isEventHandled;
|
||||
if (isSupposedToConsumeEvents())
|
||||
return isEventHandled;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
@ -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<QMouseEvent*>( 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<QMouseEvent*> ( 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<QMouseEvent*>( 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<QMouseEvent*>( 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<QWheelEvent*> ( inputEvent);
|
||||
int translatedMousePosX = we->x();
|
||||
int translatedMousePosY = m_viewer->height() - we->y();
|
||||
int delta = we->delta();
|
||||
|
||||
cvf::ref<cvf::Ray> 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
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user