Commit c542170d authored by Stéphane Albert's avatar Stéphane Albert

ENH: Dragging ROI in quicklook-view.

parent 97373c2b
......@@ -69,8 +69,8 @@ ImageViewManipulator
::ImageViewManipulator( const otb::ViewSettings::Pointer& viewSettings,
QObject* parent ) :
AbstractImageViewManipulator( parent ),
m_ViewSettings( viewSettings ),
m_MousePressPosition(),
m_ViewSettings( viewSettings ),
m_MousePressOrigin(),
m_RenderMode( AbstractImageViewRenderer::RenderingContext::RENDER_MODE_FULL ),
m_ZoomFactor( 1.0 ),
......@@ -85,8 +85,8 @@ ImageViewManipulator
ImageViewManipulator
::ImageViewManipulator( QObject* parent ) :
AbstractImageViewManipulator( parent ),
m_ViewSettings( otb::ViewSettings::New() ),
m_MousePressPosition(),
m_ViewSettings( otb::ViewSettings::New() ),
m_MousePressOrigin(),
m_RenderMode( AbstractImageViewRenderer::RenderingContext::RENDER_MODE_FULL ),
m_ZoomFactor( 1.0 ),
......@@ -579,13 +579,28 @@ ImageViewManipulator
{
// qDebug() << this << "::Translate(" << vector << ")";
// otb::ViewSettings::PointType origin( m_MousePressOrigin );
otb::ViewSettings::PointType origin( m_ViewSettings->GetOrigin() );
m_ViewSettings->SetOrigin(
ImageViewManipulator::Translate(
vector,
m_ViewSettings->GetOrigin(),
m_ViewSettings->GetSpacing()
)
);
}
/******************************************************************************/
PointType
ImageViewManipulator
::Translate( const QPoint& vector,
const PointType& origin,
const SpacingType& spacing )
{
// qDebug() << this << "::Translate(...)";
otb::ViewSettings::SpacingType spacing( m_ViewSettings->GetSpacing() );
otb::ViewSettings::PointType origin2( origin );
origin[ 0 ] += static_cast< double >( vector.x() ) * spacing[ 0 ];
origin[ 1 ] += static_cast< double >( vector.y() ) * spacing[ 1 ];
origin2[ 0 ] += static_cast< double >( vector.x() ) * spacing[ 0 ];
origin2[ 1 ] += static_cast< double >( vector.y() ) * spacing[ 1 ];
/*
qDebug()
......@@ -594,7 +609,7 @@ ImageViewManipulator
<< "(" << origin[ 0 ] << "," << origin[ 1 ] << ")";
*/
m_ViewSettings->SetOrigin( origin );
return origin2;
}
/******************************************************************************/
......
......@@ -174,10 +174,18 @@ signals:
//
// Protected methods.
protected:
/**
*/
static PointType Translate( const QPoint& vector,
const PointType& origin,
const SpacingType& spacing );
//
// Protected attributes.
protected:
/**
*/
QPoint m_MousePressPosition;
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
......@@ -208,9 +216,6 @@ private:
/**
*/
otb::ViewSettings::Pointer m_ViewSettings;
/**
*/
QPoint m_MousePressPosition;
/**
*/
otb::ViewSettings::PointType m_MousePressOrigin;
......
......@@ -71,10 +71,12 @@ QuicklookViewManipulator
QObject* parent ) :
ImageViewManipulator( viewSettings, parent ),
m_RoiOrigin(),
m_RoiExtent()
m_RoiSpacing(),
m_RoiSize()
{
m_RoiOrigin.Fill( 0 );
m_RoiExtent.Fill( 0 );
m_RoiSpacing.Fill( 0 );
m_RoiSize.Fill( 0 );
}
#else // USE_VIEW_SETTINGS_SIDE_EFFECT
......@@ -83,8 +85,12 @@ QuicklookViewManipulator
::QuicklookViewManipulator( QObject* parent ) :
ImageViewManipulator( parent ),
m_RoiOrigin(),
m_RoiExtent()
m_RoiSpacing(),
m_RoiSize()
{
m_RoiOrigin.Fill( 0 );
m_RoiSpacing.Fill( 0 );
m_RoiSize.Fill( 0 );
}
#endif // USE_VIEW_SETTINGS_SIDE_EFFECT
......@@ -109,7 +115,12 @@ QuicklookViewManipulator
dynamic_cast< QuicklookViewRenderer::RenderingContext * const >( c );
context->m_RoiOrigin = m_RoiOrigin;
context->m_RoiExtent = m_RoiExtent;
context->m_RoiExtent = m_RoiOrigin;
context->m_RoiExtent[ 0 ] +=
static_cast< double >( m_RoiSize[ 0 ] ) * m_RoiSpacing[ 0 ];
context->m_RoiExtent[ 1 ] +=
static_cast< double >( m_RoiSize[ 1 ] ) * m_RoiSpacing[ 1 ];
#if USE_VIEW_SETTINGS_SIDE_EFFECT
#else // USE_VIEW_SETTINGS_SIDE_EFFECT
......@@ -127,6 +138,24 @@ QuicklookViewManipulator
Qt::MouseButtons buttons = event->buttons();
Qt::KeyboardModifiers modifiers = event->modifiers();
if( buttons==Qt::LeftButton && modifiers==Qt::NoModifier )
{
// Cursor moves from press position to current position;
// Image moves the same direction, so apply the negative translation.
m_RoiOrigin =
ImageViewManipulator::Translate(
event->pos() - m_MousePressPosition,
m_RoiOrigin,
m_RoiSpacing
);
m_MousePressPosition = event->pos();
emit RefreshView();
emit RoiChanged( m_RoiOrigin, m_RoiSize, m_RoiSpacing );
}
}
/******************************************************************************/
......@@ -192,11 +221,8 @@ QuicklookViewManipulator
qDebug() << "spacing:" << spacing[ 0 ] << "," << spacing[ 1 ];
m_RoiOrigin = origin;
m_RoiExtent = origin;
m_RoiExtent[ 0 ] += static_cast< double >( size[ 0 ] ) * spacing[ 0 ];
m_RoiExtent[ 1 ] += static_cast< double >( size[ 1 ] ) * spacing[ 1 ];
m_RoiSize = size;
m_RoiSpacing = spacing;
emit RefreshView();
}
......
......@@ -159,7 +159,10 @@ private:
PointType m_RoiOrigin;
/**
*/
PointType m_RoiExtent;
SpacingType m_RoiSpacing;
/**
*/
SizeType m_RoiSize;
/*-[ PRIVATE SLOTS SECTION ]-----------------------------------------------*/
......
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