Cosmetics
[GPXSee.git] / src / gui.cpp
blob1ac451c20ade6cb52f0f1a90687aecf30d418ee9
1 #include <QApplication>
2 #include <QSplitter>
3 #include <QVBoxLayout>
4 #include <QMenuBar>
5 #include <QStatusBar>
6 #include <QMessageBox>
7 #include <QFileDialog>
8 #include <QPrintDialog>
9 #include <QPainter>
10 #include <QPaintEngine>
11 #include <QPaintDevice>
12 #include <QKeyEvent>
13 #include <QSignalMapper>
14 #include <QMenu>
15 #include <QToolBar>
16 #include <QTabWidget>
17 #include <QActionGroup>
18 #include <QAction>
19 #include <QLabel>
20 #include <QSettings>
21 #include <QLocale>
22 #include <QMimeData>
23 #include <QUrl>
24 #include <QPixmapCache>
25 #include "config.h"
26 #include "icons.h"
27 #include "keys.h"
28 #include "settings.h"
29 #include "data.h"
30 #include "ellipsoid.h"
31 #include "datum.h"
32 #include "map.h"
33 #include "maplist.h"
34 #include "emptymap.h"
35 #include "elevationgraph.h"
36 #include "speedgraph.h"
37 #include "heartrategraph.h"
38 #include "temperaturegraph.h"
39 #include "cadencegraph.h"
40 #include "powergraph.h"
41 #include "pathview.h"
42 #include "trackinfo.h"
43 #include "filebrowser.h"
44 #include "cpuarch.h"
45 #include "graphtab.h"
46 #include "format.h"
47 #include "gui.h"
50 GUI::GUI()
52 loadDatums();
53 loadMaps();
54 loadPOIs();
56 createPathView();
57 createGraphTabs();
58 createStatusBar();
59 createActions();
60 createMenus();
61 createToolBars();
63 createBrowser();
65 QSplitter *splitter = new QSplitter();
66 splitter->setOrientation(Qt::Vertical);
67 splitter->setChildrenCollapsible(false);
68 splitter->addWidget(_pathView);
69 splitter->addWidget(_graphTabWidget);
70 splitter->setContentsMargins(0, 0, 0, 0);
71 splitter->setStretchFactor(0, 255);
72 splitter->setStretchFactor(1, 1);
73 setCentralWidget(splitter);
75 setWindowIcon(QIcon(QPixmap(APP_ICON)));
76 setWindowTitle(APP_NAME);
77 setUnifiedTitleAndToolBarOnMac(true);
78 setAcceptDrops(true);
80 _trackCount = 0;
81 _routeCount = 0;
82 _waypointCount = 0;
83 _trackDistance = 0;
84 _routeDistance = 0;
85 _time = 0;
86 _movingTime = 0;
88 _sliderPos = 0;
90 updateGraphTabs();
91 updatePathView();
92 updateStatusBarInfo();
94 readSettings();
97 GUI::~GUI()
99 for (int i = 0; i < _tabs.size(); i++) {
100 if (_graphTabWidget->indexOf(_tabs.at(i)) < 0)
101 delete _tabs.at(i);
105 const QString GUI::fileFormats() const
107 return tr("Supported files (*.csv *.fit *.gpx *.igc *.kml *.nmea *.tcx)")
108 + ";;" + tr("CSV files (*.csv)") + ";;" + tr("FIT files (*.fit)") + ";;"
109 + tr("GPX files (*.gpx)") + ";;" + tr("IGC files (*.igc)") + ";;"
110 + tr("KML files (*.kml)") + ";;" + tr("NMEA files (*.nmea)") + ";;"
111 + tr("TCX files (*.tcx)") + ";;" + tr("All files (*)");
114 void GUI::createBrowser()
116 QStringList filter;
117 filter << "*.gpx" << "*.tcx" << "*.kml" << "*.fit" << "*.csv" << "*.igc"
118 << "*.nmea";
119 _browser = new FileBrowser(this);
120 _browser->setFilter(filter);
123 void GUI::loadDatums()
125 QString ef, df;
126 bool ok = false;
128 if (QFile::exists(USER_ELLIPSOID_FILE))
129 ef = USER_ELLIPSOID_FILE;
130 else if (QFile::exists(GLOBAL_ELLIPSOID_FILE))
131 ef = GLOBAL_ELLIPSOID_FILE;
132 else
133 qWarning("No ellipsoids file found.");
135 if (QFile::exists(USER_DATUM_FILE))
136 df = USER_DATUM_FILE;
137 else if (QFile::exists(GLOBAL_DATUM_FILE))
138 df = GLOBAL_DATUM_FILE;
139 else
140 qWarning("No datums file found.");
142 if (!ef.isNull() && !df.isNull()) {
143 if (!Ellipsoid::loadList(ef)) {
144 if (Ellipsoid::errorLine())
145 qWarning("%s: parse error on line %d: %s", qPrintable(ef),
146 Ellipsoid::errorLine(), qPrintable(Ellipsoid::errorString()));
147 else
148 qWarning("%s: %s", qPrintable(ef), qPrintable(
149 Ellipsoid::errorString()));
150 } else {
151 if (!Datum::loadList(df)) {
152 if (Datum::errorLine())
153 qWarning("%s: parse error on line %d: %s", qPrintable(ef),
154 Datum::errorLine(), qPrintable(Datum::errorString()));
155 else
156 qWarning("%s: %s", qPrintable(ef), qPrintable(
157 Datum::errorString()));
158 } else
159 ok = true;
163 if (!ok)
164 qWarning("Maps based on a datum different from WGS84 won't work.");
167 void GUI::loadMaps()
169 _ml = new MapList(this);
171 QString offline, online;
173 if (QFile::exists(USER_MAP_FILE))
174 online = USER_MAP_FILE;
175 else if (QFile::exists(GLOBAL_MAP_FILE))
176 online = GLOBAL_MAP_FILE;
178 if (!online.isNull() && !_ml->loadList(online))
179 qWarning("%s: %s", qPrintable(online), qPrintable(_ml->errorString()));
182 if (QFile::exists(USER_MAP_DIR))
183 offline = USER_MAP_DIR;
184 else if (QFile::exists(GLOBAL_MAP_DIR))
185 offline = GLOBAL_MAP_DIR;
187 if (!offline.isNull()) {
188 QDir md(offline);
189 QFileInfoList ml = md.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
190 QStringList filters;
191 filters << "*.map" << "*.tba" << "*.tar";
193 for (int i = 0; i < ml.size(); i++) {
194 QDir dir(ml.at(i).absoluteFilePath());
195 QFileInfoList fl = dir.entryInfoList(filters, QDir::Files);
197 if (fl.isEmpty())
198 qWarning("%s: no map/atlas file found",
199 qPrintable(ml.at(i).absoluteFilePath()));
200 else if (fl.size() > 1)
201 qWarning("%s: ambiguous directory content",
202 qPrintable(ml.at(i).absoluteFilePath()));
203 else
204 if (!_ml->loadMap(fl.first().absoluteFilePath()))
205 qWarning("%s: %s", qPrintable(fl.first().absoluteFilePath()),
206 qPrintable(_ml->errorString()));
210 _map = _ml->maps().isEmpty() ? new EmptyMap(this) : _ml->maps().first();
213 void GUI::loadPOIs()
215 QFileInfoList list;
216 QDir userDir(USER_POI_DIR);
217 QDir globalDir(GLOBAL_POI_DIR);
219 _poi = new POI(this);
221 if (userDir.exists())
222 list = userDir.entryInfoList(QStringList(), QDir::Files);
223 else
224 list = globalDir.entryInfoList(QStringList(), QDir::Files);
226 for (int i = 0; i < list.size(); ++i) {
227 if (!_poi->loadFile(list.at(i).absoluteFilePath())) {
228 qWarning("Error loading POI file: %s: %s\n",
229 qPrintable(list.at(i).fileName()),
230 qPrintable(_poi->errorString()));
231 if (_poi->errorLine())
232 qWarning("Line: %d\n", _poi->errorLine());
237 void GUI::createMapActions()
239 _mapsSignalMapper = new QSignalMapper(this);
240 _mapsActionGroup = new QActionGroup(this);
241 _mapsActionGroup->setExclusive(true);
243 for (int i = 0; i < _ml->maps().count(); i++) {
244 QAction *a = new QAction(_ml->maps().at(i)->name(), this);
245 a->setCheckable(true);
246 a->setActionGroup(_mapsActionGroup);
248 _mapsSignalMapper->setMapping(a, i);
249 connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
251 _mapActions.append(a);
254 connect(_mapsSignalMapper, SIGNAL(mapped(int)), this,
255 SLOT(mapChanged(int)));
258 void GUI::createPOIFilesActions()
260 _poiFilesSignalMapper = new QSignalMapper(this);
262 for (int i = 0; i < _poi->files().count(); i++)
263 createPOIFileAction(i);
265 connect(_poiFilesSignalMapper, SIGNAL(mapped(int)), this,
266 SLOT(poiFileChecked(int)));
269 QAction *GUI::createPOIFileAction(int index)
271 QAction *a = new QAction(QFileInfo(_poi->files().at(index)).fileName(),
272 this);
273 a->setCheckable(true);
275 _poiFilesSignalMapper->setMapping(a, index);
276 connect(a, SIGNAL(triggered()), _poiFilesSignalMapper, SLOT(map()));
278 _poiFilesActions.append(a);
280 return a;
283 void GUI::createActions()
285 QActionGroup *ag;
287 // Action Groups
288 _fileActionGroup = new QActionGroup(this);
289 _fileActionGroup->setExclusive(false);
290 _fileActionGroup->setEnabled(false);
292 _navigationActionGroup = new QActionGroup(this);
293 _navigationActionGroup->setEnabled(false);
295 // General actions
296 _exitAction = new QAction(QIcon(QPixmap(QUIT_ICON)), tr("Quit"), this);
297 _exitAction->setShortcut(QUIT_SHORTCUT);
298 _exitAction->setMenuRole(QAction::QuitRole);
299 connect(_exitAction, SIGNAL(triggered()), this, SLOT(close()));
300 addAction(_exitAction);
302 // Help & About
303 _dataSourcesAction = new QAction(tr("Data sources"), this);
304 connect(_dataSourcesAction, SIGNAL(triggered()), this, SLOT(dataSources()));
305 _keysAction = new QAction(tr("Keyboard controls"), this);
306 connect(_keysAction, SIGNAL(triggered()), this, SLOT(keys()));
307 _aboutAction = new QAction(QIcon(QPixmap(APP_ICON)),
308 tr("About GPXSee"), this);
309 _aboutAction->setMenuRole(QAction::AboutRole);
310 connect(_aboutAction, SIGNAL(triggered()), this, SLOT(about()));
312 // File actions
313 _openFileAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
314 tr("Open..."), this);
315 _openFileAction->setShortcut(OPEN_SHORTCUT);
316 connect(_openFileAction, SIGNAL(triggered()), this, SLOT(openFile()));
317 addAction(_openFileAction);
318 _printFileAction = new QAction(QIcon(QPixmap(PRINT_FILE_ICON)),
319 tr("Print..."), this);
320 _printFileAction->setActionGroup(_fileActionGroup);
321 connect(_printFileAction, SIGNAL(triggered()), this, SLOT(printFile()));
322 addAction(_printFileAction);
323 _exportFileAction = new QAction(QIcon(QPixmap(EXPORT_FILE_ICON)),
324 tr("Export to PDF..."), this);
325 _exportFileAction->setShortcut(EXPORT_SHORTCUT);
326 _exportFileAction->setActionGroup(_fileActionGroup);
327 connect(_exportFileAction, SIGNAL(triggered()), this, SLOT(exportFile()));
328 addAction(_exportFileAction);
329 _closeFileAction = new QAction(QIcon(QPixmap(CLOSE_FILE_ICON)),
330 tr("Close"), this);
331 _closeFileAction->setShortcut(CLOSE_SHORTCUT);
332 _closeFileAction->setActionGroup(_fileActionGroup);
333 connect(_closeFileAction, SIGNAL(triggered()), this, SLOT(closeAll()));
334 addAction(_closeFileAction);
335 _reloadFileAction = new QAction(QIcon(QPixmap(RELOAD_FILE_ICON)),
336 tr("Reload"), this);
337 _reloadFileAction->setShortcut(RELOAD_SHORTCUT);
338 _reloadFileAction->setActionGroup(_fileActionGroup);
339 connect(_reloadFileAction, SIGNAL(triggered()), this, SLOT(reloadFile()));
340 addAction(_reloadFileAction);
342 // POI actions
343 _openPOIAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
344 tr("Load POI file..."), this);
345 connect(_openPOIAction, SIGNAL(triggered()), this, SLOT(openPOIFile()));
346 _closePOIAction = new QAction(QIcon(QPixmap(CLOSE_FILE_ICON)),
347 tr("Close POI files"), this);
348 connect(_closePOIAction, SIGNAL(triggered()), this, SLOT(closePOIFiles()));
349 _overlapPOIAction = new QAction(tr("Overlap POIs"), this);
350 _overlapPOIAction->setCheckable(true);
351 connect(_overlapPOIAction, SIGNAL(triggered(bool)), _pathView,
352 SLOT(setPOIOverlap(bool)));
353 _showPOILabelsAction = new QAction(tr("Show POI labels"), this);
354 _showPOILabelsAction->setCheckable(true);
355 connect(_showPOILabelsAction, SIGNAL(triggered(bool)), _pathView,
356 SLOT(showPOILabels(bool)));
357 _showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)),
358 tr("Show POIs"), this);
359 _showPOIAction->setCheckable(true);
360 _showPOIAction->setShortcut(SHOW_POI_SHORTCUT);
361 connect(_showPOIAction, SIGNAL(triggered(bool)), _pathView,
362 SLOT(showPOI(bool)));
363 addAction(_showPOIAction);
364 createPOIFilesActions();
366 // Map actions
367 _showMapAction = new QAction(QIcon(QPixmap(SHOW_MAP_ICON)), tr("Show map"),
368 this);
369 _showMapAction->setCheckable(true);
370 _showMapAction->setShortcut(SHOW_MAP_SHORTCUT);
371 connect(_showMapAction, SIGNAL(triggered(bool)), _pathView,
372 SLOT(showMap(bool)));
373 addAction(_showMapAction);
374 _loadMapAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
375 tr("Load map..."), this);
376 connect(_loadMapAction, SIGNAL(triggered()), this, SLOT(loadMap()));
377 _clearMapCacheAction = new QAction(tr("Clear tile cache"), this);
378 connect(_clearMapCacheAction, SIGNAL(triggered()), this,
379 SLOT(clearMapCache()));
380 createMapActions();
381 _nextMapAction = new QAction(tr("Next map"), this);
382 _nextMapAction->setShortcut(NEXT_MAP_SHORTCUT);
383 connect(_nextMapAction, SIGNAL(triggered()), this, SLOT(nextMap()));
384 addAction(_nextMapAction);
385 _prevMapAction = new QAction(tr("Next map"), this);
386 _prevMapAction->setShortcut(PREV_MAP_SHORTCUT);
387 connect(_prevMapAction, SIGNAL(triggered()), this, SLOT(prevMap()));
388 addAction(_prevMapAction);
389 if (_ml->maps().isEmpty()) {
390 _showMapAction->setEnabled(false);
391 _clearMapCacheAction->setEnabled(false);
394 // Data actions
395 _showTracksAction = new QAction(tr("Show tracks"), this);
396 _showTracksAction->setCheckable(true);
397 connect(_showTracksAction, SIGNAL(triggered(bool)), this,
398 SLOT(showTracks(bool)));
399 _showRoutesAction = new QAction(tr("Show routes"), this);
400 _showRoutesAction->setCheckable(true);
401 connect(_showRoutesAction, SIGNAL(triggered(bool)), this,
402 SLOT(showRoutes(bool)));
403 _showWaypointsAction = new QAction(tr("Show waypoints"), this);
404 _showWaypointsAction->setCheckable(true);
405 connect(_showWaypointsAction, SIGNAL(triggered(bool)), _pathView,
406 SLOT(showWaypoints(bool)));
407 _showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this);
408 _showWaypointLabelsAction->setCheckable(true);
409 connect(_showWaypointLabelsAction, SIGNAL(triggered(bool)), _pathView,
410 SLOT(showWaypointLabels(bool)));
411 _showRouteWaypointsAction = new QAction(tr("Route waypoints"), this);
412 _showRouteWaypointsAction->setCheckable(true);
413 connect(_showRouteWaypointsAction, SIGNAL(triggered(bool)), _pathView,
414 SLOT(showRouteWaypoints(bool)));
416 // Graph actions
417 _showGraphsAction = new QAction(QIcon(QPixmap(SHOW_GRAPHS_ICON)),
418 tr("Show graphs"), this);
419 _showGraphsAction->setCheckable(true);
420 _showGraphsAction->setShortcut(SHOW_GRAPHS_SHORTCUT);
421 connect(_showGraphsAction, SIGNAL(triggered(bool)), this,
422 SLOT(showGraphs(bool)));
423 addAction(_showGraphsAction);
424 ag = new QActionGroup(this);
425 ag->setExclusive(true);
426 _distanceGraphAction = new QAction(tr("Distance"), this);
427 _distanceGraphAction->setCheckable(true);
428 _distanceGraphAction->setActionGroup(ag);
429 _distanceGraphAction->setShortcut(DISTANCE_GRAPH_SHORTCUT);
430 connect(_distanceGraphAction, SIGNAL(triggered()), this,
431 SLOT(setDistanceGraph()));
432 addAction(_distanceGraphAction);
433 _timeGraphAction = new QAction(tr("Time"), this);
434 _timeGraphAction->setCheckable(true);
435 _timeGraphAction->setActionGroup(ag);
436 _timeGraphAction->setShortcut(TIME_GRAPH_SHORTCUT);
437 connect(_timeGraphAction, SIGNAL(triggered()), this,
438 SLOT(setTimeGraph()));
439 addAction(_timeGraphAction);
440 _showGraphGridAction = new QAction(tr("Show grid"), this);
441 _showGraphGridAction->setCheckable(true);
442 connect(_showGraphGridAction, SIGNAL(triggered(bool)), this,
443 SLOT(showGraphGrids(bool)));
445 // Settings actions
446 _showToolbarsAction = new QAction(tr("Show toolbars"), this);
447 _showToolbarsAction->setCheckable(true);
448 connect(_showToolbarsAction, SIGNAL(triggered(bool)), this,
449 SLOT(showToolbars(bool)));
450 ag = new QActionGroup(this);
451 ag->setExclusive(true);
452 _totalTimeAction = new QAction(tr("Total time"), this);
453 _totalTimeAction->setCheckable(true);
454 _totalTimeAction->setActionGroup(ag);
455 connect(_totalTimeAction, SIGNAL(triggered()), this,
456 SLOT(setTotalTime()));
457 _movingTimeAction = new QAction(tr("Moving time"), this);
458 _movingTimeAction->setCheckable(true);
459 _movingTimeAction->setActionGroup(ag);
460 connect(_movingTimeAction, SIGNAL(triggered()), this,
461 SLOT(setMovingTime()));
462 ag = new QActionGroup(this);
463 ag->setExclusive(true);
464 _metricUnitsAction = new QAction(tr("Metric"), this);
465 _metricUnitsAction->setCheckable(true);
466 _metricUnitsAction->setActionGroup(ag);
467 connect(_metricUnitsAction, SIGNAL(triggered()), this,
468 SLOT(setMetricUnits()));
469 _imperialUnitsAction = new QAction(tr("Imperial"), this);
470 _imperialUnitsAction->setCheckable(true);
471 _imperialUnitsAction->setActionGroup(ag);
472 connect(_imperialUnitsAction, SIGNAL(triggered()), this,
473 SLOT(setImperialUnits()));
474 _fullscreenAction = new QAction(QIcon(QPixmap(FULLSCREEN_ICON)),
475 tr("Fullscreen mode"), this);
476 _fullscreenAction->setCheckable(true);
477 _fullscreenAction->setShortcut(FULLSCREEN_SHORTCUT);
478 connect(_fullscreenAction, SIGNAL(triggered(bool)), this,
479 SLOT(showFullscreen(bool)));
480 addAction(_fullscreenAction);
481 _openOptionsAction = new QAction(tr("Options..."), this);
482 _openOptionsAction->setMenuRole(QAction::PreferencesRole);
483 connect(_openOptionsAction, SIGNAL(triggered()), this,
484 SLOT(openOptions()));
486 // Navigation actions
487 _nextAction = new QAction(QIcon(QPixmap(NEXT_FILE_ICON)), tr("Next"), this);
488 _nextAction->setActionGroup(_navigationActionGroup);
489 connect(_nextAction, SIGNAL(triggered()), this, SLOT(next()));
490 _prevAction = new QAction(QIcon(QPixmap(PREV_FILE_ICON)), tr("Previous"),
491 this);
492 _prevAction->setActionGroup(_navigationActionGroup);
493 connect(_prevAction, SIGNAL(triggered()), this, SLOT(prev()));
494 _lastAction = new QAction(QIcon(QPixmap(LAST_FILE_ICON)), tr("Last"), this);
495 _lastAction->setActionGroup(_navigationActionGroup);
496 connect(_lastAction, SIGNAL(triggered()), this, SLOT(last()));
497 _firstAction = new QAction(QIcon(QPixmap(FIRST_FILE_ICON)), tr("First"),
498 this);
499 _firstAction->setActionGroup(_navigationActionGroup);
500 connect(_firstAction, SIGNAL(triggered()), this, SLOT(first()));
503 void GUI::createMenus()
505 QMenu *fileMenu = menuBar()->addMenu(tr("File"));
506 fileMenu->addAction(_openFileAction);
507 fileMenu->addSeparator();
508 fileMenu->addAction(_printFileAction);
509 fileMenu->addAction(_exportFileAction);
510 fileMenu->addSeparator();
511 fileMenu->addAction(_reloadFileAction);
512 fileMenu->addSeparator();
513 fileMenu->addAction(_closeFileAction);
514 #ifndef Q_OS_MAC
515 fileMenu->addSeparator();
516 fileMenu->addAction(_exitAction);
517 #endif // Q_OS_MAC
519 _mapMenu = menuBar()->addMenu(tr("Map"));
520 _mapMenu->addActions(_mapActions);
521 _mapsEnd = _mapMenu->addSeparator();
522 _mapMenu->addAction(_loadMapAction);
523 _mapMenu->addAction(_clearMapCacheAction);
524 _mapMenu->addSeparator();
525 _mapMenu->addAction(_showMapAction);
527 QMenu *graphMenu = menuBar()->addMenu(tr("Graph"));
528 graphMenu->addAction(_distanceGraphAction);
529 graphMenu->addAction(_timeGraphAction);
530 graphMenu->addSeparator();
531 graphMenu->addAction(_showGraphGridAction);
532 graphMenu->addSeparator();
533 graphMenu->addAction(_showGraphsAction);
535 QMenu *poiMenu = menuBar()->addMenu(tr("POI"));
536 _poiFilesMenu = poiMenu->addMenu(tr("POI files"));
537 _poiFilesMenu->addActions(_poiFilesActions);
538 poiMenu->addSeparator();
539 poiMenu->addAction(_openPOIAction);
540 poiMenu->addAction(_closePOIAction);
541 poiMenu->addSeparator();
542 poiMenu->addAction(_showPOILabelsAction);
543 poiMenu->addAction(_overlapPOIAction);
544 poiMenu->addSeparator();
545 poiMenu->addAction(_showPOIAction);
547 QMenu *dataMenu = menuBar()->addMenu(tr("Data"));
548 QMenu *displayMenu = dataMenu->addMenu(tr("Display"));
549 displayMenu->addAction(_showWaypointLabelsAction);
550 displayMenu->addAction(_showRouteWaypointsAction);
551 dataMenu->addSeparator();
552 dataMenu->addAction(_showTracksAction);
553 dataMenu->addAction(_showRoutesAction);
554 dataMenu->addAction(_showWaypointsAction);
556 QMenu *settingsMenu = menuBar()->addMenu(tr("Settings"));
557 QMenu *timeMenu = settingsMenu->addMenu(tr("Time"));
558 timeMenu->addAction(_totalTimeAction);
559 timeMenu->addAction(_movingTimeAction);
560 QMenu *unitsMenu = settingsMenu->addMenu(tr("Units"));
561 unitsMenu->addAction(_metricUnitsAction);
562 unitsMenu->addAction(_imperialUnitsAction);
563 settingsMenu->addSeparator();
564 settingsMenu->addAction(_showToolbarsAction);
565 settingsMenu->addAction(_fullscreenAction);
566 settingsMenu->addSeparator();
567 settingsMenu->addAction(_openOptionsAction);
569 QMenu *helpMenu = menuBar()->addMenu(tr("Help"));
570 helpMenu->addAction(_dataSourcesAction);
571 helpMenu->addAction(_keysAction);
572 helpMenu->addSeparator();
573 helpMenu->addAction(_aboutAction);
576 void GUI::createToolBars()
578 #ifdef Q_OS_MAC
579 setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
580 #endif // Q_OS_MAC
582 _fileToolBar = addToolBar(tr("File"));
583 _fileToolBar->addAction(_openFileAction);
584 _fileToolBar->addAction(_reloadFileAction);
585 _fileToolBar->addAction(_closeFileAction);
586 _fileToolBar->addAction(_printFileAction);
588 _showToolBar = addToolBar(tr("Show"));
589 _showToolBar->addAction(_showPOIAction);
590 _showToolBar->addAction(_showMapAction);
591 _showToolBar->addAction(_showGraphsAction);
593 _navigationToolBar = addToolBar(tr("Navigation"));
594 _navigationToolBar->addAction(_firstAction);
595 _navigationToolBar->addAction(_prevAction);
596 _navigationToolBar->addAction(_nextAction);
597 _navigationToolBar->addAction(_lastAction);
600 void GUI::createPathView()
602 _pathView = new PathView(_map, _poi, this);
603 _pathView->setSizePolicy(QSizePolicy(QSizePolicy::Ignored,
604 QSizePolicy::Expanding));
605 _pathView->setMinimumHeight(200);
606 #ifdef Q_OS_WIN32
607 _pathView->setFrameShape(QFrame::NoFrame);
608 #endif // Q_OS_WIN32
611 void GUI::createGraphTabs()
613 _graphTabWidget = new QTabWidget();
614 connect(_graphTabWidget, SIGNAL(currentChanged(int)), this,
615 SLOT(graphChanged(int)));
617 _graphTabWidget->setSizePolicy(QSizePolicy(QSizePolicy::Ignored,
618 QSizePolicy::Preferred));
619 _graphTabWidget->setMinimumHeight(200);
620 #ifdef Q_OS_WIN32
621 _graphTabWidget->setDocumentMode(true);
622 #endif // Q_OS_WIN32
624 _tabs.append(new ElevationGraph);
625 _tabs.append(new SpeedGraph);
626 _tabs.append(new HeartRateGraph);
627 _tabs.append(new CadenceGraph);
628 _tabs.append(new PowerGraph);
629 _tabs.append(new TemperatureGraph);
631 for (int i = 0; i < _tabs.count(); i++)
632 connect(_tabs.at(i), SIGNAL(sliderPositionChanged(qreal)), this,
633 SLOT(sliderPositionChanged(qreal)));
636 void GUI::createStatusBar()
638 _fileNameLabel = new QLabel();
639 _distanceLabel = new QLabel();
640 _timeLabel = new QLabel();
641 _distanceLabel->setAlignment(Qt::AlignHCenter);
642 _timeLabel->setAlignment(Qt::AlignHCenter);
644 statusBar()->addPermanentWidget(_fileNameLabel, 8);
645 statusBar()->addPermanentWidget(_distanceLabel, 1);
646 statusBar()->addPermanentWidget(_timeLabel, 1);
647 statusBar()->setSizeGripEnabled(false);
650 void GUI::about()
652 QMessageBox msgBox(this);
654 msgBox.setWindowTitle(tr("About GPXSee"));
655 msgBox.setText("<h2>" + QString(APP_NAME) + "</h2><p><p>" + tr("Version ")
656 + APP_VERSION + " (" + CPU_ARCH + ", Qt " + QT_VERSION_STR + ")</p>");
657 msgBox.setInformativeText("<table width=\"300\"><tr><td>"
658 + tr("GPXSee is distributed under the terms of the GNU General Public "
659 "License version 3. For more info about GPXSee visit the project "
660 "homepage at ") + "<a href=\"" + APP_HOMEPAGE + "\">" + APP_HOMEPAGE
661 + "</a>.</td></tr></table>");
663 QIcon icon = msgBox.windowIcon();
664 QSize size = icon.actualSize(QSize(64, 64));
665 msgBox.setIconPixmap(icon.pixmap(size));
667 msgBox.exec();
670 void GUI::keys()
672 QMessageBox msgBox(this);
674 msgBox.setWindowTitle(tr("Keyboard controls"));
675 msgBox.setText("<h3>" + tr("Keyboard controls") + "</h3>");
676 msgBox.setInformativeText(
677 "<style>td {padding-right: 1.5em;}</style><div><table><tr><td>"
678 + tr("Next file") + "</td><td><i>" + QKeySequence(NEXT_KEY).toString()
679 + "</i></td></tr><tr><td>" + tr("Previous file")
680 + "</td><td><i>" + QKeySequence(PREV_KEY).toString()
681 + "</i></td></tr><tr><td>" + tr("First file") + "</td><td><i>"
682 + QKeySequence(FIRST_KEY).toString() + "</i></td></tr><tr><td>"
683 + tr("Last file") + "</td><td><i>" + QKeySequence(LAST_KEY).toString()
684 + "</i></td></tr><tr><td>" + tr("Append file")
685 + "</td><td><i>" + QKeySequence(MODIFIER).toString() + tr("Next/Previous")
686 + "</i></td></tr><tr><td></td><td></td></tr><tr><td>" + tr("Next map")
687 + "</td><td><i>" + NEXT_MAP_SHORTCUT.toString() + "</i></td></tr><tr><td>"
688 + tr("Previous map") + "</td><td><i>" + PREV_MAP_SHORTCUT.toString()
689 + "</i></td></tr><tr><td></td><td></td></tr><tr><td>" + tr("Zoom in")
690 + "</td><td><i>" + QKeySequence(ZOOM_IN).toString()
691 + "</i></td></tr><tr><td>" + tr("Zoom out") + "</td><td><i>"
692 + QKeySequence(ZOOM_OUT).toString() + "</i></td></tr><tr><td>"
693 + tr("Digital zoom") + "</td><td><i>" + QKeySequence(MODIFIER).toString()
694 + tr("Zoom") + "</i></td></tr></table></div>");
696 msgBox.exec();
699 void GUI::dataSources()
701 QMessageBox msgBox(this);
703 msgBox.setWindowTitle(tr("Data sources"));
704 msgBox.setText("<h3>" + tr("Data sources") + "</h3>");
705 msgBox.setInformativeText(
706 "<h4>" + tr("Online maps") + "</h4><p>"
707 + tr("Online map URLs are read on program startup from the "
708 "following file:")
709 + "</p><p><code>" + USER_MAP_FILE + "</code></p><p>"
710 + tr("The file format is one map entry per line, consisting of the map "
711 "name and tiles URL delimited by a TAB character. The tile X and Y "
712 "coordinates are replaced with $x and $y in the URL and the zoom "
713 "level is replaced with $z. An example map file could look like:")
714 + "</p><p><code>Map1 http://tile.server.com/map/$z/$x/$y.png"
715 "<br/>Map2 http://mapserver.org/map/$z-$x-$y</code></p>"
717 + "<h4>" + tr("Offline maps") + "</h4><p>"
718 + tr("Offline maps are loaded on program startup from the following "
719 "directory:")
720 + "</p><p><code>" + USER_MAP_DIR + "</code></p><p>"
721 + tr("The expected structure is one map/atlas in a separate subdirectory."
722 " Supported map formats are OziExplorer maps and TrekBuddy maps/atlases"
723 " (tared and non-tared).") + "</p>"
725 + "<h4>" + tr("POIs") + "</h4><p>"
726 + tr("To make GPXSee load a POI file automatically on startup, add "
727 "the file to the following directory:")
728 + "</p><p><code>" + USER_POI_DIR + "</code></p>"
731 msgBox.exec();
734 void GUI::openFile()
736 QStringList files = QFileDialog::getOpenFileNames(this, tr("Open file"),
737 QString(), fileFormats());
738 QStringList list = files;
740 for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
741 openFile(*it);
744 bool GUI::openFile(const QString &fileName)
746 bool ret = true;
748 if (fileName.isEmpty() || _files.contains(fileName))
749 return false;
751 if (loadFile(fileName)) {
752 _files.append(fileName);
753 _browser->setCurrent(fileName);
754 _fileActionGroup->setEnabled(true);
755 _navigationActionGroup->setEnabled(true);
757 updateNavigationActions();
758 updateStatusBarInfo();
759 updateWindowTitle();
760 updateGraphTabs();
761 updatePathView();
762 } else {
763 if (_files.isEmpty())
764 _fileActionGroup->setEnabled(false);
765 ret = false;
768 return ret;
771 bool GUI::loadFile(const QString &fileName)
773 Data data;
774 QList<PathItem*> paths;
776 if (data.loadFile(fileName)) {
777 paths = _pathView->loadData(data);
778 for (int i = 0; i < _tabs.count(); i++)
779 _tabs.at(i)->loadData(data, paths);
781 for (int i = 0; i < data.tracks().count(); i++) {
782 _trackDistance += data.tracks().at(i)->distance();
783 _time += data.tracks().at(i)->time();
784 _movingTime += data.tracks().at(i)->movingTime();
785 const QDate &date = data.tracks().at(i)->date().date();
786 if (_dateRange.first.isNull() || _dateRange.first > date)
787 _dateRange.first = date;
788 if (_dateRange.second.isNull() || _dateRange.second < date)
789 _dateRange.second = date;
791 _trackCount += data.tracks().count();
793 for (int i = 0; i < data.routes().count(); i++)
794 _routeDistance += data.routes().at(i)->distance();
795 _routeCount += data.routes().count();
797 _waypointCount += data.waypoints().count();
799 if (_pathName.isNull()) {
800 if (data.tracks().count() == 1 && !data.routes().count())
801 _pathName = data.tracks().first()->name();
802 else if (data.routes().count() == 1 && !data.tracks().count())
803 _pathName = data.routes().first()->name();
804 } else
805 _pathName = QString();
807 return true;
808 } else {
809 updateNavigationActions();
810 updateStatusBarInfo();
811 updateWindowTitle();
812 updateGraphTabs();
813 updatePathView();
815 QString error = tr("Error loading data file:") + "\n\n"
816 + fileName + "\n\n" + data.errorString();
817 if (data.errorLine())
818 error.append("\n" + tr("Line: %1").arg(data.errorLine()));
819 QMessageBox::critical(this, APP_NAME, error);
820 return false;
824 void GUI::openPOIFile()
826 QStringList files = QFileDialog::getOpenFileNames(this, tr("Open POI file"),
827 QString(), fileFormats());
828 QStringList list = files;
830 for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
831 openPOIFile(*it);
834 bool GUI::openPOIFile(const QString &fileName)
836 if (fileName.isEmpty() || _poi->files().contains(fileName))
837 return false;
839 if (!_poi->loadFile(fileName)) {
840 QString error = tr("Error loading POI file:") + "\n\n"
841 + fileName + "\n\n" + _poi->errorString();
842 if (_poi->errorLine())
843 error.append("\n" + tr("Line: %1").arg(_poi->errorLine()));
844 QMessageBox::critical(this, APP_NAME, error);
846 return false;
847 } else {
848 _pathView->showPOI(true);
849 _showPOIAction->setChecked(true);
850 QAction *action = createPOIFileAction(_poi->files().indexOf(fileName));
851 action->setChecked(true);
852 _poiFilesMenu->addAction(action);
854 return true;
858 void GUI::closePOIFiles()
860 _poiFilesMenu->clear();
862 for (int i = 0; i < _poiFilesActions.count(); i++)
863 delete _poiFilesActions[i];
864 _poiFilesActions.clear();
866 _poi->clear();
869 void GUI::printFile()
871 QPrinter printer(QPrinter::HighResolution);
872 QPrintDialog dialog(&printer, this);
874 if (dialog.exec() == QDialog::Accepted)
875 plot(&printer);
878 void GUI::openOptions()
880 Options options(_options);
881 bool reload = false;
883 OptionsDialog dialog(&options, this);
884 if (dialog.exec() != QDialog::Accepted)
885 return;
887 if (options.palette != _options.palette) {
888 _pathView->setPalette(options.palette);
889 for (int i = 0; i < _tabs.count(); i++)
890 _tabs.at(i)->setPalette(options.palette);
892 if (options.trackWidth != _options.trackWidth)
893 _pathView->setTrackWidth(options.trackWidth);
894 if (options.routeWidth != _options.routeWidth)
895 _pathView->setRouteWidth(options.routeWidth);
896 if (options.trackStyle != _options.trackStyle)
897 _pathView->setTrackStyle(options.trackStyle);
898 if (options.routeStyle != _options.routeStyle)
899 _pathView->setRouteStyle(options.routeStyle);
900 if (options.pathAntiAliasing != _options.pathAntiAliasing)
901 _pathView->setRenderHint(QPainter::Antialiasing,
902 options.pathAntiAliasing);
903 if (options.graphWidth != _options.graphWidth)
904 for (int i = 0; i < _tabs.count(); i++)
905 _tabs.at(i)->setGraphWidth(options.graphWidth);
906 if (options.graphAntiAliasing != _options.graphAntiAliasing)
907 for (int i = 0; i < _tabs.count(); i++)
908 _tabs.at(i)->setRenderHint(QPainter::Antialiasing,
909 options.graphAntiAliasing);
911 if (options.elevationFilter != _options.elevationFilter) {
912 Track::setElevationFilter(options.elevationFilter);
913 reload = true;
915 if (options.speedFilter != _options.speedFilter) {
916 Track::setSpeedFilter(options.speedFilter);
917 reload = true;
919 if (options.heartRateFilter != _options.heartRateFilter) {
920 Track::setHeartRateFilter(options.heartRateFilter);
921 reload = true;
923 if (options.cadenceFilter != _options.cadenceFilter) {
924 Track::setCadenceFilter(options.cadenceFilter);
925 reload = true;
927 if (options.powerFilter != _options.powerFilter) {
928 Track::setPowerFilter(options.powerFilter);
929 reload = true;
931 if (options.outlierEliminate != _options.outlierEliminate) {
932 Track::setOutlierElimination(options.outlierEliminate);
933 reload = true;
935 if (options.pauseSpeed != _options.pauseSpeed) {
936 Track::setPauseSpeed(options.pauseSpeed);
937 reload = true;
939 if (options.pauseInterval != _options.pauseInterval) {
940 Track::setPauseInterval(options.pauseInterval);
941 reload = true;
944 if (options.poiRadius != _options.poiRadius)
945 _poi->setRadius(options.poiRadius);
947 if (options.useOpenGL != _options.useOpenGL) {
948 _pathView->useOpenGL(options.useOpenGL);
949 for (int i = 0; i < _tabs.count(); i++)
950 _tabs.at(i)->useOpenGL(options.useOpenGL);
952 if (options.pixmapCache != _options.pixmapCache)
953 QPixmapCache::setCacheLimit(options.pixmapCache * 1024);
955 if (reload)
956 reloadFile();
958 _options = options;
961 void GUI::exportFile()
963 ExportDialog dialog(&_export, this);
964 if (dialog.exec() != QDialog::Accepted)
965 return;
967 QPrinter printer(QPrinter::HighResolution);
968 printer.setOutputFormat(QPrinter::PdfFormat);
969 printer.setCreator(QString(APP_NAME) + QString(" ")
970 + QString(APP_VERSION));
971 printer.setOrientation(_export.orientation);
972 printer.setOutputFileName(_export.fileName);
973 printer.setPaperSize(_export.paperSize);
974 printer.setPageMargins(_export.margins.left(), _export.margins.top(),
975 _export.margins.right(), _export.margins.bottom(), QPrinter::Millimeter);
977 plot(&printer);
980 void GUI::plot(QPrinter *printer)
982 QPainter p(printer);
983 TrackInfo info;
984 qreal ih, gh, mh, ratio;
985 qreal d = distance();
986 qreal t = time();
987 qreal tm = movingTime();
989 if (!_pathName.isNull() && _options.printName)
990 info.insert(tr("Name"), _pathName);
992 if (_options.printItemCount) {
993 if (_trackCount > 1)
994 info.insert(tr("Tracks"), QString::number(_trackCount));
995 if (_routeCount > 1)
996 info.insert(tr("Routes"), QString::number(_routeCount));
997 if (_waypointCount > 2)
998 info.insert(tr("Waypoints"), QString::number(_waypointCount));
1001 if (_dateRange.first.isValid() && _options.printDate) {
1002 if (_dateRange.first == _dateRange.second) {
1003 QString format = QLocale::system().dateFormat(QLocale::LongFormat);
1004 info.insert(tr("Date"), _dateRange.first.toString(format));
1005 } else {
1006 QString format = QLocale::system().dateFormat(QLocale::ShortFormat);
1007 info.insert(tr("Date"), QString("%1 - %2")
1008 .arg(_dateRange.first.toString(format),
1009 _dateRange.second.toString(format)));
1013 if (d > 0 && _options.printDistance)
1014 info.insert(tr("Distance"), Format::distance(d, units()));
1015 if (t > 0 && _options.printTime)
1016 info.insert(tr("Time"), Format::timeSpan(t));
1017 if (tm > 0 && _options.printMovingTime)
1018 info.insert(tr("Moving time"), Format::timeSpan(tm));
1021 ratio = p.paintEngine()->paintDevice()->logicalDpiX() / SCREEN_DPI;
1022 if (info.isEmpty()) {
1023 ih = 0;
1024 mh = 0;
1025 } else {
1026 ih = info.contentSize().height() * ratio;
1027 mh = ih / 2;
1028 info.plot(&p, QRectF(0, 0, printer->width(), ih));
1030 if (_graphTabWidget->isVisible() && !_options.separateGraphPage) {
1031 qreal r = (((qreal)(printer)->width()) / (qreal)(printer->height()));
1032 gh = (printer->width() > printer->height())
1033 ? 0.15 * r * (printer->height() - ih - 2*mh)
1034 : 0.15 * (printer->height() - ih - 2*mh);
1035 gh = qMax(gh, ratio * 150);
1036 GraphTab *gt = static_cast<GraphTab*>(_graphTabWidget->currentWidget());
1037 gt->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh));
1038 } else
1039 gh = 0;
1040 _pathView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height()
1041 - (ih + 2*mh + gh)));
1043 if (_graphTabWidget->isVisible() && _options.separateGraphPage) {
1044 printer->newPage();
1046 int cnt = 0;
1047 for (int i = 0; i < _tabs.size(); i++)
1048 if (_tabs.at(i)->count())
1049 cnt++;
1051 qreal sp = ratio * 20;
1052 gh = qMin((printer->height() - ((cnt - 1) * sp))/(qreal)cnt,
1053 0.20 * printer->height());
1055 qreal y = 0;
1056 for (int i = 0; i < _tabs.size(); i++) {
1057 if (_tabs.at(i)->count()) {
1058 _tabs.at(i)->plot(&p, QRectF(0, y, printer->width(), gh));
1059 y += gh + sp;
1065 void GUI::reloadFile()
1067 _trackCount = 0;
1068 _routeCount = 0;
1069 _waypointCount = 0;
1070 _trackDistance = 0;
1071 _routeDistance = 0;
1072 _time = 0;
1073 _movingTime = 0;
1074 _dateRange = DateRange(QDate(), QDate());
1075 _pathName = QString();
1077 for (int i = 0; i < _tabs.count(); i++)
1078 _tabs.at(i)->clear();
1079 _pathView->clear();
1081 _sliderPos = 0;
1083 for (int i = 0; i < _files.size(); i++) {
1084 if (!loadFile(_files.at(i))) {
1085 _files.removeAt(i);
1086 i--;
1090 updateStatusBarInfo();
1091 updateWindowTitle();
1092 updateGraphTabs();
1093 updatePathView();
1094 if (_files.isEmpty())
1095 _fileActionGroup->setEnabled(false);
1096 else
1097 _browser->setCurrent(_files.last());
1100 void GUI::closeFiles()
1102 _trackCount = 0;
1103 _routeCount = 0;
1104 _waypointCount = 0;
1105 _trackDistance = 0;
1106 _routeDistance = 0;
1107 _time = 0;
1108 _movingTime = 0;
1109 _dateRange = DateRange(QDate(), QDate());
1110 _pathName = QString();
1112 _sliderPos = 0;
1114 for (int i = 0; i < _tabs.count(); i++)
1115 _tabs.at(i)->clear();
1116 _pathView->clear();
1118 _files.clear();
1121 void GUI::closeAll()
1123 closeFiles();
1125 _fileActionGroup->setEnabled(false);
1126 updateStatusBarInfo();
1127 updateWindowTitle();
1128 updateGraphTabs();
1129 updatePathView();
1132 void GUI::showGraphs(bool show)
1134 _graphTabWidget->setHidden(!show);
1137 void GUI::showToolbars(bool show)
1139 if (show) {
1140 addToolBar(_fileToolBar);
1141 addToolBar(_showToolBar);
1142 addToolBar(_navigationToolBar);
1143 _fileToolBar->show();
1144 _showToolBar->show();
1145 _navigationToolBar->show();
1146 } else {
1147 removeToolBar(_fileToolBar);
1148 removeToolBar(_showToolBar);
1149 removeToolBar(_navigationToolBar);
1153 void GUI::showFullscreen(bool show)
1155 if (show) {
1156 _frameStyle = _pathView->frameStyle();
1157 _showGraphs = _showGraphsAction->isChecked();
1159 statusBar()->hide();
1160 menuBar()->hide();
1161 showToolbars(false);
1162 showGraphs(false);
1163 _showGraphsAction->setChecked(false);
1164 _pathView->setFrameStyle(QFrame::NoFrame);
1166 showFullScreen();
1167 } else {
1168 statusBar()->show();
1169 menuBar()->show();
1170 if (_showToolbarsAction->isChecked())
1171 showToolbars(true);
1172 _showGraphsAction->setChecked(_showGraphs);
1173 if (_showGraphsAction->isEnabled())
1174 showGraphs(_showGraphs);
1175 _pathView->setFrameStyle(_frameStyle);
1177 showNormal();
1181 void GUI::showTracks(bool show)
1183 _pathView->showTracks(show);
1185 for (int i = 0; i < _tabs.size(); i++)
1186 _tabs.at(i)->showTracks(show);
1188 updateStatusBarInfo();
1191 void GUI::showRoutes(bool show)
1193 _pathView->showRoutes(show);
1195 for (int i = 0; i < _tabs.size(); i++)
1196 _tabs.at(i)->showRoutes(show);
1198 updateStatusBarInfo();
1201 void GUI::showGraphGrids(bool show)
1203 for (int i = 0; i < _tabs.size(); i++)
1204 _tabs.at(i)->showGrid(show);
1207 void GUI::loadMap()
1209 QString fileName = QFileDialog::getOpenFileName(this, tr("Open map file"),
1210 QString(), tr("Map files (*.map *.tba *.tar)"));
1212 if (fileName.isEmpty())
1213 return;
1215 if (_ml->loadMap(fileName)) {
1216 QAction *a = new QAction(_ml->maps().last()->name(), this);
1217 a->setCheckable(true);
1218 a->setActionGroup(_mapsActionGroup);
1219 _mapsSignalMapper->setMapping(a, _ml->maps().size() - 1);
1220 connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
1221 _mapActions.append(a);
1222 _mapMenu->insertAction(_mapsEnd, a);
1223 _showMapAction->setEnabled(true);
1224 _clearMapCacheAction->setEnabled(true);
1225 a->activate(QAction::Trigger);
1226 } else {
1227 QString error = tr("Error loading map:") + "\n\n"
1228 + fileName + "\n\n" + _ml->errorString();
1229 QMessageBox::critical(this, APP_NAME, error);
1233 void GUI::clearMapCache()
1235 _map->clearCache();
1236 _pathView->redraw();
1239 void GUI::updateStatusBarInfo()
1241 if (_files.count() == 0)
1242 _fileNameLabel->setText(tr("No files loaded"));
1243 else if (_files.count() == 1)
1244 _fileNameLabel->setText(_files.at(0));
1245 else
1246 _fileNameLabel->setText(tr("%n files", "", _files.count()));
1248 if (distance() > 0)
1249 _distanceLabel->setText(Format::distance(distance(), units()));
1250 else
1251 _distanceLabel->clear();
1253 if (time() > 0) {
1254 if (_movingTimeAction->isChecked()) {
1255 _timeLabel->setText(Format::timeSpan(movingTime())
1256 + "<sub>M</sub>");
1257 _timeLabel->setToolTip(Format::timeSpan(time()));
1258 } else {
1259 _timeLabel->setText(Format::timeSpan(time()));
1260 _timeLabel->setToolTip(Format::timeSpan(movingTime())
1261 + "<sub>M</sub>");
1263 } else {
1264 _timeLabel->clear();
1265 _timeLabel->setToolTip(QString());
1269 void GUI::updateWindowTitle()
1271 if (_files.count() == 1)
1272 setWindowTitle(QFileInfo(_files.at(0)).fileName() + " - " + APP_NAME);
1273 else
1274 setWindowTitle(APP_NAME);
1277 void GUI::mapChanged(int index)
1279 _map = _ml->maps().at(index);
1280 _pathView->setMap(_map);
1283 void GUI::nextMap()
1285 if (_ml->maps().count() < 2)
1286 return;
1288 int next = (_ml->maps().indexOf(_map) + 1) % _ml->maps().count();
1289 _mapActions.at(next)->setChecked(true);
1290 mapChanged(next);
1293 void GUI::prevMap()
1295 if (_ml->maps().count() < 2)
1296 return;
1298 int prev = (_ml->maps().indexOf(_map) + _ml->maps().count() - 1)
1299 % _ml->maps().count();
1300 _mapActions.at(prev)->setChecked(true);
1301 mapChanged(prev);
1304 void GUI::poiFileChecked(int index)
1306 _poi->enableFile(_poi->files().at(index),
1307 _poiFilesActions.at(index)->isChecked());
1310 void GUI::sliderPositionChanged(qreal pos)
1312 _sliderPos = pos;
1315 void GUI::graphChanged(int index)
1317 if (index < 0)
1318 return;
1320 GraphTab *gt = static_cast<GraphTab*>(_graphTabWidget->widget(index));
1321 gt->setSliderPosition(_sliderPos);
1324 void GUI::updateNavigationActions()
1326 if (_browser->isLast()) {
1327 _nextAction->setEnabled(false);
1328 _lastAction->setEnabled(false);
1329 } else {
1330 _nextAction->setEnabled(true);
1331 _lastAction->setEnabled(true);
1334 if (_browser->isFirst()) {
1335 _prevAction->setEnabled(false);
1336 _firstAction->setEnabled(false);
1337 } else {
1338 _prevAction->setEnabled(true);
1339 _firstAction->setEnabled(true);
1343 void GUI::updateGraphTabs()
1345 int index;
1346 GraphTab *tab;
1348 for (int i = 0; i < _tabs.size(); i++) {
1349 tab = _tabs.at(i);
1350 if (!tab->count() && (index = _graphTabWidget->indexOf(tab)) >= 0)
1351 _graphTabWidget->removeTab(index);
1354 for (int i = 0; i < _tabs.size(); i++) {
1355 tab = _tabs.at(i);
1356 if (tab->count() && _graphTabWidget->indexOf(tab) < 0)
1357 _graphTabWidget->insertTab(i, tab, _tabs.at(i)->label());
1360 if (_graphTabWidget->count()) {
1361 if (_showGraphsAction->isChecked())
1362 _graphTabWidget->setHidden(false);
1363 _showGraphsAction->setEnabled(true);
1364 } else {
1365 _graphTabWidget->setHidden(true);
1366 _showGraphsAction->setEnabled(false);
1370 void GUI::updatePathView()
1372 _pathView->setHidden(!(_pathView->trackCount() + _pathView->routeCount()
1373 + _pathView->waypointCount()));
1376 void GUI::setTimeType(TimeType type)
1378 for (int i = 0; i <_tabs.count(); i++)
1379 _tabs.at(i)->setTimeType(type);
1381 updateStatusBarInfo();
1384 void GUI::setUnits(Units units)
1386 _export.units = units;
1387 _options.units = units;
1389 _pathView->setUnits(units);
1390 for (int i = 0; i <_tabs.count(); i++)
1391 _tabs.at(i)->setUnits(units);
1392 updateStatusBarInfo();
1395 void GUI::setGraphType(GraphType type)
1397 _sliderPos = 0;
1399 for (int i = 0; i <_tabs.count(); i++) {
1400 _tabs.at(i)->setGraphType(type);
1401 _tabs.at(i)->setSliderPosition(0);
1405 void GUI::next()
1407 QString file = _browser->next();
1408 if (file.isNull())
1409 return;
1411 closeFiles();
1412 openFile(file);
1415 void GUI::prev()
1417 QString file = _browser->prev();
1418 if (file.isNull())
1419 return;
1421 closeFiles();
1422 openFile(file);
1425 void GUI::last()
1427 QString file = _browser->last();
1428 if (file.isNull())
1429 return;
1431 closeFiles();
1432 openFile(file);
1435 void GUI::first()
1437 QString file = _browser->first();
1438 if (file.isNull())
1439 return;
1441 closeFiles();
1442 openFile(file);
1445 void GUI::keyPressEvent(QKeyEvent *event)
1447 QString file;
1449 switch (event->key()) {
1450 case PREV_KEY:
1451 file = _browser->prev();
1452 break;
1453 case NEXT_KEY:
1454 file = _browser->next();
1455 break;
1456 case FIRST_KEY:
1457 file = _browser->first();
1458 break;
1459 case LAST_KEY:
1460 file = _browser->last();
1461 break;
1463 case Qt::Key_Escape:
1464 if (_fullscreenAction->isChecked()) {
1465 _fullscreenAction->setChecked(false);
1466 showFullscreen(false);
1467 return;
1469 break;
1472 if (!file.isNull()) {
1473 if (!(event->modifiers() & MODIFIER))
1474 closeFiles();
1475 openFile(file);
1476 return;
1479 QMainWindow::keyPressEvent(event);
1482 void GUI::closeEvent(QCloseEvent *event)
1484 writeSettings();
1485 event->accept();
1488 void GUI::dragEnterEvent(QDragEnterEvent *event)
1490 if (!event->mimeData()->hasUrls())
1491 return;
1492 if (event->proposedAction() != Qt::CopyAction)
1493 return;
1495 QList<QUrl> urls = event->mimeData()->urls();
1496 for (int i = 0; i < urls.size(); i++)
1497 if (!urls.at(i).isLocalFile())
1498 return;
1500 event->acceptProposedAction();
1503 void GUI::dropEvent(QDropEvent *event)
1505 QList<QUrl> urls = event->mimeData()->urls();
1506 for (int i = 0; i < urls.size(); i++)
1507 openFile(urls.at(i).toLocalFile());
1510 void GUI::writeSettings()
1512 QSettings settings(APP_NAME, APP_NAME);
1513 settings.clear();
1515 settings.beginGroup(WINDOW_SETTINGS_GROUP);
1516 if (size() != WINDOW_SIZE_DEFAULT)
1517 settings.setValue(WINDOW_SIZE_SETTING, size());
1518 if (pos() != WINDOW_POS_DEFAULT)
1519 settings.setValue(WINDOW_POS_SETTING, pos());
1520 settings.endGroup();
1522 settings.beginGroup(SETTINGS_SETTINGS_GROUP);
1523 if ((_movingTimeAction->isChecked() ? Moving : Total) !=
1524 TIME_TYPE_DEFAULT)
1525 settings.setValue(TIME_TYPE_SETTING, _movingTimeAction->isChecked()
1526 ? Moving : Total);
1527 if ((_imperialUnitsAction->isChecked() ? Imperial : Metric) !=
1528 UNITS_DEFAULT)
1529 settings.setValue(UNITS_SETTING, _imperialUnitsAction->isChecked()
1530 ? Imperial : Metric);
1531 if (_showToolbarsAction->isChecked() != SHOW_TOOLBARS_DEFAULT)
1532 settings.setValue(SHOW_TOOLBARS_SETTING,
1533 _showToolbarsAction->isChecked());
1534 settings.endGroup();
1536 settings.beginGroup(MAP_SETTINGS_GROUP);
1537 settings.setValue(CURRENT_MAP_SETTING, _map->name());
1538 if (_showMapAction->isChecked() != SHOW_MAP_DEFAULT)
1539 settings.setValue(SHOW_MAP_SETTING, _showMapAction->isChecked());
1540 settings.endGroup();
1542 settings.beginGroup(GRAPH_SETTINGS_GROUP);
1543 if (_showGraphsAction->isChecked() != SHOW_GRAPHS_DEFAULT)
1544 settings.setValue(SHOW_GRAPHS_SETTING, _showGraphsAction->isChecked());
1545 if ((_timeGraphAction->isChecked() ? Time : Distance) != GRAPH_TYPE_DEFAULT)
1546 settings.setValue(GRAPH_TYPE_SETTING, _timeGraphAction->isChecked()
1547 ? Time : Distance);
1548 if (_showGraphGridAction->isChecked() != SHOW_GRAPH_GRIDS_DEFAULT)
1549 settings.setValue(SHOW_GRAPH_GRIDS_SETTING,
1550 _showGraphGridAction->isChecked());
1551 settings.endGroup();
1553 settings.beginGroup(POI_SETTINGS_GROUP);
1554 if (_showPOIAction->isChecked() != SHOW_POI_DEFAULT)
1555 settings.setValue(SHOW_POI_SETTING, _showPOIAction->isChecked());
1556 if (_overlapPOIAction->isChecked() != OVERLAP_POI_DEFAULT)
1557 settings.setValue(OVERLAP_POI_SETTING, _overlapPOIAction->isChecked());
1559 int j = 0;
1560 for (int i = 0; i < _poiFilesActions.count(); i++) {
1561 if (!_poiFilesActions.at(i)->isChecked()) {
1562 if (j == 0)
1563 settings.beginWriteArray(DISABLED_POI_FILE_SETTINGS_PREFIX);
1564 settings.setArrayIndex(j++);
1565 settings.setValue(DISABLED_POI_FILE_SETTING, _poi->files().at(i));
1568 if (j != 0)
1569 settings.endArray();
1570 settings.endGroup();
1572 settings.beginGroup(DATA_SETTINGS_GROUP);
1573 if (_showTracksAction->isChecked() != SHOW_TRACKS_DEFAULT)
1574 settings.setValue(SHOW_TRACKS_SETTING, _showTracksAction->isChecked());
1575 if (_showRoutesAction->isChecked() != SHOW_ROUTES_DEFAULT)
1576 settings.setValue(SHOW_ROUTES_SETTING, _showRoutesAction->isChecked());
1577 if (_showWaypointsAction->isChecked() != SHOW_WAYPOINTS_DEFAULT)
1578 settings.setValue(SHOW_WAYPOINTS_SETTING,
1579 _showWaypointsAction->isChecked());
1580 if (_showWaypointLabelsAction->isChecked() != SHOW_WAYPOINT_LABELS_DEFAULT)
1581 settings.setValue(SHOW_WAYPOINT_LABELS_SETTING,
1582 _showWaypointLabelsAction->isChecked());
1583 if (_showRouteWaypointsAction->isChecked() != SHOW_ROUTE_WAYPOINTS_DEFAULT)
1584 settings.setValue(SHOW_ROUTE_WAYPOINTS_SETTING,
1585 _showRouteWaypointsAction->isChecked());
1586 settings.endGroup();
1588 settings.beginGroup(EXPORT_SETTINGS_GROUP);
1589 if (_export.orientation != PAPER_ORIENTATION_DEFAULT)
1590 settings.setValue(PAPER_ORIENTATION_SETTING, _export.orientation);
1591 if (_export.paperSize != PAPER_SIZE_DEFAULT)
1592 settings.setValue(PAPER_SIZE_SETTING, _export.paperSize);
1593 if (_export.margins.left() != MARGIN_LEFT_DEFAULT)
1594 settings.setValue(MARGIN_LEFT_SETTING, _export.margins.left());
1595 if (_export.margins.top() != MARGIN_TOP_DEFAULT)
1596 settings.setValue(MARGIN_TOP_SETTING, _export.margins.top());
1597 if (_export.margins.right() != MARGIN_RIGHT_DEFAULT)
1598 settings.setValue(MARGIN_RIGHT_SETTING, _export.margins.right());
1599 if (_export.margins.bottom() != MARGIN_BOTTOM_DEFAULT)
1600 settings.setValue(MARGIN_BOTTOM_SETTING, _export.margins.bottom());
1601 if (_export.fileName != EXPORT_FILENAME_DEFAULT)
1602 settings.setValue(EXPORT_FILENAME_SETTING, _export.fileName);
1603 settings.endGroup();
1605 settings.beginGroup(OPTIONS_SETTINGS_GROUP);
1606 if (_options.palette.color() != PALETTE_COLOR_DEFAULT)
1607 settings.setValue(PALETTE_COLOR_SETTING, _options.palette.color());
1608 if (_options.palette.shift() != PALETTE_SHIFT_DEFAULT)
1609 settings.setValue(PALETTE_SHIFT_SETTING, _options.palette.shift());
1610 if (_options.trackWidth != TRACK_WIDTH_DEFAULT)
1611 settings.setValue(TRACK_WIDTH_SETTING, _options.trackWidth);
1612 if (_options.routeWidth != ROUTE_WIDTH_DEFAULT)
1613 settings.setValue(ROUTE_WIDTH_SETTING, _options.routeWidth);
1614 if (_options.trackStyle != TRACK_STYLE_DEFAULT)
1615 settings.setValue(TRACK_STYLE_SETTING, (int)_options.trackStyle);
1616 if (_options.routeStyle != ROUTE_STYLE_DEFAULT)
1617 settings.setValue(ROUTE_STYLE_SETTING, (int)_options.routeStyle);
1618 if (_options.graphWidth != GRAPH_WIDTH_DEFAULT)
1619 settings.setValue(GRAPH_WIDTH_SETTING, _options.graphWidth);
1620 if (_options.pathAntiAliasing != PATH_AA_DEFAULT)
1621 settings.setValue(PATH_AA_SETTING, _options.pathAntiAliasing);
1622 if (_options.graphAntiAliasing != GRAPH_AA_DEFAULT)
1623 settings.setValue(GRAPH_AA_SETTING, _options.graphAntiAliasing);
1624 if (_options.elevationFilter != ELEVATION_FILTER_DEFAULT)
1625 settings.setValue(ELEVATION_FILTER_SETTING, _options.elevationFilter);
1626 if (_options.speedFilter != SPEED_FILTER_DEFAULT)
1627 settings.setValue(SPEED_FILTER_SETTING, _options.speedFilter);
1628 if (_options.heartRateFilter != HEARTRATE_FILTER_DEFAULT)
1629 settings.setValue(HEARTRATE_FILTER_SETTING, _options.heartRateFilter);
1630 if (_options.cadenceFilter != CADENCE_FILTER_DEFAULT)
1631 settings.setValue(CADENCE_FILTER_SETTING, _options.cadenceFilter);
1632 if (_options.powerFilter != POWER_FILTER_DEFAULT)
1633 settings.setValue(POWER_FILTER_SETTING, _options.powerFilter);
1634 if (_options.outlierEliminate != OUTLIER_ELIMINATE_DEFAULT)
1635 settings.setValue(OUTLIER_ELIMINATE_SETTING, _options.outlierEliminate);
1636 if (_options.pauseSpeed != PAUSE_SPEED_DEFAULT)
1637 settings.setValue(PAUSE_SPEED_SETTING, _options.pauseSpeed);
1638 if (_options.pauseInterval != PAUSE_INTERVAL_DEFAULT)
1639 settings.setValue(PAUSE_INTERVAL_SETTING, _options.pauseInterval);
1640 if (_options.poiRadius != POI_RADIUS_DEFAULT)
1641 settings.setValue(POI_RADIUS_SETTING, _options.poiRadius);
1642 if (_options.useOpenGL != USE_OPENGL_DEFAULT)
1643 settings.setValue(USE_OPENGL_SETTING, _options.useOpenGL);
1644 if (_options.pixmapCache != PIXMAP_CACHE_DEFAULT)
1645 settings.setValue(PIXMAP_CACHE_SETTING, _options.pixmapCache);
1646 if (_options.printName != PRINT_NAME_DEFAULT)
1647 settings.setValue(PRINT_NAME_SETTING, _options.printName);
1648 if (_options.printDate != PRINT_DATE_DEFAULT)
1649 settings.setValue(PRINT_DATE_SETTING, _options.printDate);
1650 if (_options.printDistance != PRINT_DISTANCE_DEFAULT)
1651 settings.setValue(PRINT_DISTANCE_SETTING, _options.printDistance);
1652 if (_options.printTime != PRINT_TIME_DEFAULT)
1653 settings.setValue(PRINT_TIME_SETTING, _options.printTime);
1654 if (_options.printMovingTime != PRINT_MOVING_TIME_DEFAULT)
1655 settings.setValue(PRINT_MOVING_TIME_SETTING, _options.printMovingTime);
1656 if (_options.printItemCount != PRINT_ITEM_COUNT_DEFAULT)
1657 settings.setValue(PRINT_ITEM_COUNT_SETTING, _options.printItemCount);
1658 if (_options.separateGraphPage != SEPARATE_GRAPH_PAGE_DEFAULT)
1659 settings.setValue(SEPARATE_GRAPH_PAGE_SETTING,
1660 _options.separateGraphPage);
1661 settings.endGroup();
1664 void GUI::readSettings()
1666 QSettings settings(APP_NAME, APP_NAME);
1668 settings.beginGroup(WINDOW_SETTINGS_GROUP);
1669 resize(settings.value(WINDOW_SIZE_SETTING, WINDOW_SIZE_DEFAULT).toSize());
1670 move(settings.value(WINDOW_POS_SETTING, WINDOW_POS_DEFAULT).toPoint());
1671 settings.endGroup();
1673 settings.beginGroup(SETTINGS_SETTINGS_GROUP);
1674 if (settings.value(TIME_TYPE_SETTING, TIME_TYPE_DEFAULT).toInt()
1675 == Moving) {
1676 setTimeType(Moving);
1677 _movingTimeAction->setChecked(true);
1678 } else {
1679 setTimeType(Total);
1680 _totalTimeAction->setChecked(true);
1682 if (settings.value(UNITS_SETTING, UNITS_DEFAULT).toInt() == Imperial) {
1683 setUnits(Imperial);
1684 _imperialUnitsAction->setChecked(true);
1685 } else {
1686 setUnits(Metric);
1687 _metricUnitsAction->setChecked(true);
1689 if (!settings.value(SHOW_TOOLBARS_SETTING, SHOW_TOOLBARS_DEFAULT).toBool())
1690 showToolbars(false);
1691 else
1692 _showToolbarsAction->setChecked(true);
1693 settings.endGroup();
1695 settings.beginGroup(MAP_SETTINGS_GROUP);
1696 if (settings.value(SHOW_MAP_SETTING, SHOW_MAP_DEFAULT).toBool())
1697 _showMapAction->setChecked(true);
1698 if (_ml->maps().count()) {
1699 int index = mapIndex(settings.value(CURRENT_MAP_SETTING).toString());
1700 _mapActions.at(index)->setChecked(true);
1701 _map = _ml->maps().at(index);
1702 _pathView->setMap(_map);
1704 settings.endGroup();
1706 settings.beginGroup(GRAPH_SETTINGS_GROUP);
1707 if (!settings.value(SHOW_GRAPHS_SETTING, SHOW_GRAPHS_DEFAULT).toBool())
1708 showGraphs(false);
1709 else
1710 _showGraphsAction->setChecked(true);
1711 if (settings.value(GRAPH_TYPE_SETTING, GRAPH_TYPE_DEFAULT).toInt()
1712 == Time) {
1713 setTimeGraph();
1714 _timeGraphAction->setChecked(true);
1715 } else
1716 _distanceGraphAction->setChecked(true);
1717 if (!settings.value(SHOW_GRAPH_GRIDS_SETTING, SHOW_GRAPH_GRIDS_DEFAULT)
1718 .toBool())
1719 showGraphGrids(false);
1720 else
1721 _showGraphGridAction->setChecked(true);
1722 settings.endGroup();
1724 settings.beginGroup(POI_SETTINGS_GROUP);
1725 if (!settings.value(OVERLAP_POI_SETTING, OVERLAP_POI_DEFAULT).toBool())
1726 _pathView->setPOIOverlap(false);
1727 else
1728 _overlapPOIAction->setChecked(true);
1729 if (!settings.value(LABELS_POI_SETTING, LABELS_POI_DEFAULT).toBool())
1730 _pathView->showPOILabels(false);
1731 else
1732 _showPOILabelsAction->setChecked(true);
1733 if (settings.value(SHOW_POI_SETTING, SHOW_POI_DEFAULT).toBool())
1734 _showPOIAction->setChecked(true);
1735 else
1736 _pathView->showPOI(false);
1737 for (int i = 0; i < _poiFilesActions.count(); i++)
1738 _poiFilesActions.at(i)->setChecked(true);
1739 int size = settings.beginReadArray(DISABLED_POI_FILE_SETTINGS_PREFIX);
1740 for (int i = 0; i < size; i++) {
1741 settings.setArrayIndex(i);
1742 int index = _poi->files().indexOf(settings.value(
1743 DISABLED_POI_FILE_SETTING).toString());
1744 if (index >= 0) {
1745 _poi->enableFile(_poi->files().at(index), false);
1746 _poiFilesActions.at(index)->setChecked(false);
1749 settings.endArray();
1750 settings.endGroup();
1752 settings.beginGroup(DATA_SETTINGS_GROUP);
1753 if (!settings.value(SHOW_TRACKS_SETTING, SHOW_TRACKS_DEFAULT).toBool()) {
1754 _pathView->showTracks(false);
1755 for (int i = 0; i < _tabs.count(); i++)
1756 _tabs.at(i)->showTracks(false);
1757 } else
1758 _showTracksAction->setChecked(true);
1759 if (!settings.value(SHOW_ROUTES_SETTING, SHOW_ROUTES_DEFAULT).toBool()) {
1760 _pathView->showRoutes(false);
1761 for (int i = 0; i < _tabs.count(); i++)
1762 _tabs.at(i)->showRoutes(false);
1763 } else
1764 _showRoutesAction->setChecked(true);
1765 if (!settings.value(SHOW_WAYPOINTS_SETTING, SHOW_WAYPOINTS_DEFAULT)
1766 .toBool())
1767 _pathView->showWaypoints(false);
1768 else
1769 _showWaypointsAction->setChecked(true);
1770 if (!settings.value(SHOW_WAYPOINT_LABELS_SETTING,
1771 SHOW_WAYPOINT_LABELS_DEFAULT).toBool())
1772 _pathView->showWaypointLabels(false);
1773 else
1774 _showWaypointLabelsAction->setChecked(true);
1775 if (!settings.value(SHOW_ROUTE_WAYPOINTS_SETTING,
1776 SHOW_ROUTE_WAYPOINTS_SETTING).toBool())
1777 _pathView->showRouteWaypoints(false);
1778 else
1779 _showRouteWaypointsAction->setChecked(true);
1780 settings.endGroup();
1782 settings.beginGroup(EXPORT_SETTINGS_GROUP);
1783 _export.orientation = (QPrinter::Orientation) settings.value(
1784 PAPER_ORIENTATION_SETTING, PAPER_ORIENTATION_DEFAULT).toInt();
1785 _export.paperSize = (QPrinter::PaperSize) settings.value(PAPER_SIZE_SETTING,
1786 PAPER_SIZE_DEFAULT).toInt();
1787 qreal ml = settings.value(MARGIN_LEFT_SETTING, MARGIN_LEFT_DEFAULT)
1788 .toReal();
1789 qreal mt = settings.value(MARGIN_TOP_SETTING, MARGIN_TOP_DEFAULT).toReal();
1790 qreal mr = settings.value(MARGIN_RIGHT_SETTING, MARGIN_RIGHT_DEFAULT)
1791 .toReal();
1792 qreal mb = settings.value(MARGIN_BOTTOM_SETTING, MARGIN_BOTTOM_DEFAULT)
1793 .toReal();
1794 _export.margins = MarginsF(ml, mt, mr, mb);
1795 _export.fileName = settings.value(EXPORT_FILENAME_SETTING,
1796 EXPORT_FILENAME_DEFAULT).toString();
1797 settings.endGroup();
1799 settings.beginGroup(OPTIONS_SETTINGS_GROUP);
1800 QColor pc = settings.value(PALETTE_COLOR_SETTING, PALETTE_COLOR_DEFAULT)
1801 .value<QColor>();
1802 qreal ps = settings.value(PALETTE_SHIFT_SETTING, PALETTE_SHIFT_DEFAULT)
1803 .toDouble();
1804 _options.palette = Palette(pc, ps);
1805 _options.trackWidth = settings.value(TRACK_WIDTH_SETTING,
1806 TRACK_WIDTH_DEFAULT).toInt();
1807 _options.routeWidth = settings.value(ROUTE_WIDTH_SETTING,
1808 ROUTE_WIDTH_DEFAULT).toInt();
1809 _options.trackStyle = (Qt::PenStyle) settings.value(TRACK_STYLE_SETTING,
1810 (int)TRACK_STYLE_DEFAULT).toInt();
1811 _options.routeStyle = (Qt::PenStyle) settings.value(ROUTE_STYLE_SETTING,
1812 (int)ROUTE_STYLE_DEFAULT).toInt();
1813 _options.pathAntiAliasing = settings.value(PATH_AA_SETTING, PATH_AA_DEFAULT)
1814 .toBool();
1815 _options.graphWidth = settings.value(GRAPH_WIDTH_SETTING,
1816 GRAPH_WIDTH_DEFAULT).toInt();
1817 _options.graphAntiAliasing = settings.value(GRAPH_AA_SETTING,
1818 GRAPH_AA_DEFAULT).toBool();
1819 _options.elevationFilter = settings.value(ELEVATION_FILTER_SETTING,
1820 ELEVATION_FILTER_DEFAULT).toInt();
1821 _options.speedFilter = settings.value(SPEED_FILTER_SETTING,
1822 SPEED_FILTER_DEFAULT).toInt();
1823 _options.heartRateFilter = settings.value(HEARTRATE_FILTER_SETTING,
1824 HEARTRATE_FILTER_DEFAULT).toInt();
1825 _options.cadenceFilter = settings.value(CADENCE_FILTER_SETTING,
1826 CADENCE_FILTER_DEFAULT).toInt();
1827 _options.powerFilter = settings.value(POWER_FILTER_SETTING,
1828 POWER_FILTER_DEFAULT).toInt();
1829 _options.outlierEliminate = settings.value(OUTLIER_ELIMINATE_SETTING,
1830 OUTLIER_ELIMINATE_DEFAULT).toBool();
1831 _options.pauseSpeed = settings.value(PAUSE_SPEED_SETTING,
1832 PAUSE_SPEED_DEFAULT).toFloat();
1833 _options.pauseInterval = settings.value(PAUSE_INTERVAL_SETTING,
1834 PAUSE_INTERVAL_DEFAULT).toInt();
1835 _options.poiRadius = settings.value(POI_RADIUS_SETTING, POI_RADIUS_DEFAULT)
1836 .toInt();
1837 _options.useOpenGL = settings.value(USE_OPENGL_SETTING, USE_OPENGL_DEFAULT)
1838 .toBool();
1839 _options.pixmapCache = settings.value(PIXMAP_CACHE_SETTING,
1840 PIXMAP_CACHE_DEFAULT).toInt();
1841 _options.printName = settings.value(PRINT_NAME_SETTING, PRINT_NAME_DEFAULT)
1842 .toBool();
1843 _options.printDate = settings.value(PRINT_DATE_SETTING, PRINT_DATE_DEFAULT)
1844 .toBool();
1845 _options.printDistance = settings.value(PRINT_DISTANCE_SETTING,
1846 PRINT_DISTANCE_DEFAULT).toBool();
1847 _options.printTime = settings.value(PRINT_TIME_SETTING, PRINT_TIME_DEFAULT)
1848 .toBool();
1849 _options.printMovingTime = settings.value(PRINT_MOVING_TIME_SETTING,
1850 PRINT_MOVING_TIME_DEFAULT).toBool();
1851 _options.printItemCount = settings.value(PRINT_ITEM_COUNT_SETTING,
1852 PRINT_ITEM_COUNT_DEFAULT).toBool();
1853 _options.separateGraphPage = settings.value(SEPARATE_GRAPH_PAGE_SETTING,
1854 SEPARATE_GRAPH_PAGE_DEFAULT).toBool();
1856 _pathView->setPalette(_options.palette);
1857 _pathView->setTrackWidth(_options.trackWidth);
1858 _pathView->setRouteWidth(_options.routeWidth);
1859 _pathView->setTrackStyle(_options.trackStyle);
1860 _pathView->setRouteStyle(_options.routeStyle);
1861 _pathView->setRenderHint(QPainter::Antialiasing, _options.pathAntiAliasing);
1862 if (_options.useOpenGL)
1863 _pathView->useOpenGL(true);
1865 for (int i = 0; i < _tabs.count(); i++) {
1866 _tabs.at(i)->setPalette(_options.palette);
1867 _tabs.at(i)->setGraphWidth(_options.graphWidth);
1868 _tabs.at(i)->setRenderHint(QPainter::Antialiasing,
1869 _options.graphAntiAliasing);
1870 if (_options.useOpenGL)
1871 _tabs.at(i)->useOpenGL(true);
1874 Track::setElevationFilter(_options.elevationFilter);
1875 Track::setSpeedFilter(_options.speedFilter);
1876 Track::setHeartRateFilter(_options.heartRateFilter);
1877 Track::setCadenceFilter(_options.cadenceFilter);
1878 Track::setPowerFilter(_options.powerFilter);
1879 Track::setOutlierElimination(_options.outlierEliminate);
1880 Track::setPauseSpeed(_options.pauseSpeed);
1881 Track::setPauseInterval(_options.pauseInterval);
1883 _poi->setRadius(_options.poiRadius);
1885 QPixmapCache::setCacheLimit(_options.pixmapCache * 1024);
1887 settings.endGroup();
1890 int GUI::mapIndex(const QString &name)
1892 for (int i = 0; i < _ml->maps().count(); i++)
1893 if (_ml->maps().at(i)->name() == name)
1894 return i;
1896 return 0;
1899 Units GUI::units() const
1901 return _imperialUnitsAction->isChecked() ? Imperial : Metric;
1904 qreal GUI::distance() const
1906 qreal dist = 0;
1908 if (_showTracksAction->isChecked())
1909 dist += _trackDistance;
1910 if (_showRoutesAction->isChecked())
1911 dist += _routeDistance;
1913 return dist;
1916 qreal GUI::time() const
1918 return (_showTracksAction->isChecked()) ? _time : 0;
1921 qreal GUI::movingTime() const
1923 return (_showTracksAction->isChecked()) ? _movingTime : 0;