Skip to content
39 changes: 14 additions & 25 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,9 +686,6 @@ void MainWindow::saveWidgetState(QWidget* w, QDomElement& de)
de.setAttribute("height", normalGeometry.height());
}




void MainWindow::restoreWidgetState(QWidget* w, const QDomElement& de)
{
// TODO: Only use one of these
Expand All @@ -697,44 +694,36 @@ void MainWindow::restoreWidgetState(QWidget* w, const QDomElement& de)
{
// Fall back on parent
win = qobject_cast<SubWindow*>(w->parentWidget());
if (!win)
{
// Still could not find the window - soft fail
return;
}

// Still could not find the window - soft fail
if (!win) { return; }
}

const auto normalGeometry = QRect {
const auto normalGeometry = QRect{
de.attribute("x").toInt(),
de.attribute("y").toInt(),
de.attribute("width").toInt(),
de.attribute("height").toInt()
de.attribute("height").toInt(),
};

if (normalGeometry.isValid())
{
// first restore the window, as attempting to resize a maximized window causes graphics glitching
win->setWindowState(win->windowState() & ~(Qt::WindowMaximized | Qt::WindowMinimized));
// First restore the window, as attempting to resize a maximized window can cause graphical glitches.
win->setWindowState(win->windowState() & ~(Qt::WindowMaximized | Qt::WindowMinimized));

win->setGeometry(normalGeometry);
// Then resize it. Previously present validity checks are not needed anymore and taken into account by
// `QWidget::setGeometry`.
win->setGeometry(normalGeometry);

// set the window to its correct minimized/maximized/restored state
Qt::WindowStates winState = win->windowState();
winState = de.attribute("maximized").toInt()
? (winState | Qt::WindowMaximized)
: (winState & ~Qt::WindowMaximized);
win->setWindowState(winState);
}
// Set the window to its correct "maximized?" state.
auto winState = win->windowState();
winState.setFlag(Qt::WindowMaximized, de.attribute("maximized").toInt());
win->setWindowState(winState);

if (const auto visible = de.attribute("visible"); !visible.isEmpty())
{
win->setVisible(visible.toInt());
}
}




void MainWindow::emptySlot()
{
}
Expand Down
Loading