Forráskód Böngészése

Persist window settings in system

DJWarmonger 6 éve
szülő
commit
37bebd8f62
2 módosított fájl, 24 hozzáadás és 0 törlés
  1. 22 0
      launcher/mainwindow_moc.cpp
  2. 2 0
      launcher/mainwindow_moc.h

+ 22 - 0
launcher/mainwindow_moc.cpp

@@ -45,6 +45,23 @@ MainWindow::MainWindow(QWidget * parent)
 	load(); // load FS before UI
 
 	ui->setupUi(this);
+
+	//load window settings
+	QSettings s(Ui::teamName, Ui::appName);
+
+	auto size = s.value("MainWindow/Size").toSize();
+	if (size.isValid())
+	{
+		resize(size);
+	}
+	auto position = s.value("MainWindow/Position").toPoint();
+	if (!position.isNull())
+	{
+		move(position);
+	}
+
+	//set default margins
+
 	auto width = ui->startGameTitle->fontMetrics().boundingRect(ui->startGameTitle->text()).width();
 	if(ui->startGameButton->iconSize().width() < width)
 	{
@@ -67,6 +84,11 @@ MainWindow::MainWindow(QWidget * parent)
 
 MainWindow::~MainWindow()
 {
+	//save window settings
+	QSettings s(Ui::teamName, Ui::appName);
+	s.setValue("MainWindow/Size", size());
+	s.setValue("MainWindow/Position", pos());
+
 	delete ui;
 }
 

+ 2 - 0
launcher/mainwindow_moc.h

@@ -14,6 +14,8 @@
 namespace Ui
 {
 class MainWindow;
+const QString teamName = "VCMI Team";
+const QString appName = "VCMI Launcher";
 }
 
 class QTableWidgetItem;