2
// C++ Implementation: PreferencesDialog
7
// Author: cbro <cbro@semperpax.com>, Bart Vanhauwaert (C) 2008
9
// Copyright: See COPYING file that comes with this distribution
12
#include "Preferences/PreferencesDialog.h"
13
#include "PaintStyle/EditPaintStyle.h"
15
#include "MainWindow.h"
16
#include "Maps/MapDocument.h"
17
#include "Maps/MapFeature.h"
18
#include "PropertiesDock.h"
20
#include <QFileDialog>
21
#include <QColorDialog>
22
#include <QMessageBox>
24
#include <QStyleFactory>
25
#include <QNetworkProxy>
28
static void makeBoundaryIcon(QToolButton* bt, QColor C)
31
pm.fill(QColor(255, 255, 255));
35
p.drawRect(0, 6, 36, 6);
39
PreferencesDialog::PreferencesDialog(QWidget* parent)
43
setWindowState(Qt::WindowFullScreen);
48
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
50
QDir intTemplates(BUILTIN_TEMPLATES_DIR);
51
for (int i=0; i < intTemplates.entryList().size(); ++i) {
52
cbTemplates->addItem(intTemplates.entryList().at(i));
55
#ifdef FORCED_CUSTOM_STYLE
56
cbCustomStyle->hide();
57
comboCustomStyle->hide();
61
QApplication::processEvents();
66
void PreferencesDialog::updateStyles()
69
QDir intStyles(BUILTIN_STYLES_DIR);
70
for (int i=0; i < intStyles.entryList().size(); ++i) {
71
cbStyles->addItem(intStyles.entryList().at(i) + " (int)", QVariant(intStyles.entryInfoList().at(i).absoluteFilePath()));
73
if (!CustomStylesDir->text().isEmpty()) {
74
QDir customStyles(CustomStylesDir->text(), "*.mas");
75
for (int i=0; i < customStyles.entryList().size(); ++i) {
76
cbStyles->addItem(customStyles.entryList().at(i), QVariant(customStyles.entryInfoList().at(i).absoluteFilePath()));
80
int idx = cbStyles->findData(M_PREFS->getDefaultStyle());
84
cbStyles->setCurrentIndex(idx);
87
PreferencesDialog::~PreferencesDialog()
91
void PreferencesDialog::on_buttonBox_clicked(QAbstractButton * button)
93
if ((button == buttonBox->button(QDialogButtonBox::Apply))) {
95
emit(preferencesChanged());
97
if ((button == buttonBox->button(QDialogButtonBox::Ok))) {
99
emit(preferencesChanged());
104
void PreferencesDialog::initLanguages(QComboBox* aBox)
106
aBox->addItem(tr("English"),"-");
107
aBox->addItem(tr("Arabic"),"ar");
108
aBox->addItem(tr("Czech"),"cs");
109
aBox->addItem(tr("German"),"de");
110
aBox->addItem(tr("French"),"fr");
111
aBox->addItem(tr("Italian"),"it");
112
aBox->addItem(tr("Polish"),"pl");
113
aBox->addItem(tr("Russian"),"ru");
116
void PreferencesDialog::loadPrefs()
118
initLanguages(Language);
119
QString CurrentLanguage(getDefaultLanguage());
121
for (l = 0; l < Language->count(); ++l)
122
if (CurrentLanguage == Language->itemData(l))
124
SelectLanguage->setChecked(l < Language->count());
125
Language->setEnabled(l < Language->count());
126
if (l < Language->count())
127
Language->setCurrentIndex(l);
128
TranslateTags->setChecked(M_PREFS->getTranslateTags());
129
edOsmUrl->setText(M_PREFS->getOsmWebsite());
130
edOsmUser->setText(M_PREFS->getOsmUser());
131
edOsmPwd->setText(M_PREFS->getOsmPassword());
133
edGpsPort->setText(M_PREFS->getGpsPort());
135
sbMaxDistNodes->setValue(M_PREFS->getMaxDistNodes());
137
bbUseProxy->setChecked(M_PREFS->getProxyUse());
138
edProxyHost->setText(M_PREFS->getProxyHost());
139
edProxyPort->setText(QString().setNum(M_PREFS->getProxyPort()));
140
edProxyUser->setText(M_PREFS->getProxyUser());
141
edProxyPassword->setText(M_PREFS->getProxyPassword());
143
//bbUse06Api->setChecked((M_PREFS->apiVersionNum() > 0.5));
145
edCacheDir->setText(M_PREFS->getCacheDir());
146
sbCacheSize->setValue(M_PREFS->getCacheSize());
148
QString s = M_PREFS->getDefaultStyle();
149
QString cs = M_PREFS->getCustomStyle();
150
if (QFileInfo(cs).isFile())
151
cs = QFileInfo(cs).absolutePath();
152
CustomStylesDir->setText(cs);
155
cbDisableStyleForTracks->setChecked(M_PREFS->getDisableStyleForTracks());
157
QString t = M_PREFS->getDefaultTemplate();
158
QString ct = M_PREFS->getCustomTemplate();
159
CustomTemplateName->setText(ct);
160
if (t.startsWith(BUILTIN_TEMPLATES_DIR)) {
161
TemplateBuiltin->setChecked(true);
162
cbTemplates->setEnabled(true);
163
cbTemplates->setCurrentIndex(cbTemplates->findText(t.remove(QString(BUILTIN_TEMPLATES_DIR) + "/")));
165
TemplateCustom->setChecked(true);
166
CustomTemplateName->setEnabled(true);
167
BrowseTemplate->setEnabled(true);
170
sbZoomInPerc->setValue(M_PREFS->getZoomInPerc());
171
sbZoomOutPerc->setValue(M_PREFS->getZoomOutPerc());
173
sbAlphaLow->setValue(M_PREFS->getAlpha("Low"));
174
sbAlphaHigh->setValue(M_PREFS->getAlpha("High"));
175
BgColor = M_PREFS->getBgColor();
176
cbBackgroundOverwriteStyle->setChecked(M_PREFS->getBackgroundOverwriteStyle());
177
FocusColor = M_PREFS->getFocusColor();
178
HoverColor = M_PREFS->getHoverColor();
179
HighlightColor = M_PREFS->getHighlightColor();
180
RelationsColor = M_PREFS->getRelationsColor();
181
GpxTrackColor = M_PREFS->getGpxTrackColor();
182
makeBoundaryIcon(btBgColor, BgColor);
183
makeBoundaryIcon(btHoverColor, HoverColor);
184
makeBoundaryIcon(btHighlightColor, HighlightColor);
185
makeBoundaryIcon(btFocusColor, FocusColor);
186
makeBoundaryIcon(btRelationsColor, RelationsColor);
187
makeBoundaryIcon(btGpxTrackColor, GpxTrackColor);
188
HoverWidth->setValue(M_PREFS->getHoverWidth());
189
HighlightWidth->setValue(M_PREFS->getHighlightWidth());
190
FocusWidth->setValue(M_PREFS->getFocusWidth());
191
RelationsWidth->setValue(M_PREFS->getRelationsWidth());
192
GpxTrackWidth->setValue(M_PREFS->getGpxTrackWidth());
193
cbSimpleGpxTrack->setChecked(M_PREFS->getSimpleGpxTrack());
195
cbAutoSaveDoc->setChecked(M_PREFS->getAutoSaveDoc());
196
cbAutoExtractTracks->setChecked(M_PREFS->getAutoExtractTracks());
197
cbReadonlyTracksDefault->setChecked(M_PREFS->getReadonlyTracksDefault());
199
ToolList* tl = M_PREFS->getTools();
200
ToolListIterator i(*tl);
201
while (i.hasNext()) {
203
Tool t(i.value().ToolName, i.value().ToolPath);
204
theTools.push_back(t);
205
lvTools->addItem(t.ToolName);
208
cbGgpsSaveLog->setChecked(M_PREFS->getGpsSaveLog());
209
edGpsLogDir->setText(M_PREFS->getGpsLogDir());
210
cbGpsSyncTime->setChecked(M_PREFS->getGpsSyncTime());
212
cbMouseSingleButton->setChecked(M_PREFS->getMouseSingleButton());
213
cbSeparateMoveMode->setChecked(M_PREFS->getSeparateMoveMode());
215
cbCustomStyle->setChecked(M_PREFS->getMerkaartorStyle());
216
comboCustomStyle->addItems(QStyleFactory::keys());
217
comboCustomStyle->setCurrentIndex(comboCustomStyle->findText(M_PREFS->getMerkaartorStyleString()));
219
cbUseShapefileForBackground->setChecked(M_PREFS->getUseShapefileForBackground());
222
void PreferencesDialog::savePrefs()
224
if (SelectLanguage->isChecked())
225
setDefaultLanguage(Language->itemData(Language->currentIndex()).toString());
227
setDefaultLanguage("");
229
((MainWindow*)parent())->updateLanguage();
232
M_PREFS->setTranslateTags(TranslateTags->isChecked());
233
//M_PREFS->setUse06Api(bbUse06Api->isChecked());
235
bool OsmDataChanged = false;
236
if (edOsmUrl->text() != M_PREFS->getOsmWebsite() ||
237
edOsmUser->text() != M_PREFS->getOsmUser() ||
238
edOsmPwd->text() != M_PREFS->getOsmPassword())
239
OsmDataChanged = true;
241
M_PREFS->setOsmWebsite(edOsmUrl->text());
242
M_PREFS->setOsmUser(edOsmUser->text());
243
M_PREFS->setOsmPassword(edOsmPwd->text());
245
M_PREFS->setXapiWebSite(M_PREFS->getXapiWebSite());
248
if (!edGpsPort->text().startsWith("\\\\.\\"))
249
edGpsPort->setText("\\\\.\\" + edGpsPort->text());
251
M_PREFS->setGpsPort(edGpsPort->text());
253
M_PREFS->setMaxDistNodes(sbMaxDistNodes->value());
255
M_PREFS->setProxyUse(bbUseProxy->isChecked());
256
M_PREFS->setProxyHost(edProxyHost->text());
257
M_PREFS->setProxyPort(edProxyPort->text().toInt());
258
M_PREFS->setProxyUser(edProxyUser->text());
259
M_PREFS->setProxyPassword(edProxyPassword->text());
261
M_PREFS->setCacheDir(edCacheDir->text());
262
M_PREFS->setCacheSize(sbCacheSize->value());
264
M_PREFS->setCustomStyle(CustomStylesDir->text());
266
NewStyle = cbStyles->itemData(cbStyles->currentIndex()).toString();
268
bool PainterToInvalidate = false;
269
if (NewStyle != M_PREFS->getDefaultStyle())
271
M_PREFS->setDefaultStyle(NewStyle);
272
M_STYLE->loadPainters(M_PREFS->getDefaultStyle());
273
PainterToInvalidate = true;
275
if (cbDisableStyleForTracks->isChecked() != M_PREFS->getDisableStyleForTracks()) {
276
M_PREFS->setDisableStyleForTracks(cbDisableStyleForTracks->isChecked());
277
PainterToInvalidate = true;
279
if (cbSimpleGpxTrack->isChecked() != M_PREFS->getSimpleGpxTrack()) {
280
M_PREFS->setSimpleGpxTrack(cbSimpleGpxTrack->isChecked());
281
PainterToInvalidate = true;
283
if (PainterToInvalidate) {
284
for (FeatureIterator it(((MainWindow*)parent())->document()); !it.isEnd(); ++it)
286
it.get()->invalidatePainter();
291
if (TemplateBuiltin->isChecked())
292
NewTemplate = QString(BUILTIN_TEMPLATES_DIR) + "/" + cbTemplates->currentText();
294
NewTemplate = CustomTemplateName->text();
296
if (NewTemplate != M_PREFS->getDefaultTemplate())
298
M_PREFS->setDefaultTemplate(NewTemplate);
299
((MainWindow*)parent())->properties()->loadTemplates(NewTemplate);
302
M_PREFS->setCustomStyle(CustomStylesDir->text());
303
M_PREFS->setCustomTemplate(CustomTemplateName->text());
304
M_PREFS->setZoomInPerc(sbZoomInPerc->text().toInt());
305
M_PREFS->setZoomOutPerc(sbZoomOutPerc->text().toInt());
307
M_PREFS->getAlphaPtr()->insert("Low", sbAlphaLow->value());
308
M_PREFS->getAlphaPtr()->insert("High", sbAlphaHigh->value());
309
M_PREFS->setBgColor(BgColor);
310
M_PREFS->setBackgroundOverwriteStyle(cbBackgroundOverwriteStyle->isChecked());
311
M_PREFS->setFocusColor(FocusColor,FocusWidth->value());
312
M_PREFS->setHoverColor(HoverColor,HoverWidth->value());
313
M_PREFS->setHighlightColor(HighlightColor,HighlightWidth->value());
314
M_PREFS->setRelationsColor(RelationsColor,RelationsWidth->value());
315
M_PREFS->setGpxTrackColor(GpxTrackColor,GpxTrackWidth->value());
317
M_PREFS->setAutoSaveDoc(cbAutoSaveDoc->isChecked());
318
M_PREFS->setAutoExtractTracks(cbAutoExtractTracks->isChecked());
319
M_PREFS->setReadonlyTracksDefault(cbReadonlyTracksDefault->isChecked());
321
ToolList* tl = M_PREFS->getTools();
323
for (int i = 0; i < theTools.size(); ++i) {
325
tl->insert(theTools[i].ToolName, t);
328
M_PREFS->setGpsSaveLog(cbGgpsSaveLog->isChecked());
329
M_PREFS->setGpsLogDir(edGpsLogDir->text());
330
M_PREFS->setGpsSyncTime(cbGpsSyncTime->isChecked());
332
M_PREFS->setMouseSingleButton(cbMouseSingleButton->isChecked());
333
M_PREFS->setSeparateMoveMode(cbSeparateMoveMode->isChecked());
335
M_PREFS->setMerkaartorStyle(cbCustomStyle->isChecked());
336
M_PREFS->setMerkaartorStyleString(comboCustomStyle->currentText());
338
M_PREFS->setUseShapefileForBackground(cbUseShapefileForBackground->isChecked());
340
M_PREFS->save(OsmDataChanged);
343
void PreferencesDialog::on_BrowseStyle_clicked()
345
QString s = QFileDialog::getExistingDirectory(this,tr("Custom styles directory"),"");
347
CustomStylesDir->setText(QDir::toNativeSeparators(s));
352
void PreferencesDialog::on_BrowseTemplate_clicked()
354
QString s = QFileDialog::getOpenFileName(this,tr("Tag Template"),"",tr("Merkaartor tag template (*.mat)"));
356
CustomTemplateName->setText(QDir::toNativeSeparators(s));
359
void PreferencesDialog::on_btBgColor_clicked()
362
QRgb rgb = QColorDialog::getRgba(BgColor.rgba(), &OK, this);
364
BgColor = QColor::fromRgba(rgb);
365
makeBoundaryIcon(btBgColor, BgColor);
369
void PreferencesDialog::on_btFocusColor_clicked()
372
QRgb rgb = QColorDialog::getRgba(FocusColor.rgba(), &OK, this);
374
FocusColor = QColor::fromRgba(rgb);
375
makeBoundaryIcon(btFocusColor, FocusColor);
379
void PreferencesDialog::on_btHoverColor_clicked()
382
QRgb rgb = QColorDialog::getRgba(HoverColor.rgba(), &OK, this);
384
HoverColor = QColor::fromRgba(rgb);
385
makeBoundaryIcon(btHoverColor, HoverColor);
389
void PreferencesDialog::on_btHighlightColor_clicked()
392
QRgb rgb = QColorDialog::getRgba(HighlightColor.rgba(), &OK, this);
394
HighlightColor = QColor::fromRgba(rgb);
395
makeBoundaryIcon(btHighlightColor, HoverColor);
399
void PreferencesDialog::on_btRelationsColor_clicked()
402
QRgb rgb = QColorDialog::getRgba(RelationsColor.rgba(), &OK, this);
404
RelationsColor = QColor::fromRgba(rgb);
405
makeBoundaryIcon(btRelationsColor, RelationsColor);
408
void PreferencesDialog::on_btGpxTrackColor_clicked()
411
QRgb rgb = QColorDialog::getRgba(GpxTrackColor.rgba(), &OK, this);
413
GpxTrackColor = QColor::fromRgba(rgb);
414
makeBoundaryIcon(btGpxTrackColor, GpxTrackColor);
420
void PreferencesDialog::on_btAddTool_clicked(void)
422
for (int i=0; i<theTools.size(); ++i) {
423
if (theTools[i].ToolName == edToolName->text()) {
424
QMessageBox::critical(this, tr("Tool already exists"),
425
tr("A tool of this name already exists.\nPlease select another name or click the <Apply> button if you want to modify the existing one"), QMessageBox::Ok);
429
Tool t(edToolName->text(), edToolPath->text());
430
theTools.push_back(t);
431
lvTools->addItem(t.ToolName);
433
lvTools->setCurrentRow(theTools.size() - 1);
434
on_lvTools_itemSelectionChanged();
437
void PreferencesDialog::on_btDelTool_clicked(void)
439
int idx = static_cast<int>(lvTools->currentRow());
440
if (idx >= theTools.size())
443
if (theTools[idx].ToolName == "Inkscape") {
444
QMessageBox::critical(this, tr("Cannot delete preset tool"),
445
tr("Cannot delete preset tool \"%1\"").arg(theTools[idx].ToolName), QMessageBox::Ok);
448
theTools.erase(theTools.begin() + idx);
449
delete lvTools->takeItem(idx);
450
if (idx && (idx >= theTools.size()))
452
lvTools->setCurrentRow(idx);
453
on_lvTools_itemSelectionChanged();
456
void PreferencesDialog::on_btApplyTool_clicked(void)
458
int idx = static_cast<int>(lvTools->currentRow());
459
if (idx >= theTools.size())
462
if ((theTools[idx].ToolName == "Inkscape") && edToolName->text() != theTools[idx].ToolName) {
463
QMessageBox::critical(this, tr("Cannot modify preset tool name"),
464
tr("Cannot modify preset tool \"%1\"'s name").arg(theTools[idx].ToolName), QMessageBox::Ok);
467
Tool& t(theTools[idx]);
468
t.ToolName = edToolName->text();
469
t.ToolPath = edToolPath->text();
471
lvTools->item(lvTools->currentRow())->setText(edToolName->text());
474
void PreferencesDialog::on_lvTools_itemSelectionChanged()
476
QListWidgetItem* it = lvTools->item(lvTools->currentRow());
478
int idx = static_cast<int>(lvTools->row(it));
479
if (idx >= theTools.size())
482
Tool& t(theTools[idx]);
483
edToolName->setText(t.ToolName);
484
edToolPath->setText(t.ToolPath);
487
void PreferencesDialog::on_btBrowse_clicked()
489
QString s = QFileDialog::getOpenFileName(this,tr("Select tool executable"));
491
edToolPath->setText(s);
495
void PreferencesDialog::on_btGpsLogDirBrowse_clicked()
497
QString s = QFileDialog::getExistingDirectory(this,tr("Select Log directory"));
499
edGpsLogDir->setText(s);
503
void PreferencesDialog::changeEvent(QEvent * event)
505
if (event->type() == QEvent::LanguageChange)
507
QDialog::changeEvent(event);