-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.cpp
More file actions
118 lines (93 loc) · 3.54 KB
/
Copy pathMainWindow.cpp
File metadata and controls
118 lines (93 loc) · 3.54 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
114
115
116
117
118
// MainWindow.cpp
#include "MainWindow.h"
MainWindow* MainWindow::s_instance = nullptr;
MainWindow* MainWindow::instance(QWidget *parent) {
if (!s_instance) {
s_instance = new MainWindow(parent);
}
return s_instance;
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) {
setWindowTitle("Negotium");
QFile sfile(":/main/style");
if (!sfile.open(QIODevice::ReadOnly)) {
qDebug() << "Cannot open stylesheet file.";
return;
}
QString stylesheet = QString::fromUtf8(sfile.readAll());
this->setStyleSheet(stylesheet);
qMenuBar = this->menuBar();
auto *systemMenuItem = new QMenu("System", this);
/*auto *settingsMenuAction = new QAction("Settings", this);
connect(settingsMenuAction, &QAction::triggered, this, []() {
qDebug() << "!!!WIP!!!";
});
systemMenuItem->addAction(settingsMenuAction);*/
auto *exitMenuAction = new QAction("Shutdown", this);
connect(exitMenuAction, &QAction::triggered, this, &MainWindow::close);
systemMenuItem->addAction(exitMenuAction);
qMenuBar->addMenu(systemMenuItem);
auto *gameMenuItem = new QMenu("Game", this);
auto *runLevelMenuAction = new QAction("Run level", this);
connect(runLevelMenuAction, &QAction::triggered, this, &MainWindow::runLevelWindow);
gameMenuItem->addAction(runLevelMenuAction);
auto *closeGameMenuAction = new QAction("Close all", this);
connect(closeGameMenuAction, &QAction::triggered, this, [=, this]() { mdiArea->closeAllSubWindows(); });
gameMenuItem->addAction(closeGameMenuAction);
qMenuBar->addMenu(gameMenuItem);
mdiArea = new QMdiArea(this);
mdiArea->setBackground(QBrush(QPixmap(":/main/bgPaws")));
setCentralWidget(mdiArea);
mdiArea->addSubWindow(codeEditorMdiWindow);
codeEditorMdiWindow->close();
mdiArea->addSubWindow(runOutputMdiWindow);
runOutputMdiWindow->close();
mdiArea->addSubWindow(viewMdiWindow);
viewMdiWindow->close();
mdiArea->addSubWindow(runLevelMdiWindow);
runLevelMdiWindow->close();
mdiArea->addSubWindow(guideMdiWindow);
guideMdiWindow->close();
}
MainWindow::~MainWindow() {
s_instance = nullptr;
}
void MainWindow::keyPressEvent(QKeyEvent *event) {
switch (event->key()) {
case Qt::Key_F1:
menuBar()->setActiveAction(menuBar()->actions()[0]);
break;
case Qt::Key_F2:
menuBar()->setActiveAction(menuBar()->actions()[1]);
break;
case Qt::Key_F5:
if (AppWideVariables::instance().game != nullptr)
AppWideVariables::instance().game->Run();
break;
}
QWidget::keyPressEvent(event);
}
void MainWindow::execGame() {
AppWideVariables::instance().game->Run();
}
void MainWindow::runLevelWindow() {
runLevelMdiWindow->show();
}
void MainWindow::openLevelMDIWindows() {
auto *inst = MainWindow::instance(); // Получаем ссылку на экземпляр
inst->codeEditorMdiWindow->loadLevelCode();
AppWideVariables::instance().game = new Game(
inst->codeEditorMdiWindow->textEdit,
inst->runOutputMdiWindow->textView,
AppWideVariables::instance().levelPath
);
inst->viewMdiWindow->setGame(AppWideVariables::instance().game);
inst->viewMdiWindow->update();
inst->viewMdiWindow->updateGame();
inst->guideMdiWindow->setMarkdown(AppWideVariables::instance().markdownText);
inst->viewMdiWindow->show();
inst->runOutputMdiWindow->show();
inst->codeEditorMdiWindow->show();
inst->guideMdiWindow->show();
}