From c058d5dd96ca614ecfdf524f77f519fadef91041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Zieli=C5=84ski?= Date: Thu, 8 Sep 2022 15:54:06 +0200 Subject: [PATCH] Save / load preferred editor size --- mapeditor/mainwindow.cpp | 29 +++++++++++++++++++++++++++++ mapeditor/mainwindow.h | 13 +++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/mapeditor/mainwindow.cpp b/mapeditor/mainwindow.cpp index 2d553d836..a3e145217 100644 --- a/mapeditor/mainwindow.cpp +++ b/mapeditor/mainwindow.cpp @@ -51,17 +51,45 @@ QPixmap pixmapFromJson(const QJsonValue &val) void init() { + loadDLLClasses(); const_cast(CGI)->setFromLib(); logGlobal->info("Initializing VCMI_Lib"); } +void MainWindow::loadUserSettings() +{ + //load window settings + QSettings s(Ui::teamName, Ui::appName); + + auto size = s.value(mainWindowSizeSetting).toSize(); + if (size.isValid()) + { + resize(size); + } + auto position = s.value(mainWindowPositionSetting).toPoint(); + if (!position.isNull()) + { + move(position); + } + + //TODO: New map / random template settings +} + +void MainWindow::saveUserSettings() +{ + QSettings s(Ui::teamName, Ui::appName); + s.setValue(mainWindowSizeSetting, size()); + s.setValue(mainWindowPositionSetting, pos()); +} + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), controller(this) { ui->setupUi(this); + loadUserSettings(); //For example window size setTitle(); // Set current working dir to executable folder. @@ -141,6 +169,7 @@ MainWindow::MainWindow(QWidget *parent) : MainWindow::~MainWindow() { + saveUserSettings(); //save window size etc. delete ui; } diff --git a/mapeditor/mainwindow.h b/mapeditor/mainwindow.h index 7db66b847..31b4d4993 100644 --- a/mapeditor/mainwindow.h +++ b/mapeditor/mainwindow.h @@ -12,14 +12,20 @@ class CMap; class ObjectBrowser; class CGObjectInstance; -namespace Ui { -class MainWindow; +namespace Ui +{ + class MainWindow; + const QString teamName = "VCMI Team"; + const QString appName = "VCMI Map Editor"; } class MainWindow : public QMainWindow { Q_OBJECT + const QString mainWindowSizeSetting = "MainWindow/Size"; + const QString mainWindowPositionSetting = "MainWindow/Position"; + public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow(); @@ -108,6 +114,9 @@ private: void changeBrushState(int idx); void setTitle(); + void loadUserSettings(); + void saveUserSettings(); + private: Ui::MainWindow *ui; ObjectBrowser * objectBrowser = nullptr;