diff --git a/source/app/InputStream.cpp b/source/app/InputStream.cpp index ba9ea75..6cd67ec 100755 --- a/source/app/InputStream.cpp +++ b/source/app/InputStream.cpp @@ -399,6 +399,8 @@ cv::Mat InputStream::getFrameCvMat() Void InputStream::seekInput( UInt64 new_frame_num ) { + if( !m_pFile ) + return; if( new_frame_num < 0 || new_frame_num >= m_uiTotalFrameNum ) return; #ifdef USE_FFMPEG diff --git a/source/app/ModulesHandle.cpp b/source/app/ModulesHandle.cpp index 47c49d5..ecd54e5 100644 --- a/source/app/ModulesHandle.cpp +++ b/source/app/ModulesHandle.cpp @@ -25,6 +25,9 @@ #include #include "ModulesHandle.h" +#include "SubWindowHandle.h" + +// List of modules includes #include "FilterFrame.h" namespace plaYUVer @@ -32,20 +35,22 @@ namespace plaYUVer Void ModulesHandle::ModulesList( Bool bCreate ) { + // Register Modules REGISTER_MODULE( FilterFrame ); - } - ModulesHandle::ModulesHandle( QWidget * parent ) { - ModulesList( true ); + m_pcParent = parent; + // configure class - setParent( parent ); + setParent( m_pcParent ); m_uiModulesCount = 0; - m_uiModuleSelected= -1; + m_uiModuleSelected = -1; + m_bShowModulesNewWindow = false; + ModulesList( true ); } ModulesHandle::~ModulesHandle() @@ -63,16 +68,55 @@ void ModulesHandle::selectModule( int index ) m_uiModuleSelected = index; } -PlaYUVerModuleIf* ModulesHandle::getSelectedModuleIf() +SubWindowHandle* ModulesHandle::toggleSelectedModuleIf( SubWindowHandle* pcSubWindow ) { + SubWindowHandle* interfaceChild = NULL; PlaYUVerModuleIf* currModuleIf = NULL; if( m_uiModuleSelected >= 0 ) - //if( m_arrayModulesActions.at(m_uiModuleSelected)->isChecked() ) - currModuleIf = m_pcPlaYUVerModules.at( m_uiModuleSelected ); - + currModuleIf = m_pcPlaYUVerModules.at( m_uiModuleSelected ); m_uiModuleSelected = -1; - return currModuleIf; + + if( currModuleIf->m_pcAction->isChecked() ) + { + currModuleIf->m_pcDisplaySubWindow = NULL; + if( currModuleIf->m_cModuleDef.m_bRequiresNewWindow || m_bShowModulesNewWindow ) + { + QString windowName; + interfaceChild = new SubWindowHandle( m_pcParent ); + pcSubWindow->setModuleSubWindow( interfaceChild ); + pcSubWindow->enableModule( currModuleIf ); + windowName.append( pcSubWindow->userFriendlyCurrentFile() ); + windowName.append( " - " ); + windowName.append( currModuleIf->m_cModuleDef.m_pchModuleName ); + interfaceChild->setWindowName( windowName ); + connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, PlaYUVerFrame *) ), this, + SLOT( updatePixelValueStatusBar(const QPoint &, PlaYUVerFrame *) ) ); + currModuleIf->m_pcDisplaySubWindow = interfaceChild; + } + else + { + pcSubWindow->enableModule( currModuleIf ); + } + currModuleIf->m_pcSubWindow = pcSubWindow; + } + else + { + currModuleIf->m_pcSubWindow->disableModule(); + } + return interfaceChild; +} + +Void ModulesHandle::destroyModuleIf( PlaYUVerModuleIf* pcCurrModuleIf ) +{ + pcCurrModuleIf->m_pcAction->setChecked( false ); + if( pcCurrModuleIf->m_pcDisplaySubWindow ) + { + pcCurrModuleIf->m_pcDisplaySubWindow->close(); + pcCurrModuleIf->m_pcDisplaySubWindow = NULL; + } + pcCurrModuleIf->m_pcSubWindow = NULL; + pcCurrModuleIf->destroy(); } QMenu* ModulesHandle::createMenus( QMenuBar *MainAppMenuBar ) @@ -88,8 +132,6 @@ QMenu* ModulesHandle::createMenus( QMenuBar *MainAppMenuBar ) //m_arrayModulesActions.resize( m_uiModulesCount ); - - for( Int i = 0; i < m_pcPlaYUVerModules.size(); i++ ) { currModuleIf = m_pcPlaYUVerModules.at( i ); diff --git a/source/app/ModulesHandle.h b/source/app/ModulesHandle.h index b859dda..528eaa6 100644 --- a/source/app/ModulesHandle.h +++ b/source/app/ModulesHandle.h @@ -42,18 +42,24 @@ namespace plaYUVer { -class ModulesHandle : public QObject +class SubWindowHandle; + +class ModulesHandle: public QObject { - Q_OBJECT +Q_OBJECT public: ModulesHandle( QWidget * parent = 0 ); ~ModulesHandle(); QMenu* createMenus( QMenuBar *MainAppMenuBar ); Void updateMenus( Bool hasSubWindow ); - PlaYUVerModuleIf* getSelectedModuleIf(); + SubWindowHandle* toggleSelectedModuleIf( SubWindowHandle* pcSubWindow ); + static Void destroyModuleIf( PlaYUVerModuleIf* pcCurrModuleIf ); private: + QWidget *m_pcParent; + + Bool m_bShowModulesNewWindow; UInt m_uiModulesCount; Int m_uiModuleSelected; QMenu* m_pcModulesMenu; @@ -64,6 +70,7 @@ private: Void appendModule( PlaYUVerModuleIf* ); Void ModulesList( Bool bCreate ); + private Q_SLOTS: void selectModule( int index ); }; diff --git a/source/app/PlaYUVerModuleIf.h b/source/app/PlaYUVerModuleIf.h index d52d777..f3d74cc 100644 --- a/source/app/PlaYUVerModuleIf.h +++ b/source/app/PlaYUVerModuleIf.h @@ -73,9 +73,16 @@ typedef struct __PlaYUVerModuleDefinition bool m_bRequiresNewWindow; }PlaYUVerModuleDefinition; +class SubWindowHandle; class PlaYUVerModuleIf { + friend class ModulesHandle; +private: + QAction* m_pcAction; + SubWindowHandle* m_pcSubWindow; + SubWindowHandle* m_pcDisplaySubWindow; + public: PlaYUVerModuleIf() { @@ -85,8 +92,6 @@ public: { } - QAction* m_pcAction; - PlaYUVerModuleDefinition m_cModuleDef; virtual Void create() {}; diff --git a/source/app/SubWindowHandle.cpp b/source/app/SubWindowHandle.cpp index 5d425d2..1051cdf 100644 --- a/source/app/SubWindowHandle.cpp +++ b/source/app/SubWindowHandle.cpp @@ -52,8 +52,9 @@ SubWindowHandle::SubWindowHandle( QWidget * parent ) : m_cScrollArea->setWidget( m_cViewArea ); m_cScrollArea->setWidgetResizable( true ); + m_pCurrStream = NULL; m_pCurrStream = new InputStream; - + m_pcCurrFrame = NULL; m_pcCurrentModule = NULL; m_pcModuleSubWindow = NULL; @@ -64,15 +65,11 @@ SubWindowHandle::SubWindowHandle( QWidget * parent ) : SubWindowHandle::~SubWindowHandle() { + disableModule(); delete m_cViewArea; delete m_cScrollArea; - delete m_pCurrStream; - if( m_pcCurrentModule ) - { - m_pcCurrentModule->m_pcAction->setChecked( false ); - m_pcCurrentModule->destroy(); - m_pcCurrentModule = NULL; - } + if( m_pCurrStream ) + delete m_pCurrStream; } Bool SubWindowHandle::loadFile( const QString &fileName ) @@ -80,6 +77,9 @@ Bool SubWindowHandle::loadFile( const QString &fileName ) UInt Width = 0, Height = 0, FrameRate = 30; Int InputFormat = -1; + if( !m_pCurrStream ) + m_pCurrStream = new InputStream; + m_pCurrStream->getFormat( Width, Height, InputFormat, FrameRate ); if( m_pCurrStream->guessFormat( fileName, Width, Height, InputFormat, FrameRate ) ) @@ -102,7 +102,6 @@ Bool SubWindowHandle::loadFile( const QString &fileName ) QApplication::restoreOverrideCursor(); refreshFrame(); - //normalSize(); m_cCurrFileName = fileName; m_cWindowName = m_pCurrStream->getStreamInformationString(); @@ -116,11 +115,6 @@ Bool SubWindowHandle::loadFile( const QString &fileName ) */ Void SubWindowHandle::enableModule( PlaYUVerModuleIf* select_module ) { - if( m_pcCurrentModule == select_module ) - { - disableModule(); - return; - } m_pcCurrentModule = select_module; m_pcCurrentModule->create( m_pCurrStream->getCurrFrame() ); refreshFrame(); @@ -130,10 +124,9 @@ Void SubWindowHandle::disableModule() { if( !m_pcCurrentModule ) return; - - m_pcCurrentModule->m_pcAction->setCheckable( false ); - m_pcCurrentModule->destroy(); + ModulesHandle::destroyModuleIf( m_pcCurrentModule ); m_pcCurrentModule = NULL; + m_pcModuleSubWindow = NULL; refreshFrame(); } @@ -268,7 +261,11 @@ Void SubWindowHandle::scaleView( Int width, Int height ) Void SubWindowHandle::scaleView( const QSize & size ) { - QSize imgViewSize( m_pCurrStream->getWidth(), m_pCurrStream->getHeight() ); + QSize imgViewSize; + if( m_pcCurrFrame ) + imgViewSize = QSize( m_pcCurrFrame->getWidth(), m_pcCurrFrame->getHeight() ); + else + imgViewSize = QSize( m_pCurrStream->getWidth(), m_pCurrStream->getHeight() ); QSize newSize = imgViewSize; newSize.scale( size, Qt::KeepAspectRatio ); @@ -361,7 +358,11 @@ QSize SubWindowHandle::sizeHint() const maxSize = p->size(); } - QSize isize = QSize( m_pCurrStream->getWidth() + 50, m_pCurrStream->getHeight() + 50 ); + QSize isize; + if( m_pcCurrFrame ) + isize = QSize( m_pcCurrFrame->getWidth() + 50, m_pcCurrFrame->getHeight() + 50 ); + else + isize = QSize( m_pCurrStream->getWidth() + 50, m_pCurrStream->getHeight() + 50 ); // If the SubWindowHandle needs more space that the avaiable, we'll give // to the subwindow a reasonable size preserving the image aspect ratio. diff --git a/source/app/SubWindowHandle.h b/source/app/SubWindowHandle.h index 44fecb5..6f3e708 100644 --- a/source/app/SubWindowHandle.h +++ b/source/app/SubWindowHandle.h @@ -36,7 +36,7 @@ #include "TypeDef.h" #include "InputStream.h" #include "ViewArea.h" -#include "PlaYUVerModuleIf.h" +#include "ModulesHandle.h" namespace plaYUVer { @@ -94,6 +94,11 @@ public: return m_pCurrStream; } + PlaYUVerFrame* getCurrFrame() + { + return m_pcCurrFrame; + } + ViewArea* getViewArea() { return m_cViewArea; @@ -146,6 +151,12 @@ public: QSize sizeHint() const; + Void setWindowName( QString name ) + { + m_cWindowName = name; + setWindowTitle( m_cWindowName ); + } + QString userFriendlyCurrentFile() { return m_cWindowName; diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index 182ea32..9021902 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -49,7 +49,6 @@ plaYUVerApp::plaYUVerApp() //mdiArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( chageSubWindowSelection() ) ); - //connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( updateMenus() ) ); mapperWindow = new QSignalMapper( this ); connect( mapperWindow, SIGNAL( mapped(QWidget*) ), this, SLOT( setActiveSubWindow(QWidget*) ) ); @@ -221,32 +220,13 @@ void plaYUVerApp::closeAll() void plaYUVerApp::selectModule( QAction *curr_action ) { - //emit curr_action->triggered(); - if( m_pcCurrentSubWindow ) + SubWindowHandle *interfaceChild = m_pcModulesHandle->toggleSelectedModuleIf( m_pcCurrentSubWindow ); + if( interfaceChild ) { - PlaYUVerModuleIf* pcCurrMod = m_pcModulesHandle->getSelectedModuleIf(); - if( pcCurrMod ) - { - if( pcCurrMod->m_cModuleDef.m_bRequiresNewWindow ) - { - SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createSubWindow(); - mdiArea->addSubWindow( interfaceChild ); - -// connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, InputStream *) ), this, -// SLOT( updatePixelValueStatusBar(const QPoint &, PlaYUVerFrame *) ) ); - // connect( interfaceChild->getViewArea(), SIGNAL( selectionChanged( QRect ) ), this, - // SLOT( updatePixelValueStatusBar(const QPoint &, PlaYUVerFrame *) ) ); - m_pcCurrentSubWindow->setModuleSubWindow( interfaceChild ); - m_pcCurrentSubWindow->enableModule( pcCurrMod ); - interfaceChild->show(); - interfaceChild->zoomToFit(); - interfaceChild->getViewArea()->setTool( m_appTool ); - } - else - { - m_pcCurrentSubWindow->enableModule( pcCurrMod ); - } - } + mdiArea->addSubWindow( interfaceChild ); + interfaceChild->show(); + interfaceChild->zoomToFit(); + interfaceChild->getViewArea()->setTool( m_appTool ); } return; } @@ -269,7 +249,7 @@ Void plaYUVerApp::updateFrameProperties() { if( m_pcCurrentSubWindow ) { - m_pcFrameProperties->setData( m_pcCurrentSubWindow->getInputStream()->getCurrFrame() ); + m_pcFrameProperties->setData( m_pcCurrentSubWindow->getCurrFrame() ); //m_pcFrameProperties->setSelection( m_pcCurrentSubWindow->getViewArea()->selectedArea() ); } else @@ -319,47 +299,51 @@ Void plaYUVerApp::setTimerStatus() void plaYUVerApp::play() { - if( m_pcCurrentSubWindow ) + if( !m_pcCurrentSubWindow ) + return; + + if( !m_pcCurrentSubWindow->getInputStream() ) + return; + + if( actionVideoLock->isChecked() && m_acPlayingSubWindows.size() ) { - if( actionVideoLock->isChecked() && m_acPlayingSubWindows.size() ) + Bool bFind = false; + for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) { - Bool bFind = false; - for( Int i = 0; i < m_acPlayingSubWindows.size(); i++ ) + if( m_acPlayingSubWindows.at( i ) == m_pcCurrentSubWindow ) { - if( m_acPlayingSubWindows.at( i ) == m_pcCurrentSubWindow ) - { - bFind = true; - break; - } - } - if( !bFind ) - { - m_acPlayingSubWindows.append( m_pcCurrentSubWindow ); - m_pcCurrentSubWindow->seekAbsoluteEvent( m_acPlayingSubWindows.at( 0 )->getInputStream()->getCurrFrameNum() ); - m_pcCurrentSubWindow->play(); - m_pcFrameSlider->setMaximum( qMin( m_pcFrameSlider->maximum(), ( Int )m_pcCurrentSubWindow->getInputStream()->getFrameNum() - 1 ) ); + bFind = true; + break; } } - else + if( !bFind ) { - playingTimer->stop(); - m_acPlayingSubWindows.clear(); m_acPlayingSubWindows.append( m_pcCurrentSubWindow ); + m_pcCurrentSubWindow->seekAbsoluteEvent( m_acPlayingSubWindows.at( 0 )->getInputStream()->getCurrFrameNum() ); m_pcCurrentSubWindow->play(); - m_uiAveragePlayInterval = 0; - m_bIsPlaying = false; - } - if( !m_bIsPlaying ) - { - UInt frameRate = m_acPlayingSubWindows.at( 0 )->getInputStream()->getFrameRate(); - UInt timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); - qDebug( ) << "Desired frame rate: " - << QString::number( 1000 / timeInterval ) - << " fps"; - playingTimer->start( timeInterval ); - m_cTimer.start(); + m_pcFrameSlider->setMaximum( qMin( m_pcFrameSlider->maximum(), ( Int )m_pcCurrentSubWindow->getInputStream()->getFrameNum() - 1 ) ); } } + else + { + playingTimer->stop(); + m_acPlayingSubWindows.clear(); + m_acPlayingSubWindows.append( m_pcCurrentSubWindow ); + m_pcCurrentSubWindow->play(); + m_uiAveragePlayInterval = 0; + m_bIsPlaying = false; + } + if( !m_bIsPlaying ) + { + UInt frameRate = m_acPlayingSubWindows.at( 0 )->getInputStream()->getFrameRate(); + UInt timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); + qDebug( ) << "Desired frame rate: " + << QString::number( 1000 / timeInterval ) + << " fps"; + playingTimer->start( timeInterval ); + m_cTimer.start(); + } + } void plaYUVerApp::pause() @@ -475,7 +459,6 @@ void plaYUVerApp::seekEvent( int direction ) else { m_pcCurrentSubWindow->seekRelativeEvent( direction > 0 ? true : false ); - } updateFrameProperties(); updateCurrFrameNum(); @@ -555,15 +538,9 @@ void plaYUVerApp::chageSubWindowSelection() SubWindowHandle *new_window = activeSubWindow(); if( activeSubWindow() != m_pcCurrentSubWindow ) { - if( activeSubWindow() ) + if( activeSubWindow() ) { - if( m_pcCurrentSubWindow ) - { - m_pcCurrentSubWindow->disableModule(); - } m_pcCurrentSubWindow = new_window; - m_pcStreamProperties->setData( m_pcCurrentSubWindow->getInputStream() ); - m_pcFrameProperties->setData( m_pcCurrentSubWindow->getInputStream()->getCurrFrame() ); updateCurrFrameNum(); updateTotalFrameNum(); updateStreamProperties();