Fix a window placement bug.

Placing Eliot on a secondary monitor, and restarting it later when the
monitor is unplugged, made the window invisible (it was still at the
old position, thus off screen).
This commit is contained in:
Olivier Teulière 2012-11-06 22:02:53 +01:00
parent f267b045b6
commit b0a9f44ab7
2 changed files with 22 additions and 2 deletions

View file

@ -25,6 +25,7 @@
#include <QtGui/QWidget>
#include <QtGui/QVBoxLayout>
#include <QtGui/QCloseEvent>
#include <QtGui/QDesktopWidget>
#include <QtCore/QSettings>
#include "aux_window.h"
@ -107,7 +108,16 @@ void AuxWindow::readSettings()
QSize size = settings.value("size").toSize();
if (size.isValid())
resize(size);
move(settings.value("pos", QPoint(200, 200)).toPoint());
const QRect &desktopRect = QApplication::desktop()->screenGeometry();
QPoint point = settings.value("pos", QPoint(20, 20)).toPoint();
// If the position was saved when an external monitor was plugged, and
// is restored when the monitor is not there anymore, the window could
// be off screen...
if (point.x() < 0 || point.x() > desktopRect.right())
point.setX(20);
if (point.y() < 0 || point.y() > desktopRect.bottom())
point.setY(20);
move(point);
settings.endGroup();
}

View file

@ -30,6 +30,7 @@
#include <QtGui/QPrinter>
#include <QtGui/QPainter>
#include <QtGui/QDesktopServices>
#include <QtGui/QDesktopWidget>
#include <QtCore/QSettings>
#include <QtCore/QUrl>
@ -616,7 +617,16 @@ void MainWindow::readSettings()
QSize size = settings.value("size").toSize();
if (size.isValid())
resize(size);
move(settings.value("pos", QPoint(200, 200)).toPoint());
const QRect &desktopRect = QApplication::desktop()->screenGeometry();
QPoint point = settings.value("pos", QPoint(20, 20)).toPoint();
// If the position was saved when an external monitor was plugged, and
// is restored when the monitor is not there anymore, the window could
// be off screen...
if (point.x() < 0 || point.x() > desktopRect.right())
point.setX(20);
if (point.y() < 0 || point.y() > desktopRect.bottom())
point.setY(20);
move(point);
m_ui.splitterHoriz->restoreState(settings.value("splitterHoriz").toByteArray());
m_ui.splitterVert->restoreState(settings.value("splitterVert").toByteArray());
settings.endGroup();