Qt: Fix display window geometry not saving

This commit is contained in:
Connor McLaughlin 2020-10-03 12:10:11 +10:00
parent e2a4129c30
commit f7de39f3d0
2 changed files with 25 additions and 0 deletions

View File

@ -97,6 +97,7 @@ QtDisplayWidget* MainWindow::createDisplay(QThread* worker_thread, const QString
}
else if (!render_to_main)
{
restoreDisplayWindowGeometryFromConfig();
m_display_widget->showNormal();
}
else
@ -149,6 +150,7 @@ QtDisplayWidget* MainWindow::updateDisplay(QThread* worker_thread, bool fullscre
}
else if (!render_to_main)
{
restoreDisplayWindowGeometryFromConfig();
m_display_widget->showNormal();
}
else
@ -195,6 +197,10 @@ void MainWindow::destroyDisplayWidget()
switchToGameListView();
m_ui.mainContainer->removeWidget(m_display_widget);
}
else if (!m_display_widget->isFullScreen())
{
saveDisplayWindowGeometryToConfig();
}
delete m_display_widget;
m_display_widget = nullptr;
@ -943,6 +949,23 @@ void MainWindow::restoreStateFromConfig()
}
}
void MainWindow::saveDisplayWindowGeometryToConfig()
{
const QByteArray geometry = m_display_widget->saveGeometry();
const QByteArray geometry_b64 = geometry.toBase64();
const std::string old_geometry_b64 = m_host_interface->GetStringSettingValue("UI", "DisplayWindowGeometry");
if (old_geometry_b64 != geometry_b64.constData())
m_host_interface->SetStringSettingValue("UI", "DisplayWindowGeometry", geometry_b64.constData());
}
void MainWindow::restoreDisplayWindowGeometryFromConfig()
{
const std::string geometry_b64 = m_host_interface->GetStringSettingValue("UI", "DisplayWindowGeometry");
const QByteArray geometry = QByteArray::fromBase64(QByteArray::fromStdString(geometry_b64));
if (!geometry.isEmpty())
m_display_widget->restoreGeometry(geometry);
}
SettingsDialog* MainWindow::getSettingsDialog()
{
if (!m_settings_dialog)

View File

@ -98,6 +98,8 @@ private:
void switchToEmulationView();
void saveStateToConfig();
void restoreStateFromConfig();
void saveDisplayWindowGeometryToConfig();
void restoreDisplayWindowGeometryFromConfig();
void destroyDisplayWidget();
SettingsDialog* getSettingsDialog();
void doSettings(SettingsDialog::Category category = SettingsDialog::Category::Count);