| 1 |
#include "preferences.h" |
| 2 |
#include "ui_preferences.h" |
| 3 |
|
| 4 |
Preferences::Preferences(QWidget *parent, QSettings *vagoSettings) : |
| 5 |
QDialog(parent), |
| 6 |
ui(new Ui::Preferences) |
| 7 |
{ |
| 8 |
ui->setupUi(this); |
| 9 |
this->setAttribute(Qt::WA_DeleteOnClose,true ); //destroy itself once finished. |
| 10 |
|
| 11 |
this->vagoSettings=vagoSettings; |
| 12 |
|
| 13 |
ui->leAEfolder->setText(this->vagoSettings->value("AeFolder").toString()); |
| 14 |
ui->leWorkspace->setText(this->vagoSettings->value("Workspace").toString()); |
| 15 |
ui->leWidth->setText(this->vagoSettings->value("WindowWidth").toString()); |
| 16 |
ui->leHeight->setText(this->vagoSettings->value("WindowHeight").toString()); |
| 17 |
ui->cbOniWindow->setChecked(this->vagoSettings->value("OniWindow").toBool()); |
| 18 |
ui->cbSeparate->setChecked(this->vagoSettings->value("SeparateInWorkspace").toBool()); |
| 19 |
ui->cbVagoExit->setChecked(this->vagoSettings->value("ConfirmExit").toBool()); |
| 20 |
|
| 21 |
} |
| 22 |
|
| 23 |
Preferences::~Preferences() |
| 24 |
{ |
| 25 |
delete ui; |
| 26 |
} |
| 27 |
|
| 28 |
// Need to override to do the verification |
| 29 |
// http://stackoverflow.com/questions/3261676/how-to-make-qdialogbuttonbox-not-close-its-parent-qdialog |
| 30 |
void Preferences::accept (){ |
| 31 |
QStringList options; |
| 32 |
QRect screenRes = Util::getScreenResolution(); |
| 33 |
|
| 34 |
options << ui->leAEfolder->text() << ui->leWorkspace->text() << ui->leWidth->text() << ui->leHeight->text(); |
| 35 |
|
| 36 |
if(Util::checkEmptySpaces(options)){ |
| 37 |
Util::showErrorPopUp("Setting not saved! There are empty settings."); |
| 38 |
return; |
| 39 |
} |
| 40 |
|
| 41 |
if(Util::checkIfIntegers(QStringList() << ui->leWidth->text() << ui->leHeight->text() )){ |
| 42 |
Util::showErrorPopUp("Setting not saved! Width and Height must be numbers."); |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
if(ui->leWidth->text().toInt() > screenRes.width() || ui->leHeight->text().toInt() > screenRes.height()){ |
| 47 |
Util::showErrorPopUp("Setting not saved! Width or Height specified are greater than actual screen resolution."); |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
if(ui->leWidth->text().toInt() <= 0 || ui->leHeight->text().toInt() <= 0 ){ |
| 52 |
Util::showErrorPopUp("Settings not saved! Width and Height must be greater than 0."); |
| 53 |
return; |
| 54 |
} |
| 55 |
|
| 56 |
this->vagoSettings->setValue("AeFolder",ui->leAEfolder->text()); |
| 57 |
this->vagoSettings->setValue("Workspace",ui->leWorkspace->text()); |
| 58 |
this->vagoSettings->setValue("WindowWidth",ui->leWidth->text()); |
| 59 |
this->vagoSettings->setValue("WindowHeight",ui->leHeight->text()); |
| 60 |
this->vagoSettings->setValue("OniWindow",ui->cbOniWindow->isChecked()); |
| 61 |
this->vagoSettings->setValue("SeparateInWorkspace",ui->cbSeparate->isChecked()); |
| 62 |
this->vagoSettings->setValue("ConfirmExit",ui->cbVagoExit->isChecked()); |
| 63 |
|
| 64 |
Util::showPopUp("You need to restart the application to all changes take effect."); |
| 65 |
|
| 66 |
QDialog::accept(); |
| 67 |
} |
| 68 |
|
| 69 |
void Preferences::on_pbChooseWorkspace_clicked() |
| 70 |
{ |
| 71 |
QString newDir=QFileDialog::getExistingDirectory(this,"Choose workspace folder..."); |
| 72 |
newDir=Util::normalizePath(newDir); |
| 73 |
|
| 74 |
if(!newDir.isEmpty()){ |
| 75 |
ui->leWorkspace->setText(newDir); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
void Preferences::on_pbChooseAE_clicked() |
| 80 |
{ |
| 81 |
QString newDir=QFileDialog::getExistingDirectory(this,"Choose AE folder..."); |
| 82 |
newDir=Util::normalizePath(newDir); |
| 83 |
|
| 84 |
if(!newDir.isEmpty()){ |
| 85 |
ui->leAEfolder->setText(newDir); |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
void Preferences::on_buttonBox_rejected() |
| 90 |
{ |
| 91 |
this->destroy(true,true); |
| 92 |
} |
| 93 |
|