Mercurial > hg > sonic-visualiser
diff main/MainWindow.cpp @ 484:1f3afbce6c2f integration_library
Merge from the default branch
author | mathieub <mathieu.barthet@eecs.qmul.ac.uk> |
---|---|
date | Mon, 17 Oct 2011 15:24:22 +0100 |
parents | e5c6aed2bf6b a6cbec451508 |
children | b6c00a0a618e |
line wrap: on
line diff
--- a/main/MainWindow.cpp Mon Oct 17 14:05:54 2011 +0100 +++ b/main/MainWindow.cpp Mon Oct 17 15:24:22 2011 +0100 @@ -114,6 +114,7 @@ #include <QRegExp> #include <QScrollArea> #include <QDesktopServices> +#include <QDialogButtonBox> #include <QFileSystemWatcher> #include <iostream> @@ -2913,27 +2914,50 @@ void MainWindow::saveSessionAsTemplate() { - QString name = QInputDialog::getText - (this, tr("Enter template name"), - tr("Please enter a name for the saved template:")); - if (name == "") return; + QDialog *d = new QDialog; + d->setWindowTitle(tr("Enter template name")); + + QGridLayout *layout = new QGridLayout; + d->setLayout(layout); + + layout->addWidget(new QLabel(tr("Please enter a name for the saved template:")), + 0, 0); + QLineEdit *lineEdit = new QLineEdit; + layout->addWidget(lineEdit, 1, 0); + QCheckBox *makeDefault = new QCheckBox(tr("Set as default template for future audio files")); + layout->addWidget(makeDefault, 2, 0); - name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_"); - - ResourceFinder rf; - QString dir = rf.getResourceSaveDir("templates"); - QString filename = QString("%1/%2.svt").arg(dir).arg(name); - if (QFile(filename).exists()) { - if (QMessageBox::warning(this, - tr("Template file exists"), - tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name), - QMessageBox::Ok | QMessageBox::Cancel, - QMessageBox::Cancel) != QMessageBox::Ok) { - return; + QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok | + QDialogButtonBox::Cancel); + layout->addWidget(bb, 3, 0); + connect(bb, SIGNAL(accepted()), d, SLOT(accept())); + connect(bb, SIGNAL(accepted()), d, SLOT(accept())); + connect(bb, SIGNAL(rejected()), d, SLOT(reject())); + + if (d->exec() == QDialog::Accepted) { + + QString name = lineEdit->text(); + name.replace(QRegExp("[^\\w\\s\\.\"'-]"), "_"); + + ResourceFinder rf; + QString dir = rf.getResourceSaveDir("templates"); + QString filename = QString("%1/%2.svt").arg(dir).arg(name); + if (QFile(filename).exists()) { + if (QMessageBox::warning(this, + tr("Template file exists"), + tr("<b>Template file exists</b><p>The template \"%1\" already exists.<br>Overwrite it?").arg(name), + QMessageBox::Ok | QMessageBox::Cancel, + QMessageBox::Cancel) != QMessageBox::Ok) { + return; + } + } + + if (saveSessionTemplate(filename)) { + if (makeDefault->isChecked()) { + setDefaultSessionTemplate(name); + } } } - - saveSessionTemplate(filename); } void