This repository has been archived by the owner on Apr 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathoptionsdialog.cpp
279 lines (254 loc) · 12.2 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/*
* optionsdialog.cpp
*
* Copyright 2015 Joseph Zatarski
* Copyright 2016, 2017 TheMontezuma
*
* This file is copyrighted by either Fatih Aygun, Ray Ataergin, or both.
* However, the years for these copyrights are unfortunately unknown. If you
* know the specific year(s) please let the current maintainer know.
*/
#include "optionsdialog.h"
#include "ui_optionsdialog.h"
#include "respeqtsettings.h"
#include <QtSerialPort/QtSerialPort>
#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->serialPortComboBox->clear();
const QList<QSerialPortInfo>& infos = QSerialPortInfo::availablePorts();
for (QList<QSerialPortInfo>::const_iterator it = infos.begin() ; it!=infos.end() ; it++)
{
m_ui->serialPortComboBox->addItem(it->portName(),it->systemLocation());
}
m_ui->serialPortComboBox->setCurrentText(respeqtSettings->serialPortName());
if(0 != m_ui->serialPortComboBox->currentText().compare(respeqtSettings->serialPortName(),Qt::CaseInsensitive))
{
m_ui->serialPortComboBox->setEditable(true);
m_ui->serialPortComboBox->addItem(respeqtSettings->serialPortName());
m_ui->serialPortComboBox->setCurrentText(respeqtSettings->serialPortName());
}
else
{
m_ui->serialPortComboBox->addItem(tr("Custom"));
}
m_ui->serialPortHandshakeCombo->setCurrentIndex(respeqtSettings->serialPortHandshakingMethod());
m_ui->serialPortFallingEdge->setChecked(respeqtSettings->serialPortTriggerOnFallingEdge());
m_ui->serialPortWriteDelayCombo->setCurrentIndex(respeqtSettings->serialPortWriteDelay());
m_ui->serialPortBaudCombo->setCurrentIndex(respeqtSettings->serialPortMaximumSpeed());
m_ui->serialPortUseDivisorsBox->setChecked(respeqtSettings->serialPortUsePokeyDivisors());
m_ui->serialPortDivisorEdit->setValue(respeqtSettings->serialPortPokeyDivisor());
m_ui->serialPortCompErrDelayBox->setValue(respeqtSettings->serialPortCompErrDelay());
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->capitalLettersPCLINK->setChecked(respeqtSettings->capitalLettersInPCLINK());
m_ui->URLSubmit->setChecked(respeqtSettings->isURLSubmitEnabled());
m_ui->useLargerFont->setChecked(respeqtSettings->useLargeFont());
m_ui->enableShade->setChecked(respeqtSettings->enableShade());
switch (respeqtSettings->backend()) {
case SERIAL_BACKEND_STANDARD:
itemStandard->setCheckState(0, Qt::Checked);
itemAtariSio->setCheckState(0, Qt::Unchecked);
m_ui->treeWidget->setCurrentItem(itemStandard);
break;
case SERIAL_BACKEND_SIO_DRIVER:
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].replace("respeqt_", "").replace(".qm", ""));
if (dir.entryList()[i].replace("respeqt_", "").replace(".qm", "").compare(respeqtSettings->i18nLanguage()) == 0) {
m_ui->i18nLanguageCombo->setCurrentIndex(i+2);
}
}
bool no_handshake = (respeqtSettings->serialPortHandshakingMethod()==HANDSHAKE_NO_HANDSHAKE);
bool software_handshake = (respeqtSettings->serialPortHandshakingMethod()==HANDSHAKE_SOFTWARE);
m_ui->serialPortWriteDelayLabel->setVisible(software_handshake);
m_ui->serialPortWriteDelayCombo->setVisible(software_handshake);
m_ui->serialPortBaudLabel->setVisible(!software_handshake);
m_ui->serialPortBaudCombo->setVisible(!software_handshake);
m_ui->serialPortUseDivisorsBox->setVisible(!software_handshake);
m_ui->serialPortDivisorLabel->setVisible(!software_handshake);
m_ui->serialPortDivisorEdit->setVisible(!software_handshake);
m_ui->serialPortCompErrDelayLabel->setVisible(!software_handshake);
m_ui->serialPortCompErrDelayBox->setVisible(!software_handshake);
#ifdef Q_OS_WIN
m_ui->serialPortFallingEdge->setVisible(!no_handshake && !software_handshake);
#else
m_ui->serialPortFallingEdge->setVisible(false);
#endif
if((SERIAL_BACKEND_STANDARD == respeqtSettings->backend()) && software_handshake)
{
m_ui->emulationHighSpeedExeLoaderBox->setVisible(false);
}
else
{
m_ui->emulationHighSpeedExeLoaderBox->setVisible(true);
}
}
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::on_serialPortComboBox_currentIndexChanged(int index)
{
bool isCustomPath = !m_ui->serialPortComboBox->itemData(index).isValid();
m_ui->serialPortComboBox->setEditable(isCustomPath);
}
void OptionsDialog::on_serialPortHandshakeCombo_currentIndexChanged(int index)
{
bool no_handshake = (index==HANDSHAKE_NO_HANDSHAKE);
bool software_handshake = (index==HANDSHAKE_SOFTWARE);
m_ui->serialPortWriteDelayLabel->setVisible(software_handshake);
m_ui->serialPortWriteDelayCombo->setVisible(software_handshake);
m_ui->serialPortBaudLabel->setVisible(!software_handshake);
m_ui->serialPortBaudCombo->setVisible(!software_handshake);
m_ui->serialPortUseDivisorsBox->setVisible(!software_handshake);
m_ui->serialPortDivisorLabel->setVisible(!software_handshake);
m_ui->serialPortDivisorEdit->setVisible(!software_handshake);
m_ui->serialPortCompErrDelayLabel->setVisible(!software_handshake);
m_ui->serialPortCompErrDelayBox->setVisible(!software_handshake);
#ifdef Q_OS_WIN
m_ui->serialPortFallingEdge->setVisible(!no_handshake && !software_handshake);
#endif
if(itemStandard->checkState((0)) == Qt::Checked)
{
m_ui->emulationHighSpeedExeLoaderBox->setVisible(!software_handshake);
}
}
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_treeWidget_itemClicked(QTreeWidgetItem* item, int /*column*/)
{
if (item->checkState(0) == Qt::Checked)
{
if (item == itemStandard)
{
m_ui->emulationHighSpeedExeLoaderBox->setVisible(HANDSHAKE_SOFTWARE != m_ui->serialPortHandshakeCombo->currentIndex());
}
else
{
itemStandard->setCheckState(0, Qt::Unchecked);
}
if (item == itemAtariSio)
{
m_ui->emulationHighSpeedExeLoaderBox->setVisible(true);
}
else
{
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_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::OptionsDialog_accepted()
{
respeqtSettings->setSerialPortName(m_ui->serialPortComboBox->currentText());
respeqtSettings->setSerialPortHandshakingMethod(m_ui->serialPortHandshakeCombo->currentIndex());
respeqtSettings->setSerialPortTriggerOnFallingEdge(m_ui->serialPortFallingEdge->isChecked());
respeqtSettings->setSerialPortWriteDelay(m_ui->serialPortWriteDelayCombo->currentIndex());
respeqtSettings->setSerialPortCompErrDelay(m_ui->serialPortCompErrDelayBox->value());
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->setCapitalLettersInPCLINK(m_ui->capitalLettersPCLINK->isChecked());
respeqtSettings->setURLSubmit(m_ui->URLSubmit->isChecked());
respeqtSettings->setUseLargeFont(m_ui->useLargerFont->isChecked());
respeqtSettings->setEnableShade(m_ui->enableShade->isChecked());
int backend = SERIAL_BACKEND_STANDARD;
if (itemAtariSio->checkState(0) == Qt::Checked)
{
backend = SERIAL_BACKEND_SIO_DRIVER;
}
respeqtSettings->setBackend(backend);
respeqtSettings->setI18nLanguage(m_ui->i18nLanguageCombo->itemData(m_ui->i18nLanguageCombo->currentIndex()).toString());
}
void OptionsDialog::on_useEmulationCustomCasBaudBox_toggled(bool checked)
{
m_ui->emulationCustomCasBaudSpin->setEnabled(checked);
}