-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettingsdialog.cpp
More file actions
129 lines (114 loc) · 4.6 KB
/
settingsdialog.cpp
File metadata and controls
129 lines (114 loc) · 4.6 KB
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
#include "settingsdialog.h"
SettingsDialog::SettingsDialog(QSettings &s, QWidget *parent) : QDialog(parent),settings(s)
{
setupUi(this);
connect(buttonBox, &QDialogButtonBox::accepted, this, &SettingsDialog::acceptChanges);
connect(buttonBox, &QDialogButtonBox::rejected, this, &SettingsDialog::rejectChanges);
connect(pbBrowse, &QPushButton::released, this, &SettingsDialog::browseFileDialog);
connect(pbShadeColor, &QPushButton::released,
this, &SettingsDialog::setMapShadeColor);
loadSettings();
}
SettingsDialog::~SettingsDialog()
{
}
void SettingsDialog::setMapShadeColor()
{
QColor c;
// options: QColorDialog::DontUseNativeDialog|QColorDialog::ShowAlphaChannel|QColorDialog::NoButtons
c = QColorDialog::getColor(mapShadeColor,
this,
"Select Color",
QColorDialog::ShowAlphaChannel|QColorDialog::DontUseNativeDialog
);
if (c.isValid()) {
mapShadeColor = c;
}
QPixmap pixmap_fill(16, 16);
pixmap_fill.fill(mapShadeColor.rgba());
QIcon icon_fill(pixmap_fill);
pbShadeColor->setIcon(icon_fill);
}
void SettingsDialog::loadSettings()
{
serverIp->setText(settings.value(s_serverIp, s_serverIp_def).toString());
serverPort->setText(settings.value(s_serverPort, s_serverPort_def).toString());
serverAutoConnect->setChecked(settings.value(s_serverAutoConnect, s_serverAutoConnect_def).toBool());
mapFile->setText(settings.value(s_mapFile, s_mapFile_def).toString());
mapShadeColor = settings.value(s_mapShadeColor, s_mapShadeColor_def).value<QColor>();
cbShadeUnavailable->setChecked(settings.value(s_mapShadeUnavailable, s_mapShadeUnavailable_def).toBool());
cbTheme->setChecked(settings.value(s_darkPalette, s_darkPalette_def).toBool());
cbNightShade->setChecked(settings.value(s_nightshading, s_nightshading_def).toBool());
gridLocator->setText(settings.value(s_gridlocator, s_gridlocator_def).toString());
cbNightTransparency->setCurrentIndex(settings.value(s_nighttransparency,s_nighttransparency_def).toInt());
QPixmap pixmap_fill(16, 16);
pixmap_fill.fill(mapShadeColor.rgba());
QIcon icon_fill(pixmap_fill);
pbShadeColor->setIcon(icon_fill);
//qDebug() << "loadsettings";
}
void SettingsDialog::acceptChanges()
{
bool updateMaps = false;
bool updateWebsocket = false;
bool updateNightMaps = false;
bool toggleNightMap = false;
if (settings.value(s_mapFile, s_mapFile_def).toString() != mapFile->text()
|| settings.value(s_gridlocator, s_gridlocator_def).toString() != gridLocator->text()) {
updateMaps = true;
}
if (settings.value(s_serverIp, s_serverIp_def).toString() != serverIp->text()
|| settings.value(s_serverPort, s_serverPort_def).toString() != serverPort->text()) {
updateWebsocket = true;
}
if (settings.value(s_nightshading, s_nightshading_def).toBool() != cbNightShade->isChecked()) {
toggleNightMap = true;
}
if (settings.value(s_nighttransparency,s_nighttransparency_def).toInt() !=
cbNightTransparency->currentIndex()) {
updateNightMaps = true;
}
settings.setValue(s_serverIp, serverIp->text());
settings.setValue(s_serverPort, serverPort->text());
settings.setValue(s_serverAutoConnect, serverAutoConnect->isChecked());
settings.setValue(s_mapFile, mapFile->text());
settings.setValue(s_mapShadeColor, mapShadeColor);
settings.setValue(s_mapShadeUnavailable, cbShadeUnavailable->isChecked());
settings.setValue(s_darkPalette, cbTheme->isChecked());
settings.setValue(s_gridlocator, gridLocator->text());
settings.setValue(s_nightshading, cbNightShade->isChecked());
settings.setValue(s_nighttransparency, cbNightTransparency->currentIndex());
settings.sync();
emit settingsUpdated();
if (updateMaps) {
emit updateMapImages();
} else if (updateNightMaps) {
emit updateNightMapImages();
} else if (toggleNightMap) {
emit toggleNightMapImage();
}
if (updateWebsocket) {
emit webSocketReconnect();
}
//qDebug() << "accepted";
accept();
}
void SettingsDialog::rejectChanges()
{
loadSettings();
//qDebug() << "rejected";
reject();
}
void SettingsDialog::browseFileDialog()
{
QFileDialog *fileDialog = new QFileDialog(this);
fileDialog->setFileMode(QFileDialog::ExistingFile);
QString filename = fileDialog->getOpenFileName(this,
tr("Map File"),
mapFile->text(),
tr("Images (*.png *.jpg *.PNG *.JPG)"));
if (!filename.isNull() && !filename.isEmpty()){
mapFile->setText(filename);
}
delete fileDialog;
}