Rewrite some zoom functions. Zoom is done in the middle of the image.
This commit is contained in:
@@ -41,7 +41,8 @@ SubWindowHandle::SubWindowHandle( QWidget * parent ) :
|
||||
setWidget( m_cScrollArea );
|
||||
|
||||
// Create a new interface to show images
|
||||
m_cViewArea = new ViewArea( m_cScrollArea );
|
||||
m_cViewArea = new ViewArea( this );
|
||||
connect(m_cViewArea, SIGNAL(zoomFactorChanged(double)), this, SLOT(adjustScrollBar(double)));
|
||||
|
||||
// Define the cViewArea as the widget inside the scroll area
|
||||
m_cScrollArea->setWidget( m_cViewArea );
|
||||
@@ -262,10 +263,7 @@ Void SubWindowHandle::zoomToFit()
|
||||
Void SubWindowHandle::scaleView( Double factor )
|
||||
{
|
||||
Q_ASSERT( m_cViewArea->image() );
|
||||
Double scaleFactor = m_cViewArea->getZoomFactor();
|
||||
scaleFactor *= factor;
|
||||
m_cViewArea->setZoomFactor( scaleFactor );
|
||||
adjustScrollBar( scaleFactor );
|
||||
m_cViewArea->zoomChangeEvent(factor);
|
||||
}
|
||||
|
||||
Void SubWindowHandle::scaleView( Int width, Int height )
|
||||
@@ -292,7 +290,7 @@ Void SubWindowHandle::scaleView( const QSize & size )
|
||||
scaleView( hfactor );
|
||||
}
|
||||
|
||||
Void SubWindowHandle::adjustScrollBar( Double factor )
|
||||
void SubWindowHandle::adjustScrollBar( double factor )
|
||||
{
|
||||
QScrollBar *scrollBar = m_cScrollArea->horizontalScrollBar();
|
||||
scrollBar->setValue( int( factor * scrollBar->value() + ( ( factor - 1 ) * scrollBar->pageStep() / 2 ) ) );
|
||||
|
||||
@@ -59,6 +59,9 @@ private:
|
||||
|
||||
Bool m_bIsPlaying;
|
||||
|
||||
private slots:
|
||||
void adjustScrollBar( double factor );
|
||||
|
||||
public:
|
||||
SubWindowHandle( QWidget * parent = 0 );
|
||||
~SubWindowHandle();
|
||||
@@ -118,8 +121,6 @@ public:
|
||||
*/
|
||||
Void scaleView( const QSize & size );
|
||||
|
||||
Void adjustScrollBar( Double factor );
|
||||
|
||||
Double getScaleFactor()
|
||||
{
|
||||
return m_cViewArea->getZoomFactor();
|
||||
@@ -145,6 +146,7 @@ protected:
|
||||
|
||||
public Q_SLOTS:
|
||||
bool playEvent();
|
||||
|
||||
};
|
||||
|
||||
} // NAMESPACE
|
||||
|
||||
+32
-14
@@ -104,19 +104,34 @@ Double ViewArea::getZoomFactor()
|
||||
// return QSize( w, h );
|
||||
// }
|
||||
|
||||
Void ViewArea::zoomChangeEvent(Double factor)
|
||||
{
|
||||
Double zoomFactor;
|
||||
Double maxZoom = 10.0;
|
||||
Double minZoom = ( 32.0 / m_pixmap.width() );
|
||||
|
||||
if( ( m_zoomFactor == minZoom ) && (factor < 1 ) )
|
||||
return;
|
||||
|
||||
if( ( m_zoomFactor == maxZoom ) && (factor > 1 ) )
|
||||
return;
|
||||
|
||||
zoomFactor = m_zoomFactor * factor;
|
||||
|
||||
if( zoomFactor < minZoom )
|
||||
zoomFactor = minZoom;
|
||||
|
||||
if( zoomFactor > maxZoom )
|
||||
zoomFactor = maxZoom;
|
||||
|
||||
setZoomFactor( zoomFactor );
|
||||
emit zoomFactorChanged(factor);
|
||||
|
||||
}
|
||||
|
||||
void ViewArea::setZoomFactor( double f )
|
||||
{
|
||||
//if( f == m_zoomFactor )
|
||||
//return;
|
||||
|
||||
if( f < ( 32.0 / m_pixmap.width() ) )
|
||||
f = 32.0 / m_pixmap.width();
|
||||
|
||||
if( f > 10.0 )
|
||||
f = 10.0;
|
||||
|
||||
m_zoomFactor = f;
|
||||
//emit( zoomFactorChanged( m_zoomFactor ) );
|
||||
|
||||
updateSize();
|
||||
update();
|
||||
@@ -432,12 +447,15 @@ void ViewArea::paintEvent( QPaintEvent *event )
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void ViewArea::wheelEvent( QWheelEvent *event )
|
||||
{
|
||||
double f;
|
||||
Double factor;
|
||||
|
||||
f = m_zoomFactor + 0.001 * event->delta();
|
||||
|
||||
setZoomFactor( f );
|
||||
factor = 0.001 * event->delta();
|
||||
if(factor>0)
|
||||
factor=1.25;
|
||||
else
|
||||
factor=0.8;
|
||||
|
||||
zoomChangeEvent( factor );
|
||||
}
|
||||
|
||||
void ViewArea::mousePressEvent( QMouseEvent *event )
|
||||
|
||||
@@ -105,6 +105,7 @@ public:
|
||||
void setInputStream( InputStream *stream );
|
||||
InputStream* getInputStream();
|
||||
|
||||
Void zoomChangeEvent(Double factor);
|
||||
Double getZoomFactor();
|
||||
|
||||
// QSize sizeHint() const;
|
||||
|
||||
Reference in New Issue
Block a user