From 8fb945e819051a4ee68936677be80a1ea072c566 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Fri, 11 Apr 2014 15:44:50 +0100 Subject: [PATCH] Add function to parse command line args: currently only supporting one --- source/app/main.cpp | 3 +- source/app/plaYUVerApp.cpp | 75 ++++++++++++++++++-------------------- source/app/plaYUVerApp.h | 2 + 3 files changed, 39 insertions(+), 41 deletions(-) diff --git a/source/app/main.cpp b/source/app/main.cpp index 293eff3..36114d2 100755 --- a/source/app/main.cpp +++ b/source/app/main.cpp @@ -31,8 +31,7 @@ int main( int argc, char *argv[] ) { QApplication a( argc, argv ); plaYUVerApp w; - w.show(); - + w.parseArgs( argc, argv ); return a.exec(); } diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index 8c2e667..8fc325f 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -82,6 +82,14 @@ plaYUVerApp::plaYUVerApp() m_pcCurrentSubWindow = NULL; } +Void plaYUVerApp::parseArgs( Int argc, Char *argv[] ) +{ + if( argc == 2 ) + { + loadFile( argv[1] ); + } +} + Void plaYUVerApp::closeEvent( QCloseEvent *event ) { Int mayCloseAll = true; @@ -124,6 +132,32 @@ Void plaYUVerApp::closeEvent( QCloseEvent *event ) } } +Void plaYUVerApp::loadFile( QString fileName ) +{ + QMdiSubWindow *existing = findSubWindow( fileName ); + if( existing ) + { + mdiArea->setActiveSubWindow( existing ); + return; + } + + SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createSubWindow(); + if( interfaceChild->loadFile( fileName ) ) + { + mdiArea->addSubWindow( interfaceChild ); + statusBar()->showMessage( tr( "File loaded" ), 2000 ); + interfaceChild->show(); + connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, InputStream *) ), this, + SLOT( updatePixelValueStatusBar(const QPoint &, InputStream *) ) ); + interfaceChild->zoomToFit(); + } + else + { + interfaceChild->close(); + } +} + + // ----------------------- File Functions ----------------------- void plaYUVerApp::open() @@ -144,28 +178,7 @@ void plaYUVerApp::open() if( !fileName.isEmpty() ) { m_cLastOpenPath = QFileInfo( fileName ).path(); - - QMdiSubWindow *existing = findSubWindow( fileName ); - if( existing ) - { - mdiArea->setActiveSubWindow( existing ); - return; - } - - SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createSubWindow(); - if( interfaceChild->loadFile( fileName ) ) - { - mdiArea->addSubWindow( interfaceChild ); - statusBar()->showMessage( tr( "File loaded" ), 2000 ); - interfaceChild->show(); - connect( interfaceChild->getViewArea(), SIGNAL( positionChanged(const QPoint &, InputStream *) ), this, - SLOT( updatePixelValueStatusBar(const QPoint &, InputStream *) ) ); - interfaceChild->zoomToFit(); - } - else - { - interfaceChild->close(); - } + loadFile( fileName ); } } @@ -522,24 +535,8 @@ void plaYUVerApp::dropEvent( QDropEvent *event ) if( urlList.size() == 1 ) { QString fileName = urlList.at( 0 ).toLocalFile(); - m_cLastOpenPath = QFileInfo( fileName ).path(); - - QMdiSubWindow *existing = findSubWindow( fileName ); - if( !existing ) - { - SubWindowHandle *interfaceChild = new SubWindowHandle( this ); //createSubWindow(); - if( interfaceChild->loadFile( fileName ) ) - { - mdiArea->addSubWindow( interfaceChild ); - statusBar()->showMessage( tr( "File loaded" ), 2000 ); - interfaceChild->show(); - } - else - { - interfaceChild->close(); - } - } + loadFile( fileName ); } } diff --git a/source/app/plaYUVerApp.h b/source/app/plaYUVerApp.h index f3c0c79..fd19fc2 100644 --- a/source/app/plaYUVerApp.h +++ b/source/app/plaYUVerApp.h @@ -50,6 +50,7 @@ Q_OBJECT public: plaYUVerApp(); + Void parseArgs( Int argc, Char *argv[] ); protected: Void closeEvent( QCloseEvent *event ); @@ -108,6 +109,7 @@ private: QTime m_cTimer; UInt m_uiAveragePlayInterval; + Void loadFile( QString fileName ); //! Playing functions Void setTimerStatus();