From 4ee0b6e90d649238f55190d87c62ebbe61f803f0 Mon Sep 17 00:00:00 2001 From: Maxime Date: Fri, 6 May 2011 15:51:54 +0200 Subject: [PATCH] When an image is opened it is now added to the recently opened files menu --- vv/vvMainWindow.cxx | 43 +++++++++++++++++++++++++++++++++---------- vv/vvMainWindow.h | 8 +++++++- 2 files changed, 40 insertions(+), 11 deletions(-) diff --git a/vv/vvMainWindow.cxx b/vv/vvMainWindow.cxx index 3a11afe..df3b675 100644 --- a/vv/vvMainWindow.cxx +++ b/vv/vvMainWindow.cxx @@ -308,17 +308,10 @@ vvMainWindow::vvMainWindow():vvMainWindowBase() //Recently opened files std::list recent_files = GetRecentlyOpenedImages(); + recentlyOpenedFilesMenu=NULL; if ( !recent_files.empty() ) { - QMenu * rmenu = new QMenu("Recently opened files..."); - rmenu->setIcon(QIcon(QString::fromUtf8(":/common/icons/open.png"))); - menuFile->insertMenu(actionOpen_Image_With_Time,rmenu); - menuFile->insertSeparator(actionOpen_Image_With_Time); - for (std::list::iterator i = recent_files.begin(); i!=recent_files.end(); i++) { - QAction* current=new QAction(QIcon(QString::fromUtf8(":/common/icons/open.png")), - (*i).c_str(),this); - rmenu->addAction(current); - connect(current,SIGNAL(triggered()),this,SLOT(OpenRecentImage())); - } + createRecentlyOpenedFilesMenu(); + updateRecentlyOpenedFilesMenu(recent_files); } // Adding all new tools (insertion in the menu) @@ -351,6 +344,35 @@ void vvMainWindow::UpdateMemoryUsage() //------------------------------------------------------------------------------ +//------------------------------------------------------------------------------ +void vvMainWindow::createRecentlyOpenedFilesMenu() +{ + recentlyOpenedFilesMenu = new QMenu("Recently opened files..."); + recentlyOpenedFilesMenu->setIcon(QIcon(QString::fromUtf8(":/common/icons/open.png"))); + menuFile->insertMenu(actionOpen_Image_With_Time,recentlyOpenedFilesMenu); + menuFile->insertSeparator(actionOpen_Image_With_Time); +} +//------------------------------------------------------------------------------ + + +//------------------------------------------------------------------------------ + +void vvMainWindow::updateRecentlyOpenedFilesMenu(const std::list &recent_files) +{ + if(recentlyOpenedFilesMenu==NULL){ + createRecentlyOpenedFilesMenu(); + }else{ + recentlyOpenedFilesMenu->clear(); + } + for (std::list::const_iterator i = recent_files.begin(); i!=recent_files.end(); i++) { + QAction* current=new QAction(QIcon(QString::fromUtf8(":/common/icons/open.png")), i->c_str(),this); + recentlyOpenedFilesMenu->addAction(current); + connect(current,SIGNAL(triggered()),this,SLOT(OpenRecentImage())); + } +} +//------------------------------------------------------------------------------ + + //------------------------------------------------------------------------------ void vvMainWindow::ComputeMidPosition() { @@ -796,6 +818,7 @@ void vvMainWindow::LoadImages(std::vector files, vvImageReader::Loa if (files.size() == 1) { QFileInfo finfo=tr(files[0].c_str()); AddToRecentlyOpenedImages(finfo.absoluteFilePath().toStdString()); + updateRecentlyOpenedFilesMenu(GetRecentlyOpenedImages()); } //init the progress events QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); diff --git a/vv/vvMainWindow.h b/vv/vvMainWindow.h index d95e7fa..e01bcec 100644 --- a/vv/vvMainWindow.h +++ b/vv/vvMainWindow.h @@ -152,7 +152,12 @@ public slots: } void UpdateRenderWindows(); void UpdateMemoryUsage(); - + +protected: + + void createRecentlyOpenedFilesMenu(); + void updateRecentlyOpenedFilesMenu(const std::list &files); + private: //variables @@ -184,6 +189,7 @@ private: int GetImageDuplicateFilenameNumber(std::string filename); QMenu contextMenu; + QMenu* recentlyOpenedFilesMenu; //QMenu *AddSubImageMenu; std::vector contextActions; std::vector horizontalSliders; -- 2.47.1