From 02b2bfac437e6768fe45024962cdf44bf54c00e7 Mon Sep 17 00:00:00 2001 From: Luis Lucas Date: Sun, 6 Apr 2014 01:08:35 +0100 Subject: [PATCH] Fix minor bugs related to zoom functions. Zoom relative to mouse position can now be performed without strange jumps on image. --- source/app/SubWindowHandle.cpp | 32 +++++++++++++++++++++++--------- source/app/SubWindowHandle.h | 4 ++-- source/app/plaYUVerApp.cpp | 2 +- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/source/app/SubWindowHandle.cpp b/source/app/SubWindowHandle.cpp index e15e061..5adec30 100644 --- a/source/app/SubWindowHandle.cpp +++ b/source/app/SubWindowHandle.cpp @@ -42,9 +42,11 @@ SubWindowHandle::SubWindowHandle( QWidget * parent ) : setWidget( m_cScrollArea ); // Create a new interface to show images - m_cViewArea = new ViewArea( this ); + m_cViewArea = new ViewArea( m_cScrollArea ); connect( m_cViewArea, SIGNAL( zoomFactorChanged( double , QPoint) ), this, SLOT( adjustScrollBarByZoom(double, QPoint) ) ); connect( m_cViewArea, SIGNAL( moveScroll( QPoint ) ), this, SLOT( adjustScrollBarByOffset(QPoint) ) ); + connect( m_cScrollArea->horizontalScrollBar() , SIGNAL( actionTriggered( int ) ), this, SLOT ( updateLastScrollValue() ) ); + connect( m_cScrollArea->verticalScrollBar() , SIGNAL( actionTriggered( int ) ), this, SLOT ( updateLastScrollValue() ) ); // Define the cViewArea as the widget inside the scroll area m_cScrollArea->setWidget( m_cViewArea ); @@ -232,6 +234,7 @@ Void SubWindowHandle::normalSize() { Double scaleFactor = 1.0; m_cViewArea->setZoomFactor( scaleFactor ); + updateLastScrollValue(); } Void SubWindowHandle::zoomToFit() @@ -241,16 +244,11 @@ Void SubWindowHandle::zoomToFit() scaleView( niceFit ); } -Void SubWindowHandle::scaleViewFactor( Double factor ) -{ - Q_ASSERT( m_cViewArea->image() ); - m_cViewArea->zoomChangeEvent( factor , QPoint() ); -} - Void SubWindowHandle::scaleView( Double scale ) { Q_ASSERT( m_cViewArea->image() ); m_cViewArea->setZoomFactor( scale ); + updateLastScrollValue(); } Void SubWindowHandle::scaleView( Int width, Int height ) @@ -277,6 +275,12 @@ Void SubWindowHandle::scaleView( const QSize & size ) scaleView( hfactor ); } +Void SubWindowHandle::scaleViewByRatio( Double ratio ) +{ + Q_ASSERT( m_cViewArea->image() ); + m_cViewArea->zoomChangeEvent( ratio , QPoint() ); +} + void SubWindowHandle::adjustScrollBarByOffset( QPoint Offset ) { QScrollBar *scrollBar = m_cScrollArea->horizontalScrollBar(); @@ -285,6 +289,8 @@ void SubWindowHandle::adjustScrollBarByOffset( QPoint Offset ) scrollBar = m_cScrollArea->verticalScrollBar(); scrollBar->setValue( int( scrollBar->value() + Offset.y() ) ); m_cLastScroll.setY( scrollBar->value() ); + + updateLastScrollValue(); } // This function was developed with help of the schematics presented in @@ -305,7 +311,6 @@ void SubWindowHandle::adjustScrollBarByZoom( double factor , QPoint center ) if ( value < scrollBar->minimum() ) value = scrollBar->minimum(); scrollBar->setValue( value ); - m_cLastScroll.setX( value ); } scrollBar = m_cScrollArea->verticalScrollBar(); @@ -322,8 +327,17 @@ void SubWindowHandle::adjustScrollBarByZoom( double factor , QPoint center ) if ( value < scrollBar->minimum() ) value = scrollBar->minimum(); scrollBar->setValue( value ); - m_cLastScroll.setY( value ); } + + updateLastScrollValue(); +} + +void SubWindowHandle::updateLastScrollValue( ) +{ + QScrollBar *scrollBar = m_cScrollArea->horizontalScrollBar(); + m_cLastScroll.setX( scrollBar->value() ); + scrollBar = m_cScrollArea->verticalScrollBar(); + m_cLastScroll.setY( scrollBar->value() ); } diff --git a/source/app/SubWindowHandle.h b/source/app/SubWindowHandle.h index 4a13ced..c231ec9 100644 --- a/source/app/SubWindowHandle.h +++ b/source/app/SubWindowHandle.h @@ -131,8 +131,7 @@ public: */ Void scaleView( const QSize & size ); - Void scaleViewFactor( Double factor ); - + Void scaleViewByRatio( Double ratio ); Double getScaleFactor() { return m_cViewArea->getZoomFactor(); @@ -156,6 +155,7 @@ protected: public Q_SLOTS: void adjustScrollBarByZoom( double factor , QPoint center ); void adjustScrollBarByOffset( QPoint Offset ); + void updateLastScrollValue( ); }; } // NAMESPACE diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index e38cc28..8c2e667 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -438,7 +438,7 @@ void plaYUVerApp::scaleFrame( int ratio ) { if( activeSubWindow() ) { - activeSubWindow()->scaleViewFactor( ( Double )( ratio ) / 100.0 ); + activeSubWindow()->scaleViewByRatio( ( Double )( ratio ) / 100.0 ); // actionZoomIn->setEnabled( activeSubWindow()->getScaleFactor() < 3.0 ); // actionZoomOut->setEnabled( activeSubWindow()->getScaleFactor() > 0.333 );