diff --git a/src/config.h b/src/config.h index 52ecca13..ada15db4 100644 --- a/src/config.h +++ b/src/config.h @@ -7,6 +7,7 @@ #include #define APP_NAME "GPXSee" +#define APP_VENDOR "Martin Tuma" #define APP_HOMEPAGE "http://tumic.wz.cz/gpxsee" #define APP_VERSION "2.12" diff --git a/src/gui.cpp b/src/gui.cpp index c221f0e9..21f3770a 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -14,6 +14,7 @@ #include #include #include +#include #include "config.h" #include "icons.h" #include "keys.h" @@ -96,7 +97,7 @@ GUI::GUI(QWidget *parent) : QMainWindow(parent) updateGraphTabs(); updateTrackView(); - resize(600, 800); + readSettings(); } void GUI::loadMaps() @@ -272,14 +273,12 @@ void GUI::createActions() // Settings actions _showGraphsAction = new QAction(tr("Show graphs"), this); _showGraphsAction->setCheckable(true); - _showGraphsAction->setChecked(true); _showGraphsAction->setShortcut(SHOW_GRAPHS_SHORTCUT); connect(_showGraphsAction, SIGNAL(triggered(bool)), this, SLOT(showGraphs(bool))); addAction(_showGraphsAction); _showToolbarsAction = new QAction(tr("Show toolbars"), this); _showToolbarsAction->setCheckable(true); - _showToolbarsAction->setChecked(true); connect(_showToolbarsAction, SIGNAL(triggered(bool)), this, SLOT(showToolbars(bool))); QActionGroup *ag = new QActionGroup(this); @@ -287,7 +286,6 @@ void GUI::createActions() _metricUnitsAction = new QAction(tr("Metric"), this); _metricUnitsAction->setCheckable(true); _metricUnitsAction->setActionGroup(ag); - _metricUnitsAction->setChecked(true); connect(_metricUnitsAction, SIGNAL(triggered()), this, SLOT(setMetricUnits())); _imperialUnitsAction = new QAction(tr("Imperial"), this); @@ -1062,3 +1060,54 @@ void GUI::keyPressEvent(QKeyEvent *event) openFile(file); } } + +void GUI::closeEvent(QCloseEvent *event) +{ + writeSettings(); + event->accept(); +} + +void GUI::writeSettings() +{ + QSettings settings(APP_VENDOR, APP_NAME); + + settings.beginGroup("Window"); + settings.setValue("size", size()); + settings.setValue("pos", pos()); + settings.endGroup(); + + settings.beginGroup("Settings"); + settings.setValue("units", _imperialUnitsAction->isChecked() + ? Imperial : Metric); + settings.setValue("toolbar", _showToolbarsAction->isChecked()); + settings.setValue("graphs", _showGraphsAction->isChecked()); + settings.endGroup(); +} + +void GUI::readSettings() +{ + QSettings settings(APP_VENDOR, APP_NAME); + + settings.beginGroup("Window"); + resize(settings.value("size", QSize(600, 800)).toSize()); + move(settings.value("pos", QPoint(10, 10)).toPoint()); + settings.endGroup(); + + settings.beginGroup("Settings"); + if (settings.value("units", Metric) == Imperial) { + setImperialUnits(); + _imperialUnitsAction->setChecked(true); + } else + _metricUnitsAction->setChecked(true); + if (settings.value("toolbar", true) == false) { + showToolbars(false); + _showToolbarsAction->setChecked(false); + } else + _showToolbarsAction->setChecked(true); + if (settings.value("graphs", true) == false) { + showGraphs(false); + _showGraphsAction->setChecked(false); + } else + _showGraphsAction->setChecked(true); + settings.endGroup(); +} diff --git a/src/gui.h b/src/gui.h index 6c597d88..5f1da126 100644 --- a/src/gui.h +++ b/src/gui.h @@ -89,6 +89,10 @@ private: void updateTrackView(); void keyPressEvent(QKeyEvent * event); + void closeEvent(QCloseEvent *event); + + void readSettings(); + void writeSettings(); QMenu *_fileMenu; QMenu *_helpMenu;