Skip to content

Commit 4c9f2db

Browse files
committed
Added save and restore of window size and position
1 parent 885b461 commit 4c9f2db

File tree

5 files changed

+42
-8
lines changed

5 files changed

+42
-8
lines changed

UI/mainwindow.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@
2929
#include <QStyle>
3030
#include <utils.h>
3131

32-
#define MAJOR_VERSION 0
33-
#define MINOR_VERSION 0
34-
#define BUGFIX_VERSION 2
3532

3633
MainWindow::MainWindow(QWidget *parent) :
3734
QMainWindow(parent),
@@ -92,6 +89,7 @@ MainWindow::MainWindow(QWidget *parent) :
9289

9390
QMenu* menu_Add = new QMenu("Add", this);
9491
ui->menuComponents->addMenu(menu_Add);
92+
ui->nodalView->setMenuAdd(menu_Add);
9593

9694
// Create commponents buttons and actions
9795
for(QString component : componentList)
@@ -265,6 +263,9 @@ void MainWindow::closeEvent(QCloseEvent *event)
265263
{
266264
save();
267265
}
266+
QSettings settings;
267+
settings.setValue("geometry", saveGeometry());
268+
settings.setValue("windowState", saveState());
268269
event->accept();
269270
}
270271
else
@@ -273,6 +274,13 @@ void MainWindow::closeEvent(QCloseEvent *event)
273274
}
274275
}
275276

277+
void MainWindow::readSettings()
278+
{
279+
QSettings settings;
280+
restoreGeometry(settings.value("geometry").toByteArray());
281+
restoreState(settings.value("windowState").toByteArray());
282+
}
283+
276284
void MainWindow::mousePressEvent(QMouseEvent *event)
277285
{
278286
QWidget* focusedWidget = qApp->focusWidget();
@@ -355,10 +363,8 @@ void MainWindow::open()
355363

356364
void MainWindow::about()
357365
{
358-
QString version = QString::number(MAJOR_VERSION) + "." + QString::number(MINOR_VERSION) + "." + QString::number(BUGFIX_VERSION);
359-
360-
QMessageBox box(QMessageBox::NoIcon, "About Sound Generator",
361-
"Alpha " + version + "<br><br>Copyright 2019 Pelletier Benoit<br><br>\
366+
QMessageBox box(QMessageBox::NoIcon, "About " + Utils::AppName,
367+
"Alpha " + Utils::GetAppVersion() + "<br><br>Copyright 2019 " + Utils::CompanyName + "<br><br>\
362368
This software is free and under <a style=\"color:#00FFFF\" href=\"https://www.gnu.org/licenses/gpl-3.0.txt\">GPLv3</a> license. <br>This software is dynamically linked to Qt5.<br>\
363369
The source code of Qt SDK can be found <a style=\"color:#00FFFF\" href=\"http://download.qt.io/official_releases/qt/5.12/5.12.2/\">here</a>.<br>\
364370
The full text for the GPLv3 license was distributed as a text file with this software.<br><br> \
@@ -457,5 +463,5 @@ QMessageBox::StandardButton MainWindow::askSaveChanges(QString action)
457463

458464
void MainWindow::updateWindowTitle()
459465
{
460-
setWindowTitle("Sound Generator [" + m_windowTitle + (m_dirty ? " *" : "") + "]");
466+
setWindowTitle(Utils::AppName + " [" + m_windowTitle + (m_dirty ? " *" : "") + "]");
461467
}

UI/mainwindow.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class MainWindow : public QMainWindow
4545
QString fileName() { return m_fileName; }
4646
void setFileName(QString fileName);
4747

48+
void readSettings();
49+
50+
4851
protected:
4952
virtual void closeEvent(QCloseEvent* event) override;
5053
virtual void mousePressEvent(QMouseEvent* event) override;

main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
#include "mainwindow.h"
22
#include <QApplication>
3+
#include "utils.h"
34

45
int main(int argc, char *argv[])
56
{
67
QApplication a(argc, argv);
8+
9+
QCoreApplication::setOrganizationName(Utils::CompanyName);
10+
QCoreApplication::setApplicationName(Utils::AppName);
11+
QCoreApplication::setApplicationVersion(Utils::GetAppVersion());
12+
713
MainWindow w;
14+
w.readSettings();
815
w.show();
916

1017
return a.exec();

utils.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
#include <QString>
2626
#include <QJsonArray>
2727

28+
29+
#define MAJOR_VERSION 0
30+
#define MINOR_VERSION 0
31+
#define BUGFIX_VERSION 3
32+
33+
const QString Utils::AppName = "Sound Generator";
34+
const QString Utils::CompanyName = "Benoit Pelletier";
35+
2836
qreal Utils::SmoothDamp(qreal current,
2937
qreal target,
3038
qreal& currentVelocity,
@@ -88,3 +96,8 @@ void Utils::ErrorMsg(int code, QString msg)
8896
QMessageBox::critical(qApp->activeWindow(), "Load Error", "[Error #" + QString::number(code) + "] " + msg);
8997
}
9098

99+
QString Utils::GetAppVersion()
100+
{
101+
return QString::number(MAJOR_VERSION) + "." + QString::number(MINOR_VERSION) + "." + QString::number(BUGFIX_VERSION);
102+
}
103+

utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class Utils
5656
static bool CheckJsonValue(QJsonObject& object, QString name, QJsonValue::Type type, int startErrorCode);
5757

5858
static void ErrorMsg(int code, QString msg);
59+
60+
static QString GetAppVersion();
61+
62+
static const QString AppName;
63+
static const QString CompanyName;
5964
};
6065

6166

0 commit comments

Comments
 (0)