1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00

Save / load preferred editor size

This commit is contained in:
Tomasz Zieliński 2022-09-08 15:54:06 +02:00
parent aa1cf5e16c
commit c058d5dd96
2 changed files with 40 additions and 2 deletions

View File

@ -51,17 +51,45 @@ QPixmap pixmapFromJson(const QJsonValue &val)
void init() void init()
{ {
loadDLLClasses(); loadDLLClasses();
const_cast<CGameInfo*>(CGI)->setFromLib(); const_cast<CGameInfo*>(CGI)->setFromLib();
logGlobal->info("Initializing VCMI_Lib"); 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) : MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent), QMainWindow(parent),
ui(new Ui::MainWindow), ui(new Ui::MainWindow),
controller(this) controller(this)
{ {
ui->setupUi(this); ui->setupUi(this);
loadUserSettings(); //For example window size
setTitle(); setTitle();
// Set current working dir to executable folder. // Set current working dir to executable folder.
@ -141,6 +169,7 @@ MainWindow::MainWindow(QWidget *parent) :
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
saveUserSettings(); //save window size etc.
delete ui; delete ui;
} }

View File

@ -12,14 +12,20 @@ class CMap;
class ObjectBrowser; class ObjectBrowser;
class CGObjectInstance; class CGObjectInstance;
namespace Ui { namespace Ui
class MainWindow; {
class MainWindow;
const QString teamName = "VCMI Team";
const QString appName = "VCMI Map Editor";
} }
class MainWindow : public QMainWindow class MainWindow : public QMainWindow
{ {
Q_OBJECT Q_OBJECT
const QString mainWindowSizeSetting = "MainWindow/Size";
const QString mainWindowPositionSetting = "MainWindow/Position";
public: public:
explicit MainWindow(QWidget *parent = nullptr); explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
@ -108,6 +114,9 @@ private:
void changeBrushState(int idx); void changeBrushState(int idx);
void setTitle(); void setTitle();
void loadUserSettings();
void saveUserSettings();
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
ObjectBrowser * objectBrowser = nullptr; ObjectBrowser * objectBrowser = nullptr;