1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-10-07 07:13:21 +02:00
GPXSee/src/gui.cpp

1934 lines
58 KiB
C++
Raw Normal View History

#include <QApplication>
2016-10-19 23:38:28 +02:00
#include <QSplitter>
2015-10-05 01:43:48 +02:00
#include <QVBoxLayout>
#include <QMenuBar>
#include <QStatusBar>
#include <QMessageBox>
#include <QFileDialog>
#include <QPrintDialog>
2015-10-05 01:43:48 +02:00
#include <QPainter>
2016-05-22 15:47:23 +02:00
#include <QPaintEngine>
#include <QPaintDevice>
2015-10-05 01:43:48 +02:00
#include <QKeyEvent>
2015-11-23 02:37:08 +01:00
#include <QSignalMapper>
#include <QMenu>
#include <QToolBar>
#include <QTabWidget>
#include <QActionGroup>
#include <QAction>
#include <QLabel>
2016-04-26 09:39:16 +02:00
#include <QSettings>
2016-05-21 16:18:48 +02:00
#include <QLocale>
2016-10-04 10:16:46 +02:00
#include <QMimeData>
2016-10-08 21:16:56 +02:00
#include <QUrl>
#include <QPixmapCache>
2015-10-05 01:43:48 +02:00
#include "config.h"
#include "icons.h"
#include "keys.h"
2016-04-28 08:49:06 +02:00
#include "settings.h"
2016-10-23 11:09:20 +02:00
#include "data.h"
#include "ellipsoid.h"
#include "datum.h"
2015-11-23 02:37:08 +01:00
#include "map.h"
#include "maplist.h"
#include "emptymap.h"
2015-10-12 01:12:12 +02:00
#include "elevationgraph.h"
#include "speedgraph.h"
#include "heartrategraph.h"
2016-06-16 20:47:32 +02:00
#include "temperaturegraph.h"
2016-11-06 03:28:08 +01:00
#include "cadencegraph.h"
#include "powergraph.h"
2016-09-26 21:01:58 +02:00
#include "pathview.h"
2016-05-12 09:03:05 +02:00
#include "trackinfo.h"
2015-10-20 22:18:41 +02:00
#include "filebrowser.h"
#include "cpuarch.h"
2016-06-24 00:55:44 +02:00
#include "graphtab.h"
2016-11-02 17:35:26 +01:00
#include "format.h"
#include "gui.h"
2015-10-05 01:43:48 +02:00
GUI::GUI()
2015-10-05 01:43:48 +02:00
{
loadDatums();
loadMaps();
loadPOIs();
2015-11-23 02:37:08 +01:00
createPathView();
createGraphTabs();
2015-10-05 01:43:48 +02:00
createStatusBar();
2016-08-09 01:16:19 +02:00
createActions();
createMenus();
createToolBars();
2015-10-05 01:43:48 +02:00
2016-10-23 11:09:20 +02:00
createBrowser();
2015-10-20 22:18:41 +02:00
2016-10-19 23:38:28 +02:00
QSplitter *splitter = new QSplitter();
splitter->setOrientation(Qt::Vertical);
splitter->setChildrenCollapsible(false);
splitter->addWidget(_pathView);
splitter->addWidget(_graphTabWidget);
splitter->setContentsMargins(0, 0, 0, 0);
splitter->setStretchFactor(0, 255);
splitter->setStretchFactor(1, 1);
setCentralWidget(splitter);
2015-10-05 01:43:48 +02:00
2016-04-30 10:54:07 +02:00
setWindowIcon(QIcon(QPixmap(APP_ICON)));
2015-10-05 01:43:48 +02:00
setWindowTitle(APP_NAME);
setUnifiedTitleAndToolBarOnMac(true);
2016-12-06 21:02:44 +01:00
setAcceptDrops(true);
2015-10-05 01:43:48 +02:00
_trackCount = 0;
_routeCount = 0;
_waypointCount = 0;
_trackDistance = 0;
_routeDistance = 0;
_time = 0;
_movingTime = 0;
2015-10-05 01:43:48 +02:00
2016-03-30 20:50:51 +02:00
_sliderPos = 0;
2016-03-23 09:38:22 +01:00
updateGraphTabs();
2016-10-28 19:29:42 +02:00
updatePathView();
2016-08-10 21:17:12 +02:00
updateStatusBarInfo();
2016-04-26 09:39:16 +02:00
readSettings();
2015-10-05 01:43:48 +02:00
}
2016-05-13 18:48:42 +02:00
GUI::~GUI()
{
for (int i = 0; i < _tabs.size(); i++) {
if (_graphTabWidget->indexOf(_tabs.at(i)) < 0)
2016-06-24 00:55:44 +02:00
delete _tabs.at(i);
2016-05-13 18:48:42 +02:00
}
}
void GUI::loadDatums()
{
QString ef, df;
2017-04-17 19:15:20 +02:00
bool ok = false;
if (QFile::exists(USER_ELLIPSOID_FILE))
ef = USER_ELLIPSOID_FILE;
else if (QFile::exists(GLOBAL_ELLIPSOID_FILE))
ef = GLOBAL_ELLIPSOID_FILE;
else
qWarning("No ellipsoids file found.");
if (QFile::exists(USER_DATUM_FILE))
df = USER_DATUM_FILE;
else if (QFile::exists(GLOBAL_DATUM_FILE))
df = GLOBAL_DATUM_FILE;
else
qWarning("No datums file found.");
if (!ef.isNull() && !df.isNull()) {
if (!Ellipsoid::loadList(ef)) {
if (Ellipsoid::errorLine())
qWarning("%s: parse error on line %d: %s", qPrintable(ef),
Ellipsoid::errorLine(), qPrintable(Ellipsoid::errorString()));
else
qWarning("%s: %s", qPrintable(ef), qPrintable(
Ellipsoid::errorString()));
} else {
if (!Datum::loadList(df)) {
if (Datum::errorLine())
qWarning("%s: parse error on line %d: %s", qPrintable(ef),
Datum::errorLine(), qPrintable(Datum::errorString()));
else
qWarning("%s: %s", qPrintable(ef), qPrintable(
Datum::errorString()));
2017-04-17 19:15:20 +02:00
} else
ok = true;
}
}
2017-04-17 19:15:20 +02:00
if (!ok)
qWarning("Maps based on a datum different from WGS84 won't work.");
}
void GUI::loadMaps()
2015-11-23 02:37:08 +01:00
{
_ml = new MapList(this);
QString offline, online;
if (QFile::exists(USER_MAP_FILE))
online = USER_MAP_FILE;
else if (QFile::exists(GLOBAL_MAP_FILE))
online = GLOBAL_MAP_FILE;
2017-07-27 19:47:46 +02:00
if (!online.isNull() && !_ml->loadFile(online))
qWarning("%s: %s", qPrintable(online), qPrintable(_ml->errorString()));
if (QFile::exists(USER_MAP_DIR))
offline = USER_MAP_DIR;
else if (QFile::exists(GLOBAL_MAP_DIR))
offline = GLOBAL_MAP_DIR;
if (!offline.isNull()) {
QDir md(offline);
QFileInfoList ml = md.entryInfoList(QDir::Dirs | QDir::NoDotAndDotDot);
for (int i = 0; i < ml.size(); i++) {
QDir dir(ml.at(i).absoluteFilePath());
2017-07-27 19:47:46 +02:00
QFileInfoList fl = dir.entryInfoList(MapList::filter(), QDir::Files);
if (fl.isEmpty())
qWarning("%s: no map/atlas file found",
qPrintable(ml.at(i).absoluteFilePath()));
else if (fl.size() > 1)
qWarning("%s: ambiguous directory content",
qPrintable(ml.at(i).absoluteFilePath()));
else
2017-07-27 19:47:46 +02:00
if (!_ml->loadFile(fl.first().absoluteFilePath()))
qWarning("%s: %s", qPrintable(fl.first().absoluteFilePath()),
qPrintable(_ml->errorString()));
}
}
_map = _ml->maps().isEmpty() ? new EmptyMap(this) : _ml->maps().first();
}
void GUI::loadPOIs()
{
QFileInfoList list;
QDir userDir(USER_POI_DIR);
QDir globalDir(GLOBAL_POI_DIR);
2016-10-09 23:46:30 +02:00
_poi = new POI(this);
if (userDir.exists())
list = userDir.entryInfoList(QStringList(), QDir::Files);
else
list = globalDir.entryInfoList(QStringList(), QDir::Files);
2017-01-02 23:01:50 +01:00
for (int i = 0; i < list.size(); ++i) {
if (!_poi->loadFile(list.at(i).absoluteFilePath())) {
qWarning("Error loading POI file: %s: %s\n",
2017-01-02 23:01:50 +01:00
qPrintable(list.at(i).fileName()),
qPrintable(_poi->errorString()));
if (_poi->errorLine())
qWarning("Line: %d\n", _poi->errorLine());
2017-01-02 23:01:50 +01:00
}
}
2015-11-23 02:37:08 +01:00
}
2017-07-27 19:47:46 +02:00
void GUI::createBrowser()
{
_browser = new FileBrowser(this);
_browser->setFilter(Data::filter());
}
2015-11-23 02:37:08 +01:00
void GUI::createMapActions()
{
_mapsSignalMapper = new QSignalMapper(this);
_mapsActionGroup = new QActionGroup(this);
_mapsActionGroup->setExclusive(true);
2015-11-23 02:37:08 +01:00
for (int i = 0; i < _ml->maps().count(); i++) {
QAction *a = new QAction(_ml->maps().at(i)->name(), this);
2015-11-23 02:37:08 +01:00
a->setCheckable(true);
a->setActionGroup(_mapsActionGroup);
2015-11-23 02:37:08 +01:00
_mapsSignalMapper->setMapping(a, i);
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
2015-11-23 02:37:08 +01:00
_mapActions.append(a);
}
connect(_mapsSignalMapper, SIGNAL(mapped(int)), this,
SLOT(mapChanged(int)));
2015-11-23 02:37:08 +01:00
}
void GUI::createPOIFilesActions()
{
_poiFilesSignalMapper = new QSignalMapper(this);
2016-10-09 23:46:30 +02:00
for (int i = 0; i < _poi->files().count(); i++)
2016-03-05 22:42:22 +01:00
createPOIFileAction(i);
2017-05-23 13:23:14 +02:00
connect(_poiFilesSignalMapper, SIGNAL(mapped(int)), this,
SLOT(poiFileChecked(int)));
2016-03-05 22:42:22 +01:00
}
2016-03-05 22:42:22 +01:00
QAction *GUI::createPOIFileAction(int index)
{
2016-10-09 23:46:30 +02:00
QAction *a = new QAction(QFileInfo(_poi->files().at(index)).fileName(),
2016-03-05 22:42:22 +01:00
this);
a->setCheckable(true);
_poiFilesSignalMapper->setMapping(a, index);
connect(a, SIGNAL(triggered()), _poiFilesSignalMapper, SLOT(map()));
2016-03-05 22:42:22 +01:00
_poiFilesActions.append(a);
return a;
}
2015-10-05 01:43:48 +02:00
void GUI::createActions()
{
2016-09-19 00:56:10 +02:00
QActionGroup *ag;
2015-10-05 01:43:48 +02:00
// Action Groups
_fileActionGroup = new QActionGroup(this);
_fileActionGroup->setExclusive(false);
_fileActionGroup->setEnabled(false);
2015-12-18 22:21:11 +01:00
_navigationActionGroup = new QActionGroup(this);
_navigationActionGroup->setEnabled(false);
2015-10-05 01:43:48 +02:00
// General actions
_exitAction = new QAction(QIcon(QPixmap(QUIT_ICON)), tr("Quit"), this);
_exitAction->setShortcut(QUIT_SHORTCUT);
_exitAction->setMenuRole(QAction::QuitRole);
2016-03-24 19:16:26 +01:00
connect(_exitAction, SIGNAL(triggered()), this, SLOT(close()));
2016-04-05 09:10:19 +02:00
addAction(_exitAction);
2015-10-05 01:43:48 +02:00
2015-10-21 01:09:17 +02:00
// Help & About
_dataSourcesAction = new QAction(tr("Data sources"), this);
connect(_dataSourcesAction, SIGNAL(triggered()), this, SLOT(dataSources()));
2015-10-21 01:09:17 +02:00
_keysAction = new QAction(tr("Keyboard controls"), this);
connect(_keysAction, SIGNAL(triggered()), this, SLOT(keys()));
2015-10-05 01:43:48 +02:00
_aboutAction = new QAction(QIcon(QPixmap(APP_ICON)),
tr("About GPXSee"), this);
_aboutAction->setMenuRole(QAction::AboutRole);
2015-10-05 01:43:48 +02:00
connect(_aboutAction, SIGNAL(triggered()), this, SLOT(about()));
2016-08-09 01:16:19 +02:00
// File actions
2015-10-05 01:43:48 +02:00
_openFileAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
2017-05-16 12:59:59 +02:00
tr("Open..."), this);
_openFileAction->setShortcut(OPEN_SHORTCUT);
2015-10-05 01:43:48 +02:00
connect(_openFileAction, SIGNAL(triggered()), this, SLOT(openFile()));
2016-04-05 09:10:19 +02:00
addAction(_openFileAction);
_printFileAction = new QAction(QIcon(QPixmap(PRINT_FILE_ICON)),
2016-05-27 22:45:58 +02:00
tr("Print..."), this);
_printFileAction->setActionGroup(_fileActionGroup);
connect(_printFileAction, SIGNAL(triggered()), this, SLOT(printFile()));
addAction(_printFileAction);
_exportFileAction = new QAction(QIcon(QPixmap(EXPORT_FILE_ICON)),
2016-05-27 22:45:58 +02:00
tr("Export to PDF..."), this);
_exportFileAction->setShortcut(EXPORT_SHORTCUT);
_exportFileAction->setActionGroup(_fileActionGroup);
connect(_exportFileAction, SIGNAL(triggered()), this, SLOT(exportFile()));
addAction(_exportFileAction);
2015-10-05 01:43:48 +02:00
_closeFileAction = new QAction(QIcon(QPixmap(CLOSE_FILE_ICON)),
tr("Close"), this);
_closeFileAction->setShortcut(CLOSE_SHORTCUT);
2015-10-05 01:43:48 +02:00
_closeFileAction->setActionGroup(_fileActionGroup);
2016-03-23 20:56:39 +01:00
connect(_closeFileAction, SIGNAL(triggered()), this, SLOT(closeAll()));
2016-04-05 09:10:19 +02:00
addAction(_closeFileAction);
2015-10-20 22:18:41 +02:00
_reloadFileAction = new QAction(QIcon(QPixmap(RELOAD_FILE_ICON)),
tr("Reload"), this);
_reloadFileAction->setShortcut(RELOAD_SHORTCUT);
2015-10-20 22:18:41 +02:00
_reloadFileAction->setActionGroup(_fileActionGroup);
connect(_reloadFileAction, SIGNAL(triggered()), this, SLOT(reloadFile()));
2016-04-05 09:10:19 +02:00
addAction(_reloadFileAction);
2015-10-05 01:43:48 +02:00
// POI actions
_openPOIAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
2017-05-16 12:59:59 +02:00
tr("Load POI file..."), this);
2015-10-05 01:43:48 +02:00
connect(_openPOIAction, SIGNAL(triggered()), this, SLOT(openPOIFile()));
_closePOIAction = new QAction(QIcon(QPixmap(CLOSE_FILE_ICON)),
tr("Close POI files"), this);
connect(_closePOIAction, SIGNAL(triggered()), this, SLOT(closePOIFiles()));
_overlapPOIAction = new QAction(tr("Overlap POIs"), this);
_overlapPOIAction->setCheckable(true);
2016-09-26 21:01:58 +02:00
connect(_overlapPOIAction, SIGNAL(triggered(bool)), _pathView,
2016-08-09 01:16:19 +02:00
SLOT(setPOIOverlap(bool)));
_showPOILabelsAction = new QAction(tr("Show POI labels"), this);
_showPOILabelsAction->setCheckable(true);
2016-09-26 21:01:58 +02:00
connect(_showPOILabelsAction, SIGNAL(triggered(bool)), _pathView,
2016-08-09 01:16:19 +02:00
SLOT(showPOILabels(bool)));
2015-10-05 01:43:48 +02:00
_showPOIAction = new QAction(QIcon(QPixmap(SHOW_POI_ICON)),
2015-11-23 02:37:08 +01:00
tr("Show POIs"), this);
2015-10-05 01:43:48 +02:00
_showPOIAction->setCheckable(true);
_showPOIAction->setShortcut(SHOW_POI_SHORTCUT);
2016-10-08 14:53:10 +02:00
connect(_showPOIAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showPOI(bool)));
2016-04-05 09:10:19 +02:00
addAction(_showPOIAction);
createPOIFilesActions();
2015-11-23 02:37:08 +01:00
// Map actions
_showMapAction = new QAction(QIcon(QPixmap(SHOW_MAP_ICON)), tr("Show map"),
this);
_showMapAction->setCheckable(true);
_showMapAction->setShortcut(SHOW_MAP_SHORTCUT);
connect(_showMapAction, SIGNAL(triggered(bool)), _pathView,
SLOT(showMap(bool)));
2016-04-05 09:10:19 +02:00
addAction(_showMapAction);
2017-05-16 12:59:59 +02:00
_loadMapAction = new QAction(QIcon(QPixmap(OPEN_FILE_ICON)),
tr("Load map..."), this);
connect(_loadMapAction, SIGNAL(triggered()), this, SLOT(loadMap()));
2016-04-01 19:25:34 +02:00
_clearMapCacheAction = new QAction(tr("Clear tile cache"), this);
connect(_clearMapCacheAction, SIGNAL(triggered()), this,
SLOT(clearMapCache()));
createMapActions();
_nextMapAction = new QAction(tr("Next map"), this);
_nextMapAction->setShortcut(NEXT_MAP_SHORTCUT);
connect(_nextMapAction, SIGNAL(triggered()), this, SLOT(nextMap()));
addAction(_nextMapAction);
_prevMapAction = new QAction(tr("Next map"), this);
_prevMapAction->setShortcut(PREV_MAP_SHORTCUT);
connect(_prevMapAction, SIGNAL(triggered()), this, SLOT(prevMap()));
addAction(_prevMapAction);
if (_ml->maps().isEmpty()) {
2015-11-23 02:37:08 +01:00
_showMapAction->setEnabled(false);
2016-04-01 19:25:34 +02:00
_clearMapCacheAction->setEnabled(false);
2016-02-07 18:12:03 +01:00
}
2016-08-09 01:16:19 +02:00
// Data actions
_showTracksAction = new QAction(tr("Show tracks"), this);
2016-08-09 01:16:19 +02:00
_showTracksAction->setCheckable(true);
connect(_showTracksAction, SIGNAL(triggered(bool)), this,
2016-08-09 01:16:19 +02:00
SLOT(showTracks(bool)));
_showRoutesAction = new QAction(tr("Show routes"), this);
2016-08-09 01:16:19 +02:00
_showRoutesAction->setCheckable(true);
connect(_showRoutesAction, SIGNAL(triggered(bool)), this,
2016-08-09 01:16:19 +02:00
SLOT(showRoutes(bool)));
_showWaypointsAction = new QAction(tr("Show waypoints"), this);
2016-08-09 01:16:19 +02:00
_showWaypointsAction->setCheckable(true);
2016-09-26 21:01:58 +02:00
connect(_showWaypointsAction, SIGNAL(triggered(bool)), _pathView,
2016-08-09 01:16:19 +02:00
SLOT(showWaypoints(bool)));
2016-08-09 10:47:49 +02:00
_showWaypointLabelsAction = new QAction(tr("Waypoint labels"), this);
2016-08-09 01:16:19 +02:00
_showWaypointLabelsAction->setCheckable(true);
2016-09-26 21:01:58 +02:00
connect(_showWaypointLabelsAction, SIGNAL(triggered(bool)), _pathView,
2016-08-09 01:16:19 +02:00
SLOT(showWaypointLabels(bool)));
_showRouteWaypointsAction = new QAction(tr("Route waypoints"), this);
2016-08-09 10:47:49 +02:00
_showRouteWaypointsAction->setCheckable(true);
2016-09-26 21:01:58 +02:00
connect(_showRouteWaypointsAction, SIGNAL(triggered(bool)), _pathView,
2016-08-09 10:47:49 +02:00
SLOT(showRouteWaypoints(bool)));
2016-08-09 01:16:19 +02:00
2016-09-19 00:56:10 +02:00
// Graph actions
_showGraphsAction = new QAction(QIcon(QPixmap(SHOW_GRAPHS_ICON)),
tr("Show graphs"), this);
_showGraphsAction->setCheckable(true);
_showGraphsAction->setShortcut(SHOW_GRAPHS_SHORTCUT);
connect(_showGraphsAction, SIGNAL(triggered(bool)), this,
SLOT(showGraphs(bool)));
2016-04-05 09:10:19 +02:00
addAction(_showGraphsAction);
2016-09-19 00:56:10 +02:00
ag = new QActionGroup(this);
ag->setExclusive(true);
_distanceGraphAction = new QAction(tr("Distance"), this);
_distanceGraphAction->setCheckable(true);
_distanceGraphAction->setActionGroup(ag);
_distanceGraphAction->setShortcut(DISTANCE_GRAPH_SHORTCUT);
connect(_distanceGraphAction, SIGNAL(triggered()), this,
SLOT(setDistanceGraph()));
2016-10-17 23:14:07 +02:00
addAction(_distanceGraphAction);
2016-09-19 00:56:10 +02:00
_timeGraphAction = new QAction(tr("Time"), this);
_timeGraphAction->setCheckable(true);
_timeGraphAction->setActionGroup(ag);
_timeGraphAction->setShortcut(TIME_GRAPH_SHORTCUT);
connect(_timeGraphAction, SIGNAL(triggered()), this,
SLOT(setTimeGraph()));
2016-10-17 23:14:07 +02:00
addAction(_timeGraphAction);
_showGraphGridAction = new QAction(tr("Show grid"), this);
_showGraphGridAction->setCheckable(true);
connect(_showGraphGridAction, SIGNAL(triggered(bool)), this,
SLOT(showGraphGrids(bool)));
2016-09-19 00:56:10 +02:00
// Settings actions
_showToolbarsAction = new QAction(tr("Show toolbars"), this);
_showToolbarsAction->setCheckable(true);
connect(_showToolbarsAction, SIGNAL(triggered(bool)), this,
SLOT(showToolbars(bool)));
2016-09-19 00:56:10 +02:00
ag = new QActionGroup(this);
2015-12-19 20:23:07 +01:00
ag->setExclusive(true);
_totalTimeAction = new QAction(tr("Total time"), this);
_totalTimeAction->setCheckable(true);
_totalTimeAction->setActionGroup(ag);
connect(_totalTimeAction, SIGNAL(triggered()), this,
SLOT(setTotalTime()));
_movingTimeAction = new QAction(tr("Moving time"), this);
_movingTimeAction->setCheckable(true);
_movingTimeAction->setActionGroup(ag);
connect(_movingTimeAction, SIGNAL(triggered()), this,
SLOT(setMovingTime()));
ag = new QActionGroup(this);
ag->setExclusive(true);
2015-12-19 20:23:07 +01:00
_metricUnitsAction = new QAction(tr("Metric"), this);
_metricUnitsAction->setCheckable(true);
_metricUnitsAction->setActionGroup(ag);
connect(_metricUnitsAction, SIGNAL(triggered()), this,
SLOT(setMetricUnits()));
_imperialUnitsAction = new QAction(tr("Imperial"), this);
_imperialUnitsAction->setCheckable(true);
_imperialUnitsAction->setActionGroup(ag);
connect(_imperialUnitsAction, SIGNAL(triggered()), this,
SLOT(setImperialUnits()));
2016-04-05 09:10:19 +02:00
_fullscreenAction = new QAction(QIcon(QPixmap(FULLSCREEN_ICON)),
tr("Fullscreen mode"), this);
_fullscreenAction->setCheckable(true);
_fullscreenAction->setShortcut(FULLSCREEN_SHORTCUT);
2016-04-05 09:10:19 +02:00
connect(_fullscreenAction, SIGNAL(triggered(bool)), this,
SLOT(showFullscreen(bool)));
addAction(_fullscreenAction);
2016-12-06 01:48:26 +01:00
_openOptionsAction = new QAction(tr("Options..."), this);
_openOptionsAction->setMenuRole(QAction::PreferencesRole);
2016-12-06 01:48:26 +01:00
connect(_openOptionsAction, SIGNAL(triggered()), this,
SLOT(openOptions()));
2015-12-18 22:21:11 +01:00
// Navigation actions
_nextAction = new QAction(QIcon(QPixmap(NEXT_FILE_ICON)), tr("Next"), this);
_nextAction->setActionGroup(_navigationActionGroup);
connect(_nextAction, SIGNAL(triggered()), this, SLOT(next()));
_prevAction = new QAction(QIcon(QPixmap(PREV_FILE_ICON)), tr("Previous"),
this);
_prevAction->setActionGroup(_navigationActionGroup);
connect(_prevAction, SIGNAL(triggered()), this, SLOT(prev()));
_lastAction = new QAction(QIcon(QPixmap(LAST_FILE_ICON)), tr("Last"), this);
_lastAction->setActionGroup(_navigationActionGroup);
connect(_lastAction, SIGNAL(triggered()), this, SLOT(last()));
_firstAction = new QAction(QIcon(QPixmap(FIRST_FILE_ICON)), tr("First"),
this);
_firstAction->setActionGroup(_navigationActionGroup);
connect(_firstAction, SIGNAL(triggered()), this, SLOT(first()));
2015-10-05 01:43:48 +02:00
}
void GUI::createMenus()
{
2016-08-09 01:16:19 +02:00
QMenu *fileMenu = menuBar()->addMenu(tr("File"));
fileMenu->addAction(_openFileAction);
fileMenu->addSeparator();
fileMenu->addAction(_printFileAction);
fileMenu->addAction(_exportFileAction);
fileMenu->addSeparator();
fileMenu->addAction(_reloadFileAction);
fileMenu->addSeparator();
fileMenu->addAction(_closeFileAction);
2015-12-01 23:13:20 +01:00
#ifndef Q_OS_MAC
2016-08-09 01:16:19 +02:00
fileMenu->addSeparator();
fileMenu->addAction(_exitAction);
2015-12-01 23:13:20 +01:00
#endif // Q_OS_MAC
2015-10-05 01:43:48 +02:00
_mapMenu = menuBar()->addMenu(tr("Map"));
_mapMenu->addActions(_mapActions);
_mapsEnd = _mapMenu->addSeparator();
_mapMenu->addAction(_loadMapAction);
_mapMenu->addAction(_clearMapCacheAction);
_mapMenu->addSeparator();
_mapMenu->addAction(_showMapAction);
2015-11-23 02:37:08 +01:00
2016-09-19 00:56:10 +02:00
QMenu *graphMenu = menuBar()->addMenu(tr("Graph"));
graphMenu->addAction(_distanceGraphAction);
graphMenu->addAction(_timeGraphAction);
graphMenu->addSeparator();
2016-10-17 23:14:07 +02:00
graphMenu->addAction(_showGraphGridAction);
graphMenu->addSeparator();
2016-09-19 00:56:10 +02:00
graphMenu->addAction(_showGraphsAction);
2016-08-09 01:16:19 +02:00
QMenu *poiMenu = menuBar()->addMenu(tr("POI"));
_poiFilesMenu = poiMenu->addMenu(tr("POI files"));
_poiFilesMenu->addActions(_poiFilesActions);
2016-08-09 01:16:19 +02:00
poiMenu->addSeparator();
poiMenu->addAction(_openPOIAction);
poiMenu->addAction(_closePOIAction);
poiMenu->addSeparator();
poiMenu->addAction(_showPOILabelsAction);
poiMenu->addAction(_overlapPOIAction);
poiMenu->addSeparator();
poiMenu->addAction(_showPOIAction);
QMenu *dataMenu = menuBar()->addMenu(tr("Data"));
2016-08-09 10:47:49 +02:00
QMenu *displayMenu = dataMenu->addMenu(tr("Display"));
displayMenu->addAction(_showWaypointLabelsAction);
displayMenu->addAction(_showRouteWaypointsAction);
dataMenu->addSeparator();
2016-08-09 01:16:19 +02:00
dataMenu->addAction(_showTracksAction);
dataMenu->addAction(_showRoutesAction);
dataMenu->addAction(_showWaypointsAction);
QMenu *settingsMenu = menuBar()->addMenu(tr("Settings"));
QMenu *timeMenu = settingsMenu->addMenu(tr("Time"));
timeMenu->addAction(_totalTimeAction);
timeMenu->addAction(_movingTimeAction);
2016-08-09 01:16:19 +02:00
QMenu *unitsMenu = settingsMenu->addMenu(tr("Units"));
unitsMenu->addAction(_metricUnitsAction);
unitsMenu->addAction(_imperialUnitsAction);
settingsMenu->addSeparator();
settingsMenu->addAction(_showToolbarsAction);
settingsMenu->addAction(_fullscreenAction);
2016-12-06 01:48:26 +01:00
settingsMenu->addSeparator();
settingsMenu->addAction(_openOptionsAction);
2016-08-09 01:16:19 +02:00
QMenu *helpMenu = menuBar()->addMenu(tr("Help"));
helpMenu->addAction(_dataSourcesAction);
helpMenu->addAction(_keysAction);
helpMenu->addSeparator();
helpMenu->addAction(_aboutAction);
2015-10-05 01:43:48 +02:00
}
void GUI::createToolBars()
{
2016-05-14 09:28:56 +02:00
#ifdef Q_OS_MAC
setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
#endif // Q_OS_MAC
2015-10-05 01:43:48 +02:00
_fileToolBar = addToolBar(tr("File"));
_fileToolBar->addAction(_openFileAction);
2015-10-20 22:18:41 +02:00
_fileToolBar->addAction(_reloadFileAction);
2015-10-05 01:43:48 +02:00
_fileToolBar->addAction(_closeFileAction);
_fileToolBar->addAction(_printFileAction);
2015-10-05 01:43:48 +02:00
2015-11-23 02:37:08 +01:00
_showToolBar = addToolBar(tr("Show"));
_showToolBar->addAction(_showPOIAction);
_showToolBar->addAction(_showMapAction);
2016-09-19 00:56:10 +02:00
_showToolBar->addAction(_showGraphsAction);
2015-12-18 22:21:11 +01:00
_navigationToolBar = addToolBar(tr("Navigation"));
_navigationToolBar->addAction(_firstAction);
_navigationToolBar->addAction(_prevAction);
_navigationToolBar->addAction(_nextAction);
_navigationToolBar->addAction(_lastAction);
2015-10-05 01:43:48 +02:00
}
void GUI::createPathView()
2015-10-05 01:43:48 +02:00
{
_pathView = new PathView(_map, _poi, this);
2016-10-19 23:38:28 +02:00
_pathView->setSizePolicy(QSizePolicy(QSizePolicy::Ignored,
QSizePolicy::Expanding));
_pathView->setMinimumHeight(200);
#ifdef Q_OS_WIN32
_pathView->setFrameShape(QFrame::NoFrame);
#endif // Q_OS_WIN32
2015-10-05 01:43:48 +02:00
}
void GUI::createGraphTabs()
2015-10-05 01:43:48 +02:00
{
2016-10-19 23:38:28 +02:00
_graphTabWidget = new QTabWidget();
connect(_graphTabWidget, SIGNAL(currentChanged(int)), this,
2015-10-05 01:43:48 +02:00
SLOT(graphChanged(int)));
2016-10-19 23:38:28 +02:00
_graphTabWidget->setSizePolicy(QSizePolicy(QSizePolicy::Ignored,
QSizePolicy::Preferred));
_graphTabWidget->setMinimumHeight(200);
#ifdef Q_OS_WIN32
_graphTabWidget->setDocumentMode(true);
#endif // Q_OS_WIN32
2016-05-13 18:48:42 +02:00
2016-06-24 00:55:44 +02:00
_tabs.append(new ElevationGraph);
_tabs.append(new SpeedGraph);
_tabs.append(new HeartRateGraph);
2016-11-06 03:28:08 +01:00
_tabs.append(new CadenceGraph);
_tabs.append(new PowerGraph);
2016-06-24 00:55:44 +02:00
_tabs.append(new TemperatureGraph);
for (int i = 0; i < _tabs.count(); i++)
connect(_tabs.at(i), SIGNAL(sliderPositionChanged(qreal)), this,
SLOT(sliderPositionChanged(qreal)));
2015-10-05 01:43:48 +02:00
}
void GUI::createStatusBar()
{
2015-10-14 02:54:36 +02:00
_fileNameLabel = new QLabel();
_distanceLabel = new QLabel();
_timeLabel = new QLabel();
2015-10-14 02:54:36 +02:00
_distanceLabel->setAlignment(Qt::AlignHCenter);
_timeLabel->setAlignment(Qt::AlignHCenter);
statusBar()->addPermanentWidget(_fileNameLabel, 8);
statusBar()->addPermanentWidget(_distanceLabel, 1);
statusBar()->addPermanentWidget(_timeLabel, 1);
2015-10-05 01:43:48 +02:00
statusBar()->setSizeGripEnabled(false);
}
void GUI::about()
{
QMessageBox msgBox(this);
2017-06-26 00:16:38 +02:00
QUrl homepage(APP_HOMEPAGE);
msgBox.setWindowTitle(tr("About GPXSee"));
2017-02-02 20:06:17 +01:00
msgBox.setText("<h2>" + QString(APP_NAME) + "</h2><p><p>" + tr("Version ")
+ APP_VERSION + " (" + CPU_ARCH + ", Qt " + QT_VERSION_STR + ")</p>");
msgBox.setInformativeText("<table width=\"300\"><tr><td>"
+ tr("GPXSee is distributed under the terms of the GNU General Public "
"License version 3. For more info about GPXSee visit the project "
2017-06-26 00:16:38 +02:00
"homepage at ") + "<a href=\"" + homepage.toString() + "\">"
+ homepage.toString(QUrl::RemoveScheme).mid(2)
2017-02-02 20:06:17 +01:00
+ "</a>.</td></tr></table>");
QIcon icon = msgBox.windowIcon();
QSize size = icon.actualSize(QSize(64, 64));
msgBox.setIconPixmap(icon.pixmap(size));
msgBox.exec();
2015-10-05 01:43:48 +02:00
}
2015-10-21 01:09:17 +02:00
void GUI::keys()
{
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Keyboard controls"));
2017-02-02 20:06:17 +01:00
msgBox.setText("<h3>" + tr("Keyboard controls") + "</h3>");
msgBox.setInformativeText(
2017-04-05 22:53:25 +02:00
"<style>td {padding-right: 1.5em;}</style><div><table><tr><td>"
+ tr("Next file") + "</td><td><i>" + QKeySequence(NEXT_KEY).toString()
2017-02-02 20:06:17 +01:00
+ "</i></td></tr><tr><td>" + tr("Previous file")
+ "</td><td><i>" + QKeySequence(PREV_KEY).toString()
+ "</i></td></tr><tr><td>" + tr("First file") + "</td><td><i>"
+ QKeySequence(FIRST_KEY).toString() + "</i></td></tr><tr><td>"
+ tr("Last file") + "</td><td><i>" + QKeySequence(LAST_KEY).toString()
2017-04-05 22:53:25 +02:00
+ "</i></td></tr><tr><td>" + tr("Append file")
+ "</td><td><i>" + QKeySequence(MODIFIER).toString() + tr("Next/Previous")
+ "</i></td></tr><tr><td></td><td></td></tr><tr><td>" + tr("Next map")
+ "</td><td><i>" + NEXT_MAP_SHORTCUT.toString() + "</i></td></tr><tr><td>"
+ tr("Previous map") + "</td><td><i>" + PREV_MAP_SHORTCUT.toString()
+ "</i></td></tr><tr><td></td><td></td></tr><tr><td>" + tr("Zoom in")
+ "</td><td><i>" + QKeySequence(ZOOM_IN).toString()
+ "</i></td></tr><tr><td>" + tr("Zoom out") + "</td><td><i>"
+ QKeySequence(ZOOM_OUT).toString() + "</i></td></tr><tr><td>"
+ tr("Digital zoom") + "</td><td><i>" + QKeySequence(MODIFIER).toString()
+ tr("Zoom") + "</i></td></tr></table></div>");
2015-10-21 01:09:17 +02:00
msgBox.exec();
}
void GUI::dataSources()
{
QMessageBox msgBox(this);
msgBox.setWindowTitle(tr("Data sources"));
2017-02-02 20:06:17 +01:00
msgBox.setText("<h3>" + tr("Data sources") + "</h3>");
msgBox.setInformativeText(
"<h4>" + tr("Online maps") + "</h4><p>"
+ tr("Online map URLs are read on program startup from the "
"following file:")
+ "</p><p><code>" + USER_MAP_FILE + "</code></p><p>"
+ tr("The file format is one map entry per line, consisting of the map "
"name and tiles URL delimited by a TAB character. The tile X and Y "
"coordinates are replaced with $x and $y in the URL and the zoom "
"level is replaced with $z. An example map file could look like:")
+ "</p><p><code>Map1 http://tile.server.com/map/$z/$x/$y.png"
2017-02-02 20:06:17 +01:00
"<br/>Map2 http://mapserver.org/map/$z-$x-$y</code></p>"
2017-04-06 09:08:25 +02:00
+ "<h4>" + tr("Offline maps") + "</h4><p>"
+ tr("Offline maps are loaded on program startup from the following "
"directory:")
+ "</p><p><code>" + USER_MAP_DIR + "</code></p><p>"
+ tr("The expected structure is one map/atlas in a separate subdirectory."
" Supported map formats are OziExplorer maps and TrekBuddy maps/atlases"
" (tared and non-tared).") + "</p>"
2017-02-02 20:06:17 +01:00
+ "<h4>" + tr("POIs") + "</h4><p>"
+ tr("To make GPXSee load a POI file automatically on startup, add "
"the file to the following directory:")
2017-02-02 20:06:17 +01:00
+ "</p><p><code>" + USER_POI_DIR + "</code></p>"
);
msgBox.exec();
}
2015-10-05 01:43:48 +02:00
void GUI::openFile()
{
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open file"),
2017-07-27 19:47:46 +02:00
QString(), Data::formats());
2015-10-05 01:43:48 +02:00
QStringList list = files;
2015-10-07 01:30:03 +02:00
for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
2015-10-20 22:18:41 +02:00
openFile(*it);
2015-10-05 01:43:48 +02:00
}
bool GUI::openFile(const QString &fileName)
{
2016-03-23 20:56:39 +01:00
bool ret = true;
2015-10-20 22:18:41 +02:00
if (fileName.isEmpty() || _files.contains(fileName))
return false;
if (loadFile(fileName)) {
_files.append(fileName);
_browser->setCurrent(fileName);
_fileActionGroup->setEnabled(true);
2015-12-18 22:21:11 +01:00
_navigationActionGroup->setEnabled(true);
2016-10-28 19:29:42 +02:00
updateNavigationActions();
updateStatusBarInfo();
updateWindowTitle();
updateGraphTabs();
updatePathView();
} else {
2016-03-29 20:58:33 +02:00
if (_files.isEmpty())
_fileActionGroup->setEnabled(false);
2016-03-23 20:56:39 +01:00
ret = false;
}
2016-03-23 20:56:39 +01:00
return ret;
2015-10-20 22:18:41 +02:00
}
2015-10-05 01:43:48 +02:00
2015-10-20 22:18:41 +02:00
bool GUI::loadFile(const QString &fileName)
{
2016-10-23 11:09:20 +02:00
Data data;
2016-09-19 00:56:10 +02:00
QList<PathItem*> paths;
2015-10-17 12:08:30 +02:00
2016-10-23 11:09:20 +02:00
if (data.loadFile(fileName)) {
paths = _pathView->loadData(data);
2016-06-24 00:55:44 +02:00
for (int i = 0; i < _tabs.count(); i++)
2016-10-23 11:09:20 +02:00
_tabs.at(i)->loadData(data, paths);
2015-10-17 12:08:30 +02:00
2016-10-23 11:09:20 +02:00
for (int i = 0; i < data.tracks().count(); i++) {
_trackDistance += data.tracks().at(i)->distance();
_time += data.tracks().at(i)->time();
_movingTime += data.tracks().at(i)->movingTime();
2016-10-23 11:09:20 +02:00
const QDate &date = data.tracks().at(i)->date().date();
if (_dateRange.first.isNull() || _dateRange.first > date)
_dateRange.first = date;
if (_dateRange.second.isNull() || _dateRange.second < date)
_dateRange.second = date;
}
2016-10-23 11:09:20 +02:00
_trackCount += data.tracks().count();
2016-10-23 11:09:20 +02:00
for (int i = 0; i < data.routes().count(); i++)
_routeDistance += data.routes().at(i)->distance();
_routeCount += data.routes().count();
2016-10-23 11:09:20 +02:00
_waypointCount += data.waypoints().count();
2015-10-05 01:43:48 +02:00
if (_pathName.isNull()) {
if (data.tracks().count() == 1 && !data.routes().count())
_pathName = data.tracks().first()->name();
else if (data.routes().count() == 1 && !data.tracks().count())
_pathName = data.routes().first()->name();
} else
_pathName = QString();
2015-10-20 22:18:41 +02:00
return true;
} else {
2016-10-28 19:29:42 +02:00
updateNavigationActions();
updateStatusBarInfo();
updateWindowTitle();
updateGraphTabs();
updatePathView();
2016-10-29 12:22:28 +02:00
QString error = tr("Error loading data file:") + "\n\n"
+ fileName + "\n\n" + data.errorString();
2016-10-23 11:09:20 +02:00
if (data.errorLine())
2016-10-29 12:22:28 +02:00
error.append("\n" + tr("Line: %1").arg(data.errorLine()));
QMessageBox::critical(this, APP_NAME, error);
2015-10-20 22:18:41 +02:00
return false;
2015-10-05 01:43:48 +02:00
}
}
void GUI::openPOIFile()
{
QStringList files = QFileDialog::getOpenFileNames(this, tr("Open POI file"),
2017-07-27 19:47:46 +02:00
QString(), Data::formats());
QStringList list = files;
2015-10-05 01:43:48 +02:00
for (QStringList::Iterator it = list.begin(); it != list.end(); it++)
openPOIFile(*it);
}
bool GUI::openPOIFile(const QString &fileName)
{
2016-10-11 00:19:42 +02:00
if (fileName.isEmpty() || _poi->files().contains(fileName))
return false;
2016-10-09 23:46:30 +02:00
if (!_poi->loadFile(fileName)) {
2016-10-29 12:22:28 +02:00
QString error = tr("Error loading POI file:") + "\n\n"
+ fileName + "\n\n" + _poi->errorString();
2016-10-09 23:46:30 +02:00
if (_poi->errorLine())
2016-10-29 12:22:28 +02:00
error.append("\n" + tr("Line: %1").arg(_poi->errorLine()));
QMessageBox::critical(this, APP_NAME, error);
return false;
} else {
2016-10-08 14:53:10 +02:00
_pathView->showPOI(true);
_showPOIAction->setChecked(true);
2016-10-09 23:46:30 +02:00
QAction *action = createPOIFileAction(_poi->files().indexOf(fileName));
action->setChecked(true);
_poiFilesMenu->addAction(action);
return true;
2015-10-05 01:43:48 +02:00
}
}
void GUI::closePOIFiles()
{
_poiFilesMenu->clear();
for (int i = 0; i < _poiFilesActions.count(); i++)
delete _poiFilesActions[i];
_poiFilesActions.clear();
2016-10-09 23:46:30 +02:00
_poi->clear();
}
2016-12-06 01:48:26 +01:00
void GUI::openOptions()
{
Options options(_options);
2017-05-22 14:54:22 +02:00
bool reload = false;
2016-12-06 01:48:26 +01:00
OptionsDialog dialog(&options, this);
if (dialog.exec() != QDialog::Accepted)
return;
if (options.palette != _options.palette) {
_pathView->setPalette(options.palette);
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->setPalette(options.palette);
}
if (options.mapOpacity != _options.mapOpacity)
_pathView->setMapOpacity(options.mapOpacity);
2016-12-06 01:48:26 +01:00
if (options.trackWidth != _options.trackWidth)
_pathView->setTrackWidth(options.trackWidth);
if (options.routeWidth != _options.routeWidth)
_pathView->setRouteWidth(options.routeWidth);
if (options.trackStyle != _options.trackStyle)
_pathView->setTrackStyle(options.trackStyle);
if (options.routeStyle != _options.routeStyle)
_pathView->setRouteStyle(options.routeStyle);
if (options.pathAntiAliasing != _options.pathAntiAliasing)
_pathView->setRenderHint(QPainter::Antialiasing,
options.pathAntiAliasing);
if (options.graphWidth != _options.graphWidth)
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->setGraphWidth(options.graphWidth);
if (options.graphAntiAliasing != _options.graphAntiAliasing)
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->setRenderHint(QPainter::Antialiasing,
options.graphAntiAliasing);
2017-05-22 14:54:22 +02:00
if (options.elevationFilter != _options.elevationFilter) {
Track::setElevationFilter(options.elevationFilter);
reload = true;
}
if (options.speedFilter != _options.speedFilter) {
Track::setSpeedFilter(options.speedFilter);
reload = true;
}
if (options.heartRateFilter != _options.heartRateFilter) {
Track::setHeartRateFilter(options.heartRateFilter);
reload = true;
}
if (options.cadenceFilter != _options.cadenceFilter) {
Track::setCadenceFilter(options.cadenceFilter);
reload = true;
}
if (options.powerFilter != _options.powerFilter) {
Track::setPowerFilter(options.powerFilter);
reload = true;
}
if (options.outlierEliminate != _options.outlierEliminate) {
Track::setOutlierElimination(options.outlierEliminate);
reload = true;
}
if (options.pauseSpeed != _options.pauseSpeed) {
Track::setPauseSpeed(options.pauseSpeed);
reload = true;
}
if (options.pauseInterval != _options.pauseInterval) {
Track::setPauseInterval(options.pauseInterval);
reload = true;
}
2016-12-06 01:48:26 +01:00
if (options.poiRadius != _options.poiRadius)
_poi->setRadius(options.poiRadius);
if (options.useOpenGL != _options.useOpenGL) {
2016-12-06 01:48:26 +01:00
_pathView->useOpenGL(options.useOpenGL);
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->useOpenGL(options.useOpenGL);
}
if (options.pixmapCache != _options.pixmapCache)
2017-05-04 00:04:28 +02:00
QPixmapCache::setCacheLimit(options.pixmapCache * 1024);
2016-12-06 01:48:26 +01:00
2017-05-22 14:54:22 +02:00
if (reload)
reloadFile();
2016-12-06 01:48:26 +01:00
_options = options;
}
void GUI::printFile()
{
QPrinter printer(QPrinter::HighResolution);
QPrintDialog dialog(&printer, this);
if (dialog.exec() == QDialog::Accepted)
plot(&printer);
}
void GUI::exportFile()
2015-10-05 01:43:48 +02:00
{
2016-12-06 01:48:26 +01:00
ExportDialog dialog(&_export, this);
if (dialog.exec() != QDialog::Accepted)
return;
2015-10-05 01:43:48 +02:00
QPrinter printer(QPrinter::HighResolution);
2016-12-06 01:48:26 +01:00
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setCreator(QString(APP_NAME) + QString(" ")
+ QString(APP_VERSION));
printer.setResolution(_export.resolution);
2016-12-06 01:48:26 +01:00
printer.setOrientation(_export.orientation);
printer.setOutputFileName(_export.fileName);
printer.setPaperSize(_export.paperSize);
printer.setPageMargins(_export.margins.left(), _export.margins.top(),
_export.margins.right(), _export.margins.bottom(), QPrinter::Millimeter);
plot(&printer);
}
void GUI::plot(QPrinter *printer)
{
QPainter p(printer);
2016-05-12 09:03:05 +02:00
TrackInfo info;
2016-05-25 23:27:07 +02:00
qreal ih, gh, mh, ratio;
qreal d = distance();
qreal t = time();
qreal tm = movingTime();
if (!_pathName.isNull() && _options.printName)
info.insert(tr("Name"), _pathName);
if (_options.printItemCount) {
if (_trackCount > 1)
info.insert(tr("Tracks"), QString::number(_trackCount));
if (_routeCount > 1)
info.insert(tr("Routes"), QString::number(_routeCount));
if (_waypointCount > 2)
info.insert(tr("Waypoints"), QString::number(_waypointCount));
}
if (_dateRange.first.isValid() && _options.printDate) {
if (_dateRange.first == _dateRange.second) {
QString format = QLocale::system().dateFormat(QLocale::LongFormat);
info.insert(tr("Date"), _dateRange.first.toString(format));
} else {
QString format = QLocale::system().dateFormat(QLocale::ShortFormat);
info.insert(tr("Date"), QString("%1 - %2")
.arg(_dateRange.first.toString(format),
_dateRange.second.toString(format)));
}
}
if (d > 0 && _options.printDistance)
info.insert(tr("Distance"), Format::distance(d, units()));
if (t > 0 && _options.printTime)
2016-11-02 17:35:26 +01:00
info.insert(tr("Time"), Format::timeSpan(t));
if (tm > 0 && _options.printMovingTime)
info.insert(tr("Moving time"), Format::timeSpan(tm));
qreal fsr = 1085.0 / (qMax(printer->width(), printer->height())
/ (qreal)printer->resolution());
ratio = p.paintEngine()->paintDevice()->logicalDpiX() / fsr;
if (info.isEmpty()) {
2016-05-24 03:01:22 +02:00
ih = 0;
mh = 0;
2016-05-21 00:28:06 +02:00
} else {
2016-05-25 23:27:07 +02:00
ih = info.contentSize().height() * ratio;
2016-05-24 03:01:22 +02:00
mh = ih / 2;
info.plot(&p, QRectF(0, 0, printer->width(), ih), ratio);
}
if (_graphTabWidget->isVisible() && !_options.separateGraphPage) {
2016-05-24 03:01:22 +02:00
qreal r = (((qreal)(printer)->width()) / (qreal)(printer->height()));
gh = (printer->width() > printer->height())
? 0.15 * r * (printer->height() - ih - 2*mh)
: 0.15 * (printer->height() - ih - 2*mh);
GraphTab *gt = static_cast<GraphTab*>(_graphTabWidget->currentWidget());
gt->plot(&p, QRectF(0, printer->height() - gh, printer->width(), gh),
ratio);
2016-05-24 03:01:22 +02:00
} else
gh = 0;
2016-09-26 21:01:58 +02:00
_pathView->plot(&p, QRectF(0, ih + mh, printer->width(), printer->height()
- (ih + 2*mh + gh)), _options.hiresPrint);
if (_graphTabWidget->isVisible() && _options.separateGraphPage) {
printer->newPage();
int cnt = 0;
for (int i = 0; i < _tabs.size(); i++)
if (_tabs.at(i)->count())
cnt++;
qreal sp = ratio * 20;
gh = qMin((printer->height() - ((cnt - 1) * sp))/(qreal)cnt,
0.20 * printer->height());
qreal y = 0;
for (int i = 0; i < _tabs.size(); i++) {
if (_tabs.at(i)->count()) {
_tabs.at(i)->plot(&p, QRectF(0, y, printer->width(), gh),
ratio);
y += gh + sp;
}
}
}
2015-10-05 01:43:48 +02:00
}
2015-10-20 22:18:41 +02:00
void GUI::reloadFile()
{
_trackCount = 0;
_routeCount = 0;
_waypointCount = 0;
_trackDistance = 0;
_routeDistance = 0;
_time = 0;
_movingTime = 0;
_dateRange = DateRange(QDate(), QDate());
_pathName = QString();
2015-10-20 22:18:41 +02:00
2016-06-24 00:55:44 +02:00
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->clear();
2016-09-26 21:01:58 +02:00
_pathView->clear();
2015-10-20 22:18:41 +02:00
_sliderPos = 0;
2015-10-20 22:18:41 +02:00
for (int i = 0; i < _files.size(); i++) {
if (!loadFile(_files.at(i))) {
_files.removeAt(i);
i--;
}
}
updateStatusBarInfo();
2016-04-19 08:51:11 +02:00
updateWindowTitle();
2016-03-25 09:50:19 +01:00
updateGraphTabs();
2016-10-28 19:29:42 +02:00
updatePathView();
2015-10-20 22:18:41 +02:00
if (_files.isEmpty())
_fileActionGroup->setEnabled(false);
else
_browser->setCurrent(_files.last());
}
2016-03-23 20:56:39 +01:00
void GUI::closeFiles()
2015-10-05 01:43:48 +02:00
{
_trackCount = 0;
_routeCount = 0;
_waypointCount = 0;
_trackDistance = 0;
_routeDistance = 0;
_time = 0;
_movingTime = 0;
_dateRange = DateRange(QDate(), QDate());
_pathName = QString();
2015-10-12 01:12:12 +02:00
2016-03-30 20:50:51 +02:00
_sliderPos = 0;
2016-06-24 00:55:44 +02:00
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->clear();
2016-09-26 21:01:58 +02:00
_pathView->clear();
2015-10-20 22:18:41 +02:00
_files.clear();
2016-03-23 20:56:39 +01:00
}
void GUI::closeAll()
{
closeFiles();
2015-10-05 01:43:48 +02:00
_fileActionGroup->setEnabled(false);
2015-10-20 22:18:41 +02:00
updateStatusBarInfo();
2016-04-19 08:51:11 +02:00
updateWindowTitle();
2016-03-23 09:38:22 +01:00
updateGraphTabs();
2016-10-28 19:29:42 +02:00
updatePathView();
2015-10-05 01:43:48 +02:00
}
2016-10-17 23:14:07 +02:00
void GUI::showGraphs(bool show)
{
2016-10-17 23:14:07 +02:00
_graphTabWidget->setHidden(!show);
}
2016-10-17 23:14:07 +02:00
void GUI::showToolbars(bool show)
{
2016-10-17 23:14:07 +02:00
if (show) {
addToolBar(_fileToolBar);
addToolBar(_showToolBar);
addToolBar(_navigationToolBar);
_fileToolBar->show();
_showToolBar->show();
2015-12-18 22:21:11 +01:00
_navigationToolBar->show();
} else {
removeToolBar(_fileToolBar);
removeToolBar(_showToolBar);
2015-12-18 22:21:11 +01:00
removeToolBar(_navigationToolBar);
}
}
2016-10-17 23:14:07 +02:00
void GUI::showFullscreen(bool show)
2016-04-05 09:10:19 +02:00
{
2016-10-17 23:14:07 +02:00
if (show) {
2016-09-26 21:01:58 +02:00
_frameStyle = _pathView->frameStyle();
2016-04-05 09:10:19 +02:00
_showGraphs = _showGraphsAction->isChecked();
statusBar()->hide();
menuBar()->hide();
showToolbars(false);
showGraphs(false);
_showGraphsAction->setChecked(false);
2016-09-26 21:01:58 +02:00
_pathView->setFrameStyle(QFrame::NoFrame);
2016-04-05 09:10:19 +02:00
showFullScreen();
} else {
statusBar()->show();
menuBar()->show();
if (_showToolbarsAction->isChecked())
showToolbars(true);
_showGraphsAction->setChecked(_showGraphs);
if (_showGraphsAction->isEnabled())
showGraphs(_showGraphs);
2016-09-26 21:01:58 +02:00
_pathView->setFrameStyle(_frameStyle);
2016-04-05 09:10:19 +02:00
showNormal();
}
}
void GUI::showTracks(bool show)
2016-08-09 01:16:19 +02:00
{
2016-09-26 21:01:58 +02:00
_pathView->showTracks(show);
for (int i = 0; i < _tabs.size(); i++)
_tabs.at(i)->showTracks(show);
updateStatusBarInfo();
}
void GUI::showRoutes(bool show)
{
2016-09-26 21:01:58 +02:00
_pathView->showRoutes(show);
for (int i = 0; i < _tabs.size(); i++)
_tabs.at(i)->showRoutes(show);
updateStatusBarInfo();
2016-08-09 01:16:19 +02:00
}
2016-10-17 23:14:07 +02:00
void GUI::showGraphGrids(bool show)
{
for (int i = 0; i < _tabs.size(); i++)
_tabs.at(i)->showGrid(show);
}
void GUI::loadMap()
{
2017-05-16 12:59:59 +02:00
QString fileName = QFileDialog::getOpenFileName(this, tr("Open map file"),
2017-07-27 19:47:46 +02:00
QString(), MapList::formats());
if (fileName.isEmpty())
return;
2017-07-27 19:47:46 +02:00
int count = _ml->maps().count();
if (_ml->loadFile(fileName)) {
for (int i = count; i < _ml->maps().count(); i++) {
QAction *a = new QAction(_ml->maps().at(i)->name(), this);
a->setCheckable(true);
a->setActionGroup(_mapsActionGroup);
_mapsSignalMapper->setMapping(a, i);
connect(a, SIGNAL(triggered()), _mapsSignalMapper, SLOT(map()));
_mapActions.append(a);
_mapMenu->insertAction(_mapsEnd, a);
}
_showMapAction->setEnabled(true);
_clearMapCacheAction->setEnabled(true);
2017-07-27 19:47:46 +02:00
_mapActions.last()->activate(QAction::Trigger);
} else {
QString error = tr("Error loading map:") + "\n\n"
+ fileName + "\n\n" + _ml->errorString();
QMessageBox::critical(this, APP_NAME, error);
}
}
2016-04-01 19:25:34 +02:00
void GUI::clearMapCache()
{
_map->clearCache();
2016-09-26 21:01:58 +02:00
_pathView->redraw();
2016-04-01 19:25:34 +02:00
}
2015-10-20 22:18:41 +02:00
void GUI::updateStatusBarInfo()
2015-10-17 12:08:30 +02:00
{
2016-08-10 21:17:12 +02:00
if (_files.count() == 0)
2017-01-24 18:23:56 +01:00
_fileNameLabel->setText(tr("No files loaded"));
2016-08-10 21:17:12 +02:00
else if (_files.count() == 1)
2015-10-20 22:18:41 +02:00
_fileNameLabel->setText(_files.at(0));
2015-10-17 12:08:30 +02:00
else
2016-10-29 12:22:28 +02:00
_fileNameLabel->setText(tr("%n files", "", _files.count()));
2015-10-17 12:08:30 +02:00
if (distance() > 0)
_distanceLabel->setText(Format::distance(distance(), units()));
2016-08-10 21:17:12 +02:00
else
_distanceLabel->clear();
if (time() > 0) {
2017-02-12 20:11:36 +01:00
if (_movingTimeAction->isChecked()) {
_timeLabel->setText(Format::timeSpan(movingTime())
+ "<sub>M</sub>");
_timeLabel->setToolTip(Format::timeSpan(time()));
} else {
_timeLabel->setText(Format::timeSpan(time()));
_timeLabel->setToolTip(Format::timeSpan(movingTime())
+ "<sub>M</sub>");
2017-02-12 20:11:36 +01:00
}
} else {
2016-08-10 21:17:12 +02:00
_timeLabel->clear();
2017-02-12 20:11:36 +01:00
_timeLabel->setToolTip(QString());
}
2015-10-17 12:08:30 +02:00
}
2016-04-19 08:51:11 +02:00
void GUI::updateWindowTitle()
{
if (_files.count() == 1)
2017-02-02 20:06:17 +01:00
setWindowTitle(QFileInfo(_files.at(0)).fileName() + " - " + APP_NAME);
2016-04-19 08:51:11 +02:00
else
setWindowTitle(APP_NAME);
}
2015-11-23 02:37:08 +01:00
void GUI::mapChanged(int index)
{
_map = _ml->maps().at(index);
_pathView->setMap(_map);
2015-11-23 02:37:08 +01:00
}
2016-04-08 22:33:19 +02:00
void GUI::nextMap()
{
if (_ml->maps().count() < 2)
2016-04-08 22:33:19 +02:00
return;
int next = (_ml->maps().indexOf(_map) + 1) % _ml->maps().count();
2016-04-08 22:33:19 +02:00
_mapActions.at(next)->setChecked(true);
mapChanged(next);
}
void GUI::prevMap()
{
if (_ml->maps().count() < 2)
2016-04-08 22:33:19 +02:00
return;
int prev = (_ml->maps().indexOf(_map) + _ml->maps().count() - 1)
% _ml->maps().count();
2016-04-08 22:33:19 +02:00
_mapActions.at(prev)->setChecked(true);
mapChanged(prev);
}
void GUI::poiFileChecked(int index)
{
2016-10-09 23:46:30 +02:00
_poi->enableFile(_poi->files().at(index),
_poiFilesActions.at(index)->isChecked());
}
2016-03-30 20:50:51 +02:00
void GUI::sliderPositionChanged(qreal pos)
{
_sliderPos = pos;
}
2015-10-05 01:43:48 +02:00
void GUI::graphChanged(int index)
{
if (index < 0)
return;
GraphTab *gt = static_cast<GraphTab*>(_graphTabWidget->widget(index));
2016-08-09 01:16:19 +02:00
gt->setSliderPosition(_sliderPos);
2015-10-05 01:43:48 +02:00
}
2015-12-18 22:21:11 +01:00
void GUI::updateNavigationActions()
{
if (_browser->isLast()) {
_nextAction->setEnabled(false);
_lastAction->setEnabled(false);
} else {
_nextAction->setEnabled(true);
_lastAction->setEnabled(true);
}
if (_browser->isFirst()) {
_prevAction->setEnabled(false);
_firstAction->setEnabled(false);
} else {
_prevAction->setEnabled(true);
_firstAction->setEnabled(true);
}
}
2016-03-23 09:38:22 +01:00
void GUI::updateGraphTabs()
{
int index;
2016-06-24 00:55:44 +02:00
GraphTab *tab;
2016-05-13 18:48:42 +02:00
for (int i = 0; i < _tabs.size(); i++) {
2016-06-24 00:55:44 +02:00
tab = _tabs.at(i);
if (!tab->count() && (index = _graphTabWidget->indexOf(tab)) >= 0)
_graphTabWidget->removeTab(index);
2016-03-23 09:38:22 +01:00
}
2016-05-13 18:48:42 +02:00
for (int i = 0; i < _tabs.size(); i++) {
2016-06-24 00:55:44 +02:00
tab = _tabs.at(i);
if (tab->count() && _graphTabWidget->indexOf(tab) < 0)
_graphTabWidget->insertTab(i, tab, _tabs.at(i)->label());
}
if (_graphTabWidget->count()) {
2016-04-05 09:10:19 +02:00
if (_showGraphsAction->isChecked())
_graphTabWidget->setHidden(false);
2016-04-05 09:10:19 +02:00
_showGraphsAction->setEnabled(true);
} else {
_graphTabWidget->setHidden(true);
2016-04-05 09:10:19 +02:00
_showGraphsAction->setEnabled(false);
}
2016-03-23 09:38:22 +01:00
}
2016-10-28 19:29:42 +02:00
void GUI::updatePathView()
2016-03-25 09:50:19 +01:00
{
2016-09-26 21:01:58 +02:00
_pathView->setHidden(!(_pathView->trackCount() + _pathView->routeCount()
+ _pathView->waypointCount()));
2016-03-25 09:50:19 +01:00
}
void GUI::setTimeType(TimeType type)
{
for (int i = 0; i <_tabs.count(); i++)
_tabs.at(i)->setTimeType(type);
updateStatusBarInfo();
}
2016-09-21 23:48:11 +02:00
void GUI::setUnits(Units units)
2015-12-19 20:23:07 +01:00
{
2016-12-07 21:38:36 +01:00
_export.units = units;
_options.units = units;
2016-09-26 21:01:58 +02:00
_pathView->setUnits(units);
2016-06-24 00:55:44 +02:00
for (int i = 0; i <_tabs.count(); i++)
2016-09-21 23:48:11 +02:00
_tabs.at(i)->setUnits(units);
2015-12-19 20:23:07 +01:00
updateStatusBarInfo();
}
2016-09-21 23:48:11 +02:00
void GUI::setGraphType(GraphType type)
2015-12-19 20:23:07 +01:00
{
2016-09-21 23:48:11 +02:00
_sliderPos = 0;
2016-09-19 00:56:10 +02:00
2016-09-21 23:48:11 +02:00
for (int i = 0; i <_tabs.count(); i++) {
_tabs.at(i)->setGraphType(type);
_tabs.at(i)->setSliderPosition(0);
}
2016-09-19 00:56:10 +02:00
}
2015-12-18 22:21:11 +01:00
void GUI::next()
{
QString file = _browser->next();
if (file.isNull())
return;
2016-03-23 20:56:39 +01:00
closeFiles();
2015-12-18 22:21:11 +01:00
openFile(file);
}
void GUI::prev()
{
QString file = _browser->prev();
if (file.isNull())
return;
2016-03-23 20:56:39 +01:00
closeFiles();
2015-12-18 22:21:11 +01:00
openFile(file);
}
void GUI::last()
{
QString file = _browser->last();
if (file.isNull())
return;
2016-03-23 20:56:39 +01:00
closeFiles();
2015-12-18 22:21:11 +01:00
openFile(file);
}
void GUI::first()
{
QString file = _browser->first();
if (file.isNull())
return;
2016-03-23 20:56:39 +01:00
closeFiles();
2015-12-18 22:21:11 +01:00
openFile(file);
}
2015-10-05 01:43:48 +02:00
void GUI::keyPressEvent(QKeyEvent *event)
{
2015-10-20 22:18:41 +02:00
QString file;
2015-10-05 01:43:48 +02:00
2015-12-18 22:21:11 +01:00
switch (event->key()) {
case PREV_KEY:
file = _browser->prev();
break;
case NEXT_KEY:
file = _browser->next();
break;
case FIRST_KEY:
file = _browser->first();
break;
case LAST_KEY:
file = _browser->last();
break;
case Qt::Key_Escape:
if (_fullscreenAction->isChecked()) {
_fullscreenAction->setChecked(false);
showFullscreen(false);
return;
}
break;
2015-12-18 22:21:11 +01:00
}
2015-10-05 01:43:48 +02:00
2015-10-20 22:18:41 +02:00
if (!file.isNull()) {
if (!(event->modifiers() & MODIFIER))
2016-03-23 20:56:39 +01:00
closeFiles();
2015-10-20 22:18:41 +02:00
openFile(file);
return;
2015-10-20 22:18:41 +02:00
}
2017-04-05 22:53:25 +02:00
QMainWindow::keyPressEvent(event);
2015-10-05 01:43:48 +02:00
}
2016-04-26 09:39:16 +02:00
void GUI::closeEvent(QCloseEvent *event)
{
writeSettings();
event->accept();
}
2016-10-04 10:16:46 +02:00
void GUI::dragEnterEvent(QDragEnterEvent *event)
{
if (!event->mimeData()->hasUrls())
return;
if (event->proposedAction() != Qt::CopyAction)
return;
QList<QUrl> urls = event->mimeData()->urls();
for (int i = 0; i < urls.size(); i++)
if (!urls.at(i).isLocalFile())
return;
event->acceptProposedAction();
}
void GUI::dropEvent(QDropEvent *event)
{
QList<QUrl> urls = event->mimeData()->urls();
for (int i = 0; i < urls.size(); i++)
openFile(urls.at(i).toLocalFile());
}
2016-04-26 09:39:16 +02:00
void GUI::writeSettings()
{
2016-04-26 20:55:29 +02:00
QSettings settings(APP_NAME, APP_NAME);
2016-12-06 01:48:26 +01:00
settings.clear();
2016-04-26 09:39:16 +02:00
2016-04-28 08:49:06 +02:00
settings.beginGroup(WINDOW_SETTINGS_GROUP);
2016-12-06 01:48:26 +01:00
if (size() != WINDOW_SIZE_DEFAULT)
settings.setValue(WINDOW_SIZE_SETTING, size());
if (pos() != WINDOW_POS_DEFAULT)
settings.setValue(WINDOW_POS_SETTING, pos());
2016-04-26 09:39:16 +02:00
settings.endGroup();
2016-04-28 08:49:06 +02:00
settings.beginGroup(SETTINGS_SETTINGS_GROUP);
if ((_movingTimeAction->isChecked() ? Moving : Total) !=
TIME_TYPE_DEFAULT)
settings.setValue(TIME_TYPE_SETTING, _movingTimeAction->isChecked()
? Moving : Total);
2016-12-06 21:02:44 +01:00
if ((_imperialUnitsAction->isChecked() ? Imperial : Metric) !=
UNITS_DEFAULT)
settings.setValue(UNITS_SETTING, _imperialUnitsAction->isChecked()
2016-04-26 09:39:16 +02:00
? Imperial : Metric);
2016-12-06 01:48:26 +01:00
if (_showToolbarsAction->isChecked() != SHOW_TOOLBARS_DEFAULT)
settings.setValue(SHOW_TOOLBARS_SETTING,
_showToolbarsAction->isChecked());
2016-04-26 09:39:16 +02:00
settings.endGroup();
2016-04-26 20:55:29 +02:00
2016-04-28 08:49:06 +02:00
settings.beginGroup(MAP_SETTINGS_GROUP);
settings.setValue(CURRENT_MAP_SETTING, _map->name());
2016-12-06 01:48:26 +01:00
if (_showMapAction->isChecked() != SHOW_MAP_DEFAULT)
settings.setValue(SHOW_MAP_SETTING, _showMapAction->isChecked());
2016-04-26 20:55:29 +02:00
settings.endGroup();
2016-09-19 00:56:10 +02:00
settings.beginGroup(GRAPH_SETTINGS_GROUP);
2016-12-06 01:48:26 +01:00
if (_showGraphsAction->isChecked() != SHOW_GRAPHS_DEFAULT)
settings.setValue(SHOW_GRAPHS_SETTING, _showGraphsAction->isChecked());
if ((_timeGraphAction->isChecked() ? Time : Distance) != GRAPH_TYPE_DEFAULT)
settings.setValue(GRAPH_TYPE_SETTING, _timeGraphAction->isChecked()
? Time : Distance);
if (_showGraphGridAction->isChecked() != SHOW_GRAPH_GRIDS_DEFAULT)
settings.setValue(SHOW_GRAPH_GRIDS_SETTING,
_showGraphGridAction->isChecked());
2016-09-19 00:56:10 +02:00
settings.endGroup();
2016-04-28 08:49:06 +02:00
settings.beginGroup(POI_SETTINGS_GROUP);
2016-12-06 01:48:26 +01:00
if (_showPOIAction->isChecked() != SHOW_POI_DEFAULT)
settings.setValue(SHOW_POI_SETTING, _showPOIAction->isChecked());
if (_overlapPOIAction->isChecked() != OVERLAP_POI_DEFAULT)
settings.setValue(OVERLAP_POI_SETTING, _overlapPOIAction->isChecked());
2016-04-28 08:49:06 +02:00
2016-12-06 21:02:44 +01:00
int j = 0;
for (int i = 0; i < _poiFilesActions.count(); i++) {
2016-04-28 08:49:06 +02:00
if (!_poiFilesActions.at(i)->isChecked()) {
2016-12-06 21:02:44 +01:00
if (j == 0)
settings.beginWriteArray(DISABLED_POI_FILE_SETTINGS_PREFIX);
2016-04-28 08:49:06 +02:00
settings.setArrayIndex(j++);
2016-10-09 23:46:30 +02:00
settings.setValue(DISABLED_POI_FILE_SETTING, _poi->files().at(i));
2016-04-28 08:49:06 +02:00
}
}
2016-12-06 21:02:44 +01:00
if (j != 0)
settings.endArray();
2016-04-26 20:55:29 +02:00
settings.endGroup();
2016-08-09 01:16:19 +02:00
settings.beginGroup(DATA_SETTINGS_GROUP);
2016-12-06 01:48:26 +01:00
if (_showTracksAction->isChecked() != SHOW_TRACKS_DEFAULT)
settings.setValue(SHOW_TRACKS_SETTING, _showTracksAction->isChecked());
if (_showRoutesAction->isChecked() != SHOW_ROUTES_DEFAULT)
settings.setValue(SHOW_ROUTES_SETTING, _showRoutesAction->isChecked());
if (_showWaypointsAction->isChecked() != SHOW_WAYPOINTS_DEFAULT)
settings.setValue(SHOW_WAYPOINTS_SETTING,
_showWaypointsAction->isChecked());
if (_showWaypointLabelsAction->isChecked() != SHOW_WAYPOINT_LABELS_DEFAULT)
settings.setValue(SHOW_WAYPOINT_LABELS_SETTING,
_showWaypointLabelsAction->isChecked());
if (_showRouteWaypointsAction->isChecked() != SHOW_ROUTE_WAYPOINTS_DEFAULT)
settings.setValue(SHOW_ROUTE_WAYPOINTS_SETTING,
_showRouteWaypointsAction->isChecked());
settings.endGroup();
settings.beginGroup(EXPORT_SETTINGS_GROUP);
if (_export.orientation != PAPER_ORIENTATION_DEFAULT)
settings.setValue(PAPER_ORIENTATION_SETTING, _export.orientation);
if (_export.resolution != RESOLUTION_DEFAULT)
settings.setValue(RESOLUTION_SETTING, _export.resolution);
2016-12-06 01:48:26 +01:00
if (_export.paperSize != PAPER_SIZE_DEFAULT)
settings.setValue(PAPER_SIZE_SETTING, _export.paperSize);
if (_export.margins.left() != MARGIN_LEFT_DEFAULT)
settings.setValue(MARGIN_LEFT_SETTING, _export.margins.left());
if (_export.margins.top() != MARGIN_TOP_DEFAULT)
settings.setValue(MARGIN_TOP_SETTING, _export.margins.top());
if (_export.margins.right() != MARGIN_RIGHT_DEFAULT)
settings.setValue(MARGIN_RIGHT_SETTING, _export.margins.right());
if (_export.margins.bottom() != MARGIN_BOTTOM_DEFAULT)
settings.setValue(MARGIN_BOTTOM_SETTING, _export.margins.bottom());
if (_export.fileName != EXPORT_FILENAME_DEFAULT)
settings.setValue(EXPORT_FILENAME_SETTING, _export.fileName);
settings.endGroup();
2016-08-09 01:16:19 +02:00
2016-12-06 01:48:26 +01:00
settings.beginGroup(OPTIONS_SETTINGS_GROUP);
if (_options.palette.color() != PALETTE_COLOR_DEFAULT)
settings.setValue(PALETTE_COLOR_SETTING, _options.palette.color());
if (_options.palette.shift() != PALETTE_SHIFT_DEFAULT)
settings.setValue(PALETTE_SHIFT_SETTING, _options.palette.shift());
if (_options.mapOpacity != MAP_OPACITY_DEFAULT)
settings.setValue(MAP_OPACITY_SETTING, _options.mapOpacity);
2016-12-06 01:48:26 +01:00
if (_options.trackWidth != TRACK_WIDTH_DEFAULT)
settings.setValue(TRACK_WIDTH_SETTING, _options.trackWidth);
if (_options.routeWidth != ROUTE_WIDTH_DEFAULT)
settings.setValue(ROUTE_WIDTH_SETTING, _options.routeWidth);
if (_options.trackStyle != TRACK_STYLE_DEFAULT)
settings.setValue(TRACK_STYLE_SETTING, (int)_options.trackStyle);
if (_options.routeStyle != ROUTE_STYLE_DEFAULT)
settings.setValue(ROUTE_STYLE_SETTING, (int)_options.routeStyle);
if (_options.graphWidth != GRAPH_WIDTH_DEFAULT)
settings.setValue(GRAPH_WIDTH_SETTING, _options.graphWidth);
if (_options.pathAntiAliasing != PATH_AA_DEFAULT)
settings.setValue(PATH_AA_SETTING, _options.pathAntiAliasing);
if (_options.graphAntiAliasing != GRAPH_AA_DEFAULT)
settings.setValue(GRAPH_AA_SETTING, _options.graphAntiAliasing);
2017-05-22 14:54:22 +02:00
if (_options.elevationFilter != ELEVATION_FILTER_DEFAULT)
settings.setValue(ELEVATION_FILTER_SETTING, _options.elevationFilter);
if (_options.speedFilter != SPEED_FILTER_DEFAULT)
settings.setValue(SPEED_FILTER_SETTING, _options.speedFilter);
if (_options.heartRateFilter != HEARTRATE_FILTER_DEFAULT)
settings.setValue(HEARTRATE_FILTER_SETTING, _options.heartRateFilter);
if (_options.cadenceFilter != CADENCE_FILTER_DEFAULT)
settings.setValue(CADENCE_FILTER_SETTING, _options.cadenceFilter);
if (_options.powerFilter != POWER_FILTER_DEFAULT)
settings.setValue(POWER_FILTER_SETTING, _options.powerFilter);
if (_options.outlierEliminate != OUTLIER_ELIMINATE_DEFAULT)
settings.setValue(OUTLIER_ELIMINATE_SETTING, _options.outlierEliminate);
if (_options.pauseSpeed != PAUSE_SPEED_DEFAULT)
settings.setValue(PAUSE_SPEED_SETTING, _options.pauseSpeed);
if (_options.pauseInterval != PAUSE_INTERVAL_DEFAULT)
settings.setValue(PAUSE_INTERVAL_SETTING, _options.pauseInterval);
2016-12-06 01:48:26 +01:00
if (_options.poiRadius != POI_RADIUS_DEFAULT)
settings.setValue(POI_RADIUS_SETTING, _options.poiRadius);
if (_options.useOpenGL != USE_OPENGL_DEFAULT)
settings.setValue(USE_OPENGL_SETTING, _options.useOpenGL);
if (_options.pixmapCache != PIXMAP_CACHE_DEFAULT)
settings.setValue(PIXMAP_CACHE_SETTING, _options.pixmapCache);
if (_options.hiresPrint != HIRES_PRINT_DEFAULT)
settings.setValue(HIRES_PRINT_SETTING, _options.hiresPrint);
if (_options.printName != PRINT_NAME_DEFAULT)
settings.setValue(PRINT_NAME_SETTING, _options.printName);
if (_options.printDate != PRINT_DATE_DEFAULT)
settings.setValue(PRINT_DATE_SETTING, _options.printDate);
if (_options.printDistance != PRINT_DISTANCE_DEFAULT)
settings.setValue(PRINT_DISTANCE_SETTING, _options.printDistance);
if (_options.printTime != PRINT_TIME_DEFAULT)
settings.setValue(PRINT_TIME_SETTING, _options.printTime);
if (_options.printMovingTime != PRINT_MOVING_TIME_DEFAULT)
settings.setValue(PRINT_MOVING_TIME_SETTING, _options.printMovingTime);
if (_options.printItemCount != PRINT_ITEM_COUNT_DEFAULT)
settings.setValue(PRINT_ITEM_COUNT_SETTING, _options.printItemCount);
if (_options.separateGraphPage != SEPARATE_GRAPH_PAGE_DEFAULT)
settings.setValue(SEPARATE_GRAPH_PAGE_SETTING,
_options.separateGraphPage);
2016-08-09 01:16:19 +02:00
settings.endGroup();
2016-04-26 09:39:16 +02:00
}
void GUI::readSettings()
{
2016-04-26 20:55:29 +02:00
QSettings settings(APP_NAME, APP_NAME);
2016-04-26 09:39:16 +02:00
2016-04-28 08:49:06 +02:00
settings.beginGroup(WINDOW_SETTINGS_GROUP);
2016-12-06 01:48:26 +01:00
resize(settings.value(WINDOW_SIZE_SETTING, WINDOW_SIZE_DEFAULT).toSize());
move(settings.value(WINDOW_POS_SETTING, WINDOW_POS_DEFAULT).toPoint());
2016-04-26 09:39:16 +02:00
settings.endGroup();
2016-04-28 08:49:06 +02:00
settings.beginGroup(SETTINGS_SETTINGS_GROUP);
if (settings.value(TIME_TYPE_SETTING, TIME_TYPE_DEFAULT).toInt()
== Moving) {
setTimeType(Moving);
_movingTimeAction->setChecked(true);
} else {
setTimeType(Total);
_totalTimeAction->setChecked(true);
}
2016-12-06 01:48:26 +01:00
if (settings.value(UNITS_SETTING, UNITS_DEFAULT).toInt() == Imperial) {
2016-12-07 21:38:36 +01:00
setUnits(Imperial);
2016-04-26 09:39:16 +02:00
_imperialUnitsAction->setChecked(true);
2016-12-07 21:38:36 +01:00
} else {
setUnits(Metric);
2016-04-26 09:39:16 +02:00
_metricUnitsAction->setChecked(true);
2016-12-07 21:38:36 +01:00
}
2016-12-06 01:48:26 +01:00
if (!settings.value(SHOW_TOOLBARS_SETTING, SHOW_TOOLBARS_DEFAULT).toBool())
2016-04-26 09:39:16 +02:00
showToolbars(false);
2016-08-09 01:16:19 +02:00
else
2016-04-26 09:39:16 +02:00
_showToolbarsAction->setChecked(true);
settings.endGroup();
2016-04-26 20:55:29 +02:00
2016-04-28 08:49:06 +02:00
settings.beginGroup(MAP_SETTINGS_GROUP);
2016-12-06 01:48:26 +01:00
if (settings.value(SHOW_MAP_SETTING, SHOW_MAP_DEFAULT).toBool())
2016-04-26 20:55:29 +02:00
_showMapAction->setChecked(true);
if (_ml->maps().count()) {
2016-04-28 08:49:06 +02:00
int index = mapIndex(settings.value(CURRENT_MAP_SETTING).toString());
2016-04-26 20:55:29 +02:00
_mapActions.at(index)->setChecked(true);
_map = _ml->maps().at(index);
_pathView->setMap(_map);
}
2016-04-26 20:55:29 +02:00
settings.endGroup();
2016-09-19 00:56:10 +02:00
settings.beginGroup(GRAPH_SETTINGS_GROUP);
2016-12-06 01:48:26 +01:00
if (!settings.value(SHOW_GRAPHS_SETTING, SHOW_GRAPHS_DEFAULT).toBool())
2016-09-19 00:56:10 +02:00
showGraphs(false);
else
_showGraphsAction->setChecked(true);
2016-12-06 01:48:26 +01:00
if (settings.value(GRAPH_TYPE_SETTING, GRAPH_TYPE_DEFAULT).toInt()
== Time) {
2016-09-19 00:56:10 +02:00
setTimeGraph();
_timeGraphAction->setChecked(true);
} else
_distanceGraphAction->setChecked(true);
2016-12-06 01:48:26 +01:00
if (!settings.value(SHOW_GRAPH_GRIDS_SETTING, SHOW_GRAPH_GRIDS_DEFAULT)
.toBool())
2016-10-17 23:14:07 +02:00
showGraphGrids(false);
else
_showGraphGridAction->setChecked(true);
2016-09-19 00:56:10 +02:00
settings.endGroup();
2016-04-28 08:49:06 +02:00
settings.beginGroup(POI_SETTINGS_GROUP);
2016-12-06 01:48:26 +01:00
if (!settings.value(OVERLAP_POI_SETTING, OVERLAP_POI_DEFAULT).toBool())
2016-09-26 21:01:58 +02:00
_pathView->setPOIOverlap(false);
2016-08-09 01:16:19 +02:00
else
_overlapPOIAction->setChecked(true);
2016-12-06 01:48:26 +01:00
if (!settings.value(LABELS_POI_SETTING, LABELS_POI_DEFAULT).toBool())
2016-09-26 21:01:58 +02:00
_pathView->showPOILabels(false);
2016-08-09 01:16:19 +02:00
else
_showPOILabelsAction->setChecked(true);
2016-12-06 01:48:26 +01:00
if (settings.value(SHOW_POI_SETTING, SHOW_POI_DEFAULT).toBool())
2016-04-26 20:55:29 +02:00
_showPOIAction->setChecked(true);
2016-10-08 14:53:10 +02:00
else
_pathView->showPOI(false);
2016-04-28 08:49:06 +02:00
for (int i = 0; i < _poiFilesActions.count(); i++)
_poiFilesActions.at(i)->setChecked(true);
int size = settings.beginReadArray(DISABLED_POI_FILE_SETTINGS_PREFIX);
for (int i = 0; i < size; i++) {
settings.setArrayIndex(i);
2016-10-09 23:46:30 +02:00
int index = _poi->files().indexOf(settings.value(
2016-04-28 08:49:06 +02:00
DISABLED_POI_FILE_SETTING).toString());
if (index >= 0) {
2016-10-09 23:46:30 +02:00
_poi->enableFile(_poi->files().at(index), false);
2016-04-28 08:49:06 +02:00
_poiFilesActions.at(index)->setChecked(false);
}
}
settings.endArray();
2016-04-26 20:55:29 +02:00
settings.endGroup();
2016-08-09 01:16:19 +02:00
settings.beginGroup(DATA_SETTINGS_GROUP);
2016-12-06 01:48:26 +01:00
if (!settings.value(SHOW_TRACKS_SETTING, SHOW_TRACKS_DEFAULT).toBool()) {
2016-09-26 21:01:58 +02:00
_pathView->showTracks(false);
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->showTracks(false);
} else
2016-08-09 01:16:19 +02:00
_showTracksAction->setChecked(true);
2016-12-06 01:48:26 +01:00
if (!settings.value(SHOW_ROUTES_SETTING, SHOW_ROUTES_DEFAULT).toBool()) {
2016-09-26 21:01:58 +02:00
_pathView->showRoutes(false);
for (int i = 0; i < _tabs.count(); i++)
_tabs.at(i)->showRoutes(false);
} else
2016-08-09 01:16:19 +02:00
_showRoutesAction->setChecked(true);
2016-12-06 01:48:26 +01:00
if (!settings.value(SHOW_WAYPOINTS_SETTING, SHOW_WAYPOINTS_DEFAULT)
.toBool())
2016-09-26 21:01:58 +02:00
_pathView->showWaypoints(false);
2016-08-09 01:16:19 +02:00
else
_showWaypointsAction->setChecked(true);
2016-12-06 01:48:26 +01:00
if (!settings.value(SHOW_WAYPOINT_LABELS_SETTING,
SHOW_WAYPOINT_LABELS_DEFAULT).toBool())
2016-09-26 21:01:58 +02:00
_pathView->showWaypointLabels(false);
2016-08-09 01:16:19 +02:00
else
_showWaypointLabelsAction->setChecked(true);
2016-12-06 01:48:26 +01:00
if (!settings.value(SHOW_ROUTE_WAYPOINTS_SETTING,
SHOW_ROUTE_WAYPOINTS_SETTING).toBool())
2016-09-26 21:01:58 +02:00
_pathView->showRouteWaypoints(false);
2016-08-09 10:47:49 +02:00
else
_showRouteWaypointsAction->setChecked(true);
2016-08-09 01:16:19 +02:00
settings.endGroup();
2016-12-06 01:48:26 +01:00
settings.beginGroup(EXPORT_SETTINGS_GROUP);
_export.orientation = (QPrinter::Orientation) settings.value(
PAPER_ORIENTATION_SETTING, PAPER_ORIENTATION_DEFAULT).toInt();
_export.resolution = settings.value(RESOLUTION_SETTING, RESOLUTION_DEFAULT)
.toInt();
2016-12-06 01:48:26 +01:00
_export.paperSize = (QPrinter::PaperSize) settings.value(PAPER_SIZE_SETTING,
PAPER_SIZE_DEFAULT).toInt();
qreal ml = settings.value(MARGIN_LEFT_SETTING, MARGIN_LEFT_DEFAULT)
.toReal();
qreal mt = settings.value(MARGIN_TOP_SETTING, MARGIN_TOP_DEFAULT).toReal();
qreal mr = settings.value(MARGIN_RIGHT_SETTING, MARGIN_RIGHT_DEFAULT)
.toReal();
qreal mb = settings.value(MARGIN_BOTTOM_SETTING, MARGIN_BOTTOM_DEFAULT)
.toReal();
_export.margins = MarginsF(ml, mt, mr, mb);
_export.fileName = settings.value(EXPORT_FILENAME_SETTING,
EXPORT_FILENAME_DEFAULT).toString();
settings.endGroup();
settings.beginGroup(OPTIONS_SETTINGS_GROUP);
QColor pc = settings.value(PALETTE_COLOR_SETTING, PALETTE_COLOR_DEFAULT)
.value<QColor>();
qreal ps = settings.value(PALETTE_SHIFT_SETTING, PALETTE_SHIFT_DEFAULT)
.toDouble();
_options.palette = Palette(pc, ps);
_options.mapOpacity = settings.value(MAP_OPACITY_SETTING,
MAP_OPACITY_DEFAULT).toInt();
2016-12-06 01:48:26 +01:00
_options.trackWidth = settings.value(TRACK_WIDTH_SETTING,
TRACK_WIDTH_DEFAULT).toInt();
_options.routeWidth = settings.value(ROUTE_WIDTH_SETTING,
ROUTE_WIDTH_DEFAULT).toInt();
_options.trackStyle = (Qt::PenStyle) settings.value(TRACK_STYLE_SETTING,
(int)TRACK_STYLE_DEFAULT).toInt();
_options.routeStyle = (Qt::PenStyle) settings.value(ROUTE_STYLE_SETTING,
(int)ROUTE_STYLE_DEFAULT).toInt();
_options.pathAntiAliasing = settings.value(PATH_AA_SETTING, PATH_AA_DEFAULT)
.toBool();
2016-12-06 21:02:44 +01:00
_options.graphWidth = settings.value(GRAPH_WIDTH_SETTING,
GRAPH_WIDTH_DEFAULT).toInt();
2016-12-06 01:48:26 +01:00
_options.graphAntiAliasing = settings.value(GRAPH_AA_SETTING,
GRAPH_AA_DEFAULT).toBool();
2017-05-22 14:54:22 +02:00
_options.elevationFilter = settings.value(ELEVATION_FILTER_SETTING,
ELEVATION_FILTER_DEFAULT).toInt();
_options.speedFilter = settings.value(SPEED_FILTER_SETTING,
SPEED_FILTER_DEFAULT).toInt();
_options.heartRateFilter = settings.value(HEARTRATE_FILTER_SETTING,
HEARTRATE_FILTER_DEFAULT).toInt();
_options.cadenceFilter = settings.value(CADENCE_FILTER_SETTING,
CADENCE_FILTER_DEFAULT).toInt();
_options.powerFilter = settings.value(POWER_FILTER_SETTING,
POWER_FILTER_DEFAULT).toInt();
_options.outlierEliminate = settings.value(OUTLIER_ELIMINATE_SETTING,
OUTLIER_ELIMINATE_DEFAULT).toBool();
_options.pauseSpeed = settings.value(PAUSE_SPEED_SETTING,
PAUSE_SPEED_DEFAULT).toFloat();
_options.pauseInterval = settings.value(PAUSE_INTERVAL_SETTING,
PAUSE_INTERVAL_DEFAULT).toInt();
2016-12-06 01:48:26 +01:00
_options.poiRadius = settings.value(POI_RADIUS_SETTING, POI_RADIUS_DEFAULT)
.toInt();
_options.useOpenGL = settings.value(USE_OPENGL_SETTING, USE_OPENGL_DEFAULT)
.toBool();
_options.pixmapCache = settings.value(PIXMAP_CACHE_SETTING,
PIXMAP_CACHE_DEFAULT).toInt();
_options.hiresPrint = settings.value(HIRES_PRINT_SETTING,
HIRES_PRINT_DEFAULT).toBool();
_options.printName = settings.value(PRINT_NAME_SETTING, PRINT_NAME_DEFAULT)
.toBool();
_options.printDate = settings.value(PRINT_DATE_SETTING, PRINT_DATE_DEFAULT)
.toBool();
_options.printDistance = settings.value(PRINT_DISTANCE_SETTING,
PRINT_DISTANCE_DEFAULT).toBool();
_options.printTime = settings.value(PRINT_TIME_SETTING, PRINT_TIME_DEFAULT)
.toBool();
_options.printMovingTime = settings.value(PRINT_MOVING_TIME_SETTING,
PRINT_MOVING_TIME_DEFAULT).toBool();
_options.printItemCount = settings.value(PRINT_ITEM_COUNT_SETTING,
PRINT_ITEM_COUNT_DEFAULT).toBool();
_options.separateGraphPage = settings.value(SEPARATE_GRAPH_PAGE_SETTING,
SEPARATE_GRAPH_PAGE_DEFAULT).toBool();
2016-12-06 21:02:44 +01:00
_pathView->setPalette(_options.palette);
_pathView->setMapOpacity(_options.mapOpacity);
2016-12-06 21:02:44 +01:00
_pathView->setTrackWidth(_options.trackWidth);
_pathView->setRouteWidth(_options.routeWidth);
_pathView->setTrackStyle(_options.trackStyle);
_pathView->setRouteStyle(_options.routeStyle);
_pathView->setRenderHint(QPainter::Antialiasing, _options.pathAntiAliasing);
if (_options.useOpenGL)
_pathView->useOpenGL(true);
for (int i = 0; i < _tabs.count(); i++) {
_tabs.at(i)->setPalette(_options.palette);
_tabs.at(i)->setGraphWidth(_options.graphWidth);
_tabs.at(i)->setRenderHint(QPainter::Antialiasing,
_options.graphAntiAliasing);
if (_options.useOpenGL)
_tabs.at(i)->useOpenGL(true);
2016-12-06 21:02:44 +01:00
}
2017-05-22 14:54:22 +02:00
Track::setElevationFilter(_options.elevationFilter);
Track::setSpeedFilter(_options.speedFilter);
Track::setHeartRateFilter(_options.heartRateFilter);
Track::setCadenceFilter(_options.cadenceFilter);
Track::setPowerFilter(_options.powerFilter);
Track::setOutlierElimination(_options.outlierEliminate);
Track::setPauseSpeed(_options.pauseSpeed);
Track::setPauseInterval(_options.pauseInterval);
2016-12-06 21:02:44 +01:00
_poi->setRadius(_options.poiRadius);
QPixmapCache::setCacheLimit(_options.pixmapCache * 1024);
2016-12-06 01:48:26 +01:00
settings.endGroup();
2016-04-26 20:55:29 +02:00
}
int GUI::mapIndex(const QString &name)
{
for (int i = 0; i < _ml->maps().count(); i++)
if (_ml->maps().at(i)->name() == name)
2016-04-26 20:55:29 +02:00
return i;
return 0;
2016-04-26 09:39:16 +02:00
}
Units GUI::units() const
{
return _imperialUnitsAction->isChecked() ? Imperial : Metric;
}
2016-11-01 08:42:16 +01:00
qreal GUI::distance() const
{
qreal dist = 0;
if (_showTracksAction->isChecked())
dist += _trackDistance;
if (_showRoutesAction->isChecked())
dist += _routeDistance;
return dist;
}
2016-11-01 08:42:16 +01:00
qreal GUI::time() const
{
return (_showTracksAction->isChecked()) ? _time : 0;
}
qreal GUI::movingTime() const
{
return (_showTracksAction->isChecked()) ? _movingTime : 0;
}