Implement "Remember size and position" for main manager window
This commit is contained in:
@@ -120,6 +120,32 @@ VMManagerMainWindow(QWidget *parent)
|
||||
connect(this, &VMManagerMainWindow::darkModeUpdated, vmm, &VMManagerMain::onDarkModeUpdated);
|
||||
#endif
|
||||
|
||||
{
|
||||
auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General);
|
||||
this->ui->actionRemember_size_and_position->setChecked(!!config->getStringValue("window_remember").toInt());
|
||||
if (ui->actionRemember_size_and_position->isChecked()) {
|
||||
QStringList list = config->getStringValue("window_coordinates").split(',');
|
||||
for (auto& cur : list) {
|
||||
cur = cur.trimmed();
|
||||
}
|
||||
QRect geom;
|
||||
geom.setX(list[0].toInt());
|
||||
geom.setY(list[1].toInt());
|
||||
geom.setWidth(list[2].toInt());
|
||||
geom.setHeight(list[3].toInt());
|
||||
|
||||
setGeometry(geom);
|
||||
if (!!config->getStringValue("window_maximized").toInt()) {
|
||||
setWindowState(windowState() | Qt::WindowMaximized);
|
||||
}
|
||||
} else {
|
||||
config->setStringValue("window_remember", "");
|
||||
config->setStringValue("window_coordinates", "");
|
||||
config->setStringValue("window_maximized", "");
|
||||
}
|
||||
delete config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
VMManagerMainWindow::~
|
||||
@@ -167,6 +193,15 @@ VMManagerMainWindow::saveSettings() const
|
||||
const auto currentSelection = vmm->getCurrentSelection();
|
||||
const auto config = new VMManagerConfig(VMManagerConfig::ConfigType::General);
|
||||
config->setStringValue("last_selection", currentSelection);
|
||||
config->setStringValue("window_remember", QString::number(ui->actionRemember_size_and_position->isChecked()));
|
||||
if (ui->actionRemember_size_and_position->isChecked()) {
|
||||
config->setStringValue("window_coordinates", QString::asprintf("%i, %i, %i, %i", this->geometry().x(), this->geometry().y(), this->geometry().width(), this->geometry().height()));
|
||||
config->setStringValue("window_maximized", this->isMaximized() ? "1" : "");
|
||||
} else {
|
||||
config->setStringValue("window_remember", "");
|
||||
config->setStringValue("window_coordinates", "");
|
||||
config->setStringValue("window_maximized", "");
|
||||
}
|
||||
// Sometimes required to ensure the settings save before the app exits
|
||||
config->sync();
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
<string>&Tools</string>
|
||||
</property>
|
||||
<addaction name="actionPreferences"/>
|
||||
<addaction name="actionRemember_size_and_position"/>
|
||||
<addaction name="actionCheck_for_updates"/>
|
||||
</widget>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
@@ -186,6 +187,14 @@
|
||||
<string>New machine...</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRemember_size_and_position">
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>R&emember size && position</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionPreferences">
|
||||
<property name="text">
|
||||
<string>&Preferences...</string>
|
||||
|
||||
Reference in New Issue
Block a user