forked from trolley813/OpenFool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsdialog.cpp
98 lines (80 loc) · 3.62 KB
/
settingsdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
#include <QColorDialog>
static QMap<QString, QString> LANGUAGES = {
{"en", QObject::tr("English")}, {"ru", QObject::tr("Russian")},
};
const QColor DEFAULT_BACKGROUND(86, 156, 30, 230);
SettingsDialog::SettingsDialog(QSettings *settings, QWidget *parent)
: QDialog(parent), ui(new Ui::SettingsDialog), settings(settings)
{
ui->setupUi(this);
ui->lineEditPlayer1Name->setText(
settings->value("players/name1", "Denis").toString());
ui->lineEditPlayer2Name->setText(
settings->value("players/name2", "Girotte").toString());
ui->lineEditPlayer3Name->setText(
settings->value("players/name3", "Mama").toString());
ui->lineEditPlayer4Name->setText(
settings->value("players/name4", "Kot").toString());
ui->checkBoxGL->setChecked(
settings->value("rendering/opengl", false).toBool());
ui->radioButtonRus->setChecked(settings->value("cards/deck", "rus")
== "rus");
ui->radioButtonInt->setChecked(settings->value("cards/deck", "rus")
== "int");
ui->radioButtonFra->setChecked(settings->value("cards/deck", "rus")
== "fra");
ui->radioButtonUnsorted->setChecked(settings->value("rendering/sorting", 0)
== 0);
ui->radioButtonAscending->setChecked(settings->value("rendering/sorting", 0)
== 1);
ui->radioButtonDescending->setChecked(settings->value("rendering/sorting", 0)
== 2);
for (auto language : LANGUAGES)
ui->comboBoxLanguage->addItem(language);
ui->comboBoxLanguage->setCurrentIndex(LANGUAGES.keys().indexOf(
settings->value("general/language", "").toString()));
backgroundColor = settings->value("rendering/background",
DEFAULT_BACKGROUND).value<QColor>();
}
SettingsDialog::~SettingsDialog() { delete ui; }
void SettingsDialog::saveSettings()
{
settings->setValue("players/name1", ui->lineEditPlayer1Name->text());
settings->setValue("players/name2", ui->lineEditPlayer2Name->text());
settings->setValue("players/name3", ui->lineEditPlayer3Name->text());
settings->setValue("players/name4", ui->lineEditPlayer4Name->text());
settings->setValue("rendering/opengl", ui->checkBoxGL->isChecked());
if (ui->radioButtonRus->isChecked())
settings->setValue("cards/deck", "rus");
if (ui->radioButtonInt->isChecked())
settings->setValue("cards/deck", "int");
if (ui->radioButtonFra->isChecked())
settings->setValue("cards/deck", "fra");
if(ui->radioButtonUnsorted->isChecked())
settings->setValue("rendering/sorting", 0);
if(ui->radioButtonAscending->isChecked())
settings->setValue("rendering/sorting", 1);
if(ui->radioButtonDescending->isChecked())
settings->setValue("rendering/sorting", 2);
settings->setValue("general/language",
LANGUAGES.key(ui->comboBoxLanguage->currentText()));
settings->setValue("rendering/background", backgroundColor);
}
void SettingsDialog::accept()
{
saveSettings();
QDialog::accept();
}
void SettingsDialog::apply() { saveSettings(); }
void SettingsDialog::onClick(QAbstractButton *button)
{
if (ui->buttonBox->standardButton(button) == QDialogButtonBox::Apply)
apply();
}
void SettingsDialog::on_pushButtonSelectColor_clicked()
{
backgroundColor = QColorDialog::getColor(backgroundColor, this,
tr("Select background color"));
}