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 |
#ifdef Q_OS_MAC |
21 |
ui->cbUseYesAsDefaultWhenRemovingItems->setChecked(this->vagoSettings->value("useYesAsDefaultWhenRemovingItems").toBool()); |
22 |
#endif |
23 |
|
24 |
#ifdef Q_OS_WIN |
25 |
ui->cbUseYesAsDefaultWhenRemovingItems->hide(); // don't display this mac os only option in windows |
26 |
#endif |
27 |
|
28 |
} |
29 |
|
30 |
Preferences::~Preferences() |
31 |
{ |
32 |
delete ui; |
33 |
} |
34 |
|
35 |
// Need to override to do the verification |
36 |
// http://stackoverflow.com/questions/3261676/how-to-make-qdialogbuttonbox-not-close-its-parent-qdialog |
37 |
void Preferences::accept (){ |
38 |
QStringList options; |
39 |
QRect screenRes = Util::getScreenResolution(); |
40 |
|
41 |
options << ui->leAEfolder->text() << ui->leWorkspace->text() << ui->leWidth->text() << ui->leHeight->text(); |
42 |
|
43 |
if(Util::checkEmptySpaces(options)){ |
44 |
Util::showErrorPopUp("Setting not saved! There are empty settings."); |
45 |
return; |
46 |
} |
47 |
|
48 |
if(Util::checkIfIntegers(QStringList() << ui->leWidth->text() << ui->leHeight->text() )){ |
49 |
Util::showErrorPopUp("Setting not saved! Width and Height must be numbers."); |
50 |
return; |
51 |
} |
52 |
|
53 |
if(ui->leWidth->text().toInt() > screenRes.width() || ui->leHeight->text().toInt() > screenRes.height()){ |
54 |
Util::showErrorPopUp("Setting not saved! Width or Height specified are greater than actual screen resolution."); |
55 |
return; |
56 |
} |
57 |
|
58 |
if(ui->leWidth->text().toInt() <= 0 || ui->leHeight->text().toInt() <= 0 ){ |
59 |
Util::showErrorPopUp("Settings not saved! Width and Height must be greater than 0."); |
60 |
return; |
61 |
} |
62 |
|
63 |
this->vagoSettings->setValue("AeFolder",ui->leAEfolder->text()); |
64 |
this->vagoSettings->setValue("Workspace",ui->leWorkspace->text()); |
65 |
this->vagoSettings->setValue("WindowWidth",ui->leWidth->text()); |
66 |
this->vagoSettings->setValue("WindowHeight",ui->leHeight->text()); |
67 |
this->vagoSettings->setValue("OniWindow",ui->cbOniWindow->isChecked()); |
68 |
this->vagoSettings->setValue("SeparateInWorkspace",ui->cbSeparate->isChecked()); |
69 |
this->vagoSettings->setValue("ConfirmExit",ui->cbVagoExit->isChecked()); |
70 |
#ifdef Q_OS_MAC |
71 |
this->vagoSettings->setValue("useYesAsDefaultWhenRemovingItems",ui->cbUseYesAsDefaultWhenRemovingItems->isChecked()); |
72 |
#endif |
73 |
|
74 |
|
75 |
Util::showPopUp("You need to restart the application to all changes take effect."); |
76 |
|
77 |
QDialog::accept(); |
78 |
} |
79 |
|
80 |
void Preferences::on_pbChooseWorkspace_clicked() |
81 |
{ |
82 |
QString newDir=QFileDialog::getExistingDirectory(this,"Choose workspace folder..."); |
83 |
newDir=Util::normalizePath(newDir); |
84 |
|
85 |
if(!newDir.isEmpty()){ |
86 |
ui->leWorkspace->setText(newDir); |
87 |
} |
88 |
} |
89 |
|
90 |
void Preferences::on_pbChooseAE_clicked() |
91 |
{ |
92 |
QString newDir=QFileDialog::getExistingDirectory(this,"Choose AE folder..."); |
93 |
newDir=Util::normalizePath(newDir); |
94 |
|
95 |
if(!newDir.isEmpty()){ |
96 |
ui->leAEfolder->setText(newDir); |
97 |
} |
98 |
} |
99 |
|
100 |
void Preferences::on_buttonBox_rejected() |
101 |
{ |
102 |
this->destroy(true,true); |
103 |
} |
104 |
|