From 6cce56879196379cf66f982f07747ad25e523699 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 30 Jan 2018 05:30:04 +0000 Subject: [PATCH] Change zoom lock inner works Now zoom is locked based on the ratio of the position of the scroll bar --- app/PlaYUVerApp.cpp | 13 +--- app/PlaYUVerSubWindowHandle.cpp | 3 +- app/SubWindowAbstract.h | 4 +- app/VideoHandle.cpp | 53 ++++++++++++--- app/VideoHandle.h | 2 +- app/VideoSubWindow.cpp | 116 +++++++++++++++----------------- app/VideoSubWindow.h | 8 ++- 7 files changed, 110 insertions(+), 89 deletions(-) diff --git a/app/PlaYUVerApp.cpp b/app/PlaYUVerApp.cpp index 296a2aa..9b65ff9 100644 --- a/app/PlaYUVerApp.cpp +++ b/app/PlaYUVerApp.cpp @@ -197,7 +197,6 @@ Void PlaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo ) return; } videoSubWindow = new VideoSubWindow( VideoSubWindow::VIDEO_STREAM_SUBWINDOW ); // createSubWindow(); - SubWindowAbstract* subWindow = videoSubWindow; if( !pStreamInfo ) { Int idx = findPlaYUVerStreamInfo( m_aRecentFileStreamInfo, fileName ); @@ -219,18 +218,10 @@ Void PlaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo ) m_pcWindowHandle->addSubWindow( videoSubWindow ); videoSubWindow->show(); - connect( subWindow, SIGNAL( aboutToClose( SubWindowAbstract* ) ), m_appModuleVideo, - SLOT( closeSubWindow( SubWindowAbstract* ) ) ); - connect( subWindow, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), m_appModuleVideo, - SLOT( zoomToFactorAll( double, QPoint ) ) ); - connect( subWindow, SIGNAL( scrollBarMoved_SWindow( const QPoint ) ), m_appModuleVideo, - SLOT( moveAllScrollBars( const QPoint ) ) ); - - videoSubWindow->zoomToFit(); - updateZoomFactorSBox(); - m_appModuleVideo->openSubWindow( videoSubWindow ); + updateZoomFactorSBox(); + addStreamInfoToRecentList( videoSubWindow->getStreamInfo() ); printMessage( "File loaded", LOG_INFO ); diff --git a/app/PlaYUVerSubWindowHandle.cpp b/app/PlaYUVerSubWindowHandle.cpp index fbeac2d..a4d9f87 100644 --- a/app/PlaYUVerSubWindowHandle.cpp +++ b/app/PlaYUVerSubWindowHandle.cpp @@ -234,8 +234,7 @@ Void PlaYUVerSubWindowHandle::addSubWindow( SubWindowAbstract* window, Qt::Windo if( window ) { connect( window, SIGNAL( updateStatusBar( const QString& ) ), m_pcApp, SLOT( printMessage( const QString& ) ) ); - connect( window, SIGNAL( zoomFactorChanged_SWindow( const double, const QPoint ) ), m_pcApp, - SLOT( updateZoomFactorSBox() ) ); + connect( window, SIGNAL( zoomFactorChanged( const double, const QPoint ) ), m_pcApp, SLOT( updateZoomFactorSBox() ) ); if( m_iWindowMode == DETACHEDSUBWINDOWMODE ) { connect( window, SIGNAL( aboutToActivate( SubWindowAbstract* ) ), this, diff --git a/app/SubWindowAbstract.h b/app/SubWindowAbstract.h index 342530a..4c5023b 100644 --- a/app/SubWindowAbstract.h +++ b/app/SubWindowAbstract.h @@ -144,12 +144,12 @@ Q_SIGNALS: /** * Notify that zoom factor was changed by internal event (e.g. by mouse wheel) */ - void zoomFactorChanged_SWindow( const double, const QPoint ); + void zoomFactorChanged( const double, const QPoint ); /** * Notify that scrollbar position was changed by internal event (e.g. by mouse * panning ) */ - void scrollBarMoved_SWindow( const QPoint ); + void scrollBarMoved( const double&, const double& ); /** * Update stauts bars */ diff --git a/app/VideoHandle.cpp b/app/VideoHandle.cpp index 5bd4a75..37d4026 100644 --- a/app/VideoHandle.cpp +++ b/app/VideoHandle.cpp @@ -252,9 +252,7 @@ Void VideoHandle::updateMenus() m_arrayActions[STOP_ACT]->setEnabled( hasSubWindow ); m_arrayActions[VIDEO_BACKWARD_ACT]->setEnabled( hasSubWindow ); m_arrayActions[VIDEO_FORWARD_ACT]->setEnabled( hasSubWindow ); - m_arrayActions[VIDEO_REPEAT_ACT]->setEnabled( hasSubWindow ); m_arrayActions[VIDEO_GOTO_ACT]->setEnabled( hasSubWindow ); - m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->setEnabled( hasSubWindow ); m_arrayActions[VIDEO_LOCK_SELECTION_ACT]->setEnabled( hasSubWindow ); m_pcFrameSlider->setEnabled( hasSubWindow ); if( !hasSubWindow ) @@ -345,10 +343,9 @@ Void VideoHandle::update() m_pcFrameNumInfo->setCurrFrameNum( frame_num ); - - m_pcFrameSlider->blockSignals( true ); // Disable signals otherwise it will loop this function + m_pcFrameSlider->blockSignals( true ); // Disable signals otherwise it will loop this function m_pcFrameSlider->setValue( frame_num ); - m_pcFrameSlider->blockSignals( false ); + m_pcFrameSlider->blockSignals( false ); if( m_pcCurrentVideoSubWindow->isPlaying() ) { @@ -385,11 +382,25 @@ Void VideoHandle::updateSelectionArea( QRect area ) } } -Void VideoHandle::openSubWindow( VideoSubWindow* subWindow ) +Void VideoHandle::openSubWindow( VideoSubWindow* window ) { - connect( subWindow->getViewArea(), SIGNAL( selectionChanged( QRect ) ), this, SLOT( updateSelectionArea( QRect ) ) ); - subWindow->getViewArea()->setTool( m_uiViewTool ); - subWindow->getViewArea()->setGridVisible( m_arrayActions[SHOW_GRID_ACT]->isChecked() ); + window->zoomToFit(); + window->getViewArea()->setTool( m_uiViewTool ); + window->getViewArea()->setGridVisible( m_arrayActions[SHOW_GRID_ACT]->isChecked() ); + + connect( window, &SubWindowAbstract::aboutToClose, + this, &VideoHandle::closeSubWindow ); + + connect( window, &SubWindowAbstract::zoomFactorChanged, + this, &VideoHandle::zoomToFactorAll ); + + connect( window, &SubWindowAbstract::scrollBarMoved, + this, &VideoHandle::moveAllScrollBars ); + + //connect( window, SIGNAL( aboutToClose( SubWindowAbstract* ) ), this, SLOT( closeSubWindow( SubWindowAbstract* ) ) ); + //connect( window, SIGNAL( zoomFactorChanged( const double, const QPoint ) ), this, SLOT( zoomToFactorAll( double, QPoint ) ) ); + //connect( window, SIGNAL( scrollBarMoved( const QPoint ) ), this, SLOT( moveAllScrollBars( const QPoint ) ) ); + connect( window->getViewArea(), SIGNAL( selectionChanged( QRect ) ), this, SLOT( updateSelectionArea( QRect ) ) ); } Void VideoHandle::closeSubWindow( SubWindowAbstract* subWindow ) @@ -432,7 +443,8 @@ Void VideoHandle::zoomToFactorAll( const Double scale, const QPoint center ) } } -Void VideoHandle::moveAllScrollBars( const QPoint offset ) +#if 0 +Void VideoHandle::moveAllScrollBars( const QPoint& offset ) { QPoint newOffset = offset; if( m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->isChecked() && m_pcCurrentVideoSubWindow ) @@ -469,6 +481,27 @@ Void VideoHandle::moveAllScrollBars( const QPoint offset ) } } } +#else +Void VideoHandle::moveAllScrollBars( const double& horRatio, const double& verRatio ) +{ + if( m_arrayActions[VIDEO_ZOOM_LOCK_ACT]->isChecked() && m_pcCurrentVideoSubWindow ) + { + VideoSubWindow* videoSubWindow; + QList subWindowList = m_pcMainWindowManager->findSubWindow( SubWindowAbstract::VIDEO_SUBWINDOW ); + + for( Int i = 0; i < subWindowList.size(); i++ ) + { + videoSubWindow = qobject_cast( subWindowList.at( i ) ); + if( m_pcCurrentVideoSubWindow == videoSubWindow ) + continue; + else + { + videoSubWindow->adjustScrollBarToRatio( horRatio, verRatio ); + } + } + } +} +#endif UInt64 VideoHandle::getMaxFrameNumber() { diff --git a/app/VideoHandle.h b/app/VideoHandle.h index 1b74471..82beeff 100644 --- a/app/VideoHandle.h +++ b/app/VideoHandle.h @@ -135,7 +135,7 @@ private Q_SLOTS: void updateSelectionArea( QRect area ); void closeSubWindow( SubWindowAbstract* subWindow ); void zoomToFactorAll( const double factor, const QPoint center = QPoint() ); - void moveAllScrollBars( const QPoint offset ); + void moveAllScrollBars( const double&, const double& ); void play(); void stop(); void playEvent(); diff --git a/app/VideoSubWindow.cpp b/app/VideoSubWindow.cpp index 0bd97b2..f7a9937 100644 --- a/app/VideoSubWindow.cpp +++ b/app/VideoSubWindow.cpp @@ -143,19 +143,20 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* // Create a new scroll area inside the sub-window m_pcScrollArea = new QScrollArea; connect( m_pcScrollArea->horizontalScrollBar(), SIGNAL( actionTriggered( int ) ), this, - SLOT( updateCurScrollValues() ) ); + SLOT( updateScrollValues() ) ); connect( m_pcScrollArea->verticalScrollBar(), SIGNAL( actionTriggered( int ) ), this, - SLOT( updateCurScrollValues() ) ); + SLOT( updateScrollValues() ) ); // Create a new interface to show images m_cViewArea = new ViewArea; connect( m_cViewArea, SIGNAL( zoomFactorChanged_byWheel( double, QPoint ) ), this, SLOT( adjustScrollBarByScale( double, QPoint ) ) ); + connect( m_cViewArea, SIGNAL( zoomFactorChanged_byWheel( double, QPoint ) ), this, - SIGNAL( zoomFactorChanged_SWindow( double, QPoint ) ) ); + SIGNAL( zoomFactorChanged( double, QPoint ) ) ); connect( m_cViewArea, SIGNAL( scrollBarMoved( QPoint ) ), this, SLOT( adjustScrollBarByOffset( QPoint ) ) ); - connect( m_cViewArea, SIGNAL( scrollBarMoved( QPoint ) ), this, SIGNAL( scrollBarMoved_SWindow( QPoint ) ) ); + //connect( m_cViewArea, SIGNAL( scrollBarMoved( QPoint ) ), this, SIGNAL( scrollBarMoved( QPoint ) ) ); connect( m_cViewArea, SIGNAL( selectionChanged( QRect ) ), this, SLOT( updateSelectedArea( QRect ) ) ); connect( m_cViewArea, SIGNAL( positionChanged( const QPoint& ) ), this, @@ -167,11 +168,8 @@ VideoSubWindow::VideoSubWindow( enum VideoSubWindowCategories category, QWidget* // Define the cViewArea as the widget inside the scroll area m_pcScrollArea->setWidget( m_cViewArea ); m_pcScrollArea->setWidgetResizable( true ); - setWidget( m_pcScrollArea ); - m_cLastScroll = QPoint(); - m_apcCurrentModule.clear(); m_pcUpdateTimer = new QTimer(); @@ -801,32 +799,30 @@ QSize VideoSubWindow::getScrollSize() return QSize( m_pcScrollArea->viewport()->size().width() - 5, m_pcScrollArea->viewport()->size().height() - 5 ); } +Void VideoSubWindow::adjustScrollBarToRatio( const Double& horRatio, const Double& verRatio ) +{ + QScrollBar* scrollBarH = m_pcScrollArea->horizontalScrollBar(); + QScrollBar* scrollBarV = m_pcScrollArea->verticalScrollBar(); + scrollBarH->setValue( scrollBarH->maximum() * horRatio ); + scrollBarV->setValue( scrollBarV->maximum() * verRatio ); + updateScrollValues(); +} + Void VideoSubWindow::adjustScrollBarByOffset( QPoint Offset ) { QPoint cLastScroll = m_cCurrScroll; - QScrollBar *scrollBarH, *scrollBarV; - Int valueX, valueY; + QScrollBar* scrollBarH = m_pcScrollArea->horizontalScrollBar(); + QScrollBar* scrollBarV = m_pcScrollArea->verticalScrollBar(); - valueX = int( cLastScroll.x() + Offset.x() ); - valueY = int( cLastScroll.y() + Offset.y() ); + Int valueX = int( cLastScroll.x() + Offset.x() ); + Int valueY = int( cLastScroll.y() + Offset.y() ); - scrollBarH = m_pcScrollArea->horizontalScrollBar(); - if( valueX > scrollBarH->maximum() ) - valueX = scrollBarH->maximum(); - if( valueX < scrollBarH->minimum() ) - valueX = scrollBarH->minimum(); - m_cCurrScroll.setX( valueX ); + scrollBarH->setValue( valueX ); + scrollBarV->setValue( valueY ); - scrollBarV = m_pcScrollArea->verticalScrollBar(); - if( valueY > scrollBarV->maximum() ) - valueY = scrollBarV->maximum(); - if( valueY < scrollBarV->minimum() ) - valueY = scrollBarV->minimum(); - m_cCurrScroll.setY( valueY ); + updateScrollValues(); - // Update window scroll - scrollBarH->setValue( m_cCurrScroll.x() ); - scrollBarV->setValue( m_cCurrScroll.y() ); + scrollBarMoved( m_dHorScroll, m_dVerScroll ); } // This function was developed with help of the schematics presented in @@ -834,60 +830,60 @@ Void VideoSubWindow::adjustScrollBarByOffset( QPoint Offset ) Void VideoSubWindow::adjustScrollBarByScale( Double scale, QPoint center ) { QPoint cLastScroll = m_cCurrScroll; - QScrollBar *scrollBarH, *scrollBarV; + QScrollBar* scrollBarH = m_pcScrollArea->horizontalScrollBar(); + QScrollBar* scrollBarV = m_pcScrollArea->verticalScrollBar(); - scrollBarH = m_pcScrollArea->horizontalScrollBar(); if( center.isNull() ) { m_cCurrScroll.setX( int( scale * cLastScroll.x() + ( ( scale - 1 ) * scrollBarH->pageStep() / 2 ) ) ); - } - else - { - Int x = center.x() - cLastScroll.x(); - Int value = int( scale * cLastScroll.x() + ( ( scale - 1 ) * x ) ); - if( value > scrollBarH->maximum() ) - value = scrollBarH->maximum(); - if( value < scrollBarH->minimum() ) - value = scrollBarH->minimum(); - m_cCurrScroll.setX( value ); - } - - scrollBarV = m_pcScrollArea->verticalScrollBar(); - if( center.isNull() ) - { m_cCurrScroll.setY( int( scale * cLastScroll.y() + ( ( scale - 1 ) * scrollBarV->pageStep() / 2 ) ) ); } else { + Int value; + + Int x = center.x() - cLastScroll.x(); + value = int( scale * cLastScroll.x() + ( ( scale - 1 ) * x ) ); + m_cCurrScroll.setX( value ); + Int y = center.y() - cLastScroll.y(); - Int value = int( scale * cLastScroll.y() + ( ( scale - 1 ) * y ) ); - if( value > scrollBarV->maximum() ) - value = scrollBarV->maximum(); - if( value < scrollBarV->minimum() ) - value = scrollBarV->minimum(); + value = int( scale * cLastScroll.y() + ( ( scale - 1 ) * y ) ); m_cCurrScroll.setY( value ); } // Update window scroll scrollBarH->setValue( m_cCurrScroll.x() ); scrollBarV->setValue( m_cCurrScroll.y() ); + + updateScrollValues(); + + scrollBarMoved( m_dHorScroll, m_dVerScroll ); } -Void VideoSubWindow::updateCurScrollValues() +Void VideoSubWindow::updateScrollValues() { - QScrollBar* scrollBar = m_pcScrollArea->horizontalScrollBar(); - m_cCurrScroll.setX( scrollBar->value() ); - scrollBar = m_pcScrollArea->verticalScrollBar(); - m_cCurrScroll.setY( scrollBar->value() ); + Double xPos = m_pcScrollArea->horizontalScrollBar()->value(); + Double yPos = m_pcScrollArea->verticalScrollBar()->value(); + + m_cCurrScroll.setX( xPos ); + m_cCurrScroll.setY( yPos ); + + m_dHorScroll = m_dVerScroll = 0; + + if( xPos ) + m_dHorScroll = xPos / Double( m_pcScrollArea->horizontalScrollBar()->maximum() ); + + if( yPos ) + m_dVerScroll = yPos / Double( m_pcScrollArea->verticalScrollBar()->maximum() ); } -Void VideoSubWindow::setCurScrollValues() -{ - QScrollBar* scrollBar = m_pcScrollArea->horizontalScrollBar(); - scrollBar->setValue( m_cCurrScroll.x() ); - scrollBar = m_pcScrollArea->verticalScrollBar(); - scrollBar->setValue( m_cCurrScroll.y() ); -} +//Void VideoSubWindow::setCurScrollValues() +//{ +// QScrollBar* scrollBar = m_pcScrollArea->horizontalScrollBar(); +// scrollBar->setValue( m_cCurrScroll.x() ); +// scrollBar = m_pcScrollArea->verticalScrollBar(); +// scrollBar->setValue( m_cCurrScroll.y() ); +//} Void VideoSubWindow::normalSize() { diff --git a/app/VideoSubWindow.h b/app/VideoSubWindow.h index f662851..8984c36 100644 --- a/app/VideoSubWindow.h +++ b/app/VideoSubWindow.h @@ -67,8 +67,9 @@ private: Bool m_bWindowBusy; QScrollArea* m_pcScrollArea; - QPoint m_cLastScroll; QPoint m_cCurrScroll; + Double m_dHorScroll; + Double m_dVerScroll; ViewArea* m_cViewArea; @@ -183,6 +184,8 @@ public: Void clearWindowBusy() { m_bWindowBusy = false; } Void setFillWindow( Bool bFlag ); + Void adjustScrollBarToRatio( const Double& horRatio, const Double& verRatio ); + private: Void refreshFrameOperation(); Bool goToNextFrame( Bool bThreaded = false ); @@ -210,8 +213,7 @@ public Q_SLOTS: void updateWindowOnTimeout(); void adjustScrollBarByScale( double scale, QPoint center ); void adjustScrollBarByOffset( QPoint Offset ); - void updateCurScrollValues(); - void setCurScrollValues(); + void updateScrollValues(); void updateSelectedArea( QRect area ); void updatePixelValueStatusBar( const QPoint& pos ); };