This repository was archived by the owner on Jan 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
113 lines (89 loc) · 3.13 KB
/
Copy pathmainwindow.cpp
File metadata and controls
113 lines (89 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "mainwindow.h"
// Qt headers
#include <QCoreApplication>
#include <QSettings>
/* ===================== */
/* Main Window */
/* ===================== */
// --- Default constructor --- //
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
// Window title details
this->setWindowTitle(QCoreApplication::applicationName() + " v" + QCoreApplication::applicationVersion());
this->setWindowIcon(QIcon("application.ico"));
// Create user interface
this->setUserInterface();
// Set window
QSettings settings;
this->restoreGeometry(settings.value("window_geometry").toByteArray());
this->restoreState(settings.value("window_state").toByteArray());
this->setMinimumSize(1152,648);
}
// --- Default destructor --- //
MainWindow::~MainWindow()
{
}
/* ============================== */
/* Exit the Application */
/* ============================== */
// --- Detect any attempt to close the application and prompt the user to save the database first --- //
void MainWindow::closeEvent(QCloseEvent *event)
{
QSettings settings;
settings.setValue("window_geometry", this->saveGeometry());
settings.setValue("window_state", this->saveState());
QMainWindow::closeEvent(event);
}
/* ================== */
/* File I/O */
/* ================== */
// --- Open database --- //
void MainWindow::openDatabase()
{
// Open the database
const bool result = m_Database.open(this);
// Set the user interface status
m_MainUserInterface->setStatus(result);
}
// --- Save database --- //
void MainWindow::saveDatabase()
{
// Save the database
const bool result = m_Database.save();
}
// --- Save as database --- //
void MainWindow::saveAsDatabase()
{
// Save the database
const bool result = m_Database.saveAs(this);
}
/* ======================== */
/* User Interface */
/* ======================== */
// --- Create user interface --- //
void MainWindow::setUserInterface()
{
// Main Ui with toolbar and stacked widget
m_MainUserInterface = new MainUi(this);
// Action: Open database
m_ActOpenDatabase = new QAction("&Open", m_MainUserInterface);
m_MainUserInterface->addButton(m_ActOpenDatabase, MainUi::ACTIVE_WHEN_DB_IS_CLOSED);
QObject::connect(m_ActOpenDatabase, &QAction::triggered,
this, &MainWindow::openDatabase);
// Action: Save database
m_ActSaveDatabase = new QAction("&Save", m_MainUserInterface);
m_MainUserInterface->addButton(m_ActSaveDatabase, MainUi::ACTIVE_WHEN_DB_IS_OPEN);
QObject::connect(m_ActSaveDatabase, &QAction::triggered,
this, &MainWindow::saveDatabase);
// Action: Save as database
m_ActSaveAsDatabase = new QAction("Save &As", m_MainUserInterface);
m_MainUserInterface->addButton(m_ActSaveAsDatabase, MainUi::ACTIVE_WHEN_DB_IS_OPEN);
QObject::connect(m_ActSaveAsDatabase, &QAction::triggered,
this, &MainWindow::saveAsDatabase);
// Settings menu
m_Settings = new Settings(this);
m_MainUserInterface->addMenu(m_Settings);
// Shadow editor
m_ShadowEditor = new Editor(m_MainUserInterface);
}