mirror of
https://github.com/OPM/ResInsight.git
synced 2025-01-08 07:03:25 -06:00
#3794 Improve wheel zooming
This commit is contained in:
parent
240c748910
commit
914daded6b
@ -60,7 +60,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
cvfEventPos(me->x(), me->y(), &translatedMousePosX, &translatedMousePosY);
|
cvfEventPos(me->x(), me->y(), &translatedMousePosX, &translatedMousePosY);
|
||||||
|
|
||||||
if (me->button() == Qt::MidButton && me->modifiers() == Qt::NoModifier && isRotationEnabled())
|
if (me->button() == Qt::MidButton && me->modifiers() == Qt::NoModifier && isRotationEnabled())
|
||||||
{
|
{
|
||||||
cvf::HitItemCollection hic;
|
cvf::HitItemCollection hic;
|
||||||
bool hitSomething = m_viewer->rayPick( me->x(), me->y(), &hic);
|
bool hitSomething = m_viewer->rayPick( me->x(), me->y(), &hic);
|
||||||
|
|
||||||
@ -86,6 +86,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
m_hasMovedMouseDuringNavigation = false;
|
m_hasMovedMouseDuringNavigation = false;
|
||||||
isEventHandled = true;
|
isEventHandled = true;
|
||||||
}
|
}
|
||||||
|
forcePointOfInterestUpdateDuringNextWheelZoom();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEvent::MouseButtonRelease:
|
case QEvent::MouseButtonRelease:
|
||||||
@ -103,6 +104,7 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
forcePointOfInterestUpdateDuringNextWheelZoom();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEvent::MouseMove:
|
case QEvent::MouseMove:
|
||||||
@ -133,11 +135,12 @@ bool RiuCadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
{
|
{
|
||||||
if (inputEvent->modifiers() == Qt::NoModifier)
|
if (inputEvent->modifiers() == Qt::NoModifier)
|
||||||
{
|
{
|
||||||
initializeRotationCenter();
|
QWheelEvent* we = static_cast<QWheelEvent*>(inputEvent);
|
||||||
|
|
||||||
|
updatePointOfInterestDuringZoomIfNecessary(we->x(), we->y());
|
||||||
|
|
||||||
if (m_isRotCenterInitialized)
|
if (m_isRotCenterInitialized)
|
||||||
{
|
{
|
||||||
QWheelEvent* we = static_cast<QWheelEvent*> ( inputEvent);
|
|
||||||
|
|
||||||
int translatedMousePosX, translatedMousePosY;
|
int translatedMousePosX, translatedMousePosY;
|
||||||
cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY);
|
cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY);
|
||||||
|
|
||||||
|
@ -89,6 +89,7 @@ bool RiuGeoQuestNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
isEventHandled = true;
|
isEventHandled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
forcePointOfInterestUpdateDuringNextWheelZoom();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEvent::MouseButtonRelease:
|
case QEvent::MouseButtonRelease:
|
||||||
@ -144,11 +145,12 @@ bool RiuGeoQuestNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
{
|
{
|
||||||
if (inputEvent->modifiers() == Qt::NoModifier)
|
if (inputEvent->modifiers() == Qt::NoModifier)
|
||||||
{
|
{
|
||||||
initializeRotationCenter();
|
QWheelEvent* we = static_cast<QWheelEvent*>(inputEvent);
|
||||||
|
|
||||||
|
updatePointOfInterestDuringZoomIfNecessary(we->x(), we->y());
|
||||||
|
|
||||||
if (m_isRotCenterInitialized)
|
if (m_isRotCenterInitialized)
|
||||||
{
|
{
|
||||||
QWheelEvent* we = static_cast<QWheelEvent*>(inputEvent);
|
|
||||||
|
|
||||||
int translatedMousePosX, translatedMousePosY;
|
int translatedMousePosX, translatedMousePosY;
|
||||||
cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY);
|
cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY);
|
||||||
|
|
||||||
|
@ -105,7 +105,7 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
m_isZooming = true;
|
m_isZooming = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
forcePointOfInterestUpdateDuringNextWheelZoom();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEvent::MouseButtonRelease:
|
case QEvent::MouseButtonRelease:
|
||||||
@ -130,6 +130,7 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
m_hasMovedMouseDuringNavigation = false;
|
m_hasMovedMouseDuringNavigation = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
forcePointOfInterestUpdateDuringNextWheelZoom();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEvent::MouseMove:
|
case QEvent::MouseMove:
|
||||||
@ -169,7 +170,10 @@ bool RiuRmsNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
{
|
{
|
||||||
if (inputEvent->modifiers() == Qt::NoModifier)
|
if (inputEvent->modifiers() == Qt::NoModifier)
|
||||||
{
|
{
|
||||||
initializeRotationCenter();
|
QWheelEvent* we = static_cast<QWheelEvent*>(inputEvent);
|
||||||
|
|
||||||
|
updatePointOfInterestDuringZoomIfNecessary(we->x(), we->y());
|
||||||
|
|
||||||
if (m_isRotCenterInitialized)
|
if (m_isRotCenterInitialized)
|
||||||
{
|
{
|
||||||
QWheelEvent* we = static_cast<QWheelEvent*> ( inputEvent);
|
QWheelEvent* we = static_cast<QWheelEvent*> ( inputEvent);
|
||||||
|
@ -104,6 +104,7 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
m_hasMovedMouseDuringNavigation = false;
|
m_hasMovedMouseDuringNavigation = false;
|
||||||
isEventHandled = true;
|
isEventHandled = true;
|
||||||
}
|
}
|
||||||
|
forcePointOfInterestUpdateDuringNextWheelZoom();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEvent::MouseButtonRelease:
|
case QEvent::MouseButtonRelease:
|
||||||
@ -121,6 +122,7 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
forcePointOfInterestUpdateDuringNextWheelZoom();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEvent::MouseMove:
|
case QEvent::MouseMove:
|
||||||
@ -151,11 +153,12 @@ bool caf::CadNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
{
|
{
|
||||||
if (inputEvent->modifiers() == Qt::NoModifier)
|
if (inputEvent->modifiers() == Qt::NoModifier)
|
||||||
{
|
{
|
||||||
initializeRotationCenter();
|
QWheelEvent* we = static_cast<QWheelEvent*>(inputEvent);
|
||||||
|
|
||||||
|
updatePointOfInterestDuringZoomIfNecessary(we->x(), we->y());
|
||||||
|
|
||||||
if (m_isRotCenterInitialized)
|
if (m_isRotCenterInitialized)
|
||||||
{
|
{
|
||||||
QWheelEvent* we = static_cast<QWheelEvent*> ( inputEvent);
|
|
||||||
|
|
||||||
int translatedMousePosX, translatedMousePosY;
|
int translatedMousePosX, translatedMousePosY;
|
||||||
cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY);
|
cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY);
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "cvfRay.h"
|
#include "cvfRay.h"
|
||||||
#include "cvfManipulatorTrackball.h"
|
#include "cvfManipulatorTrackball.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QInputEvent>
|
#include <QInputEvent>
|
||||||
#include "cvfTrace.h"
|
#include "cvfTrace.h"
|
||||||
|
|
||||||
@ -68,6 +69,7 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
{
|
{
|
||||||
if (! inputEvent) return false;
|
if (! inputEvent) return false;
|
||||||
bool isEventHandled = false;
|
bool isEventHandled = false;
|
||||||
|
|
||||||
switch (inputEvent->type())
|
switch (inputEvent->type())
|
||||||
{
|
{
|
||||||
case QEvent::MouseButtonPress:
|
case QEvent::MouseButtonPress:
|
||||||
@ -123,6 +125,7 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
m_isZooming = true;
|
m_isZooming = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
forcePointOfInterestUpdateDuringNextWheelZoom();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEvent::MouseButtonRelease:
|
case QEvent::MouseButtonRelease:
|
||||||
@ -147,6 +150,7 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
m_hasMovedMouseDuringNavigation = false;
|
m_hasMovedMouseDuringNavigation = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
forcePointOfInterestUpdateDuringNextWheelZoom();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QEvent::MouseMove:
|
case QEvent::MouseMove:
|
||||||
@ -186,11 +190,12 @@ bool caf::CeetronPlusNavigation::handleInputEvent(QInputEvent* inputEvent)
|
|||||||
{
|
{
|
||||||
if (inputEvent->modifiers() == Qt::NoModifier)
|
if (inputEvent->modifiers() == Qt::NoModifier)
|
||||||
{
|
{
|
||||||
initializeRotationCenter();
|
QWheelEvent* we = static_cast<QWheelEvent*>(inputEvent);
|
||||||
|
|
||||||
|
updatePointOfInterestDuringZoomIfNecessary(we->x(), we->y());
|
||||||
|
|
||||||
if (m_isRotCenterInitialized)
|
if (m_isRotCenterInitialized)
|
||||||
{
|
{
|
||||||
QWheelEvent* we = static_cast<QWheelEvent*> ( inputEvent);
|
|
||||||
|
|
||||||
int translatedMousePosX, translatedMousePosY;
|
int translatedMousePosX, translatedMousePosY;
|
||||||
cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY);
|
cvfEventPos(we->x(), we->y(), &translatedMousePosX, &translatedMousePosY);
|
||||||
|
|
||||||
|
@ -45,6 +45,7 @@
|
|||||||
#include "cvfRay.h"
|
#include "cvfRay.h"
|
||||||
#include "cvfManipulatorTrackball.h"
|
#include "cvfManipulatorTrackball.h"
|
||||||
|
|
||||||
|
#include <QDebug>
|
||||||
#include <QInputEvent>
|
#include <QInputEvent>
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@ -59,6 +60,8 @@ caf::TrackBallBasedNavigation::TrackBallBasedNavigation() :
|
|||||||
m_isZooming(false),
|
m_isZooming(false),
|
||||||
m_lastPosX(0),
|
m_lastPosX(0),
|
||||||
m_lastPosY(0),
|
m_lastPosY(0),
|
||||||
|
m_lastWheelZoomPosX(-1),
|
||||||
|
m_lastWheelZoomPosY(-1),
|
||||||
m_consumeEvents(false)
|
m_consumeEvents(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -86,6 +89,8 @@ void caf::TrackBallBasedNavigation::init()
|
|||||||
m_isZooming = false;
|
m_isZooming = false;
|
||||||
m_lastPosX = 0;
|
m_lastPosX = 0;
|
||||||
m_lastPosY = 0;
|
m_lastPosY = 0;
|
||||||
|
m_lastWheelZoomPosX = -1;
|
||||||
|
m_lastWheelZoomPosY = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -149,7 +154,39 @@ void caf::TrackBallBasedNavigation::setPointOfInterest(cvf::Vec3d poi)
|
|||||||
m_trackball->setRotationPoint(poi);
|
m_trackball->setRotationPoint(poi);
|
||||||
m_isRotCenterInitialized = true;
|
m_isRotCenterInitialized = true;
|
||||||
m_viewer->updateParallelProjectionCameraPosFromPointOfInterestMove(m_pointOfInterest);
|
m_viewer->updateParallelProjectionCameraPosFromPointOfInterestMove(m_pointOfInterest);
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void caf::TrackBallBasedNavigation::updatePointOfInterestDuringZoomIfNecessary(int zoomX, int zoomY)
|
||||||
|
{
|
||||||
|
bool hitSomething = false;
|
||||||
|
cvf::HitItemCollection hic;
|
||||||
|
if (shouldRaytraceForNewPoiDuringWheelZoom(zoomX, zoomY))
|
||||||
|
{
|
||||||
|
hitSomething = m_viewer->rayPick(zoomX, zoomY, &hic);
|
||||||
|
updateWheelZoomPosition(zoomX, zoomY);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hitSomething)
|
||||||
|
{
|
||||||
|
cvf::Vec3d pointOfInterest = hic.firstItem()->intersectionPoint();
|
||||||
|
this->setPointOfInterest(pointOfInterest);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
initializeRotationCenter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void caf::TrackBallBasedNavigation::forcePointOfInterestUpdateDuringNextWheelZoom()
|
||||||
|
{
|
||||||
|
m_lastWheelZoomPosX = -1;
|
||||||
|
m_lastWheelZoomPosY = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -230,3 +267,33 @@ cvf::ref<cvf::Ray> caf::TrackBallBasedNavigation::createZoomRay(int cvfXPos, int
|
|||||||
|
|
||||||
return ray;
|
return ray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void caf::TrackBallBasedNavigation::updateWheelZoomPosition(int zoomX, int zoomY)
|
||||||
|
{
|
||||||
|
m_lastWheelZoomPosX = zoomX;
|
||||||
|
m_lastWheelZoomPosY = zoomY;
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
bool caf::TrackBallBasedNavigation::shouldRaytraceForNewPoiDuringWheelZoom(int zoomX, int zoomY) const
|
||||||
|
{
|
||||||
|
// Raytrace if the last zoom position isn't set
|
||||||
|
if (m_lastWheelZoomPosX == -1 || m_lastWheelZoomPosY == -1)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int diffX = zoomX - m_lastWheelZoomPosX;
|
||||||
|
int diffY = zoomY - m_lastWheelZoomPosY;
|
||||||
|
|
||||||
|
const int pixelThreshold = 5;
|
||||||
|
if (diffX * diffX + diffY * diffY > pixelThreshold * pixelThreshold)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -37,6 +37,8 @@
|
|||||||
|
|
||||||
#include "cafNavigationPolicy.h"
|
#include "cafNavigationPolicy.h"
|
||||||
|
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
namespace cvf {
|
namespace cvf {
|
||||||
class ManipulatorTrackball;
|
class ManipulatorTrackball;
|
||||||
class Ray;
|
class Ray;
|
||||||
@ -68,6 +70,8 @@ protected:
|
|||||||
virtual void setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection );
|
virtual void setView( const cvf::Vec3d& alongDirection, const cvf::Vec3d& upDirection );
|
||||||
virtual cvf::Vec3d pointOfInterest();
|
virtual cvf::Vec3d pointOfInterest();
|
||||||
virtual void setPointOfInterest(cvf::Vec3d poi);
|
virtual void setPointOfInterest(cvf::Vec3d poi);
|
||||||
|
void updatePointOfInterestDuringZoomIfNecessary(int zoomX, int zoomY);
|
||||||
|
void forcePointOfInterestUpdateDuringNextWheelZoom();
|
||||||
|
|
||||||
// Track ball navigation specific
|
// Track ball navigation specific
|
||||||
void initializeRotationCenter();
|
void initializeRotationCenter();
|
||||||
@ -91,9 +95,15 @@ protected:
|
|||||||
bool isSupposedToConsumeEvents() { return m_consumeEvents; }
|
bool isSupposedToConsumeEvents() { return m_consumeEvents; }
|
||||||
bool isRotationEnabled() { return m_isRotationEnabled; }
|
bool isRotationEnabled() { return m_isRotationEnabled; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateWheelZoomPosition(int zoomX, int zoomY);
|
||||||
|
bool shouldRaytraceForNewPoiDuringWheelZoom(int zoomX, int zoomY) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_consumeEvents;
|
bool m_consumeEvents;
|
||||||
bool m_isRotationEnabled;
|
bool m_isRotationEnabled;
|
||||||
|
int m_lastWheelZoomPosX;
|
||||||
|
int m_lastWheelZoomPosY;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End namespace caf
|
} // End namespace caf
|
||||||
|
Loading…
Reference in New Issue
Block a user