From ef54330831b62f457a1f32c6dddd4544313bdfa0 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 7 Feb 2014 22:10:14 +0000 Subject: [PATCH 01/13] Change ImageInterface to SubWindows --- source/plaYUVerApp.cpp | 94 +++++++++++++++++++++--------------------- source/plaYUVerApp.h | 24 +++++------ 2 files changed, 59 insertions(+), 59 deletions(-) diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index e0b6e0c..b607a04 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -48,7 +48,7 @@ plaYUVerApp::plaYUVerApp() connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( updateMenus() ) ); windowMapper = new QSignalMapper( this ); - connect( windowMapper, SIGNAL( mapped(QWidget*) ), this, SLOT( setActiveImageInterface(QWidget*) ) ); + connect( windowMapper, SIGNAL( mapped(QWidget*) ), this, SLOT( setActiveSubWindow(QWidget*) ) ); createActions(); createMenus(); @@ -104,17 +104,17 @@ void plaYUVerApp::open() { m_cLastOpenPath = QFileInfo( fileName ).path(); - QMdiSubWindow *existing = findImageInterface( fileName ); + QMdiSubWindow *existing = findSubWindow( fileName ); if( existing ) { mdiArea->setActiveSubWindow( existing ); return; } - SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createImageInterface(); + SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createSubWindow(); if( interfaceChild->loadFile( fileName ) ) { - addImageInterface( interfaceChild ); + addSubWindow( interfaceChild ); statusBar()->showMessage( tr( "File loaded" ), 2000 ); interfaceChild->show(); } @@ -127,8 +127,8 @@ void plaYUVerApp::open() void plaYUVerApp::save() { - if( activeImageInterface() ) - activeImageInterface()->save(); + if( activeSubWindow() ) + activeSubWindow()->save(); } // ----------------------- Playing Functions -------------------- @@ -138,7 +138,7 @@ void plaYUVerApp::play() UInt frameRate; UInt timeInterval; - frameRate = activeImageInterface()->getInputStream()->getFrameRate(); + frameRate = activeSubWindow()->getInputStream()->getFrameRate(); timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); playingTimer->start( timeInterval ); @@ -158,9 +158,9 @@ void plaYUVerApp::stop() void plaYUVerApp::playEvent() { - if( activeImageInterface() ) + if( activeSubWindow() ) { - if( !activeImageInterface()->playEvent() ) + if( !activeSubWindow()->playEvent() ) { playingTimer->stop(); } @@ -182,25 +182,25 @@ void plaYUVerApp::zoomOut() void plaYUVerApp::normalSize() { - if( activeImageInterface() ) - activeImageInterface()->normalSize(); + if( activeSubWindow() ) + activeSubWindow()->normalSize(); } void plaYUVerApp::zoomToFit() { - if( activeImageInterface() ) - activeImageInterface()->zoomToFit(); + if( activeSubWindow() ) + activeSubWindow()->zoomToFit(); } -Void plaYUVerApp::scaleImage( Double factor ) +void plaYUVerApp::scaleImage( double factor ) { - if( activeImageInterface() ) + if( activeSubWindow() ) { - activeImageInterface()->scaleView( factor ); + activeSubWindow()->scaleView( factor ); - zoomInAct->setEnabled( activeImageInterface()->getScaleFactor() < 3.0 ); - zoomOutAct->setEnabled( activeImageInterface()->getScaleFactor() > 0.333 ); + zoomInAct->setEnabled( activeSubWindow()->getScaleFactor() < 3.0 ); + zoomOutAct->setEnabled( activeSubWindow()->getScaleFactor() > 0.333 ); } } @@ -213,26 +213,26 @@ void plaYUVerApp::about() void plaYUVerApp::updateMenus() { - Bool hasImageInterface = ( activeImageInterface() != 0 ); - saveAct->setEnabled( hasImageInterface ); - closeAct->setEnabled( hasImageInterface ); - closeAllAct->setEnabled( hasImageInterface ); - tileAct->setEnabled( hasImageInterface ); - cascadeAct->setEnabled( hasImageInterface ); - nextAct->setEnabled( hasImageInterface ); - previousAct->setEnabled( hasImageInterface ); - separatorAct->setVisible( hasImageInterface ); + Bool hasSubWindow = ( activeSubWindow() != 0 ); + saveAct->setEnabled( hasSubWindow ); + closeAct->setEnabled( hasSubWindow ); + closeAllAct->setEnabled( hasSubWindow ); + tileAct->setEnabled( hasSubWindow ); + cascadeAct->setEnabled( hasSubWindow ); + nextAct->setEnabled( hasSubWindow ); + previousAct->setEnabled( hasSubWindow ); + separatorAct->setVisible( hasSubWindow ); - zoomInAct->setEnabled( hasImageInterface ); - zoomOutAct->setEnabled( hasImageInterface ); - normalSizeAct->setEnabled( hasImageInterface ); - zoomToFitAct->setEnabled( hasImageInterface ); + zoomInAct->setEnabled( hasSubWindow ); + zoomOutAct->setEnabled( hasSubWindow ); + normalSizeAct->setEnabled( hasSubWindow ); + zoomToFitAct->setEnabled( hasSubWindow ); - actionVideoPlay->setEnabled( hasImageInterface ); - actionVideoPause->setEnabled( hasImageInterface ); - actionVideoStop->setEnabled( hasImageInterface ); - actionVideoBackward->setEnabled( hasImageInterface ); - actionVideoForward->setEnabled( hasImageInterface ); + actionVideoPlay->setEnabled( hasSubWindow ); + actionVideoPause->setEnabled( hasSubWindow ); + actionVideoStop->setEnabled( hasSubWindow ); + actionVideoBackward->setEnabled( hasSubWindow ); + actionVideoForward->setEnabled( hasSubWindow ); } void plaYUVerApp::updateWindowMenu() @@ -268,13 +268,13 @@ void plaYUVerApp::updateWindowMenu() } QAction *action = windowMenu->addAction( text ); action->setCheckable( true ); - action->setChecked( child == activeImageInterface() ); + action->setChecked( child == activeSubWindow() ); connect( action, SIGNAL( triggered() ), windowMapper, SLOT( map() ) ); windowMapper->setMapping( action, windows.at( i ) ); } } -SubWindowHandle *plaYUVerApp::createImageInterface() +SubWindowHandle *plaYUVerApp::createSubWindow() { SubWindowHandle *child = new SubWindowHandle; mdiArea->addSubWindow( child ); @@ -282,7 +282,7 @@ SubWindowHandle *plaYUVerApp::createImageInterface() return child; } -void plaYUVerApp::addImageInterface( SubWindowHandle *child ) +void plaYUVerApp::addSubWindow( SubWindowHandle *child ) { //connect( child, SIGNAL( areaSelected( QRect ) ), this, SLOT( setSelection( QRect ) ) ); @@ -489,13 +489,13 @@ void plaYUVerApp::dropEvent( QDropEvent *event ) m_cLastOpenPath = QFileInfo( fileName ).path(); - QMdiSubWindow *existing = findImageInterface( fileName ); + QMdiSubWindow *existing = findSubWindow( fileName ); if( !existing ) { - SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createImageInterface(); + SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createSubWindow(); if( interfaceChild->loadFile( fileName ) ) { - addImageInterface( interfaceChild ); + addSubWindow( interfaceChild ); statusBar()->showMessage( tr( "File loaded" ), 2000 ); interfaceChild->show(); } @@ -523,14 +523,14 @@ Void plaYUVerApp::writeSettings() settings.setValue( "size", size() ); } -SubWindowHandle *plaYUVerApp::activeImageInterface() +SubWindowHandle *plaYUVerApp::activeSubWindow() { - if( QMdiSubWindow *activeImageInterface = mdiArea->activeSubWindow() ) - return qobject_cast( activeImageInterface ); + if( QMdiSubWindow *activeSubWindow = mdiArea->activeSubWindow() ) + return qobject_cast( activeSubWindow ); return 0; } -QMdiSubWindow *plaYUVerApp::findImageInterface( const QString &fileName ) +QMdiSubWindow *plaYUVerApp::findSubWindow( const QString &fileName ) { QString canonicalFilePath = QFileInfo( fileName ).canonicalFilePath(); @@ -542,7 +542,7 @@ QMdiSubWindow *plaYUVerApp::findImageInterface( const QString &fileName ) return 0; } -void plaYUVerApp::setActiveImageInterface( QWidget *window ) +void plaYUVerApp::setActiveSubWindow( QWidget *window ) { if( !window ) return; diff --git a/source/plaYUVerApp.h b/source/plaYUVerApp.h index e054d17..9705013 100644 --- a/source/plaYUVerApp.h +++ b/source/plaYUVerApp.h @@ -65,6 +65,13 @@ private slots: //! View functions void zoomIn(); void zoomOut(); + /** + * Scale the image by a given factor + * @param factor factor of scale. Ex: 1.2 scale the image up by 20% and + * 0.8 scale the image down by 25% + */ + void scaleImage( double factor = 1 ); + void normalSize(); void zoomToFit(); @@ -80,9 +87,9 @@ private slots: void dragEnterEvent(QDragEnterEvent *event); void dropEvent(QDropEvent *event); - SubWindowHandle *createImageInterface(); - void addImageInterface( SubWindowHandle *child ); - void setActiveImageInterface( QWidget *window ); + SubWindowHandle *createSubWindow(); + void addSubWindow( SubWindowHandle *child ); + void setActiveSubWindow( QWidget *window ); private: Void createActions(); @@ -91,15 +98,8 @@ private: Void createStatusBar(); Void readSettings(); Void writeSettings(); - SubWindowHandle *activeImageInterface(); - QMdiSubWindow *findImageInterface( const QString &fileName ); - - /** - * Scale the image by a given factor - * @param factor factor of scale. Ex: 1.2 scale the image up by 20% and - * 0.8 scale the image down by 25% - */ - Void scaleImage( Double factor ); + SubWindowHandle *activeSubWindow(); + QMdiSubWindow *findSubWindow( const QString &fileName ); QString m_cLastOpenPath; From 3811256fd9966d08300331a03e6b8d321544936c Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 7 Feb 2014 22:51:36 +0000 Subject: [PATCH 02/13] Use signal mapping to avoid using different functions to zoom in and zoom out --- source/plaYUVerApp.cpp | 278 ++++++++++++++++++++--------------------- source/plaYUVerApp.h | 61 ++++----- 2 files changed, 169 insertions(+), 170 deletions(-) diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index b607a04..15118ab 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -47,8 +47,9 @@ plaYUVerApp::plaYUVerApp() //mdiArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( updateMenus() ) ); - windowMapper = new QSignalMapper( this ); - connect( windowMapper, SIGNAL( mapped(QWidget*) ), this, SLOT( setActiveSubWindow(QWidget*) ) ); + + mapperWindow = new QSignalMapper( this ); + connect( mapperWindow, SIGNAL( mapped(QWidget*) ), this, SLOT( setActiveSubWindow(QWidget*) ) ); createActions(); createMenus(); @@ -170,16 +171,6 @@ void plaYUVerApp::playEvent() // ----------------------- Zoom Functions ----------------------- -void plaYUVerApp::zoomIn() -{ - scaleImage( 1.25 ); -} - -void plaYUVerApp::zoomOut() -{ - scaleImage( 0.8 ); -} - void plaYUVerApp::normalSize() { if( activeSubWindow() ) @@ -192,15 +183,14 @@ void plaYUVerApp::zoomToFit() activeSubWindow()->zoomToFit(); } -void plaYUVerApp::scaleImage( double factor ) +void plaYUVerApp::scaleFrame( int ratio ) { - if( activeSubWindow() ) { - activeSubWindow()->scaleView( factor ); + activeSubWindow()->scaleView( (Double)(ratio)/100.0 ); - zoomInAct->setEnabled( activeSubWindow()->getScaleFactor() < 3.0 ); - zoomOutAct->setEnabled( activeSubWindow()->getScaleFactor() > 0.333 ); + actionZoomIn->setEnabled( activeSubWindow()->getScaleFactor() < 3.0 ); + actionZoomOut->setEnabled( activeSubWindow()->getScaleFactor() > 0.333 ); } } @@ -214,19 +204,19 @@ void plaYUVerApp::about() void plaYUVerApp::updateMenus() { Bool hasSubWindow = ( activeSubWindow() != 0 ); - saveAct->setEnabled( hasSubWindow ); - closeAct->setEnabled( hasSubWindow ); - closeAllAct->setEnabled( hasSubWindow ); - tileAct->setEnabled( hasSubWindow ); - cascadeAct->setEnabled( hasSubWindow ); - nextAct->setEnabled( hasSubWindow ); - previousAct->setEnabled( hasSubWindow ); - separatorAct->setVisible( hasSubWindow ); + actionSave->setEnabled( hasSubWindow ); + actionClose->setEnabled( hasSubWindow ); + actionCloseAll->setEnabled( hasSubWindow ); + actionTile->setEnabled( hasSubWindow ); + actionCascade->setEnabled( hasSubWindow ); + actionNext->setEnabled( hasSubWindow ); + actionPrevious->setEnabled( hasSubWindow ); + actionSeparator->setVisible( hasSubWindow ); - zoomInAct->setEnabled( hasSubWindow ); - zoomOutAct->setEnabled( hasSubWindow ); - normalSizeAct->setEnabled( hasSubWindow ); - zoomToFitAct->setEnabled( hasSubWindow ); + actionZoomIn->setEnabled( hasSubWindow ); + actionZoomOut->setEnabled( hasSubWindow ); + actionNormalSize->setEnabled( hasSubWindow ); + actionZoomToFit->setEnabled( hasSubWindow ); actionVideoPlay->setEnabled( hasSubWindow ); actionVideoPause->setEnabled( hasSubWindow ); @@ -237,21 +227,11 @@ void plaYUVerApp::updateMenus() void plaYUVerApp::updateWindowMenu() { - windowMenu->clear(); - windowMenu->addAction( closeAct ); - windowMenu->addAction( closeAllAct ); - windowMenu->addSeparator(); - windowMenu->addAction( tileAct ); - windowMenu->addAction( cascadeAct ); - windowMenu->addSeparator(); - windowMenu->addAction( nextAct ); - windowMenu->addAction( previousAct ); - windowMenu->addAction( separatorAct ); updateMenus(); QList windows = mdiArea->subWindowList(); - separatorAct->setVisible( !windows.isEmpty() ); + actionSeparator->setVisible( !windows.isEmpty() ); for( Int i = 0; i < windows.size(); ++i ) { @@ -266,11 +246,11 @@ void plaYUVerApp::updateWindowMenu() { text = tr( "%1 %2" ).arg( i + 1 ).arg( child->userFriendlyCurrentFile() ); } - QAction *action = windowMenu->addAction( text ); + QAction *action = menuWindow->addAction( text ); action->setCheckable( true ); action->setChecked( child == activeSubWindow() ); - connect( action, SIGNAL( triggered() ), windowMapper, SLOT( map() ) ); - windowMapper->setMapping( action, windows.at( i ) ); + connect( action, SIGNAL( triggered() ), mapperWindow, SLOT( map() ) ); + mapperWindow->setMapping( action, windows.at( i ) ); } } @@ -295,55 +275,60 @@ Void plaYUVerApp::createActions() { // ------------ File ------------ - openAct = new QAction( QIcon( ":/images/open.png" ), tr( "&Open..." ), this ); - openAct->setShortcuts( QKeySequence::Open ); - openAct->setStatusTip( tr( "Open an existing file" ) ); - connect( openAct, SIGNAL( triggered() ), this, SLOT( open() ) ); + actionOpen = new QAction( QIcon( ":/images/open.png" ), tr( "&Open..." ), this ); + actionOpen->setShortcuts( QKeySequence::Open ); + actionOpen->setStatusTip( tr( "Open an existing file" ) ); + connect( actionOpen, SIGNAL( triggered() ), this, SLOT( open() ) ); - saveAct = new QAction( QIcon( ":/images/save.png" ), tr( "&Save..." ), this ); - saveAct->setShortcuts( QKeySequence::SaveAs ); - saveAct->setStatusTip( tr( "Save the document under a new name" ) ); - connect( saveAct, SIGNAL( triggered() ), this, SLOT( save() ) ); + actionSave = new QAction( QIcon( ":/images/save.png" ), tr( "&Save..." ), this ); + actionSave->setShortcuts( QKeySequence::SaveAs ); + actionSave->setStatusTip( tr( "Save the document under a new name" ) ); + connect( actionSave, SIGNAL( triggered() ), this, SLOT( save() ) ); - exitAct = new QAction( tr( "E&xit" ), this ); - exitAct->setShortcuts( QKeySequence::Quit ); - exitAct->setStatusTip( tr( "Exit the application" ) ); - connect( exitAct, SIGNAL( triggered() ), qApp, SLOT( closeAllWindows() ) ); + actionExit = new QAction( tr( "E&xit" ), this ); + actionExit->setShortcuts( QKeySequence::Quit ); + actionExit->setStatusTip( tr( "Exit the application" ) ); + connect( actionExit, SIGNAL( triggered() ), qApp, SLOT( closeAllWindows() ) ); - closeAct = new QAction( tr( "Cl&ose" ), this ); - closeAct->setIcon( QIcon( ":/images/close.png" ) ); - closeAct->setStatusTip( tr( "Close the active window" ) ); - connect( closeAct, SIGNAL( triggered() ), mdiArea, SLOT( closeActiveSubWindow() ) ); + actionClose = new QAction( tr( "Cl&ose" ), this ); + actionClose->setIcon( QIcon( ":/images/close.png" ) ); + actionClose->setStatusTip( tr( "Close the active window" ) ); + connect( actionClose, SIGNAL( triggered() ), mdiArea, SLOT( closeActiveSubWindow() ) ); - closeAllAct = new QAction( tr( "Close &All" ), this ); - closeAllAct->setStatusTip( tr( "Close all the windows" ) ); - connect( closeAllAct, SIGNAL( triggered() ), mdiArea, SLOT( closeAllSubWindows() ) ); + actionCloseAll = new QAction( tr( "Close &All" ), this ); + actionCloseAll->setStatusTip( tr( "Close all the windows" ) ); + connect( actionCloseAll, SIGNAL( triggered() ), mdiArea, SLOT( closeAllSubWindows() ) ); // ------------ View ------------ - zoomInAct = new QAction( tr( "Zoom &In (25%)" ), this ); - zoomInAct->setIcon( QIcon( ":/images/zoomin.png" ) ); - zoomInAct->setShortcut( tr( "Ctrl++" ) ); - zoomInAct->setStatusTip( tr( "Scale the image up by 25%" ) ); - connect( zoomInAct, SIGNAL( triggered() ), this, SLOT( zoomIn() ) ); + mapperZoom = new QSignalMapper( this ); + connect( mapperZoom, SIGNAL( mapped(int) ), this, SLOT( scaleFrame(int) ) ); - zoomOutAct = new QAction( tr( "Zoom &Out (25%)" ), this ); - zoomOutAct->setIcon( QIcon( ":/images/zoomout.png" ) ); - zoomOutAct->setShortcut( tr( "Ctrl+-" ) ); - zoomOutAct->setStatusTip( tr( "Scale the image down by 25%" ) ); - connect( zoomOutAct, SIGNAL( triggered() ), this, SLOT( zoomOut() ) ); + actionZoomIn = new QAction( tr( "Zoom &In (25%)" ), this ); + actionZoomIn->setIcon( QIcon( ":/images/zoomin.png" ) ); + actionZoomIn->setShortcut( tr( "Ctrl++" ) ); + actionZoomIn->setStatusTip( tr( "Scale the image up by 25%" ) ); + connect (actionZoomIn, SIGNAL(triggered()), mapperZoom, SLOT(map())) ; + mapperZoom->setMapping(actionZoomIn, 125 ); - normalSizeAct = new QAction( tr( "&Normal Size" ), this ); - normalSizeAct->setIcon( QIcon( ":/images/zoomtonormal.png" ) ); - normalSizeAct->setShortcut( tr( "Ctrl+N" ) ); - normalSizeAct->setStatusTip( tr( "Show the image at its original size" ) ); - connect( normalSizeAct, SIGNAL( triggered() ), this, SLOT( normalSize() ) ); + actionZoomOut = new QAction( tr( "Zoom &Out (25%)" ), this ); + actionZoomOut->setIcon( QIcon( ":/images/zoomout.png" ) ); + actionZoomOut->setShortcut( tr( "Ctrl+-" ) ); + actionZoomOut->setStatusTip( tr( "Scale the image down by 25%" ) ); + connect (actionZoomOut, SIGNAL(triggered()), mapperZoom, SLOT(map())) ; + mapperZoom->setMapping(actionZoomOut, 80 ); - zoomToFitAct = new QAction( tr( "Zoom to &Fit" ), this ); - zoomToFitAct->setIcon( QIcon( ":/images/fittowindow.png" ) ); - zoomToFitAct->setStatusTip( tr( "Zoom in or out to fit on the window." ) ); - zoomToFitAct->setShortcut( tr( "Ctrl+F" ) ); - connect( zoomToFitAct, SIGNAL( triggered() ), this, SLOT( zoomToFit() ) ); + actionNormalSize = new QAction( tr( "&Normal Size" ), this ); + actionNormalSize->setIcon( QIcon( ":/images/zoomtonormal.png" ) ); + actionNormalSize->setShortcut( tr( "Ctrl+N" ) ); + actionNormalSize->setStatusTip( tr( "Show the image at its original size" ) ); + connect( actionNormalSize, SIGNAL( triggered() ), this, SLOT( normalSize() ) ); + + actionZoomToFit = new QAction( tr( "Zoom to &Fit" ), this ); + actionZoomToFit->setIcon( QIcon( ":/images/fittowindow.png" ) ); + actionZoomToFit->setStatusTip( tr( "Zoom in or out to fit on the window." ) ); + actionZoomToFit->setShortcut( tr( "Ctrl+F" ) ); + connect( actionZoomToFit, SIGNAL( triggered() ), this, SLOT( zoomToFit() ) ); // ------------ Playing ------------ @@ -375,89 +360,100 @@ Void plaYUVerApp::createActions() // ------------ Window ------------ - tileAct = new QAction( tr( "&Tile" ), this ); - tileAct->setStatusTip( tr( "Tile the windows" ) ); - connect( tileAct, SIGNAL( triggered() ), mdiArea, SLOT( tileSubWindows() ) ); + actionTile = new QAction( tr( "&Tile" ), this ); + actionTile->setStatusTip( tr( "Tile the windows" ) ); + connect( actionTile, SIGNAL( triggered() ), mdiArea, SLOT( tileSubWindows() ) ); - cascadeAct = new QAction( tr( "&Cascade" ), this ); - cascadeAct->setStatusTip( tr( "Cascade the windows" ) ); - connect( cascadeAct, SIGNAL( triggered() ), mdiArea, SLOT( cascadeSubWindows() ) ); + actionCascade = new QAction( tr( "&Cascade" ), this ); + actionCascade->setStatusTip( tr( "Cascade the windows" ) ); + connect( actionCascade, SIGNAL( triggered() ), mdiArea, SLOT( cascadeSubWindows() ) ); - nextAct = new QAction( tr( "Ne&xt" ), this ); - nextAct->setShortcuts( QKeySequence::NextChild ); - nextAct->setStatusTip( tr( "Move the focus to the next window" ) ); - connect( nextAct, SIGNAL( triggered() ), mdiArea, SLOT( activateNextSubWindow() ) ); + actionNext = new QAction( tr( "Ne&xt" ), this ); + actionNext->setShortcuts( QKeySequence::NextChild ); + actionNext->setStatusTip( tr( "Move the focus to the next window" ) ); + connect( actionNext, SIGNAL( triggered() ), mdiArea, SLOT( activateNextSubWindow() ) ); - previousAct = new QAction( tr( "Pre&vious" ), this ); - previousAct->setShortcuts( QKeySequence::PreviousChild ); - previousAct->setStatusTip( tr( "Move the focus to the previous window" ) ); - connect( previousAct, SIGNAL( triggered() ), mdiArea, SLOT( activatePreviousSubWindow() ) ); + actionPrevious = new QAction( tr( "Pre&vious" ), this ); + actionPrevious->setShortcuts( QKeySequence::PreviousChild ); + actionPrevious->setStatusTip( tr( "Move the focus to the previous window" ) ); + connect( actionPrevious, SIGNAL( triggered() ), mdiArea, SLOT( activatePreviousSubWindow() ) ); - separatorAct = new QAction( this ); - separatorAct->setSeparator( true ); + actionSeparator = new QAction( this ); + actionSeparator->setSeparator( true ); // ------------ About ------------ - aboutAct = new QAction( tr( "&About" ), this ); - aboutAct->setStatusTip( tr( "Show the application's About box" ) ); - connect( aboutAct, SIGNAL( triggered() ), this, SLOT( about() ) ); + actionAbout = new QAction( tr( "&About" ), this ); + actionAbout->setStatusTip( tr( "Show the application's About box" ) ); + connect( actionAbout, SIGNAL( triggered() ), this, SLOT( about() ) ); - aboutQtAct = new QAction( tr( "About &Qt" ), this ); - aboutQtAct->setIcon( QIcon( ":images/qt.png" ) ); - aboutQtAct->setStatusTip( tr( "Show the Qt library's About box" ) ); - connect( aboutQtAct, SIGNAL( triggered() ), qApp, SLOT( aboutQt() ) ); + actionAboutQt = new QAction( tr( "About &Qt" ), this ); + actionAboutQt->setIcon( QIcon( ":images/qt.png" ) ); + actionAboutQt->setStatusTip( tr( "Show the Qt library's About box" ) ); + connect( actionAboutQt, SIGNAL( triggered() ), qApp, SLOT( aboutQt() ) ); } Void plaYUVerApp::createMenus() { - fileMenu = menuBar()->addMenu( tr( "&File" ) ); - fileMenu->addAction( openAct ); - fileMenu->addSeparator(); - fileMenu->addAction( saveAct ); - fileMenu->addSeparator(); - fileMenu->addAction( closeAct ); - fileMenu->addAction( exitAct ); + menuFile = menuBar()->addMenu( tr( "&File" ) ); + menuFile->addAction( actionOpen ); + menuFile->addSeparator(); + menuFile->addAction( actionSave ); + menuFile->addSeparator(); + menuFile->addAction( actionClose ); + menuFile->addAction( actionExit ); - viewMenu = new QMenu( tr( "&View" ), this ); - viewMenu->addAction( zoomInAct ); - viewMenu->addAction( zoomOutAct ); - viewMenu->addAction( normalSizeAct ); - viewMenu->addAction( zoomToFitAct ); + menuView = new QMenu( tr( "&View" ), this ); + menuView->addAction( actionZoomIn ); + menuView->addAction( actionZoomOut ); + menuView->addAction( actionNormalSize ); + menuView->addAction( actionZoomToFit ); - windowMenu = menuBar()->addMenu( tr( "&Window" ) ); + menuWindow = menuBar()->addMenu( tr( "&Window" ) ); + menuWindow->clear(); + menuWindow->addAction( actionClose ); + menuWindow->addAction( actionCloseAll ); + menuWindow->addSeparator(); + menuWindow->addAction( actionTile ); + menuWindow->addAction( actionCascade ); + menuWindow->addSeparator(); + menuWindow->addAction( actionNext ); + menuWindow->addAction( actionPrevious ); + menuWindow->addAction( actionSeparator ); updateWindowMenu(); - connect( windowMenu, SIGNAL( aboutToShow() ), this, SLOT( updateWindowMenu() ) ); + connect( menuWindow, SIGNAL( aboutToShow() ), this, SLOT( updateWindowMenu() ) ); menuBar()->addSeparator(); - helpMenu = menuBar()->addMenu( tr( "&Help" ) ); - helpMenu->addAction( aboutAct ); - helpMenu->addAction( aboutQtAct ); + menuHelp = menuBar()->addMenu( tr( "&Help" ) ); + menuHelp->addAction( actionAbout ); + menuHelp->addAction( actionAboutQt ); } Void plaYUVerApp::createToolBars() { - fileToolBar = addToolBar( tr( "File" ) ); - fileToolBar->addAction( openAct ); - fileToolBar->addAction( saveAct ); - fileToolBar->addAction( closeAct ); + toolbarFile = addToolBar( tr( "File" ) ); + toolbarFile->addAction( actionOpen ); + toolbarFile->addAction( actionSave ); + toolbarFile->addAction( actionClose ); - viewToolBar = addToolBar( tr( "Zoom" ) ); - viewToolBar->addAction( zoomInAct ); - viewToolBar->addAction( zoomOutAct ); - viewToolBar->addAction( normalSizeAct ); - viewToolBar->addAction( zoomToFitAct ); + toolbarView = addToolBar( tr( "Zoom" ) ); + toolbarView->addAction( actionZoomIn ); + toolbarView->addAction( actionZoomOut ); + toolbarView->addAction( actionNormalSize ); + toolbarView->addAction( actionZoomToFit ); + + toolbarVideo = addToolBar( tr( "Video" ) ); + toolbarVideo->addAction( actionVideoPlay ); + toolbarVideo->addAction( actionVideoPause ); + toolbarVideo->addAction( actionVideoStop ); + toolbarVideo->addAction( actionVideoBackward ); + toolbarVideo->addAction( actionVideoForward ); + toolbarVideo->addAction( actionVideoLoop ); + toolbarVideo->addAction( actionVideoLock ); + toolbarVideo->addAction( actionVideoInterlace ); + toolbarVideo->addAction( actionVideoCenter ); - videoToolBar = addToolBar( tr( "Video" ) ); - videoToolBar->addAction( actionVideoPlay ); - videoToolBar->addAction( actionVideoPause ); - videoToolBar->addAction( actionVideoStop ); - videoToolBar->addAction( actionVideoBackward ); - videoToolBar->addAction( actionVideoForward ); - videoToolBar->addAction( actionVideoLoop ); - videoToolBar->addAction( actionVideoLock ); - videoToolBar->addAction( actionVideoInterlace ); - videoToolBar->addAction( actionVideoCenter ); } Void plaYUVerApp::createStatusBar() diff --git a/source/plaYUVerApp.h b/source/plaYUVerApp.h index 9705013..0025dad 100644 --- a/source/plaYUVerApp.h +++ b/source/plaYUVerApp.h @@ -62,7 +62,7 @@ private slots: void stop(); void playEvent(); - //! View functions + //! Zoom functions void zoomIn(); void zoomOut(); /** @@ -70,7 +70,7 @@ private slots: * @param factor factor of scale. Ex: 1.2 scale the image up by 20% and * 0.8 scale the image down by 25% */ - void scaleImage( double factor = 1 ); + void scaleFrame( int ratio = 100 ); void normalSize(); void zoomToFit(); @@ -92,6 +92,11 @@ private slots: void setActiveSubWindow( QWidget *window ); private: + QMdiArea *mdiArea; + + QString m_cLastOpenPath; + QTimer *playingTimer; + Void createActions(); Void createMenus(); Void createToolBars(); @@ -101,36 +106,34 @@ private: SubWindowHandle *activeSubWindow(); QMdiSubWindow *findSubWindow( const QString &fileName ); - QString m_cLastOpenPath; + QSignalMapper *mapperZoom; + QSignalMapper *mapperWindow; - QTimer *playingTimer; - QMdiArea *mdiArea; - QSignalMapper *windowMapper; + QMenu *menuFile; + QMenu *menuView; + QMenu *menuWindow; + QMenu *menuHelp; - QMenu *fileMenu; - QMenu *viewMenu; - QMenu *windowMenu; - QMenu *helpMenu; - QToolBar *fileToolBar; - QToolBar *viewToolBar; - QToolBar *videoToolBar; + QToolBar *toolbarFile; + QToolBar *toolbarView; + QToolBar *toolbarVideo; - QAction *openAct; - QAction *saveAct; - QAction *exitAct; - QAction *closeAct; - QAction *closeAllAct; + QAction *actionOpen; + QAction *actionSave; + QAction *actionExit; + QAction *actionClose; + QAction *actionCloseAll; - QAction *zoomInAct; - QAction *zoomOutAct; - QAction *normalSizeAct; - QAction *zoomToFitAct; + QAction *actionZoomIn; + QAction *actionZoomOut; + QAction *actionNormalSize; + QAction *actionZoomToFit; - QAction *tileAct; - QAction *cascadeAct; - QAction *nextAct; - QAction *previousAct; - QAction *separatorAct; + QAction *actionTile; + QAction *actionCascade; + QAction *actionNext; + QAction *actionPrevious; + QAction *actionSeparator; // Video actions. QAction *actionVideoPlay; @@ -143,8 +146,8 @@ private: QAction *actionVideoInterlace; QAction *actionVideoCenter; - QAction *aboutAct; - QAction *aboutQtAct; + QAction *actionAbout; + QAction *actionAboutQt; }; From 735ff50b6c2051577807f8e302fe429ab76b5607 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 7 Feb 2014 22:51:49 +0000 Subject: [PATCH 03/13] Fix switch without default --- source/PlaYUVerFrame.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/PlaYUVerFrame.cpp b/source/PlaYUVerFrame.cpp index e358111..7f93389 100755 --- a/source/PlaYUVerFrame.cpp +++ b/source/PlaYUVerFrame.cpp @@ -201,7 +201,10 @@ UInt64 PlaYUVerFrame::getBytesPerFrame() case RGB: return m_uiWidth * m_uiHeight * 3; break; + default: + return 0; } + return 0; } } // NAMESPACE From 030821d653a609b0d38fac10d1b941a9c68fc860 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 7 Feb 2014 22:54:34 +0000 Subject: [PATCH 04/13] Fix last commit --- source/plaYUVerApp.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/source/plaYUVerApp.h b/source/plaYUVerApp.h index 0025dad..4885768 100644 --- a/source/plaYUVerApp.h +++ b/source/plaYUVerApp.h @@ -62,9 +62,6 @@ private slots: void stop(); void playEvent(); - //! Zoom functions - void zoomIn(); - void zoomOut(); /** * Scale the image by a given factor * @param factor factor of scale. Ex: 1.2 scale the image up by 20% and From bdf8dd0ca0cb65b41c78e2d11d835f57372f6323 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 7 Feb 2014 23:16:35 +0000 Subject: [PATCH 05/13] Clean some code and add connection create connection when window is selected --- source/plaYUVerApp.cpp | 58 +++++++++++++++++++++++++++--------------- source/plaYUVerApp.h | 16 ++++++++---- 2 files changed, 48 insertions(+), 26 deletions(-) diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index 15118ab..ba4feac 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -46,7 +46,7 @@ plaYUVerApp::plaYUVerApp() //mdiArea->setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded ); //mdiArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); - connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( updateMenus() ) ); + connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( chageSubWindowSelection() ) ); mapperWindow = new QSignalMapper( this ); connect( mapperWindow, SIGNAL( mapped(QWidget*) ), this, SLOT( setActiveSubWindow(QWidget*) ) ); @@ -187,7 +187,7 @@ void plaYUVerApp::scaleFrame( int ratio ) { if( activeSubWindow() ) { - activeSubWindow()->scaleView( (Double)(ratio)/100.0 ); + activeSubWindow()->scaleView( ( Double )( ratio ) / 100.0 ); actionZoomIn->setEnabled( activeSubWindow()->getScaleFactor() < 3.0 ); actionZoomOut->setEnabled( activeSubWindow()->getScaleFactor() > 0.333 ); @@ -201,7 +201,13 @@ void plaYUVerApp::about() QMessageBox::about( this, tr( "About plaYUVerApp" ), tr( "The plaYUVerApp is an open-source raw video player " ) ); } -void plaYUVerApp::updateMenus() +void plaYUVerApp::chageSubWindowSelection() +{ + updateMenus(); + //updateWindowMenu(); +} + +Void plaYUVerApp::updateMenus() { Bool hasSubWindow = ( activeSubWindow() != 0 ); actionSave->setEnabled( hasSubWindow ); @@ -209,8 +215,6 @@ void plaYUVerApp::updateMenus() actionCloseAll->setEnabled( hasSubWindow ); actionTile->setEnabled( hasSubWindow ); actionCascade->setEnabled( hasSubWindow ); - actionNext->setEnabled( hasSubWindow ); - actionPrevious->setEnabled( hasSubWindow ); actionSeparator->setVisible( hasSubWindow ); actionZoomIn->setEnabled( hasSubWindow ); @@ -227,13 +231,35 @@ void plaYUVerApp::updateMenus() void plaYUVerApp::updateWindowMenu() { + menuWindow->clear(); + menuWindow->addAction( actionClose ); + menuWindow->addAction( actionCloseAll ); + menuWindow->addSeparator(); + menuWindow->addAction( actionTile ); + menuWindow->addAction( actionCascade ); + menuWindow->addSeparator(); + menuWindow->addAction( actionNext ); + menuWindow->addAction( actionPrevious ); + menuWindow->addAction( actionSeparator ); - updateMenus(); + //updateMenus(); QList windows = mdiArea->subWindowList(); actionSeparator->setVisible( !windows.isEmpty() ); + Int number_windows = windows.size(); - for( Int i = 0; i < windows.size(); ++i ) + if( number_windows > 1 ) + { + actionNext->setEnabled( true ); + actionPrevious->setEnabled( true ); + } + else + { + actionNext->setEnabled( false ); + actionPrevious->setEnabled( false ); + } + + for( Int i = 0; i < number_windows; ++i ) { SubWindowHandle *child = qobject_cast( windows.at( i ) ); @@ -308,15 +334,15 @@ Void plaYUVerApp::createActions() actionZoomIn->setIcon( QIcon( ":/images/zoomin.png" ) ); actionZoomIn->setShortcut( tr( "Ctrl++" ) ); actionZoomIn->setStatusTip( tr( "Scale the image up by 25%" ) ); - connect (actionZoomIn, SIGNAL(triggered()), mapperZoom, SLOT(map())) ; - mapperZoom->setMapping(actionZoomIn, 125 ); + connect( actionZoomIn, SIGNAL( triggered() ), mapperZoom, SLOT( map() ) ); + mapperZoom->setMapping( actionZoomIn, 125 ); actionZoomOut = new QAction( tr( "Zoom &Out (25%)" ), this ); actionZoomOut->setIcon( QIcon( ":/images/zoomout.png" ) ); actionZoomOut->setShortcut( tr( "Ctrl+-" ) ); actionZoomOut->setStatusTip( tr( "Scale the image down by 25%" ) ); - connect (actionZoomOut, SIGNAL(triggered()), mapperZoom, SLOT(map())) ; - mapperZoom->setMapping(actionZoomOut, 80 ); + connect( actionZoomOut, SIGNAL( triggered() ), mapperZoom, SLOT( map() ) ); + mapperZoom->setMapping( actionZoomOut, 80 ); actionNormalSize = new QAction( tr( "&Normal Size" ), this ); actionNormalSize->setIcon( QIcon( ":/images/zoomtonormal.png" ) ); @@ -410,16 +436,6 @@ Void plaYUVerApp::createMenus() menuView->addAction( actionZoomToFit ); menuWindow = menuBar()->addMenu( tr( "&Window" ) ); - menuWindow->clear(); - menuWindow->addAction( actionClose ); - menuWindow->addAction( actionCloseAll ); - menuWindow->addSeparator(); - menuWindow->addAction( actionTile ); - menuWindow->addAction( actionCascade ); - menuWindow->addSeparator(); - menuWindow->addAction( actionNext ); - menuWindow->addAction( actionPrevious ); - menuWindow->addAction( actionSeparator ); updateWindowMenu(); connect( menuWindow, SIGNAL( aboutToShow() ), this, SLOT( updateWindowMenu() ) ); diff --git a/source/plaYUVerApp.h b/source/plaYUVerApp.h index 4885768..14d737e 100644 --- a/source/plaYUVerApp.h +++ b/source/plaYUVerApp.h @@ -64,8 +64,8 @@ private slots: /** * Scale the image by a given factor - * @param factor factor of scale. Ex: 1.2 scale the image up by 20% and - * 0.8 scale the image down by 25% + * @param factor factor of scale. Ex: 120 scale the image up by 20% and + * 80 scale the image down by 25% */ void scaleFrame( int ratio = 100 ); @@ -74,7 +74,9 @@ private slots: //! Show a message box with some information about the plaYUVerApp App void about(); - void updateMenus(); + + + void chageSubWindowSelection(); void updateWindowMenu(); @@ -84,8 +86,6 @@ private slots: void dragEnterEvent(QDragEnterEvent *event); void dropEvent(QDropEvent *event); - SubWindowHandle *createSubWindow(); - void addSubWindow( SubWindowHandle *child ); void setActiveSubWindow( QWidget *window ); private: @@ -94,12 +94,18 @@ private: QString m_cLastOpenPath; QTimer *playingTimer; + Void updateMenus(); + Void createActions(); Void createMenus(); Void createToolBars(); Void createStatusBar(); + Void readSettings(); Void writeSettings(); + + Void addSubWindow( SubWindowHandle *child ); + SubWindowHandle *createSubWindow(); SubWindowHandle *activeSubWindow(); QMdiSubWindow *findSubWindow( const QString &fileName ); From 05e007c1355daab5fb68d59555234d42f7bf189f Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 7 Feb 2014 23:21:03 +0000 Subject: [PATCH 06/13] replace slots by Q_SLOTS --- source/SubWindowHandle.h | 2 +- source/plaYUVerApp.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/source/SubWindowHandle.h b/source/SubWindowHandle.h index 99d0de7..2b3a0c6 100644 --- a/source/SubWindowHandle.h +++ b/source/SubWindowHandle.h @@ -124,7 +124,7 @@ public: protected: Void closeEvent( QCloseEvent *event ); -private slots: +private Q_SLOTS: }; diff --git a/source/plaYUVerApp.h b/source/plaYUVerApp.h index 14d737e..e7d99f9 100644 --- a/source/plaYUVerApp.h +++ b/source/plaYUVerApp.h @@ -50,7 +50,7 @@ public: protected: Void closeEvent( QCloseEvent *event ); -private slots: +private Q_SLOTS: //! File functions void open(); @@ -75,7 +75,6 @@ private slots: //! Show a message box with some information about the plaYUVerApp App void about(); - void chageSubWindowSelection(); void updateWindowMenu(); From 3ee9a4b2776bf12df1ff1c6961c66d01cc6a19dd Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 7 Feb 2014 23:49:58 +0000 Subject: [PATCH 07/13] Add stop function. Trying to implement a different playing behaviour with a direct connection to the SubWindow class --- source/SubWindowHandle.cpp | 35 ++++++++++++++++++++++++----------- source/SubWindowHandle.h | 8 +++++--- source/plaYUVerApp.cpp | 24 +++++++++++++----------- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/source/SubWindowHandle.cpp b/source/SubWindowHandle.cpp index 4d21efe..7a1d06f 100644 --- a/source/SubWindowHandle.cpp +++ b/source/SubWindowHandle.cpp @@ -47,6 +47,7 @@ SubWindowHandle::SubWindowHandle( QWidget * parent ) : m_cScrollArea->setWidget( m_cViewArea ); m_cWindowName = QString( " " ); + m_bIsPlaying = true; m_dScaleFactor = 1; } @@ -93,7 +94,7 @@ bool SubWindowHandle::loadFile( const QString &fileName ) normalSize(); - m_cWindowName = QString("ola"); + m_cWindowName = QString( "ola" ); m_cWindowName = m_currStream.getStreamInformationString(); m_cCurrFileName = fileName; @@ -133,23 +134,35 @@ bool SubWindowHandle::save() return true; } -bool SubWindowHandle::playEvent() +int SubWindowHandle::playEvent() { - m_currStream.readFrame(); - if( m_currStream.checkErrors( READING ) ) - { - QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( m_cCurrFileName ) ); - return false; - } - else if( m_currStream.checkErrors( END_OF_SEQ ) ) + if( m_bIsPlaying ) { + m_currStream.readFrame(); + if( m_currStream.checkErrors( READING ) ) + { + QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( m_cCurrFileName ) ); + return false; + } + else if( m_currStream.checkErrors( END_OF_SEQ ) ) + { + m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); + return false; + } m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); - return false; } - m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); return true; } +Void SubWindowHandle::stopEvent() +{ + m_currStream.seekInput( 0 ); + m_currStream.readFrame(); + m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); + return; +} + + Void SubWindowHandle::normalSize() { m_dScaleFactor = 1.0; diff --git a/source/SubWindowHandle.h b/source/SubWindowHandle.h index 2b3a0c6..174eac5 100644 --- a/source/SubWindowHandle.h +++ b/source/SubWindowHandle.h @@ -57,6 +57,8 @@ private: Double m_dScaleFactor; + Bool m_bIsPlaying; + public: SubWindowHandle( QWidget * parent = 0 ); ~SubWindowHandle(); @@ -64,7 +66,7 @@ public: bool loadFile( const QString &fileName ); bool save(); - bool playEvent(); + Void stopEvent(); InputStream* getInputStream() { @@ -124,8 +126,8 @@ public: protected: Void closeEvent( QCloseEvent *event ); -private Q_SLOTS: - +public Q_SLOTS: + int playEvent(); }; } // NAMESPACE diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index ba4feac..6f9f453 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -68,8 +68,6 @@ plaYUVerApp::plaYUVerApp() setAcceptDrops( true ); mdiArea->setAcceptDrops( true ); - connect( playingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); - } Void plaYUVerApp::closeEvent( QCloseEvent *event ) @@ -136,14 +134,14 @@ void plaYUVerApp::save() void plaYUVerApp::play() { - UInt frameRate; - UInt timeInterval; - - frameRate = activeSubWindow()->getInputStream()->getFrameRate(); - timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); - - playingTimer->start( timeInterval ); - + if( activeSubWindow() ) + { + UInt frameRate = activeSubWindow()->getInputStream()->getFrameRate(); + UInt timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); + playingTimer->start( timeInterval ); + //connect( playingTimer, SIGNAL( timeout() ), activeSubWindow(), SLOT( playEvent() ) ); + connect( playingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); + } } void plaYUVerApp::pause() @@ -153,6 +151,10 @@ void plaYUVerApp::pause() void plaYUVerApp::stop() { + if( activeSubWindow() ) + { + activeSubWindow()->stopEvent(); + } playingTimer->stop(); //disconnect( playingTimer, SIGNAL( timeout() ), 0, 0 ); } @@ -251,7 +253,7 @@ void plaYUVerApp::updateWindowMenu() if( number_windows > 1 ) { actionNext->setEnabled( true ); - actionPrevious->setEnabled( true ); + actionPrevious->setEnabled( true ); } else { From fcef6e09c463269fe42b18f62eb56d0fd76d2fa7 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 8 Feb 2014 01:02:48 +0000 Subject: [PATCH 08/13] Init LibAvContextHandle flags. fix current frame number variable. Add disconnect function when stop is clicked --- source/InputStream.cpp | 26 +++++++++++++------------- source/InputStream.h | 6 +++--- source/lib/ffmpeg/LibAvContextHandle.h | 6 ++++-- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/source/InputStream.cpp b/source/InputStream.cpp index e67064c..be2f955 100755 --- a/source/InputStream.cpp +++ b/source/InputStream.cpp @@ -39,7 +39,7 @@ InputStream::InputStream() m_uiWidth = 0; m_uiHeight = 0; m_uiTotalFrameNum = 0; - m_uiCurrFrameNum = 0; + m_iCurrFrameNum = -1; m_iErrorStatus = 0; m_iPixelFormat = -1; @@ -137,9 +137,12 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for m_cStreamInformationString = QString( "[" ); #ifdef USE_FFMPEG - avStatus = m_cLibAvContext.initAvFormat( m_cFilename.toLocal8Bit().data(), m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiFrameRate ); - m_cStreamInformationString.append( QString::fromUtf8( m_cLibAvContext.getStreamInformation() ) ); - m_uiTotalFrameNum = 100; + if( QFileInfo( filename ).completeSuffix().compare( QString( "yuv" ) ) ) + { + avStatus = m_cLibAvContext.initAvFormat( m_cFilename.toLocal8Bit().data(), m_uiWidth, m_uiHeight, m_iPixelFormat, m_uiFrameRate ); + m_cStreamInformationString.append( QString::fromUtf8( m_cLibAvContext.getStreamInformation() ) ); + m_uiTotalFrameNum = 100; + } #endif if( m_uiWidth <= 0 || m_uiHeight <= 0 ) @@ -181,7 +184,7 @@ Void InputStream::init( QString filename, UInt width, UInt height, Int input_for m_cStreamInformationString.append( QFileInfo( m_cFilename ).fileName() ); - m_uiCurrFrameNum = 0; + m_iCurrFrameNum = -1; m_iStatus = 1; return; @@ -208,15 +211,12 @@ Void InputStream::readFrame() return; } - if( m_uiCurrFrameNum < m_uiTotalFrameNum ) - { - m_uiCurrFrameNum++; - } - else + m_iCurrFrameNum++; + if( m_iCurrFrameNum >= m_uiTotalFrameNum ) { m_iErrorStatus = END_OF_SEQ; - m_uiCurrFrameNum = 0; - seekInput( m_uiCurrFrameNum ); + m_iCurrFrameNum = 0; + seekInput( m_iCurrFrameNum ); } #ifdef USE_FFMPEG @@ -292,7 +292,7 @@ Void InputStream::seekInput( Int new_frame_num ) UInt64 frame_bytes_input = m_uiWidth * m_uiHeight * 1.5; UInt64 nbytes_seek = frame_bytes_input * new_frame_num; fseek( m_pFile, nbytes_seek, SEEK_SET ); - m_uiCurrFrameNum = new_frame_num; + m_iCurrFrameNum = new_frame_num; } } diff --git a/source/InputStream.h b/source/InputStream.h index 9560171..544dc8d 100755 --- a/source/InputStream.h +++ b/source/InputStream.h @@ -78,7 +78,7 @@ private: UInt m_uiHeight; UInt m_uiFrameRate; UInt m_uiTotalFrameNum; - UInt m_uiCurrFrameNum; + Int m_iCurrFrameNum; public: InputStream(); @@ -136,9 +136,9 @@ public: { return m_uiHeight; } - UInt getCurrFrameNum() + Int getCurrFrameNum() { - return m_uiCurrFrameNum; + return m_iCurrFrameNum; } UInt getFrameRate() { diff --git a/source/lib/ffmpeg/LibAvContextHandle.h b/source/lib/ffmpeg/LibAvContextHandle.h index 96e7460..4a35751 100755 --- a/source/lib/ffmpeg/LibAvContextHandle.h +++ b/source/lib/ffmpeg/LibAvContextHandle.h @@ -43,8 +43,6 @@ extern "C" #include } - - #include "TypeDef.h" namespace plaYUVer @@ -53,6 +51,10 @@ namespace plaYUVer class LibAvContextHandle { public: + LibAvContextHandle() : + m_bHasStream( false ) + { + } Bool initAvFormat( char* filename, UInt& width, UInt& height, Int& pixel_format, UInt& frame_rate ); Void closeAvFormat(); Bool decodeAvFormat(); From 3cf0d866ad1308ba3e0a0a09e0ef67516a290b46 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 8 Feb 2014 01:29:48 +0000 Subject: [PATCH 09/13] Fix last commit. Use just one QImage for every frame --- source/InputStream.cpp | 11 ++++---- source/InputStream.h | 2 +- source/SubWindowHandle.cpp | 56 ++++++++++++++++++++++---------------- source/SubWindowHandle.h | 7 +++-- source/plaYUVerApp.cpp | 13 ++++----- 5 files changed, 48 insertions(+), 41 deletions(-) diff --git a/source/InputStream.cpp b/source/InputStream.cpp index be2f955..1a0cef5 100755 --- a/source/InputStream.cpp +++ b/source/InputStream.cpp @@ -243,14 +243,14 @@ Void InputStream::readFrame() Bool InputStream::writeFrame( const QString& filename ) { - getFrameQImage().save( filename ); + QImage img( m_uiWidth, m_uiHeight, QImage::Format_RGB888 ); + getFrame( &img ); + img.save( filename ); return true; } -QImage InputStream::getFrameQImage() +Void InputStream::getFrame( QImage *qimage ) { - // Create QImage - QImage img( m_uiWidth, m_uiHeight, QImage::Format_RGB888 ); Pel*** bufferRGB = m_cCurrFrame->getPelBufferRGB(); if( sizeof(Pel) == sizeof(unsigned char) ) @@ -259,7 +259,7 @@ QImage InputStream::getFrameQImage() { for( Int x = 0; x < m_uiWidth; x++ ) { - img.setPixel( x, y, qRgb( bufferRGB[0][y][x], bufferRGB[1][y][x], bufferRGB[2][y][x] ) ); + qimage->setPixel( x, y, qRgb( bufferRGB[0][y][x], bufferRGB[1][y][x], bufferRGB[2][y][x] ) ); } } } @@ -267,7 +267,6 @@ QImage InputStream::getFrameQImage() { Q_ASSERT( 0 ); } - return img; } #ifdef USE_OPENCV diff --git a/source/InputStream.h b/source/InputStream.h index 544dc8d..7935d41 100755 --- a/source/InputStream.h +++ b/source/InputStream.h @@ -103,7 +103,7 @@ public: Bool writeFrame( const QString& filename ); - QImage getFrameQImage(); + Void getFrame( QImage *qimage ); #ifdef USE_OPENCV cv::Mat getFrameCvMat(); #endif diff --git a/source/SubWindowHandle.cpp b/source/SubWindowHandle.cpp index 7a1d06f..e997343 100644 --- a/source/SubWindowHandle.cpp +++ b/source/SubWindowHandle.cpp @@ -61,28 +61,32 @@ bool SubWindowHandle::loadFile( const QString &fileName ) { ConfigureFormatDialog formatDialog( this ); - if( m_currStream.needFormatDialog( fileName ) ) + m_pCurrStream = new InputStream; + + if( m_pCurrStream->needFormatDialog( fileName ) ) { if( formatDialog.exec() == QDialog::Rejected ) { return false; } - m_currStream.init( fileName, formatDialog.getResolution().width(), formatDialog.getResolution().height(), formatDialog.getPixelFormat(), + m_pCurrStream->init( fileName, formatDialog.getResolution().width(), formatDialog.getResolution().height(), formatDialog.getPixelFormat(), formatDialog.getFrameRate() ); } else { - m_currStream.init( fileName, 0, 0, 0, 0 ); + m_pCurrStream->init( fileName, 0, 0, 0, 0 ); } QApplication::setOverrideCursor( Qt::WaitCursor ); QApplication::restoreOverrideCursor(); - if( m_currStream.getStatus() == 0 ) + if( m_pCurrStream->getStatus() == 0 ) { return false; } - m_currStream.readFrame(); - if( m_currStream.checkErrors( READING ) ) + m_pCurrFrameQImage = new QImage( m_pCurrStream->getWidth(), m_pCurrStream->getHeight(), QImage::Format_RGB888 ); + + m_pCurrStream->readFrame(); + if( m_pCurrStream->checkErrors( READING ) ) { QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( fileName ) ); return false; @@ -90,12 +94,13 @@ bool SubWindowHandle::loadFile( const QString &fileName ) QApplication::restoreOverrideCursor(); - m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); + m_pCurrStream->getFrame( m_pCurrFrameQImage ); + m_cViewArea->setImage( QPixmap::fromImage( *m_pCurrFrameQImage ) ); normalSize(); - m_cWindowName = QString( "ola" ); - m_cWindowName = m_currStream.getStreamInformationString(); + m_cWindowName = QString( " " ); + m_cWindowName = m_pCurrStream->getStreamInformationString(); m_cCurrFileName = fileName; @@ -122,7 +127,7 @@ bool SubWindowHandle::save() QApplication::setOverrideCursor( Qt::WaitCursor ); - if( !m_currStream.writeFrame( fileName ) ) + if( !m_pCurrStream->writeFrame( fileName ) ) { QApplication::restoreOverrideCursor(); QMessageBox::warning( this, tr( "SCode" ), tr( "Cannot save file %1" ).arg( fileName ) ); @@ -134,31 +139,34 @@ bool SubWindowHandle::save() return true; } -int SubWindowHandle::playEvent() +bool SubWindowHandle::playEvent() { + bool iRet = true; if( m_bIsPlaying ) { - m_currStream.readFrame(); - if( m_currStream.checkErrors( READING ) ) + m_pCurrStream->readFrame(); + if( m_pCurrStream->checkErrors( READING ) ) { QMessageBox::warning( this, tr( "plaYUVer" ), tr( "Cannot read %1." ).arg( m_cCurrFileName ) ); return false; } - else if( m_currStream.checkErrors( END_OF_SEQ ) ) + else if( m_pCurrStream->checkErrors( END_OF_SEQ ) ) { - m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); - return false; + iRet = false; } - m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); + m_pCurrStream->getFrame( m_pCurrFrameQImage ); + m_cViewArea->setImage( QPixmap::fromImage( *m_pCurrFrameQImage ) ); + return iRet; } - return true; + return false; } Void SubWindowHandle::stopEvent() { - m_currStream.seekInput( 0 ); - m_currStream.readFrame(); - m_cViewArea->setImage( QPixmap::fromImage( m_currStream.getFrameQImage() ) ); + m_pCurrStream->seekInput( 0 ); + m_pCurrStream->readFrame(); + m_pCurrStream->getFrame( m_pCurrFrameQImage ); + m_cViewArea->setImage( QPixmap::fromImage( *m_pCurrFrameQImage ) ); return; } @@ -173,7 +181,7 @@ Void SubWindowHandle::zoomToFit() { // Scale to a smaller size that the real to a nicer look QSize niceFit( m_cScrollArea->viewport()->size().width() - 10, m_cScrollArea->viewport()->size().height() - 10 ); - if( m_currStream.getWidth() <= niceFit.width() && m_currStream.getHeight() <= niceFit.height() ) + if( m_pCurrStream->getWidth() <= niceFit.width() && m_pCurrStream->getHeight() <= niceFit.height() ) { normalSize(); return; @@ -196,7 +204,7 @@ Void SubWindowHandle::scaleView( Int width, Int height ) Void SubWindowHandle::scaleView( const QSize & size ) { - QSize imgViewSize( m_currStream.getWidth(), m_currStream.getHeight() ); + QSize imgViewSize( m_pCurrStream->getWidth(), m_pCurrStream->getHeight() ); QSize newSize = imgViewSize; newSize.scale( size, Qt::KeepAspectRatio ); @@ -233,7 +241,7 @@ QSize SubWindowHandle::sizeHint() const maxSize = p->size(); } - QSize isize = QSize( m_currStream.getWidth() + 500, m_currStream.getHeight() + 500 ); + QSize isize = QSize( m_pCurrStream->getWidth() + 500, m_pCurrStream->getHeight() + 500 ); // 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/SubWindowHandle.h b/source/SubWindowHandle.h index 174eac5..91745d1 100644 --- a/source/SubWindowHandle.h +++ b/source/SubWindowHandle.h @@ -50,7 +50,8 @@ private: QScrollArea* m_cScrollArea; ViewArea* m_cViewArea; - InputStream m_currStream; + InputStream* m_pCurrStream; + QImage* m_pCurrFrameQImage; QString m_cWindowName; QString m_cCurrFileName; @@ -70,7 +71,7 @@ public: InputStream* getInputStream() { - return &m_currStream; + return m_pCurrStream; } /** @@ -127,7 +128,7 @@ protected: Void closeEvent( QCloseEvent *event ); public Q_SLOTS: - int playEvent(); + bool playEvent(); }; } // NAMESPACE diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index 6f9f453..c0e44e0 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -139,24 +139,23 @@ void plaYUVerApp::play() UInt frameRate = activeSubWindow()->getInputStream()->getFrameRate(); UInt timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); playingTimer->start( timeInterval ); - //connect( playingTimer, SIGNAL( timeout() ), activeSubWindow(), SLOT( playEvent() ) ); - connect( playingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); + connect( playingTimer, SIGNAL( timeout() ), activeSubWindow(), SLOT( playEvent() ) ); + //connect( playingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); } } void plaYUVerApp::pause() { playingTimer->stop(); + disconnect( activeSubWindow(), SLOT( playEvent() ) ); } void plaYUVerApp::stop() { - if( activeSubWindow() ) - { - activeSubWindow()->stopEvent(); - } + activeSubWindow()->stopEvent(); + disconnect( activeSubWindow(), SLOT( playEvent() ) ); playingTimer->stop(); - //disconnect( playingTimer, SIGNAL( timeout() ), 0, 0 ); + } void plaYUVerApp::playEvent() From 17085ae6f3424317ab64bed2213206c0542c487d Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 8 Feb 2014 01:58:20 +0000 Subject: [PATCH 10/13] Bug fix: cannot set multiple times de same connection --- source/plaYUVerApp.cpp | 16 +++++++--------- source/plaYUVerApp.h | 1 - 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index c0e44e0..f2439d0 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -47,6 +47,7 @@ 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*) ) ); @@ -63,11 +64,12 @@ plaYUVerApp::plaYUVerApp() setWindowIcon( QIcon( ":/images/playuver.png" ) ); setUnifiedTitleAndToolBarOnMac( true ); - playingTimer = new QTimer( this ); + playingTimer = new QTimer; + playingTimer->setTimerType( Qt::CoarseTimer ); + connect( playingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); setAcceptDrops( true ); mdiArea->setAcceptDrops( true ); - } Void plaYUVerApp::closeEvent( QCloseEvent *event ) @@ -134,26 +136,23 @@ void plaYUVerApp::save() void plaYUVerApp::play() { + playingTimer->stop(); if( activeSubWindow() ) { UInt frameRate = activeSubWindow()->getInputStream()->getFrameRate(); UInt timeInterval = ( UInt )( 1000.0 / frameRate + 0.5 ); playingTimer->start( timeInterval ); - connect( playingTimer, SIGNAL( timeout() ), activeSubWindow(), SLOT( playEvent() ) ); - //connect( playingTimer, SIGNAL( timeout() ), this, SLOT( playEvent() ) ); } } void plaYUVerApp::pause() { playingTimer->stop(); - disconnect( activeSubWindow(), SLOT( playEvent() ) ); } void plaYUVerApp::stop() { activeSubWindow()->stopEvent(); - disconnect( activeSubWindow(), SLOT( playEvent() ) ); playingTimer->stop(); } @@ -167,7 +166,6 @@ void plaYUVerApp::playEvent() playingTimer->stop(); } } - } // ----------------------- Zoom Functions ----------------------- @@ -204,6 +202,7 @@ void plaYUVerApp::about() void plaYUVerApp::chageSubWindowSelection() { + playingTimer->stop(); updateMenus(); //updateWindowMenu(); } @@ -243,7 +242,7 @@ void plaYUVerApp::updateWindowMenu() menuWindow->addAction( actionPrevious ); menuWindow->addAction( actionSeparator ); - //updateMenus(); + updateMenus(); QList windows = mdiArea->subWindowList(); actionSeparator->setVisible( !windows.isEmpty() ); @@ -470,7 +469,6 @@ Void plaYUVerApp::createToolBars() toolbarVideo->addAction( actionVideoLock ); toolbarVideo->addAction( actionVideoInterlace ); toolbarVideo->addAction( actionVideoCenter ); - } Void plaYUVerApp::createStatusBar() diff --git a/source/plaYUVerApp.h b/source/plaYUVerApp.h index e7d99f9..2f0feaa 100644 --- a/source/plaYUVerApp.h +++ b/source/plaYUVerApp.h @@ -76,7 +76,6 @@ private Q_SLOTS: void about(); void chageSubWindowSelection(); - void updateWindowMenu(); /* From 13ff613fa4ae35f91170cf3b9fb195f38a999976 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 8 Feb 2014 02:28:09 +0000 Subject: [PATCH 11/13] Add a slider to seek video sequence --- source/plaYUVerApp.cpp | 19 +++++++++++++------ source/plaYUVerApp.h | 13 +++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index f2439d0..7886aa7 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -21,6 +21,10 @@ * \brief Main definition of the plaYUVerApp app */ +#include "plaYUVerApp.h" +#include "SubWindowHandle.h" +#include "InputStream.h" + #if( QT_VERSION_PLAYUVER == 5 ) #include #elif( QT_VERSION_PLAYUVER == 4 ) @@ -28,11 +32,6 @@ #endif #include -#include "TypeDef.h" -#include "plaYUVerApp.h" -#include "SubWindowHandle.h" -#include "InputStream.h" - namespace plaYUVer { @@ -47,7 +46,7 @@ plaYUVerApp::plaYUVerApp() //mdiArea->setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded ); connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( chageSubWindowSelection() ) ); - connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( updateMenus() ) ); + //connect( mdiArea, SIGNAL( subWindowActivated(QMdiSubWindow*) ), this, SLOT( updateMenus() ) ); mapperWindow = new QSignalMapper( this ); connect( mapperWindow, SIGNAL( mapped(QWidget*) ), this, SLOT( setActiveSubWindow(QWidget*) ) ); @@ -463,12 +462,20 @@ Void plaYUVerApp::createToolBars() toolbarVideo->addAction( actionVideoPlay ); toolbarVideo->addAction( actionVideoPause ); toolbarVideo->addAction( actionVideoStop ); + /* toolbarVideo->addAction( actionVideoBackward ); toolbarVideo->addAction( actionVideoForward ); toolbarVideo->addAction( actionVideoLoop ); toolbarVideo->addAction( actionVideoLock ); toolbarVideo->addAction( actionVideoInterlace ); toolbarVideo->addAction( actionVideoCenter ); + */ + m_pcFrameSlider = new QSlider; + m_pcFrameSlider->setOrientation( Qt::Horizontal ); + m_pcFrameSlider->setMaximumWidth( 100 ); + m_pcFrameSlider->setMaximumWidth( 100 ); + m_pcFrameSlider->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ) ); + toolbarVideo->addWidget( m_pcFrameSlider ); } Void plaYUVerApp::createStatusBar() diff --git a/source/plaYUVerApp.h b/source/plaYUVerApp.h index 2f0feaa..fb23bca 100644 --- a/source/plaYUVerApp.h +++ b/source/plaYUVerApp.h @@ -26,15 +26,14 @@ #include "config.h" +#if( QT_VERSION_PLAYUVER == 5 ) +#include +#elif( QT_VERSION_PLAYUVER == 4 ) +#include +#endif #include #include "TypeDef.h" -class QAction; -class QMenu; -class QMdiArea; -class QMdiSubWindow; -class QSignalMapper; - namespace plaYUVer { @@ -107,6 +106,8 @@ private: SubWindowHandle *activeSubWindow(); QMdiSubWindow *findSubWindow( const QString &fileName ); + QSlider *m_pcFrameSlider; + QSignalMapper *mapperZoom; QSignalMapper *mapperWindow; From 1d1602c7d7a8c62607628b87719f9039a0f5401e Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 8 Feb 2014 03:15:01 +0000 Subject: [PATCH 12/13] All a slide into the MainWindow toolbar --- source/InputStream.cpp | 2 +- source/SubWindowHandle.cpp | 8 +++++ source/SubWindowHandle.h | 1 + source/plaYUVerApp.cpp | 67 +++++++++++++++++++++++++------------- source/plaYUVerApp.h | 2 +- 5 files changed, 55 insertions(+), 25 deletions(-) diff --git a/source/InputStream.cpp b/source/InputStream.cpp index 1a0cef5..9e7c478 100755 --- a/source/InputStream.cpp +++ b/source/InputStream.cpp @@ -291,7 +291,7 @@ Void InputStream::seekInput( Int new_frame_num ) UInt64 frame_bytes_input = m_uiWidth * m_uiHeight * 1.5; UInt64 nbytes_seek = frame_bytes_input * new_frame_num; fseek( m_pFile, nbytes_seek, SEEK_SET ); - m_iCurrFrameNum = new_frame_num; + m_iCurrFrameNum = new_frame_num - 1; } } diff --git a/source/SubWindowHandle.cpp b/source/SubWindowHandle.cpp index e997343..9ea4ca6 100644 --- a/source/SubWindowHandle.cpp +++ b/source/SubWindowHandle.cpp @@ -161,6 +161,14 @@ bool SubWindowHandle::playEvent() return false; } +Void SubWindowHandle::seekEvent( UInt new_frame_num ) +{ + m_pCurrStream->seekInput( new_frame_num ); + m_pCurrStream->readFrame(); + m_pCurrStream->getFrame( m_pCurrFrameQImage ); + m_cViewArea->setImage( QPixmap::fromImage( *m_pCurrFrameQImage ) ); +} + Void SubWindowHandle::stopEvent() { m_pCurrStream->seekInput( 0 ); diff --git a/source/SubWindowHandle.h b/source/SubWindowHandle.h index 91745d1..e92233b 100644 --- a/source/SubWindowHandle.h +++ b/source/SubWindowHandle.h @@ -68,6 +68,7 @@ public: bool save(); Void stopEvent(); + Void seekEvent( UInt new_frame_num ); InputStream* getInputStream() { diff --git a/source/plaYUVerApp.cpp b/source/plaYUVerApp.cpp index 7886aa7..53580c5 100644 --- a/source/plaYUVerApp.cpp +++ b/source/plaYUVerApp.cpp @@ -152,8 +152,8 @@ void plaYUVerApp::pause() void plaYUVerApp::stop() { activeSubWindow()->stopEvent(); + m_pcFrameSlider->setValue( activeSubWindow()->getInputStream()->getCurrFrameNum() ); playingTimer->stop(); - } void plaYUVerApp::playEvent() @@ -162,8 +162,17 @@ void plaYUVerApp::playEvent() { if( !activeSubWindow()->playEvent() ) { - playingTimer->stop(); + stop(); } + m_pcFrameSlider->setValue( activeSubWindow()->getInputStream()->getCurrFrameNum() ); + } +} + +void plaYUVerApp::seekSliderEvent( int new_frame_num ) +{ + if( activeSubWindow() ) + { + activeSubWindow()->seekEvent( new_frame_num ); } } @@ -202,6 +211,11 @@ void plaYUVerApp::about() void plaYUVerApp::chageSubWindowSelection() { playingTimer->stop(); + if( activeSubWindow() ) + { + m_pcFrameSlider->setMaximum( activeSubWindow()->getInputStream()->getFrameNum() - 1 ); + m_pcFrameSlider->setValue( activeSubWindow()->getInputStream()->getCurrFrameNum() ); + } updateMenus(); //updateWindowMenu(); } @@ -226,6 +240,7 @@ Void plaYUVerApp::updateMenus() actionVideoStop->setEnabled( hasSubWindow ); actionVideoBackward->setEnabled( hasSubWindow ); actionVideoForward->setEnabled( hasSubWindow ); + m_pcFrameSlider->setEnabled( hasSubWindow ); } void plaYUVerApp::updateWindowMenu() @@ -358,20 +373,26 @@ Void plaYUVerApp::createActions() // ------------ Playing ------------ actionVideoPlay = new QAction( "VideoPlay", this ); + actionVideoPlay->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaPlay ) ) ); + connect( actionVideoPlay, SIGNAL( triggered() ), this, SLOT( play() ) ); + actionVideoPause = new QAction( "VideoPause", this ); + actionVideoPause->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaPause ) ) ); + connect( actionVideoPause, SIGNAL( triggered() ), this, SLOT( pause() ) ); + actionVideoStop = new QAction( "VideoStop", this ); + actionVideoStop->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaStop ) ) ); + connect( actionVideoStop, SIGNAL( triggered() ), this, SLOT( stop() ) ); + actionVideoBackward = new QAction( "VideoBackward", this ); + actionVideoBackward->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaSeekBackward ) ) ); actionVideoForward = new QAction( "VideoForward", this ); + actionVideoForward->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaSeekForward ) ) ); + actionVideoLoop = new QAction( "VideoLoop", this ); actionVideoLock = new QAction( "VideoLock", this ); actionVideoInterlace = new QAction( "VideoInterlace", this ); actionVideoCenter = new QAction( "VideoCenter", this ); - - actionVideoPlay->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaPlay ) ) ); - actionVideoPause->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaPause ) ) ); - actionVideoStop->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaStop ) ) ); - actionVideoBackward->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaSeekBackward ) ) ); - actionVideoForward->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaSeekForward ) ) ); /* actionVideoLoop ->setIcon( QIcon( ":/images/videoloop.png" ) ); actionVideoLock ->setIcon( QIcon( ":/images/lock.png" ) ); @@ -379,9 +400,13 @@ Void plaYUVerApp::createActions() actionVideoCenter ->setIcon( QIcon( ":/images/center.png" ) ); */ - connect( actionVideoPlay, SIGNAL( triggered() ), this, SLOT( play() ) ); - connect( actionVideoPause, SIGNAL( triggered() ), this, SLOT( pause() ) ); - connect( actionVideoStop, SIGNAL( triggered() ), this, SLOT( stop() ) ); + m_pcFrameSlider = new QSlider; + m_pcFrameSlider->setOrientation( Qt::Horizontal ); + m_pcFrameSlider->setMaximumWidth( 100 ); + m_pcFrameSlider->setMaximumWidth( 300 ); + m_pcFrameSlider->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ) ); + m_pcFrameSlider->setEnabled( false ); + connect( m_pcFrameSlider, SIGNAL( valueChanged(int) ), this, SLOT( seekSliderEvent(int) ) ); // ------------ Window ------------ @@ -463,19 +488,15 @@ Void plaYUVerApp::createToolBars() toolbarVideo->addAction( actionVideoPause ); toolbarVideo->addAction( actionVideoStop ); /* - toolbarVideo->addAction( actionVideoBackward ); - toolbarVideo->addAction( actionVideoForward ); - toolbarVideo->addAction( actionVideoLoop ); - toolbarVideo->addAction( actionVideoLock ); - toolbarVideo->addAction( actionVideoInterlace ); - toolbarVideo->addAction( actionVideoCenter ); - */ - m_pcFrameSlider = new QSlider; - m_pcFrameSlider->setOrientation( Qt::Horizontal ); - m_pcFrameSlider->setMaximumWidth( 100 ); - m_pcFrameSlider->setMaximumWidth( 100 ); - m_pcFrameSlider->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::Fixed ) ); + toolbarVideo->addAction( actionVideoBackward ); + toolbarVideo->addAction( actionVideoForward ); + toolbarVideo->addAction( actionVideoLoop ); + toolbarVideo->addAction( actionVideoLock ); + toolbarVideo->addAction( actionVideoInterlace ); + toolbarVideo->addAction( actionVideoCenter ); + */ toolbarVideo->addWidget( m_pcFrameSlider ); + } Void plaYUVerApp::createStatusBar() diff --git a/source/plaYUVerApp.h b/source/plaYUVerApp.h index fb23bca..bd3b8db 100644 --- a/source/plaYUVerApp.h +++ b/source/plaYUVerApp.h @@ -60,7 +60,7 @@ private Q_SLOTS: void pause(); void stop(); void playEvent(); - + void seekSliderEvent(int new_frame_num ); /** * Scale the image by a given factor * @param factor factor of scale. Ex: 120 scale the image up by 20% and From b64552147077599d1313d67771a31f4c91ad873a Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 8 Feb 2014 15:12:53 +0000 Subject: [PATCH 13/13] Add a cmake folder to include CMakeList related files --- CMakeLists.txt | 155 +--------------------- cmake/CMakeMacros.cmake | 97 ++++++++++++++ FindFFmpeg.cmake => cmake/LibFFmpeg.cmake | 19 +++ cmake/LibQT.cmake | 35 +++++ 4 files changed, 156 insertions(+), 150 deletions(-) create mode 100644 cmake/CMakeMacros.cmake rename FindFFmpeg.cmake => cmake/LibFFmpeg.cmake (84%) create mode 100644 cmake/LibQT.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 0602b8a..d1d0719 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,6 +8,8 @@ cmake_minimum_required( VERSION 2.8.9 ) +INCLUDE( cmake/CMakeMacros.cmake ) + PROJECT( playuver ) SET( PROJECT_NAME playuver ) @@ -33,103 +35,6 @@ FILE( GLOB HEADERS_FILES ${INC_DIR}/*.h ) FILE( GLOB FORMS_FILES ${UI_DIR}/*.ui ) FILE( GLOB RESOURCES_FILES ${RSC_DIR}/*.qrc ) -###################################################################################### -# Macros -###################################################################################### -macro(ADD_OPTION variable description value) - set(__value ${value}) - set(__condition "") - set(__varname "__value") - foreach(arg ${ARGN}) - if(arg STREQUAL "IF" OR arg STREQUAL "if") - set(__varname "__condition") - else() - list(APPEND ${__varname} ${arg}) - endif() - endforeach() - unset(__varname) - if("${__condition}" STREQUAL "") - set(__condition 2 GREATER 1) - endif() - - if(${__condition}) - if("${__value}" MATCHES ";") - if(${__value}) - option(${variable} "${description}" ON) - else() - option(${variable} "${description}" OFF) - endif() - elseif(DEFINED ${__value}) - if(${__value}) - option(${variable} "${description}" ON) - else() - option(${variable} "${description}" OFF) - endif() - else() - option(${variable} "${description}" ${__value}) - endif() - else() - unset(${variable} CACHE) - endif() - unset(__condition) - unset(__value) -endmacro() - -# Status report function. -# Automatically align right column and selects text based on condition. -# Usage: -# status() -# status( [ ...]) -# status( THEN ELSE ) -function(status text) - set(status_cond) - set(status_then) - set(status_else) - - set(status_current_name "cond") - foreach(arg ${ARGN}) - if(arg STREQUAL "THEN") - set(status_current_name "then") - elseif(arg STREQUAL "ELSE") - set(status_current_name "else") - else() - list(APPEND status_${status_current_name} ${arg}) - endif() - endforeach() - - if(DEFINED status_cond) - set(status_placeholder_length 32) - string(RANDOM LENGTH ${status_placeholder_length} ALPHABET " " status_placeholder) - string(LENGTH "${text}" status_text_length) - if(status_text_length LESS status_placeholder_length) - string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text) - elseif(DEFINED status_then OR DEFINED status_else) - message(STATUS ${text}) - set(status_text "${status_placeholder}") - else() - set(status_text "${text}") - endif() - - if(DEFINED status_then OR DEFINED status_else) - if(${status_cond}) - string(REPLACE ";" " " status_then "${status_then}") - string(REGEX REPLACE "^[ \t]+" "" status_then "${status_then}") - message(STATUS "${status_text} ${status_then}") - else() - string(REPLACE ";" " " status_else "${status_else}") - string(REGEX REPLACE "^[ \t]+" "" status_else "${status_else}") - message(STATUS "${status_text} ${status_else}") - endif() - else() - string(REPLACE ";" " " status_cond "${status_cond}") - string(REGEX REPLACE "^[ \t]+" "" status_cond "${status_cond}") - message(STATUS "${status_text} ${status_cond}") - endif() - else() - message(STATUS "${text}") - endif() -endfunction() - ###################################################################################### # Variables @@ -139,45 +44,12 @@ ADD_OPTION(USE_QT4 "Build with QT4" OFF ) ADD_OPTION(USE_OPENCV "Add OpenCV support" OFF ) ADD_OPTION(USE_FFMPEG "Add FFMPEG support" OFF ) -##################################################################################### -# Qt library -###################################################################################### -IF( USE_QT4 ) - FIND_PACKAGE( Qt4 REQUIRED QtCore QtGui ) - IF( NOT QT4_FOUND) - SET(USE_QT4 FALSE) - ENDIF() - INCLUDE( ${QT_USE_FILE} ) - ADD_DEFINITIONS( ${QT_DEFINITIONS} ) - - QT4_WRAP_UI( FORMS_HEADERS_FILES ${FORMS_FILES} ) - QT4_ADD_RESOURCES( RESOURCES_RCC_FILES ${RESOURCES_FILES} ) - - SET( LINKER_LIBS ${LINKER_LIBS} ${QT_LIBRARIES} ) -ENDIF() - -IF( NOT USE_QT4 ) - FIND_PACKAGE( Qt5Core REQUIRED ) - FIND_PACKAGE( Qt5Gui REQUIRED ) - FIND_PACKAGE( Qt5Widgets REQUIRED ) - - INCLUDE_DIRECTORIES( ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ) - # QT5_WRAP_CPP( HEADERS_MOC_FILES ${HEADERS_FILES} ) - QT5_WRAP_UI( FORMS_HEADERS_FILES ${FORMS_FILES} ) - QT5_ADD_RESOURCES( RESOURCES_RCC_FILES ${RESOURCES_FILES} ) - - # Add compiler flags for building executables (-fPIE) - SET( CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} ) - - SET( LINKER_LIBS ${LINKER_LIBS} ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ) - - SET( CURR_QT_MODULES Core Gui Widgets ) -ENDIF() - ###################################################################################### # Dependencies ###################################################################################### +INCLUDE( cmake/LibQT.cmake ) + INCLUDE_DIRECTORIES( ${EXTERNAL_SRC}/scode ) ADD_LIBRARY( Scode ${EXTERNAL_SRC}/scode/viewarea.cpp ${EXTERNAL_SRC}/scode/gridmanager.cpp ${EXTERNAL_SRC}/scode/scosettings.cpp ) SET( LINKER_LIBS ${LINKER_LIBS} Scode ) @@ -192,24 +64,7 @@ IF( USE_OPENCV ) ENDIF() ENDIF() -IF( USE_FFMPEG ) - IF( NOT WIN32 ) - FIND_PACKAGE( FFmpeg ) - IF( NOT FFMPEG_FOUND ) - SET( USE_FFMPEG FALSE ) - ELSE() - INCLUDE_DIRECTORIES( ${LIB_DIR}/ffmpeg ) - #SET( CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS ) - INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}) - ADD_LIBRARY( FFmpeg ${LIB_DIR}/ffmpeg/LibAvContextHandle.cpp ) - TARGET_LINK_LIBRARIES( FFmpeg ${FFMPEG_LIBRARIES} ) - SET( LINKER_LIBS ${LINKER_LIBS} FFmpeg ) - ENDIF() - ELSE() - SET( USE_FFMPEG FALSE ) - ENDIF() -ENDIF() - +INCLUDE( cmake/LibFFmpeg.cmake ) ###################################################################################### # Create config.h diff --git a/cmake/CMakeMacros.cmake b/cmake/CMakeMacros.cmake new file mode 100644 index 0000000..3b381f6 --- /dev/null +++ b/cmake/CMakeMacros.cmake @@ -0,0 +1,97 @@ +###################################################################################### +# Macros definition +###################################################################################### + +macro(ADD_OPTION variable description value) + set(__value ${value}) + set(__condition "") + set(__varname "__value") + foreach(arg ${ARGN}) + if(arg STREQUAL "IF" OR arg STREQUAL "if") + set(__varname "__condition") + else() + list(APPEND ${__varname} ${arg}) + endif() + endforeach() + unset(__varname) + if("${__condition}" STREQUAL "") + set(__condition 2 GREATER 1) + endif() + + if(${__condition}) + if("${__value}" MATCHES ";") + if(${__value}) + option(${variable} "${description}" ON) + else() + option(${variable} "${description}" OFF) + endif() + elseif(DEFINED ${__value}) + if(${__value}) + option(${variable} "${description}" ON) + else() + option(${variable} "${description}" OFF) + endif() + else() + option(${variable} "${description}" ${__value}) + endif() + else() + unset(${variable} CACHE) + endif() + unset(__condition) + unset(__value) +endmacro() + +# Status report function. +# Automatically align right column and selects text based on condition. +# Usage: +# status() +# status( [ ...]) +# status( THEN ELSE ) +function(status text) + set(status_cond) + set(status_then) + set(status_else) + + set(status_current_name "cond") + foreach(arg ${ARGN}) + if(arg STREQUAL "THEN") + set(status_current_name "then") + elseif(arg STREQUAL "ELSE") + set(status_current_name "else") + else() + list(APPEND status_${status_current_name} ${arg}) + endif() + endforeach() + + if(DEFINED status_cond) + set(status_placeholder_length 32) + string(RANDOM LENGTH ${status_placeholder_length} ALPHABET " " status_placeholder) + string(LENGTH "${text}" status_text_length) + if(status_text_length LESS status_placeholder_length) + string(SUBSTRING "${text}${status_placeholder}" 0 ${status_placeholder_length} status_text) + elseif(DEFINED status_then OR DEFINED status_else) + message(STATUS ${text}) + set(status_text "${status_placeholder}") + else() + set(status_text "${text}") + endif() + + if(DEFINED status_then OR DEFINED status_else) + if(${status_cond}) + string(REPLACE ";" " " status_then "${status_then}") + string(REGEX REPLACE "^[ \t]+" "" status_then "${status_then}") + message(STATUS "${status_text} ${status_then}") + else() + string(REPLACE ";" " " status_else "${status_else}") + string(REGEX REPLACE "^[ \t]+" "" status_else "${status_else}") + message(STATUS "${status_text} ${status_else}") + endif() + else() + string(REPLACE ";" " " status_cond "${status_cond}") + string(REGEX REPLACE "^[ \t]+" "" status_cond "${status_cond}") + message(STATUS "${status_text} ${status_cond}") + endif() + else() + message(STATUS "${text}") + endif() +endfunction() \ No newline at end of file diff --git a/FindFFmpeg.cmake b/cmake/LibFFmpeg.cmake similarity index 84% rename from FindFFmpeg.cmake rename to cmake/LibFFmpeg.cmake index 6368206..2f6841c 100644 --- a/FindFFmpeg.cmake +++ b/cmake/LibFFmpeg.cmake @@ -96,3 +96,22 @@ IF ( ${INC_SUCCESS} EQUAL ${LIST_SIZE_} ) SET( FFMPEG_FOUND TRUE ) SET( FFMPEG_SWSCALE_FOUND ${SWSCALE_FOUND} ) ENDIF ( ${INC_SUCCESS} EQUAL ${LIST_SIZE_} ) + + +IF( USE_FFMPEG ) + IF( NOT WIN32 ) + IF( NOT FFMPEG_FOUND ) + SET( USE_FFMPEG FALSE ) + ELSE() + INCLUDE_DIRECTORIES( ${LIB_DIR}/ffmpeg ) + #SET( CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -D__STDC_CONSTANT_MACROS ) + INCLUDE_DIRECTORIES(${FFMPEG_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS}) + ADD_LIBRARY( FFmpeg ${LIB_DIR}/ffmpeg/LibAvContextHandle.cpp ) + TARGET_LINK_LIBRARIES( FFmpeg ${FFMPEG_LIBRARIES} ) + SET( LINKER_LIBS ${LINKER_LIBS} FFmpeg ) + ENDIF() + ELSE() + SET( USE_FFMPEG FALSE ) + ENDIF() +ENDIF() + diff --git a/cmake/LibQT.cmake b/cmake/LibQT.cmake new file mode 100644 index 0000000..73b6c8d --- /dev/null +++ b/cmake/LibQT.cmake @@ -0,0 +1,35 @@ +##################################################################################### +# Qt library cmake file +###################################################################################### + +IF( USE_QT4 ) + FIND_PACKAGE( Qt4 REQUIRED QtCore QtGui ) + IF( NOT QT4_FOUND) + SET(USE_QT4 FALSE) + ENDIF() + INCLUDE( ${QT_USE_FILE} ) + ADD_DEFINITIONS( ${QT_DEFINITIONS} ) + + QT4_WRAP_UI( FORMS_HEADERS_FILES ${FORMS_FILES} ) + QT4_ADD_RESOURCES( RESOURCES_RCC_FILES ${RESOURCES_FILES} ) + + SET( LINKER_LIBS ${LINKER_LIBS} ${QT_LIBRARIES} ) +ENDIF() + +IF( NOT USE_QT4 ) + FIND_PACKAGE( Qt5Core REQUIRED ) + FIND_PACKAGE( Qt5Gui REQUIRED ) + FIND_PACKAGE( Qt5Widgets REQUIRED ) + + INCLUDE_DIRECTORIES( ${Qt5Widgets_INCLUDE_DIRS} ${Qt5Core_INCLUDE_DIRS} ${Qt5Gui_INCLUDE_DIRS} ) + # QT5_WRAP_CPP( HEADERS_MOC_FILES ${HEADERS_FILES} ) + QT5_WRAP_UI( FORMS_HEADERS_FILES ${FORMS_FILES} ) + QT5_ADD_RESOURCES( RESOURCES_RCC_FILES ${RESOURCES_FILES} ) + + # Add compiler flags for building executables (-fPIE) + SET( CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} ${Qt5Core_EXECUTABLE_COMPILE_FLAGS} ) + + SET( LINKER_LIBS ${LINKER_LIBS} ${Qt5Core_LIBRARIES} ${Qt5Gui_LIBRARIES} ${Qt5Widgets_LIBRARIES} ) + + SET( CURR_QT_MODULES Core Gui Widgets ) +ENDIF()