diff --git a/app/SubWindowHandle.cpp b/app/SubWindowHandle.cpp index 12279ea..750f169 100644 --- a/app/SubWindowHandle.cpp +++ b/app/SubWindowHandle.cpp @@ -30,14 +30,104 @@ namespace plaYUVer SubWindowHandle::SubWindowHandle( QWidget * parent, UInt category ) : QMdiSubWindow( parent ) { + setParent( parent ); + setAttribute( Qt::WA_DeleteOnClose ); + setBackgroundRole( QPalette::Light ); + + // Create a new scroll area inside the sub-window + m_cScrollArea = new QScrollArea( this ); + connect( m_cScrollArea->horizontalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateLastScrollValue() ) ); + connect( m_cScrollArea->verticalScrollBar(), SIGNAL( actionTriggered( int ) ), this, SLOT( updateLastScrollValue() ) ); + + setWidget( m_cScrollArea ); + m_cScrollArea->setWidgetResizable( true ); + + m_cLastScroll = QPoint(); + m_uiCategory = category; m_cWindowName = QString( " " ); } SubWindowHandle::~SubWindowHandle() { + delete m_cScrollArea; } +Void SubWindowHandle::setMainWidget( QWidget *widget ) +{ + m_cScrollArea->setWidget( widget ); +} + +Void SubWindowHandle::processZoomChanged( Double factor, QPoint center ) +{ + adjustScrollBarByZoom( factor, center ); + emit zoomChanged(); +} + +QSize SubWindowHandle::getScrollSize() +{ + return QSize( m_cScrollArea->viewport()->size().width() - 5, m_cScrollArea->viewport()->size().height() - 5 ); +} + +Void SubWindowHandle::adjustScrollBarByOffset( QPoint Offset ) +{ + QScrollBar *scrollBar = m_cScrollArea->horizontalScrollBar(); + scrollBar->setValue( int( scrollBar->value() + Offset.x() ) ); + m_cLastScroll.setX( scrollBar->value() ); + 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 +// http://stackoverflow.com/questions/13155382/jscrollpane-zoom-relative-to-mouse-position +Void SubWindowHandle::adjustScrollBarByZoom( Double factor, QPoint center ) +{ + QScrollBar *scrollBar = m_cScrollArea->horizontalScrollBar(); + if( center.isNull() ) + { + scrollBar->setValue( int( factor * scrollBar->value() + ( ( factor - 1 ) * scrollBar->pageStep() / 2 ) ) ); + } + else + { + Int x = center.x() - m_cLastScroll.x(); + Int value = int( factor * m_cLastScroll.x() + ( ( factor - 1 ) * x ) ); + if( value > scrollBar->maximum() ) + value = scrollBar->maximum(); + if( value < scrollBar->minimum() ) + value = scrollBar->minimum(); + scrollBar->setValue( value ); + } + + scrollBar = m_cScrollArea->verticalScrollBar(); + if( center.isNull() ) + { + scrollBar->setValue( int( factor * scrollBar->value() + ( ( factor - 1 ) * scrollBar->pageStep() / 2 ) ) ); + } + else + { + Int y = center.y() - m_cLastScroll.y(); + Int value = int( factor * m_cLastScroll.y() + ( ( factor - 1 ) * y ) ); + if( value > scrollBar->maximum() ) + value = scrollBar->maximum(); + if( value < scrollBar->minimum() ) + value = scrollBar->minimum(); + scrollBar->setValue( value ); + } + + updateLastScrollValue(); +} + +Void SubWindowHandle::updateLastScrollValue() +{ + QScrollBar *scrollBar = m_cScrollArea->horizontalScrollBar(); + m_cLastScroll.setX( scrollBar->value() ); + scrollBar = m_cScrollArea->verticalScrollBar(); + m_cLastScroll.setY( scrollBar->value() ); +} + + Void SubWindowHandle::setWindowName( QString name ) { m_cWindowName = name; diff --git a/app/SubWindowHandle.h b/app/SubWindowHandle.h index 64596bf..7d8beff 100644 --- a/app/SubWindowHandle.h +++ b/app/SubWindowHandle.h @@ -41,9 +41,14 @@ class SubWindowHandle: public QMdiSubWindow Q_OBJECT private: + QScrollArea* m_cScrollArea; + QPoint m_cLastScroll; + UInt m_uiCategory; QString m_cWindowName; + Void adjustScrollBarByZoom( Double factor, QPoint center ); + public: enum SubWindowCategories { @@ -84,11 +89,18 @@ public: protected: virtual void closeEvent( QCloseEvent *event ) = 0; + virtual Void setMainWidget( QWidget *widget ); + QSize getScrollSize(); Q_SIGNALS: void zoomChanged(); void updateStatusBar( const QString& ); +public Q_SLOTS: + void processZoomChanged( double factor, QPoint center ); + void adjustScrollBarByOffset( QPoint Offset ); + void updateLastScrollValue(); + }; } // NAMESPACE diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index 7641cb5..3b6eeb6 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -38,9 +38,9 @@ QDataStream& operator<<( QDataStream& out, const PlaYUVerStreamInfoVector& array { d = array.at( i ); out << d.m_cFilename << d.m_uiWidth - << d.m_uiHeight - << d.m_iPelFormat - << d.m_uiFrameRate; + << d.m_uiHeight + << d.m_iPelFormat + << d.m_uiFrameRate; } return out; @@ -72,47 +72,34 @@ Int findPlaYUVerStreamInfo( PlaYUVerStreamInfoVector array, QString filename ) } VideoSubWindow::VideoSubWindow( QWidget * parent, Bool isModule ) : - SubWindowHandle( parent, SubWindowHandle::VIDEO_SUBWINDOW ), - m_pCurrStream( NULL ), - m_pcCurrFrame( NULL ), - m_pcReferenceSubWindow( NULL ), - m_bIsPlaying( false ), - m_bIsModule( isModule ) + SubWindowHandle( parent, SubWindowHandle::VIDEO_SUBWINDOW ), + m_pCurrStream( NULL ), + m_pcCurrFrame( NULL ), + m_pcReferenceSubWindow( NULL ), + m_bIsPlaying( false ), + m_bIsModule( isModule ) { - setParent( parent ); - - setAttribute( Qt::WA_DeleteOnClose ); - setBackgroundRole( QPalette::Light ); setVisible( false ); - // Create a new scroll area inside the sub-window - m_cScrollArea = new QScrollArea( this ); - 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 , QPoint) ), this, SLOT( processZoomChanged(double, QPoint) ) ); - connect( m_cViewArea, SIGNAL( moveScroll( QPoint ) ), this, SLOT( adjustScrollBarByOffset(QPoint) ) ); + connect( m_cViewArea, SIGNAL( selectionChanged( QRect ) ), this, SLOT( updateSelectedArea( QRect ) ) ); connect( m_cViewArea, SIGNAL( positionChanged( const QPoint & ) ), this, SLOT( updatePixelValueStatusBar( const 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 ); - m_cScrollArea->setWidgetResizable( true ); + // Define the cViewArea as the widget inside the scroll area + setMainWidget( m_cViewArea ); m_apcCurrentModule.clear(); - m_cLastScroll = QPoint(); } VideoSubWindow::~VideoSubWindow() { disableModule(); delete m_cViewArea; - delete m_cScrollArea; if( m_pCurrStream ) delete m_pCurrStream; } @@ -248,12 +235,6 @@ Void VideoSubWindow::setCurrFrame( PlaYUVerFrame* pcCurrFrame ) { m_pcCurrFrame = pcCurrFrame; m_cViewArea->setImage( m_pcCurrFrame ); -// if( !isVisible() ) -// { -// show(); -// resize( sizeHint() ); -// zoomToFit(); -// } } Void VideoSubWindow::refreshFrame() @@ -365,9 +346,8 @@ Void VideoSubWindow::normalSize() Void VideoSubWindow::zoomToFit() { -// Scale to a smaller size that the real to a nicer look - QSize niceFit( m_cScrollArea->viewport()->size().width() - 5, m_cScrollArea->viewport()->size().height() - 5 ); - scaleView( niceFit ); + // Scale to a smaller size that the real to a nicer look + scaleView( getScrollSize() ); } Void VideoSubWindow::scaleView( Double scale ) @@ -386,7 +366,7 @@ Void VideoSubWindow::scaleView( const QSize & size ) QSize newSize = imgViewSize; newSize.scale( size, Qt::KeepAspectRatio ); -// Calc the zoom factor + // Calc the zoom factor Double wfactor = 1; Double hfactor = 1; @@ -401,70 +381,7 @@ Void VideoSubWindow::scaleView( const QSize & size ) updateLastScrollValue(); } -Void VideoSubWindow::processZoomChanged( Double factor, QPoint center ) -{ - adjustScrollBarByZoom( factor, center ); - emit zoomChanged(); -} -void VideoSubWindow::adjustScrollBarByOffset( QPoint Offset ) -{ - QScrollBar *scrollBar = m_cScrollArea->horizontalScrollBar(); - scrollBar->setValue( int( scrollBar->value() + Offset.x() ) ); - m_cLastScroll.setX( scrollBar->value() ); - 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 -// http://stackoverflow.com/questions/13155382/jscrollpane-zoom-relative-to-mouse-position -Void VideoSubWindow::adjustScrollBarByZoom( Double factor, QPoint center ) -{ - QScrollBar *scrollBar = m_cScrollArea->horizontalScrollBar(); - if( center.isNull() ) - { - scrollBar->setValue( int( factor * scrollBar->value() + ( ( factor - 1 ) * scrollBar->pageStep() / 2 ) ) ); - } - else - { - Int x = center.x() - m_cLastScroll.x(); - Int value = int( factor * m_cLastScroll.x() + ( ( factor - 1 ) * x ) ); - if( value > scrollBar->maximum() ) - value = scrollBar->maximum(); - if( value < scrollBar->minimum() ) - value = scrollBar->minimum(); - scrollBar->setValue( value ); - } - - scrollBar = m_cScrollArea->verticalScrollBar(); - if( center.isNull() ) - { - scrollBar->setValue( int( factor * scrollBar->value() + ( ( factor - 1 ) * scrollBar->pageStep() / 2 ) ) ); - } - else - { - Int y = center.y() - m_cLastScroll.y(); - Int value = int( factor * m_cLastScroll.y() + ( ( factor - 1 ) * y ) ); - if( value > scrollBar->maximum() ) - value = scrollBar->maximum(); - if( value < scrollBar->minimum() ) - value = scrollBar->minimum(); - scrollBar->setValue( value ); - } - - updateLastScrollValue(); -} - -void VideoSubWindow::updateLastScrollValue() -{ - QScrollBar *scrollBar = m_cScrollArea->horizontalScrollBar(); - m_cLastScroll.setX( scrollBar->value() ); - scrollBar = m_cScrollArea->verticalScrollBar(); - m_cLastScroll.setY( scrollBar->value() ); -} Void VideoSubWindow::updatePixelValueStatusBar( const QPoint& pos ) { @@ -505,10 +422,11 @@ Void VideoSubWindow::updatePixelValueStatusBar( const QPoint& pos ) } } + QSize VideoSubWindow::sizeHint() const { QSize maxSize; // The size of the parent (viewport widget -// of the QMdiArea). + // of the QMdiArea). QWidget *p = parentWidget(); if( p ) @@ -522,8 +440,8 @@ QSize VideoSubWindow::sizeHint() const else if( m_pCurrStream ) isize = QSize( m_pCurrStream->getWidth() + 50, m_pCurrStream->getHeight() + 50 ); -// If the VideoSubWindow needs more space that the avaiable, we'll give -// to the subwindow a reasonable size preserving the image aspect ratio. + // If the VideoSubWindow needs more space that the avaiable, we'll give + // to the subwindow a reasonable size preserving the image aspect ratio. if( isize.width() < maxSize.width() && isize.height() < maxSize.height() ) { return isize; diff --git a/app/VideoSubWindow.h b/app/VideoSubWindow.h index 59e1b13..9d9504c 100644 --- a/app/VideoSubWindow.h +++ b/app/VideoSubWindow.h @@ -62,7 +62,6 @@ Q_OBJECT private: - QScrollArea* m_cScrollArea; ViewArea* m_cViewArea; PlaYUVerStreamInfo m_sStreamInfo; @@ -83,7 +82,13 @@ private: Bool m_bIsPlaying; Bool m_bIsModule; - QPoint m_cLastScroll; + + + /** + * Private zoom function to handle + * zoom to fit + */ + Void scaleView( const QSize & size ); public: VideoSubWindow( QWidget * parent = 0, Bool isModule = false ); @@ -168,8 +173,6 @@ public: return m_cViewArea->getZoomFactor(); } - Void adjustScrollBarByZoom( Double factor, QPoint center ); - QSize sizeHint() const; Void setWindowShortName( const QString& name) @@ -190,22 +193,11 @@ public: return m_bIsModule; } -private: - - /** - * Private zoom function to handle - * zoom to fit - */ - Void scaleView( const QSize & size ); - protected: void closeEvent( QCloseEvent *event ); public Q_SLOTS: void updateSelectedArea( QRect area ); - void processZoomChanged( double , QPoint ); - void adjustScrollBarByOffset( QPoint Offset ); - void updateLastScrollValue(); void updatePixelValueStatusBar( const QPoint& ); };