Commit eee9e078 authored by Frédéric Larue's avatar Frédéric Larue

Mouse cursor warping enabled when in grabbing mode.

parent 68fb97f4
......@@ -1639,7 +1639,7 @@ void GLViewer::enterGrabbingMode( bool translation )
m_IsGrabbingRotationEnabled = !translation;
m_GrabbingAxisConstraint = -1;
setCursor( QCursor(Qt::CursorShape::SizeAllCursor) );
m_ClickMousePos = m_PrevMousePos = mapFromGlobal( cursor().pos() );
m_GrabbingInitialCursorPos = mapFromGlobal( cursor().pos() );
setMouseTracking( true );
}
}
......@@ -1678,8 +1678,8 @@ void GLViewer::onGrabbing( QMouseEvent *evt )
if( !isProjectionOrthographic() )
viewScale *= distToFocusPoint();
double dx = viewScale * (evt->pos().x() - m_ClickMousePos.x());
double dy = viewScale * (evt->pos().y() - m_ClickMousePos.y());
double dx = viewScale * (evt->pos().x() - m_GrabbingInitialCursorPos.x());
double dy = viewScale * (evt->pos().y() - m_GrabbingInitialCursorPos.y());
double dt = dx - dy;
if( evt->modifiers() & Qt::ControlModifier )
......@@ -1701,7 +1701,7 @@ void GLViewer::onGrabbing( QMouseEvent *evt )
}
else //if( m_IsGrabbingRotationEnabled )
{
double dt = 0.5*(evt->pos().x() - m_ClickMousePos.x());
double dt = 0.5*(evt->pos().x() - m_GrabbingInitialCursorPos.x());
if( evt->modifiers() & Qt::ControlModifier )
{
......@@ -1734,6 +1734,37 @@ void GLViewer::enterEvent( QEvent* evt )
void GLViewer::leaveEvent( QEvent* evt )
{
if( isGrabbingEnabled() )
{
QPoint winPos = mapToGlobal( pos() );
int curX = cursor().pos().x();
if( curX < winPos.x() )
{
curX += width();
m_GrabbingInitialCursorPos.setX( m_GrabbingInitialCursorPos.x() + width() );
}
else if( curX >= winPos.x()+width() )
{
curX -= width();
m_GrabbingInitialCursorPos.setX( m_GrabbingInitialCursorPos.x() - width() );
}
int curY = cursor().pos().y();
if( curY < winPos.y() )
{
curY += height();
m_GrabbingInitialCursorPos.setY( m_GrabbingInitialCursorPos.y() + height() );
}
else if( curY >= winPos.y()+height() )
{
curY -= height();
m_GrabbingInitialCursorPos.setY( m_GrabbingInitialCursorPos.y() - height() );
}
cursor().setPos( curX, curY );
}
m_IsCursorInside = false;
update();
QOpenGLWidget::leaveEvent( evt );
......
......@@ -227,6 +227,7 @@ protected:
bool m_IsCursorInside;
QPoint m_GrabbingInitialCursorPos;
Box3f m_GrabbingBoundingBox;
bool m_IsGrabbingTranslationEnabled = false;
bool m_IsGrabbingRotationEnabled = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment