Add a settings syste.

Adds a settings system so that things like window size and posaition can be saved and persisted cross uses also adds an overide to the close event tosave the settings on close.
This commit is contained in:
2025-11-08 14:32:02 +00:00
parent 1fb55049a8
commit 6d4750c324
2 changed files with 31 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ MainWindow::MainWindow(QWidget *parent)
createActions();
createMenus();
this->setWindowIcon(QIcon::fromTheme(QIcon::ThemeIcon::Computer));
initSettings();
}
MainWindow::~MainWindow()
@@ -47,3 +48,28 @@ void MainWindow::about()
QMessageBox::about(this, tr("About SOM"),
tr("<b>SOM</b> is a tool to manage and organise Sparkleverse OS building."));
}
void MainWindow::initSettings()
{
QSettings settings("SOM", "SOM");
if (!settings.contains("window/size")) {
settings.setValue("window/size", QSize(800, 600));
settings.setValue("window/position", (this->screen()->geometry().center() - this->frameGeometry().center()));
settings.sync();
}
resize(settings.value("window/size", QSize(800, 600)).toSize());
move(settings.value("window/position", QPoint(100, 100)).toPoint());
}
void MainWindow::saveSettings()
{
QSettings settings("SOM", "SOM");
settings.setValue("window/size", size());
settings.setValue("window/position", pos());
}
void MainWindow::closeEvent(QCloseEvent *event)
{
saveSettings();
QMainWindow::closeEvent(event);
}

View File

@@ -25,6 +25,8 @@ private:
Ui::MainWindow *ui;
void createActions();
void createMenus();
void initSettings();
void saveSettings();
QMenu *fileMenu;
QMenu *editMenu;
QMenu *helpMenu;
@@ -35,5 +37,8 @@ private:
private slots:
void about();
protected:
void closeEvent(QCloseEvent *event) override;
};
#endif // MAINWINDOW_H