Add support for saving window state
This commit is contained in:
parent
b6b9181c66
commit
73e0629ab4
@ -27,6 +27,7 @@ int run(int argc, char **args) {
|
|||||||
MainWindow w(argProfilePath);
|
MainWindow w(argProfilePath);
|
||||||
app.setApplicationName(w.windowTitle());
|
app.setApplicationName(w.windowTitle());
|
||||||
w.show();
|
w.show();
|
||||||
|
QObject::connect(&app, SIGNAL(aboutToQuit()), &w, SLOT(onExit()));
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QMenuBar>
|
#include <QMenuBar>
|
||||||
#include <QPluginLoader>
|
#include <QPluginLoader>
|
||||||
|
#include <QSettings>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
@ -58,6 +59,7 @@ MainWindow::MainWindow(QString profilePath) {
|
|||||||
|
|
||||||
setupMenu();
|
setupMenu();
|
||||||
setupProjectExplorer();
|
setupProjectExplorer();
|
||||||
|
statusBar(); // setup status bar
|
||||||
|
|
||||||
loadPlugins(profile);
|
loadPlugins(profile);
|
||||||
|
|
||||||
@ -143,6 +145,7 @@ void MainWindow::setupProjectExplorer() {
|
|||||||
// setup dock
|
// setup dock
|
||||||
auto dock = new QDockWidget(tr("Project"), this);
|
auto dock = new QDockWidget(tr("Project"), this);
|
||||||
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
|
||||||
|
dock->setObjectName("Project Explorer");
|
||||||
addDockWidget(Qt::LeftDockWidgetArea, dock);
|
addDockWidget(Qt::LeftDockWidgetArea, dock);
|
||||||
resizeDocks({dock}, {(int) (width() * 0.25)}, Qt::Horizontal);
|
resizeDocks({dock}, {(int) (width() * 0.25)}, Qt::Horizontal);
|
||||||
|
|
||||||
@ -194,6 +197,13 @@ QAction *MainWindow::addAction(QMenu *menu, QString text, QString toolTip,
|
|||||||
|
|
||||||
int MainWindow::readState(QString path) {
|
int MainWindow::readState(QString path) {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
QSettings settings("Drinking Tea", "nostalgia-studio");
|
||||||
|
settings.beginGroup("MainWindow");
|
||||||
|
restoreGeometry(settings.value("geometry").toByteArray());
|
||||||
|
restoreState(settings.value("windowState").toByteArray());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
QString json;
|
QString json;
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
err |= !file.open(QIODevice::ReadOnly);
|
err |= !file.open(QIODevice::ReadOnly);
|
||||||
@ -206,6 +216,13 @@ int MainWindow::readState(QString path) {
|
|||||||
|
|
||||||
int MainWindow::writeState(QString path) {
|
int MainWindow::writeState(QString path) {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
QSettings settings("Drinking Tea", "nostalgia-studio");
|
||||||
|
settings.beginGroup("MainWindow");
|
||||||
|
settings.setValue("geometry", saveGeometry());
|
||||||
|
settings.setValue("windowState", saveState());
|
||||||
|
settings.endGroup();
|
||||||
|
|
||||||
QString json;
|
QString json;
|
||||||
err |= writeJson(&json, &m_state);
|
err |= writeJson(&json, &m_state);
|
||||||
QFile file(path);
|
QFile file(path);
|
||||||
@ -256,6 +273,10 @@ int MainWindow::closeProject() {
|
|||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::onExit() {
|
||||||
|
writeState();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// private slots
|
// private slots
|
||||||
|
|
||||||
|
@ -125,6 +125,9 @@ class MainWindow: public QMainWindow {
|
|||||||
|
|
||||||
int closeProject();
|
int closeProject();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void onExit();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
int openProject();
|
int openProject();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user