From a757c55870c8d29adf3180ff74eda15edd44cb5e Mon Sep 17 00:00:00 2001 From: con Date: Tue, 2 Nov 2010 13:41:03 +0100 Subject: [PATCH] Fixes restoration of main window geometry. We were handling it ourselves, now we let saveGeometry and saveState do its job. This also takes care of making the geometry valid for offscreen saved states. Task-number: QTCREATORBUG-1689 --- src/plugins/coreplugin/mainwindow.cpp | 42 +++++++++++++++++---------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/src/plugins/coreplugin/mainwindow.cpp b/src/plugins/coreplugin/mainwindow.cpp index 053cfe8ba9f..773190073ad 100644 --- a/src/plugins/coreplugin/mainwindow.cpp +++ b/src/plugins/coreplugin/mainwindow.cpp @@ -1153,8 +1153,12 @@ void MainWindow::aboutToShutdown() } static const char *settingsGroup = "MainWindow"; -static const char *geometryKey = "Geometry"; static const char *colorKey = "Color"; +static const char *windowGeometryKey = "WindowGeometry"; +static const char *windowStateKey = "WindowState"; + +// TODO compat for <= 2.1, remove later +static const char *geometryKey = "Geometry"; static const char *maxKey = "Maximized"; static const char *fullScreenKey = "FullScreen"; @@ -1172,15 +1176,27 @@ void MainWindow::readSettings() QColor(Utils::StyleHelper::DEFAULT_BASE_COLOR)).value()); } - const QVariant geom = m_settings->value(QLatin1String(geometryKey)); - if (geom.isValid()) { - setGeometry(geom.toRect()); + // TODO compat for <= 2.1, remove later + if (m_settings->contains(QLatin1String(geometryKey))) { + const QVariant geom = m_settings->value(QLatin1String(geometryKey)); + if (geom.isValid()) { + setGeometry(geom.toRect()); + } else { + resize(1024, 700); + } + if (m_settings->value(QLatin1String(maxKey), false).toBool()) + setWindowState(Qt::WindowMaximized); + setFullScreen(m_settings->value(QLatin1String(fullScreenKey), false).toBool()); + + m_settings->remove(QLatin1String(geometryKey)); + m_settings->remove(QLatin1String(maxKey)); + m_settings->remove(QLatin1String(fullScreenKey)); } else { - resize(1024, 700); + if (!restoreGeometry(m_settings->value(QLatin1String(windowGeometryKey)).toByteArray())) { + resize(1024, 700); + } + restoreState(m_settings->value(QLatin1String(windowStateKey)).toByteArray()); } - if (m_settings->value(QLatin1String(maxKey), false).toBool()) - setWindowState(Qt::WindowMaximized); - setFullScreen(m_settings->value(QLatin1String(fullScreenKey), false).toBool()); m_settings->endGroup(); @@ -1196,14 +1212,8 @@ void MainWindow::writeSettings() if (!(m_overrideColor.isValid() && Utils::StyleHelper::baseColor() == m_overrideColor)) m_settings->setValue(QLatin1String(colorKey), Utils::StyleHelper::requestedBaseColor()); - if (windowState() & (Qt::WindowMaximized | Qt::WindowFullScreen)) { - m_settings->setValue(QLatin1String(maxKey), (bool) (windowState() & Qt::WindowMaximized)); - m_settings->setValue(QLatin1String(fullScreenKey), (bool) (windowState() & Qt::WindowFullScreen)); - } else { - m_settings->setValue(QLatin1String(maxKey), false); - m_settings->setValue(QLatin1String(fullScreenKey), false); - m_settings->setValue(QLatin1String(geometryKey), geometry()); - } + m_settings->setValue(QLatin1String(windowGeometryKey), saveGeometry()); + m_settings->setValue(QLatin1String(windowStateKey), saveState()); m_settings->endGroup();