From 55c0e2b4c3f3ef31a7217cbd5bb618e5faf3e3a5 Mon Sep 17 00:00:00 2001 From: Joao Carreira Date: Sat, 4 Oct 2014 14:40:40 +0100 Subject: [PATCH] Support to save custom values. Add stream info struct in order to save relevant info about each sub window --- source/app/PlaYUVerSettings.cpp | 8 ++--- source/app/PlaYUVerSettings.h | 4 +-- source/app/SubWindowHandle.cpp | 4 +-- source/app/SubWindowHandle.h | 20 +++++------- source/app/main.cpp | 4 +-- source/app/plaYUVerApp.cpp | 57 +++++++++++++++++++++++++++++++-- source/app/plaYUVerApp.h | 17 ++++++---- 7 files changed, 82 insertions(+), 32 deletions(-) diff --git a/source/app/PlaYUVerSettings.cpp b/source/app/PlaYUVerSettings.cpp index f4745ab..f396a79 100644 --- a/source/app/PlaYUVerSettings.cpp +++ b/source/app/PlaYUVerSettings.cpp @@ -103,17 +103,17 @@ Void PlaYUVerSettings::setPlayingSettings( Bool repeat, Bool lock ) m_settings.setValue( "Playing/VideoLock", lock ); } -Void PlaYUVerSettings::setRecentFileList( PlaYUVerRecentFileListInfo recentFileList ) +Void PlaYUVerSettings::setRecentFileList( PlaYUVerStreamInfoVector recentFileList ) { QVariant var; - var.setValue( recentFileList ); + var.setValue( recentFileList ); m_settings.setValue("MainWindow/RecentFileList", var ); } -PlaYUVerRecentFileListInfo PlaYUVerSettings::getRecentFileList() +QVector PlaYUVerSettings::getRecentFileList() { QVariant value = m_settings.value("MainWindow/RecentFileList"); - return value.value(); + return value.value(); } // - - - - - - - - - - - - - - Grid Settings - - - - - - - - - - - - - - - - - - diff --git a/source/app/PlaYUVerSettings.h b/source/app/PlaYUVerSettings.h index 4449a75..be54915 100644 --- a/source/app/PlaYUVerSettings.h +++ b/source/app/PlaYUVerSettings.h @@ -61,8 +61,8 @@ public: Void getDockVisibility( Bool& statusStreamProperties, Bool& statusFrameProperties, Bool& statusQualityMeasurement ); // - - - - - - - - - - Recent Files Settings - - - - - - - - - - - - - - Void setRecentFileList( PlaYUVerRecentFileListInfo recentFileList ); - PlaYUVerRecentFileListInfo getRecentFileList(); + Void setRecentFileList( PlaYUVerStreamInfoVector recentFileList ); + PlaYUVerStreamInfoVector getRecentFileList(); // - - - - - - - - - - - - Grid Settings - - - - - - - - - - - - - - - GridManager::Style gridStyle(); diff --git a/source/app/SubWindowHandle.cpp b/source/app/SubWindowHandle.cpp index 2f20357..cea7865 100644 --- a/source/app/SubWindowHandle.cpp +++ b/source/app/SubWindowHandle.cpp @@ -29,7 +29,7 @@ namespace plaYUVer { -QDataStream& operator<<( QDataStream& out, const plaYUVer::PlaYUVerRecentFileListInfo& array ) +QDataStream& operator<<( QDataStream& out, const PlaYUVerStreamInfoVector& array ) { PlaYUVerStreamInfo d; out << array.size(); @@ -45,7 +45,7 @@ QDataStream& operator<<( QDataStream& out, const plaYUVer::PlaYUVerRecentFileLis return out; } -QDataStream& operator>>( QDataStream& in, plaYUVer::PlaYUVerRecentFileListInfo& array ) +QDataStream& operator>>( QDataStream& in, PlaYUVerStreamInfoVector& array ) { PlaYUVerStreamInfo d; Int array_size; diff --git a/source/app/SubWindowHandle.h b/source/app/SubWindowHandle.h index d9d0bca..0cc40fc 100644 --- a/source/app/SubWindowHandle.h +++ b/source/app/SubWindowHandle.h @@ -41,20 +41,17 @@ namespace plaYUVer class SubWindowHandle; -struct structPlaYUVERStreamInfo +typedef struct { QString m_cFilename; QSize m_cResolution; Int m_iPelFormat; UInt m_uiFrameRate; -}; +}PlaYUVerStreamInfo; +typedef QVector PlaYUVerStreamInfoVector; -typedef QVector PlaYUVerRecentFileListInfo; -//typedef structPlaYUVERStreamInfo PlaYUVerRecentFileListInfo; -typedef struct structPlaYUVERStreamInfo PlaYUVerStreamInfo; - -QDataStream& operator<<(QDataStream& out, const plaYUVer::PlaYUVerRecentFileListInfo& d); -QDataStream& operator>>(QDataStream& in, plaYUVer::PlaYUVerRecentFileListInfo& d); +QDataStream& operator<<(QDataStream& out, const PlaYUVerStreamInfoVector& d); +QDataStream& operator>>(QDataStream& in, PlaYUVerStreamInfoVector& d); class SubWindowHandle: public QMdiSubWindow @@ -234,9 +231,8 @@ public Q_SLOTS: } // NAMESPACE - - -Q_DECLARE_METATYPE(plaYUVer::PlaYUVerRecentFileListInfo); -//Q_DECLARE_METATYPE(plaYUVer::structPlaYUVERStreamInfo) +Q_DECLARE_METATYPE(plaYUVer::PlaYUVerStreamInfo); +Q_DECLARE_METATYPE(plaYUVer::PlaYUVerStreamInfoVector); #endif // __SUBWINDOWHANDLE_H__ + diff --git a/source/app/main.cpp b/source/app/main.cpp index d53d776..551ed6e 100644 --- a/source/app/main.cpp +++ b/source/app/main.cpp @@ -43,8 +43,8 @@ int main( int argc, char *argv[] ) QApplication::setOrganizationName("pixlra"); QApplication::setOrganizationDomain("playuver.pixlra"); - qRegisterMetaType("PlaYUVerRecentFileListInfo"); - qRegisterMetaTypeStreamOperators("PlaYUVerRecentFileListInfo"); + qRegisterMetaType("PlaYUVerStreamInfoVector"); + qRegisterMetaTypeStreamOperators("PlaYUVerStreamInfoVector"); plaYUVerApp w; w.show(); diff --git a/source/app/plaYUVerApp.cpp b/source/app/plaYUVerApp.cpp index a59762f..ea84234 100644 --- a/source/app/plaYUVerApp.cpp +++ b/source/app/plaYUVerApp.cpp @@ -102,8 +102,8 @@ Void plaYUVerApp::parseArgs( Int argc, Char *argv[] ) Void plaYUVerApp::about() { - if (!m_pcAboutDialog) - m_pcAboutDialog = new AboutDialog(this); + 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! " ); @@ -179,6 +179,12 @@ Void plaYUVerApp::loadFile( QString fileName ) interfaceChild->zoomToFit(); interfaceChild->getViewArea()->setTool( m_appTool ); updateZoomFactorSBox(); + + m_aRecentFileStreamInfo.prepend( interfaceChild->getStreamInfo() ); + while ( m_aRecentFileStreamInfo.size() > MAX_RECENT_FILES ) + m_aRecentFileStreamInfo.removeLast(); + updateRecentFileActions(); + statusBar()->showMessage( tr( "File loaded" ), 2000 ); } else @@ -226,11 +232,19 @@ Void plaYUVerApp::open() } } +Void plaYUVerApp::openRecent() +{ + QAction *action = qobject_cast( sender() ); + PlaYUVerStreamInfo recentFile = action->data().value(); + if( action ) + loadFile( recentFile.m_cFilename ); +} + Void plaYUVerApp::save() { if( m_pcCurrentSubWindow ) { - SubWindowHandle *saveWindow = m_pcCurrentSubWindow; + SubWindowHandle *saveWindow = m_pcCurrentSubWindow; QString supported = tr( "Supported Files (" ); QStringList formatsList; QStringList formatsExt = PlaYUVerStream::supportedSaveFormatsExt(); @@ -1049,6 +1063,28 @@ 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++; + } +} + Void plaYUVerApp::createActions() { m_arrayActions.resize( TOTAL_ACT ); @@ -1060,6 +1096,14 @@ Void plaYUVerApp::createActions() m_arrayActions[OPEN_ACT]->setStatusTip( tr( "Open stream" ) ); connect( m_arrayActions[OPEN_ACT], SIGNAL( triggered() ), this, SLOT( open() ) ); + m_arrayRecentFilesActions.resize( MAX_RECENT_FILES ); + for( Int i = 0; i < MAX_RECENT_FILES; i++ ) + { + m_arrayRecentFilesActions[i] = new QAction( this ); + m_arrayRecentFilesActions[i]->setVisible( false ); + connect( m_arrayRecentFilesActions[i], SIGNAL( triggered() ), this, SLOT( openRecent() ) ); + } + m_arrayActions[SAVE_ACT] = new QAction( QIcon( ":/images/save.png" ), tr( "&Save Frame" ), this ); m_arrayActions[SAVE_ACT]->setIcon( style()->standardIcon( QStyle::SP_DialogSaveButton ) ); m_arrayActions[SAVE_ACT]->setShortcuts( QKeySequence::SaveAs ); @@ -1254,6 +1298,12 @@ Void plaYUVerApp::createMenus() m_arrayMenu[FILE_MENU] = menuBar()->addMenu( tr( "&File" ) ); m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[OPEN_ACT] ); + m_arrayMenu[RECENT_MENU] = m_arrayMenu[FILE_MENU]->addMenu( tr( "Open Recent" ) ); + for( Int i = 0; i < MAX_RECENT_FILES; ++i ) + { + m_arrayMenu[RECENT_MENU]->addAction( m_arrayRecentFilesActions[i] ); + } + m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[SAVE_ACT] ); m_arrayMenu[FILE_MENU]->addSeparator(); m_arrayMenu[FILE_MENU]->addAction( m_arrayActions[FORMAT_ACT] ); @@ -1415,6 +1465,7 @@ Void plaYUVerApp::readSettings() m_arrayActions[VIDEO_LOCK_ACT]->setChecked( settings.getVideoLock() ); m_aRecentFileStreamInfo = settings.getRecentFileList(); + updateRecentFileActions(); Bool visibleStreamProp, visibleFrameProp, visibleQualityMeasure; settings.getDockVisibility( visibleStreamProp, visibleFrameProp, visibleQualityMeasure ); diff --git a/source/app/plaYUVerApp.h b/source/app/plaYUVerApp.h index 733816d..d82a8d3 100644 --- a/source/app/plaYUVerApp.h +++ b/source/app/plaYUVerApp.h @@ -52,11 +52,6 @@ public: plaYUVerApp(); Void parseArgs( Int argc, Char *argv[] ); - enum RecentFileList - { - MAXRECENTFILES = 2, - }; - protected: Void closeEvent( QCloseEvent *event ); @@ -66,6 +61,7 @@ private Q_SLOTS: * File functions slots */ void open(); + void openRecent(); void save(); void format(); void reload(); @@ -102,7 +98,7 @@ private Q_SLOTS: void about(); void chageSubWindowSelection(); - void updateWindowMenu();s + void updateWindowMenu(); void dragEnterEvent( QDragEnterEvent *event ); void dropEvent( QDropEvent *event ); @@ -177,6 +173,8 @@ private: Void updateStreamProperties(); Void updateFrameProperties(); + Void updateRecentFileActions(); + Void createActions(); Void createMenus(); Void createToolBars(); @@ -213,6 +211,7 @@ private: enum MAIN_APP_MENU_LIST { FILE_MENU = 0, + RECENT_MENU, VIEW_MENU, TOOLS_MENU, VIDEO_MENU, @@ -257,6 +256,7 @@ private: enum APP_ACTION_LIST { OPEN_ACT = 0, + OPEN_RECENT_ACT, SAVE_ACT, FORMAT_ACT, RELOAD_ACT, @@ -290,6 +290,9 @@ private: TOTAL_ACT, }; QVector m_arrayActions; + +#define MAX_RECENT_FILES 5 + QVector m_arrayRecentFilesActions; //QAction *actionPopupMenu; // Tools Actions; @@ -298,7 +301,7 @@ private: QAction *actionSelectionTool; enum eTool m_appTool; - PlaYUVerRecentFileListInfo m_aRecentFileStreamInfo; + PlaYUVerStreamInfoVector m_aRecentFileStreamInfo; AboutDialog* m_pcAboutDialog;