1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2025-01-18 19:52:09 +01:00

Properly save/restore window layout + fullscreen switch normalization

Fixes #183
This commit is contained in:
Martin Tůma 2019-02-18 22:33:18 +01:00
parent 1f5922685b
commit 8807c37770
3 changed files with 17 additions and 18 deletions

View File

@ -578,6 +578,7 @@ void GUI::createToolBars()
#endif // Q_OS_MAC #endif // Q_OS_MAC
_fileToolBar = addToolBar(tr("File")); _fileToolBar = addToolBar(tr("File"));
_fileToolBar->setObjectName("File");
_fileToolBar->setIconSize(iconSize); _fileToolBar->setIconSize(iconSize);
_fileToolBar->addAction(_openFileAction); _fileToolBar->addAction(_openFileAction);
_fileToolBar->addAction(_reloadFileAction); _fileToolBar->addAction(_reloadFileAction);
@ -585,12 +586,14 @@ void GUI::createToolBars()
_fileToolBar->addAction(_printFileAction); _fileToolBar->addAction(_printFileAction);
_showToolBar = addToolBar(tr("Show")); _showToolBar = addToolBar(tr("Show"));
_showToolBar->setObjectName("Show");
_showToolBar->setIconSize(iconSize); _showToolBar->setIconSize(iconSize);
_showToolBar->addAction(_showPOIAction); _showToolBar->addAction(_showPOIAction);
_showToolBar->addAction(_showMapAction); _showToolBar->addAction(_showMapAction);
_showToolBar->addAction(_showGraphsAction); _showToolBar->addAction(_showGraphsAction);
_navigationToolBar = addToolBar(tr("Navigation")); _navigationToolBar = addToolBar(tr("Navigation"));
_navigationToolBar->setObjectName("Navigation");
_navigationToolBar->setIconSize(iconSize); _navigationToolBar->setIconSize(iconSize);
_navigationToolBar->addAction(_firstAction); _navigationToolBar->addAction(_firstAction);
_navigationToolBar->addAction(_prevAction); _navigationToolBar->addAction(_prevAction);
@ -1238,13 +1241,11 @@ void GUI::showGraphs(bool show)
void GUI::showToolbars(bool show) void GUI::showToolbars(bool show)
{ {
if (show) { if (show) {
addToolBar(_fileToolBar); Q_ASSERT(!_windowStates.isEmpty());
addToolBar(_showToolBar); restoreState(_windowStates.last());
addToolBar(_navigationToolBar); _windowStates.pop_back();
_fileToolBar->show();
_showToolBar->show();
_navigationToolBar->show();
} else { } else {
_windowStates.append(saveState());
removeToolBar(_fileToolBar); removeToolBar(_fileToolBar);
removeToolBar(_showToolBar); removeToolBar(_showToolBar);
removeToolBar(_navigationToolBar); removeToolBar(_navigationToolBar);
@ -1255,26 +1256,16 @@ void GUI::showFullscreen(bool show)
{ {
if (show) { if (show) {
_frameStyle = _mapView->frameStyle(); _frameStyle = _mapView->frameStyle();
_showGraphs = _showGraphsAction->isChecked();
statusBar()->hide(); statusBar()->hide();
menuBar()->hide(); menuBar()->hide();
showToolbars(false); showToolbars(false);
showGraphs(false);
_showGraphsAction->setChecked(false);
_mapView->setFrameStyle(QFrame::NoFrame); _mapView->setFrameStyle(QFrame::NoFrame);
showFullScreen(); showFullScreen();
} else { } else {
statusBar()->show(); statusBar()->show();
menuBar()->show(); menuBar()->show();
if (_showToolbarsAction->isChecked()) showToolbars(true);
showToolbars(true);
_showGraphsAction->setChecked(_showGraphs);
if (_showGraphsAction->isEnabled())
showGraphs(_showGraphs);
_mapView->setFrameStyle(_frameStyle); _mapView->setFrameStyle(_frameStyle);
showNormal(); showNormal();
} }
} }
@ -1645,6 +1636,8 @@ void GUI::dropEvent(QDropEvent *event)
QList<QUrl> urls = event->mimeData()->urls(); QList<QUrl> urls = event->mimeData()->urls();
for (int i = 0; i < urls.size(); i++) for (int i = 0; i < urls.size(); i++)
openFile(urls.at(i).toLocalFile()); openFile(urls.at(i).toLocalFile());
event->acceptProposedAction();
} }
void GUI::writeSettings() void GUI::writeSettings()
@ -1657,6 +1650,10 @@ void GUI::writeSettings()
settings.setValue(WINDOW_SIZE_SETTING, size()); settings.setValue(WINDOW_SIZE_SETTING, size());
if (pos() != WINDOW_POS_DEFAULT) if (pos() != WINDOW_POS_DEFAULT)
settings.setValue(WINDOW_POS_SETTING, pos()); settings.setValue(WINDOW_POS_SETTING, pos());
if (_windowStates.isEmpty())
settings.setValue(WINDOW_STATE_SETTING, saveState());
else
settings.setValue(WINDOW_STATE_SETTING, _windowStates.first());
settings.endGroup(); settings.endGroup();
settings.beginGroup(SETTINGS_SETTINGS_GROUP); settings.beginGroup(SETTINGS_SETTINGS_GROUP);
@ -1866,6 +1863,7 @@ void GUI::readSettings()
settings.beginGroup(WINDOW_SETTINGS_GROUP); settings.beginGroup(WINDOW_SETTINGS_GROUP);
resize(settings.value(WINDOW_SIZE_SETTING, WINDOW_SIZE_DEFAULT).toSize()); resize(settings.value(WINDOW_SIZE_SETTING, WINDOW_SIZE_DEFAULT).toSize());
move(settings.value(WINDOW_POS_SETTING, WINDOW_POS_DEFAULT).toPoint()); move(settings.value(WINDOW_POS_SETTING, WINDOW_POS_DEFAULT).toPoint());
restoreState(settings.value(WINDOW_STATE_SETTING).toByteArray());
settings.endGroup(); settings.endGroup();
settings.beginGroup(SETTINGS_SETTINGS_GROUP); settings.beginGroup(SETTINGS_SETTINGS_GROUP);

View File

@ -226,8 +226,8 @@ private:
qreal _sliderPos; qreal _sliderPos;
QList<QByteArray> _windowStates;
int _frameStyle; int _frameStyle;
bool _showGraphs;
Export _export; Export _export;
Options _options; Options _options;

View File

@ -9,6 +9,7 @@
#define WINDOW_SIZE_DEFAULT QSize(600, 800) #define WINDOW_SIZE_DEFAULT QSize(600, 800)
#define WINDOW_POS_SETTING "pos" #define WINDOW_POS_SETTING "pos"
#define WINDOW_POS_DEFAULT QPoint(10, 10) #define WINDOW_POS_DEFAULT QPoint(10, 10)
#define WINDOW_STATE_SETTING "state"
#define SETTINGS_SETTINGS_GROUP "Settings" #define SETTINGS_SETTINGS_GROUP "Settings"
#define TIME_TYPE_SETTING "timeType" #define TIME_TYPE_SETTING "timeType"