MainWindow: Moved FileDialog to own subclass

This commit is contained in:
Lukas W
2014-01-22 22:10:52 +01:00
parent f073c6d11b
commit 0bbfd907ae
4 changed files with 113 additions and 45 deletions

View File

@@ -24,12 +24,10 @@
#include <QtXml/QDomElement>
#include <QtCore/QList>
#include <QtCore/QUrl>
#include <QtGui/QApplication>
#include <QtGui/QCloseEvent>
#include <QtGui/QDesktopServices>
#include <QtGui/QFileDialog>
#include <QtGui/QMdiArea>
#include <QtGui/QMdiSubWindow>
#include <QtGui/QMenuBar>
@@ -63,6 +61,7 @@
#include "ProjectJournal.h"
#include "AutomationEditor.h"
#include "templates.h"
#include "FileDialog.h"
@@ -682,47 +681,23 @@ void MainWindow::createNewProjectFromTemplate( QAction * _idx )
QFileDialog* MainWindow::newFileDialog( const QString& caption, const QString& directory, const QString& filter )
{
QFileDialog* fd = new QFileDialog( this, caption, directory, filter);
#if QT_VERSION >= 0x040806
fd->setOption( QFileDialog::DontUseCustomDirectoryIcons );
#endif
QList<QUrl> urls = fd->sidebarUrls();
urls << QUrl::fromLocalFile( QDesktopServices::storageLocation( QDesktopServices::DesktopLocation ) );
// Find downloads directory
QDir downloadDir( QDir::homePath() + "/Downloads" );
if (! downloadDir.exists())
downloadDir = QDesktopServices::storageLocation( QDesktopServices::DocumentsLocation ) + "/Downloads";
if (downloadDir.exists())
urls << QUrl::fromLocalFile( downloadDir.absolutePath() );
fd->setSidebarUrls(urls);
return fd;
}
void MainWindow::openProject( void )
{
if( mayChangeProject() )
{
QFileDialog* ofd = newFileDialog( tr( "Open project" ), "",
FileDialog ofd( this, tr( "Open project" ), "",
tr( "MultiMedia Project (*.mmp *.mmpz *.xml)" ) );
ofd->setDirectory( configManager::inst()->userProjectsDir() );
ofd->setFileMode( QFileDialog::ExistingFiles );
if( ofd->exec () == QDialog::Accepted &&
!ofd->selectedFiles().isEmpty() )
ofd.setDirectory( configManager::inst()->userProjectsDir() );
ofd.setFileMode( QFileDialog::ExistingFiles );
if( ofd.exec () == QDialog::Accepted &&
!ofd.selectedFiles().isEmpty() )
{
setCursor( Qt::WaitCursor );
engine::getSong()->loadProject(
ofd->selectedFiles()[0] );
ofd.selectedFiles()[0] );
setCursor( Qt::ArrowCursor );
}
delete ofd;
}
}
@@ -773,31 +748,29 @@ bool MainWindow::saveProject( void )
bool MainWindow::saveProjectAs( void )
{
QFileDialog* sfd = newFileDialog( tr( "Save project" ), "",
FileDialog sfd( this, tr( "Save project" ), "",
tr( "MultiMedia Project (*.mmp *.mmpz);;"
"MultiMedia Project Template (*.mpt)" ) );
sfd->setAcceptMode( QFileDialog::AcceptSave );
sfd->setFileMode( QFileDialog::AnyFile );
sfd.setAcceptMode( QFileDialog::AcceptSave );
sfd.setFileMode( QFileDialog::AnyFile );
QString f = engine::getSong()->projectFileName();
if( f != "" )
{
sfd->setDirectory( QFileInfo( f ).absolutePath() );
sfd->selectFile( QFileInfo( f ).fileName() );
sfd.setDirectory( QFileInfo( f ).absolutePath() );
sfd.selectFile( QFileInfo( f ).fileName() );
}
else
{
sfd->setDirectory( configManager::inst()->userProjectsDir() );
sfd.setDirectory( configManager::inst()->userProjectsDir() );
}
if( sfd->exec () == QFileDialog::Accepted &&
!sfd->selectedFiles().isEmpty() && sfd->selectedFiles()[0] != "" )
if( sfd.exec () == QFileDialog::Accepted &&
!sfd.selectedFiles().isEmpty() && sfd.selectedFiles()[0] != "" )
{
engine::getSong()->guiSaveProjectAs(
sfd->selectedFiles()[0] );
delete sfd;
sfd.selectedFiles()[0] );
return( TRUE );
}
delete sfd;
return( FALSE );
}