save window state on app close

This commit is contained in:
garak 2018-10-12 21:03:52 -04:00
parent 761c25ee4c
commit 25bc9e44ce
4 changed files with 45 additions and 15 deletions

View file

@ -16,7 +16,7 @@
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<widget class="QSplitter" name="splitter_main">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -197,7 +197,7 @@
<number>6</number>
</property>
<item row="0" column="0">
<widget class="QSplitter" name="splitter_2">
<widget class="QSplitter" name="splitter_map">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -482,8 +482,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>481</width>
<height>606</height>
<width>545</width>
<height>587</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_8">
@ -797,8 +797,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>70</height>
<width>256</width>
<height>74</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
@ -909,8 +909,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>304</width>
<height>372</height>
<width>222</width>
<height>353</height>
</rect>
</property>
<property name="sizePolicy">
@ -1201,7 +1201,7 @@
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QSplitter" name="splitter_3">
<widget class="QSplitter" name="splitter_events">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@ -1226,8 +1226,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>385</width>
<height>655</height>
<width>371</width>
<height>643</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
@ -1405,7 +1405,7 @@
<x>0</x>
<y>0</y>
<width>428</width>
<height>586</height>
<height>578</height>
</rect>
</property>
<property name="sizePolicy">
@ -2024,8 +2024,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>829</width>
<height>552</height>
<width>818</width>
<height>539</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_14">
@ -2197,7 +2197,7 @@
<x>0</x>
<y>0</y>
<width>1117</width>
<height>20</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">

View file

@ -8,6 +8,7 @@
#include <QGraphicsPixmapItem>
#include <QGraphicsItemGroup>
#include <QGraphicsSceneMouseEvent>
#include <QCloseEvent>
#include <QAbstractItemModel>
#include "project.h"
#include "map.h"
@ -133,6 +134,8 @@ private slots:
void on_lineEdit_filterBox_textChanged(const QString &arg1);
void closeEvent(QCloseEvent *);
private:
Ui::MainWindow *ui;
TilesetEditor *tilesetEditor = nullptr;
@ -175,6 +178,7 @@ private:
void initMiscHeapObjects();
void initMapSortOrder();
void loadUserSettings();
void restoreWindowState();
void openRecentProject();
void updateTilesetEditor();

View file

@ -43,6 +43,7 @@ MainWindow::MainWindow(QWidget *parent) :
this->initMiscHeapObjects();
this->initMapSortOrder();
this->openRecentProject();
this->restoreWindowState();
on_toolButton_Paint_clicked();
}
@ -167,6 +168,18 @@ void MainWindow::loadUserSettings() {
mapSortOrder = static_cast<MapSortOrder>(settings.value("map_sort_order").toInt());
}
void MainWindow::restoreWindowState() {
QSettings settings;
if (settings.contains("saved_widget_geometry")) {
this->restoreGeometry(settings.value("window_geometry").toByteArray());
this->restoreState(settings.value("window_state").toByteArray());
this->ui->splitter_map->restoreState(settings.value("map_splitter_state").toByteArray());
this->ui->splitter_events->restoreState(settings.value("events_splitter_state").toByteArray());
this->ui->splitter_main->restoreState(settings.value("main_splitter_state").toByteArray());
}
}
void MainWindow::openRecentProject() {
QSettings settings;
QString key = "recent_projects";
@ -1406,6 +1419,17 @@ void MainWindow::on_actionTileset_Editor_triggered()
}
}
void MainWindow::closeEvent(QCloseEvent *event) {
QSettings settings;
settings.setValue("saved_widget_geometry", "true");
settings.setValue("window_geometry", this->saveGeometry());
settings.setValue("window_state", this->saveState());
settings.setValue("map_splitter_state", this->ui->splitter_map->saveState());
settings.setValue("events_splitter_state", this->ui->splitter_events->saveState());
settings.setValue("main_splitter_state", this->ui->splitter_main->saveState());
QMainWindow::closeEvent(event);
}
void MainWindow::onTilesetEditorClosed() {
if (this->tilesetEditor) {
delete this->tilesetEditor;

View file

@ -1,5 +1,7 @@
#include "connectionpixmapitem.h"
#include <cmath>
void ConnectionPixmapItem::render(qreal opacity) {
QPixmap newPixmap = this->basePixmap.copy(0, 0, this->basePixmap.width(), this->basePixmap.height());
if (opacity < 1) {