-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettingsdialog.cpp
100 lines (95 loc) · 5.18 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
99
100
#include "settingsdialog.h"
#include "ui_settingsdialog.h"
SettingsDialog::SettingsDialog(QWidget *parent) :
QWidget(parent),
ui(new Ui::SettingsDialog)
{
ui->setupUi(this);
setWindowModality(Qt::ApplicationModal);
move(QApplication::desktop()->geometry().width() / 2 - this->geometry().width() / 2,
QApplication::desktop()->geometry().height() / 2 - this->geometry().height() / 2);
connect(ui->defaultSettingsPushButton, SIGNAL(clicked()), this, SLOT(returnDefaultSettings()));
QStringList list;
list << "black" << "white" << "darkGray" << "gray" << "lightGray" << "red" << "green" << "blue" << "cyan" << "magenta" << "yellow" <<
"darkRed" << "darkGreen" << "darkBlue" << "darkCyan" << "darkMagenta" << "darkYellow";
ui->tableColorComboBox->addItems(list);
ui->inCharsColorComboBox->addItems(list);
ui->outCharsColorComboBox->addItems(list);
ui->ArrowColorComboBox->addItems(list);
//
QSettings settings("settings", QSettings::IniFormat);
CryptoHelper::alphabet = settings.value("alphabet", tr("abcdefghijklmnopqrstuvwxyz")).toString();
CryptoHelper::extAlphabet = settings.value("extAlphabet", (" :,.")).toString();
CryptoHelper::tokenLength = settings.value("tokenLength", 4).toInt();
CryptoHelper::tableColor = Qt::GlobalColor(settings.value("tableColor", 2).toInt());
CryptoHelper::inCharsColor = Qt::GlobalColor(settings.value("inCharsColor", 8).toInt());
CryptoHelper::outCharsColor = Qt::GlobalColor(settings.value("outCharsColor", 7).toInt());
CryptoHelper::arrowColor = Qt::GlobalColor(settings.value("arrowColor", 7).toInt());
CryptoHelper::interval = settings.value("interval", 500).toInt();
ui->alphabetLineEdit->setText(CryptoHelper::alphabet);
ui->extAlphabetLineEdit->setText(CryptoHelper::extAlphabet);
ui->tokenLengthSpinBox->setValue(CryptoHelper::tokenLength);
ui->tableColorComboBox->setCurrentIndex(int(CryptoHelper::tableColor) - 2);
ui->inCharsColorComboBox->setCurrentIndex(int(CryptoHelper::inCharsColor) - 2);
ui->outCharsColorComboBox->setCurrentIndex(int(CryptoHelper::outCharsColor) - 2);
ui->ArrowColorComboBox->setCurrentIndex((CryptoHelper::arrowColor) - 2);
ui->intervalSpinBox->setValue(CryptoHelper::interval);
}
SettingsDialog::~SettingsDialog()
{
delete ui;
}
void SettingsDialog::on_cancelPushButton_clicked()
{
ui->alphabetLineEdit->setText(CryptoHelper::alphabet);
ui->extAlphabetLineEdit->setText(CryptoHelper::extAlphabet);
ui->tokenLengthSpinBox->setValue(CryptoHelper::tokenLength);
ui->tableColorComboBox->setCurrentIndex(int(CryptoHelper::tableColor) - 2);
ui->inCharsColorComboBox->setCurrentIndex(int(CryptoHelper::inCharsColor) - 2);
ui->outCharsColorComboBox->setCurrentIndex(int(CryptoHelper::outCharsColor) - 2);
ui->ArrowColorComboBox->setCurrentIndex((CryptoHelper::arrowColor) - 2);
ui->intervalSpinBox->setValue(CryptoHelper::interval);
ui->msgLabel->setText("");
this->hide();
}
void SettingsDialog::on_applyPushButton_clicked()
{
if(CryptoHelper::isUniq(ui->alphabetLineEdit->text()) && CryptoHelper::isUniq(ui->extAlphabetLineEdit->text())
&& CryptoHelper::isUniq(ui->alphabetLineEdit->text() + ui->extAlphabetLineEdit->text()))
{
CryptoHelper::alphabet = ui->alphabetLineEdit->text();
CryptoHelper::extAlphabet = ui->extAlphabetLineEdit->text();
CryptoHelper::tokenLength = ui->tokenLengthSpinBox->value();
CryptoHelper::tableColor = Qt::GlobalColor(ui->tableColorComboBox->currentIndex() + 2);
CryptoHelper::inCharsColor = Qt::GlobalColor(ui->inCharsColorComboBox->currentIndex() + 2);
CryptoHelper::outCharsColor = Qt::GlobalColor(ui->outCharsColorComboBox->currentIndex() + 2);
CryptoHelper::arrowColor = Qt::GlobalColor(ui->ArrowColorComboBox->currentIndex() + 2);
CryptoHelper::interval = ui->intervalSpinBox->value();
ui->msgLabel->setText("");
QSettings settings("settings", QSettings::IniFormat);
settings.setValue("alphabet", CryptoHelper::alphabet);
settings.setValue("extAlphabet", CryptoHelper::extAlphabet);
settings.setValue("tokenLength", CryptoHelper::tokenLength);
settings.setValue("tableColor", int(CryptoHelper::tableColor));
settings.setValue("inCharsColor", int(CryptoHelper::inCharsColor));
settings.setValue("outCharsColor", int(CryptoHelper::outCharsColor));
settings.setValue("arrowColor", int(CryptoHelper::arrowColor));
settings.setValue("interval", CryptoHelper::interval);
emit alphabetChanged();
this->hide();
}
else
ui->msgLabel->setText(QString("<font color = \"red\">%1</font>")
.arg(tr("Characters in the alphabet should not be repeated!")));
}
void SettingsDialog::returnDefaultSettings()
{
ui->alphabetLineEdit->setText(tr("abcdefghijklmnopqrstuvwxyz"));
ui->extAlphabetLineEdit->setText(" :,.");
ui->tokenLengthSpinBox->setValue(4);
ui->tableColorComboBox->setCurrentIndex(0);
ui->inCharsColorComboBox->setCurrentIndex(6);
ui->outCharsColorComboBox->setCurrentIndex(5);
ui->ArrowColorComboBox->setCurrentIndex(5);
ui->intervalSpinBox->setValue(500);
}