-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptionsdialog.cpp
executable file
·172 lines (153 loc) · 7.34 KB
/
optionsdialog.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#include "optionsdialog.h"
#include "ui_optionsdialog.h"
#include "respeqtsettings.h"
#include <QTranslator>
#include <QDir>
OptionsDialog::OptionsDialog(QWidget *parent) :
QDialog(parent),
m_ui(new Ui::OptionsDialog)
{
Qt::WindowFlags flags = windowFlags();
flags = flags & (~Qt::WindowContextHelpButtonHint);
setWindowFlags(flags);
m_ui->setupUi(this);
m_ui->treeWidget->expandAll();
itemStandard = m_ui->treeWidget->topLevelItem(0)->child(0);
itemAtariSio = m_ui->treeWidget->topLevelItem(0)->child(1);
itemEmulation = m_ui->treeWidget->topLevelItem(1);
itemI18n = m_ui->treeWidget->topLevelItem(2);
#ifndef Q_OS_LINUX
m_ui->treeWidget->topLevelItem(0)->removeChild(itemAtariSio);
#endif
connect(this, SIGNAL(accepted()), this, SLOT(OptionsDialog_accepted()));
/* Retrieve application settings */
m_ui->serialPortDeviceNameEdit->setText(respeqtSettings->serialPortName());
m_ui->serialPortHandshakeCombo->setCurrentIndex(respeqtSettings->serialPortHandshakingMethod());
m_ui->serialPortBaudCombo->setCurrentIndex(respeqtSettings->serialPortMaximumSpeed());
m_ui->serialPortUseDivisorsBox->setChecked(respeqtSettings->serialPortUsePokeyDivisors());
m_ui->serialPortDivisorEdit->setValue(respeqtSettings->serialPortPokeyDivisor());
m_ui->atariSioDriverNameEdit->setText(respeqtSettings->atariSioDriverName());
m_ui->atariSioHandshakingMethodCombo->setCurrentIndex(respeqtSettings->atariSioHandshakingMethod());
m_ui->emulationHighSpeedExeLoaderBox->setChecked(respeqtSettings->useHighSpeedExeLoader());
m_ui->emulationUseCustomCasBaudBox->setChecked(respeqtSettings->useCustomCasBaud());
m_ui->emulationCustomCasBaudSpin->setValue(respeqtSettings->customCasBaud());
m_ui->minimizeToTrayBox->setChecked(respeqtSettings->minimizeToTray());
m_ui->saveWinPosBox->setChecked(respeqtSettings->saveWindowsPos());
m_ui->saveDiskVisBox->setChecked(respeqtSettings->saveDiskVis());
m_ui->filterUscore->setChecked(respeqtSettings->filterUnderscore());
m_ui->useLargerFont->setChecked(respeqtSettings->useLargeFont());
m_ui->enableShade->setChecked(respeqtSettings->enableShade());
switch (respeqtSettings->backend()) {
case 0:
itemStandard->setCheckState(0, Qt::Checked);
itemAtariSio->setCheckState(0, Qt::Unchecked);
m_ui->treeWidget->setCurrentItem(itemStandard);
break;
case 1:
itemStandard->setCheckState(0, Qt::Unchecked);
itemAtariSio->setCheckState(0, Qt::Checked);
m_ui->treeWidget->setCurrentItem(itemAtariSio);
break;
}
m_ui->serialPortBox->setCheckState(itemStandard->checkState(0));
m_ui->atariSioBox->setCheckState(itemAtariSio->checkState(0));
/* list available translations */
QTranslator local_translator;
m_ui->i18nLanguageCombo->clear();
m_ui->i18nLanguageCombo->addItem(tr("Automatic"), "auto");
if (respeqtSettings->i18nLanguage().compare("auto") == 0)
m_ui->i18nLanguageCombo->setCurrentIndex(0);
m_ui->i18nLanguageCombo->addItem(QT_TR_NOOP("English"), "en");
if (respeqtSettings->i18nLanguage().compare("en") == 0)
m_ui->i18nLanguageCombo->setCurrentIndex(1);
QDir dir(":/translations/i18n/");
QStringList filters;
filters << "respeqt_*.qm";
dir.setNameFilters(filters);
for (int i = 0; i < dir.entryList().size(); ++i) {
local_translator.load(":/translations/i18n/" + dir.entryList()[i]);
m_ui->i18nLanguageCombo->addItem(local_translator.translate("OptionsDialog", "English"), dir.entryList()[i].mid(7).replace(".qm", ""));
if (dir.entryList()[i].mid(7).replace(".qm", "").compare(respeqtSettings->i18nLanguage()) == 0) {
m_ui->i18nLanguageCombo->setCurrentIndex(i+2);
}
}
}
OptionsDialog::~OptionsDialog()
{
delete m_ui;
}
void OptionsDialog::changeEvent(QEvent *e)
{
QDialog::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
void OptionsDialog::OptionsDialog_accepted()
{
respeqtSettings->setSerialPortName(m_ui->serialPortDeviceNameEdit->text());
respeqtSettings->setSerialPortHandshakingMethod(m_ui->serialPortHandshakeCombo->currentIndex());
respeqtSettings->setSerialPortMaximumSpeed(m_ui->serialPortBaudCombo->currentIndex());
respeqtSettings->setSerialPortUsePokeyDivisors(m_ui->serialPortUseDivisorsBox->isChecked());
respeqtSettings->setSerialPortPokeyDivisor(m_ui->serialPortDivisorEdit->value());
respeqtSettings->setAtariSioDriverName(m_ui->atariSioDriverNameEdit->text());
respeqtSettings->setAtariSioHandshakingMethod(m_ui->atariSioHandshakingMethodCombo->currentIndex());
respeqtSettings->setUseHighSpeedExeLoader(m_ui->emulationHighSpeedExeLoaderBox->isChecked());
respeqtSettings->setUseCustomCasBaud(m_ui->emulationUseCustomCasBaudBox->isChecked());
respeqtSettings->setCustomCasBaud(m_ui->emulationCustomCasBaudSpin->value());
respeqtSettings->setMinimizeToTray(m_ui->minimizeToTrayBox->isChecked());
respeqtSettings->setsaveWindowsPos(m_ui->saveWinPosBox->isChecked());
respeqtSettings->setsaveDiskVis(m_ui->saveDiskVisBox->isChecked());
respeqtSettings->setfilterUnderscore(m_ui->filterUscore->isChecked());
respeqtSettings->setUseLargeFont(m_ui->useLargerFont->isChecked());
respeqtSettings->setEnableShade(m_ui->enableShade->isChecked());
int backend = 0;
if (itemAtariSio->checkState(0) == Qt::Checked) {
backend = 1;
}
respeqtSettings->setBackend(backend);
respeqtSettings->setI18nLanguage(m_ui->i18nLanguageCombo->itemData(m_ui->i18nLanguageCombo->currentIndex()).toString());
}
void OptionsDialog::on_treeWidget_currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* /*previous*/)
{
if (current == itemStandard) {
m_ui->stackedWidget->setCurrentIndex(0);
} else if (current == itemAtariSio) {
m_ui->stackedWidget->setCurrentIndex(1);
} else if (current == itemEmulation) {
m_ui->stackedWidget->setCurrentIndex(2);
} else if (current == itemI18n) {
m_ui->stackedWidget->setCurrentIndex(3);
}
}
void OptionsDialog::on_treeWidget_itemClicked(QTreeWidgetItem* item, int /*column*/)
{
if (item->checkState(0) == Qt::Checked) {
if (item != itemStandard) {
itemStandard->setCheckState(0, Qt::Unchecked);
}
if (item != itemAtariSio) {
itemAtariSio->setCheckState(0, Qt::Unchecked);
}
} else if ((itemStandard->checkState(0) == Qt::Unchecked) &&
(itemAtariSio->checkState(0) == Qt::Unchecked)) {
item->setCheckState(0, Qt::Checked);
}
m_ui->serialPortBox->setCheckState(itemStandard->checkState(0));
m_ui->atariSioBox->setCheckState(itemAtariSio->checkState(0));
}
void OptionsDialog::on_serialPortUseDivisorsBox_toggled(bool checked)
{
m_ui->serialPortBaudLabel->setEnabled(!checked);
m_ui->serialPortBaudCombo->setEnabled(!checked);
m_ui->serialPortDivisorLabel->setEnabled(checked);
m_ui->serialPortDivisorEdit->setEnabled(checked);
}
void OptionsDialog::on_useEmulationCustomCasBaudBox_toggled(bool checked)
{
m_ui->emulationCustomCasBaudSpin->setEnabled(checked);
}