From 3e6b04e9831f515b6933e71409ecbaf69a157ea0 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Tue, 13 Jan 2015 11:42:23 +0000 Subject: [PATCH] fix recent file list --- app/plaYUVerApp.cpp | 129 +++++++++++++++++++++++--------------------- app/plaYUVerApp.h | 8 +-- 2 files changed, 71 insertions(+), 66 deletions(-) diff --git a/app/plaYUVerApp.cpp b/app/plaYUVerApp.cpp index d732321..06067b4 100644 --- a/app/plaYUVerApp.cpp +++ b/app/plaYUVerApp.cpp @@ -106,13 +106,13 @@ Void plaYUVerApp::about() if( !m_pcAboutDialog ) m_pcAboutDialog = new AboutDialog( this ); m_pcAboutDialog->exec(); -// QString about_message; -// about_message.append( "The plaYUVer is an open-source raw video player! " ); -// about_message.append( "Developed by " ); -// about_message.append( "João Carreira " ); -// about_message.append( "and " ); -// about_message.append( "Luís Lucas" ); -// QMessageBox::about( this, "About plaYUVer", about_message ); + // QString about_message; + // about_message.append( "The plaYUVer is an open-source raw video player! " ); + // about_message.append( "Developed by " ); + // about_message.append( "João Carreira " ); + // about_message.append( "and " ); + // about_message.append( "Luís Lucas" ); + // QMessageBox::about( this, "About plaYUVer", about_message ); } Void plaYUVerApp::closeEvent( QCloseEvent *event ) @@ -202,14 +202,7 @@ Void plaYUVerApp::loadFile( QString fileName, PlaYUVerStreamInfo* pStreamInfo ) videoSubWindow->getViewArea()->setTool( m_appTool ); updateZoomFactorSBox(); - Int idx = findPlaYUVerStreamInfo( m_aRecentFileStreamInfo, fileName ); - if( idx >= 0 ) - m_aRecentFileStreamInfo.remove( idx ); - PlaYUVerStreamInfo streamInfo = videoSubWindow->getStreamInfo(); - m_aRecentFileStreamInfo.prepend( streamInfo ); - while( m_aRecentFileStreamInfo.size() > MAX_RECENT_FILES ) - m_aRecentFileStreamInfo.remove( m_aRecentFileStreamInfo.size() - 1 ); - updateRecentFileActions(); + addStreamInfoToRecentList( videoSubWindow->getStreamInfo() ); statusBar()->showMessage( tr( "File loaded" ), 2000 ); m_cLastOpenPath = QFileInfo( fileName ).path(); @@ -253,8 +246,8 @@ Void plaYUVerApp::open() QStringList filter; filter << supported - << formatsList - << tr( "All Files (*)" ); + << formatsList + << tr( "All Files (*)" ); QStringList fileNameList = QFileDialog::getOpenFileNames( this, tr( "Open File" ), m_cLastOpenPath, filter.join( ";;" ) ); @@ -300,8 +293,8 @@ Void plaYUVerApp::save() QStringList filter; filter << supported - << formatsList - << tr( "All Files (*)" ); + << formatsList + << tr( "All Files (*)" ); QString fileName = QFileDialog::getSaveFileName( this, tr( "Open File" ), QString(), filter.join( ";;" ) ); @@ -318,6 +311,8 @@ Void plaYUVerApp::save() } } + + Void plaYUVerApp::format() { if( m_pcCurrentVideoSubWindow ) @@ -327,11 +322,7 @@ Void plaYUVerApp::format() { if( pcVideoSubWindow->loadFile( pcVideoSubWindow->getCurrentFileName(), true ) ) { - PlaYUVerStreamInfo streamInfo = pcVideoSubWindow->getStreamInfo(); - m_aRecentFileStreamInfo.prepend( streamInfo ); - while( m_aRecentFileStreamInfo.size() > MAX_RECENT_FILES ) - m_aRecentFileStreamInfo.remove( m_aRecentFileStreamInfo.size() - 1 ); - updateRecentFileActions(); + addStreamInfoToRecentList( pcVideoSubWindow->getStreamInfo() ); } } catch( const char *msg ) @@ -851,7 +842,7 @@ Void plaYUVerApp::updateStatusBar( const QString& statusBarString ) Void plaYUVerApp::dragEnterEvent( QDragEnterEvent *event ) { -//setText(tr("")); + //setText(tr("")); mdiArea->setBackgroundRole( QPalette::Highlight ); event->acceptProposedAction(); } @@ -948,7 +939,7 @@ Void plaYUVerApp::updateMenus() m_pcZoomFactorSBox->setEnabled( hasSubWindow ); m_arrayActions[PLAY_ACT]->setEnabled( hasSubWindow ); -//m_arrayActions[PAUSE_ACT]->setEnabled( hasSubWindow ); + //m_arrayActions[PAUSE_ACT]->setEnabled( hasSubWindow ); m_arrayActions[STOP_ACT]->setEnabled( hasSubWindow ); m_arrayActions[VIDEO_BACKWARD_ACT]->setEnabled( hasSubWindow ); m_arrayActions[VIDEO_FORWARD_ACT]->setEnabled( hasSubWindow ); @@ -1017,34 +1008,13 @@ Void plaYUVerApp::updateWindowMenu() } } -Void plaYUVerApp::updateRecentFileActions() -{ - Int numRecentFiles = m_aRecentFileStreamInfo.size(); - numRecentFiles = qMin( numRecentFiles, MAX_RECENT_FILES ); - Int actionIdx = 0; - while( actionIdx < numRecentFiles ) - { - QString text = m_aRecentFileStreamInfo.at( actionIdx ).m_cFilename; - m_arrayRecentFilesActions.at( actionIdx )->setText( QFileInfo( text ).fileName() ); - m_arrayRecentFilesActions.at( actionIdx )->setToolTip( "Open File " + text ); - m_arrayRecentFilesActions.at( actionIdx )->setStatusTip( "Open File " + text ); - m_arrayRecentFilesActions.at( actionIdx )->setData( QVariant::fromValue( m_aRecentFileStreamInfo.at( actionIdx ) ) ); - m_arrayRecentFilesActions.at( actionIdx )->setVisible( true ); - actionIdx++; - } - while( actionIdx < MAX_RECENT_FILES ) - { - m_arrayRecentFilesActions.at( actionIdx )->setVisible( false ); - actionIdx++; - } - m_arrayMenu[RECENT_MENU]->setEnabled( m_aRecentFileStreamInfo.size() > 0 ? true : false ); -} + Void plaYUVerApp::createActions() { m_arrayActions.resize( TOTAL_ACT ); -// ------------ File ------------ + // ------------ File ------------ m_arrayActions[OPEN_ACT] = new QAction( QIcon( ":/images/open.png" ), tr( "&Open" ), this ); m_arrayActions[OPEN_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogOpenButton ) ); m_arrayActions[OPEN_ACT]->setShortcuts( QKeySequence::Open ); @@ -1101,7 +1071,7 @@ Void plaYUVerApp::createActions() m_arrayActions[EXIT_ACT]->setStatusTip( tr( "Exit the application" ) ); connect( m_arrayActions[EXIT_ACT], SIGNAL( triggered() ), qApp, SLOT( closeAllWindows() ) ); -// ------------ View ------------ + // ------------ View ------------ mapperZoom = new QSignalMapper( this ); connect( mapperZoom, SIGNAL( mapped(int) ), this, SLOT( scaleFrame(int) ) ); @@ -1130,7 +1100,7 @@ Void plaYUVerApp::createActions() m_arrayActions[ZOOM_FIT_ACT]->setStatusTip( tr( "Zoom in or out to fit on the window." ) ); connect( m_arrayActions[ZOOM_FIT_ACT], SIGNAL( triggered() ), this, SLOT( zoomToFit() ) ); -// ------------ Playing ------------ + // ------------ Playing ------------ m_arrayActions[PLAY_ACT] = new QAction( "Play", this ); m_arrayActions[PLAY_ACT]->setIcon( QIcon( style()->standardIcon( QStyle::SP_MediaPlay ) ) ); @@ -1172,7 +1142,7 @@ Void plaYUVerApp::createActions() m_pcFrameSlider->setEnabled( false ); connect( m_pcFrameSlider, SIGNAL( sliderMoved(int) ), this, SLOT( seekSliderEvent(int) ) ); -// ------------ Tools ------------ + // ------------ Tools ------------ actionGroupTools = new QActionGroup( this ); actionGroupTools->setExclusive( true ); @@ -1197,7 +1167,7 @@ Void plaYUVerApp::createActions() m_appModuleQuality->createActions(); -// ------------ Window ------------ + // ------------ Window ------------ m_arrayActions[TILE_WINDOWS_ACT] = new QAction( tr( "Tile" ), this ); m_arrayActions[TILE_WINDOWS_ACT]->setIcon( QIcon( ":images/windowstile.png" ) ); @@ -1224,7 +1194,7 @@ Void plaYUVerApp::createActions() m_arrayActions[SEPARATOR_ACT] = new QAction( this ); m_arrayActions[SEPARATOR_ACT]->setSeparator( true ); -// ------------ About ------------ + // ------------ About ------------ #ifdef USE_FERVOR m_arrayActions[UPDATE_ACT] = new QAction( tr( "&Update" ), this ); @@ -1275,8 +1245,8 @@ Void plaYUVerApp::createMenus() m_arrayMenu[VIEW_MENU]->addSeparator(); -// createPopupMenu() Returns a popup menu containing checkable entries for -// the toolbars and dock widgets present in the main window. + // createPopupMenu() Returns a popup menu containing checkable entries for + // the toolbars and dock widgets present in the main window. m_arrayMenu[DOCK_VIEW_MENU] = createPopupMenu(); if( m_arrayMenu[DOCK_VIEW_MENU] ) { @@ -1284,13 +1254,13 @@ Void plaYUVerApp::createMenus() actionPopupMenu->setText( tr( "&Toolbars/Docks" ) ); } -// m_arrayMenu[TOOLS_MENU] = menuBar()->addMenu( tr( "Tools" ) ); -// m_arrayMenu[TOOLS_MENU]->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] ); -// m_arrayMenu[TOOLS_MENU]->addAction( m_arrayActions[SELECTION_TOOL_ACT] ); + // m_arrayMenu[TOOLS_MENU] = menuBar()->addMenu( tr( "Tools" ) ); + // m_arrayMenu[TOOLS_MENU]->addAction( m_arrayActions[NAVIGATION_TOOL_ACT] ); + // m_arrayMenu[TOOLS_MENU]->addAction( m_arrayActions[SELECTION_TOOL_ACT] ); m_arrayMenu[VIDEO_MENU] = menuBar()->addMenu( tr( "Video" ) ); m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[PLAY_ACT] ); -//m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[PAUSE_ACT] ); + //m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[PAUSE_ACT] ); m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[STOP_ACT] ); m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[VIDEO_BACKWARD_ACT] ); m_arrayMenu[VIDEO_MENU]->addAction( m_arrayActions[VIDEO_FORWARD_ACT] ); @@ -1370,7 +1340,7 @@ Void plaYUVerApp::createToolBars() Void plaYUVerApp::createDockWidgets() { -// Properties Dock Window + // Properties Dock Window m_arraySideBars.resize( TOTAL_DOCK ); m_pcStreamProperties = new StreamPropertiesSideBar( this ); @@ -1388,7 +1358,7 @@ Void plaYUVerApp::createDockWidgets() connect( m_arraySideBars[FRAME_DOCK], SIGNAL( visibilityChanged(bool) ), this, SLOT( updateStreamProperties() ) ); QMainWindow::tabifyDockWidget( m_arraySideBars[FRAME_DOCK], m_arraySideBars[STREAM_DOCK] ); -//QMainWindow::setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); + //QMainWindow::setTabPosition(Qt::RightDockWidgetArea, QTabWidget::North); addDockWidget( Qt::RightDockWidgetArea, m_appModuleQuality->createDock() ); } @@ -1398,6 +1368,41 @@ Void plaYUVerApp::createStatusBar() statusBar()->showMessage( tr( "Ready" ) ); } + +Void plaYUVerApp::addStreamInfoToRecentList( PlaYUVerStreamInfo streamInfo ) +{ + Int idx = findPlaYUVerStreamInfo( m_aRecentFileStreamInfo, streamInfo.m_cFilename ); + if( idx >= 0 ) + m_aRecentFileStreamInfo.remove( idx ); + m_aRecentFileStreamInfo.prepend( streamInfo ); + while( m_aRecentFileStreamInfo.size() > MAX_RECENT_FILES ) + m_aRecentFileStreamInfo.remove( m_aRecentFileStreamInfo.size() - 1 ); + updateRecentFileActions(); +} + +Void plaYUVerApp::updateRecentFileActions() +{ + Int numRecentFiles = m_aRecentFileStreamInfo.size(); + numRecentFiles = qMin( numRecentFiles, MAX_RECENT_FILES ); + Int actionIdx = 0; + while( actionIdx < numRecentFiles ) + { + QString text = m_aRecentFileStreamInfo.at( actionIdx ).m_cFilename; + m_arrayRecentFilesActions.at( actionIdx )->setText( QFileInfo( text ).fileName() ); + m_arrayRecentFilesActions.at( actionIdx )->setToolTip( "Open File " + text ); + m_arrayRecentFilesActions.at( actionIdx )->setStatusTip( "Open File " + text ); + m_arrayRecentFilesActions.at( actionIdx )->setData( QVariant::fromValue( m_aRecentFileStreamInfo.at( actionIdx ) ) ); + m_arrayRecentFilesActions.at( actionIdx )->setVisible( true ); + actionIdx++; + } + while( actionIdx < MAX_RECENT_FILES ) + { + m_arrayRecentFilesActions.at( actionIdx )->setVisible( false ); + actionIdx++; + } + m_arrayMenu[RECENT_MENU]->setEnabled( m_aRecentFileStreamInfo.size() > 0 ? true : false ); +} + Void plaYUVerApp::readSettings() { Settings settings; diff --git a/app/plaYUVerApp.h b/app/plaYUVerApp.h index 0d431d4..ce802d6 100644 --- a/app/plaYUVerApp.h +++ b/app/plaYUVerApp.h @@ -162,9 +162,6 @@ private: QTimer *m_pcPlayingTimer; Bool m_bIsPlaying; - Void readRecentFileList(); - Void writeRecentFileList(); - Void zoomToFitAll(); /** @@ -176,7 +173,7 @@ private: Void updateMenus(); - Void updateRecentFileActions(); + Void createActions(); Void createMenus(); @@ -184,6 +181,9 @@ private: Void createDockWidgets(); Void createStatusBar(); + Void addStreamInfoToRecentList( PlaYUVerStreamInfo streamInfo ); + Void updateRecentFileActions(); + Void readSettings(); Void writeSettings();