-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmainwindow.cpp
181 lines (168 loc) · 7.83 KB
/
mainwindow.cpp
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* Copyright (C) Kreogist Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QBoxLayout>
#include <QAction>
#include <QScrollArea>
#include <QScrollBar>
#include <QCloseEvent>
#include "about.h"
#include "gridwidget.h"
#include "ground.h"
#include "groundglobal.h"
#include "paneldock.h"
#include "menubar.h"
#include "robotmanagement.h"
#include "enemymanagement.h"
#include "generateground.h"
#include "languagemanager.h"
#include "mainwindow.h"
#include <QDebug>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
m_ground(new Ground(this)),
m_panel(new PanelDock(this)),
m_menuBar(new MenuBar(this)),
m_robotManagement(new RobotManagement(this)),
m_enemyManagement(new EnemyManagement(this)),
m_groundGenerator(new GenerateGround(this)),
m_about(new QAction(this))
{
//Set properties.
setWindowIcon(QIcon("://res/icon.png"));
setMinimumSize(500, 309);
//Initial the grid widget.
GridWidget *gridWidget=new GridWidget(this);
connect(m_ground->showCoordinate(),
static_cast<void (QAction::*)(bool)>(&QAction::triggered),
gridWidget, &GridWidget::setCoordinate);
setCentralWidget(gridWidget);
//Initial the scroll area.
QScrollArea *groundArea=new QScrollArea(this);
gridWidget->setWidget(groundArea);
groundArea->setAutoFillBackground(true);
groundArea->setAlignment(Qt::AlignCenter);
groundArea->setWidget(m_ground);
groundArea->setFrameStyle(QFrame::NoFrame);
groundArea->verticalScrollBar()->setStyleSheet("QScrollBar:vertical {"
" border: 0px solid grey;"
" background: rgba(0, 0, 0, 0);"
" width: 8px;"
"}"
"QScrollBar::handle:vertical {"
" background: rgba(100, 100, 100);"
" min-height: 10px;"
" border-radius: 4px;"
"}"
"QScrollBar::add-line:vertical {"
" border: 0px solid grey;"
" background: rgba(0, 0, 0, 100);"
" height: 0px;"
" subcontrol-position: down;"
" subcontrol-origin: margin;"
"}"
"QScrollBar::sub-line:vertical {"
" border: 0px solid grey;"
" background: rgba(0, 0, 0, 100);"
" height: 0px;"
" subcontrol-position: up;"
" subcontrol-origin: margin;"
"}");
groundArea->horizontalScrollBar()->setStyleSheet("QScrollBar:horizontal {"
" border: 0px solid grey;"
" background: rgba(0, 0, 0, 0);"
" height: 8px;"
"}"
"QScrollBar::handle:horizontal {"
" background: rgba(100, 100, 100);"
" min-height: 10px;"
" border-radius: 4px;"
"}"
"QScrollBar::add-line:horizontal {"
" border: 0px solid grey;"
" background: rgba(0, 0, 0, 100);"
" width: 0px;"
" subcontrol-position: down;"
" subcontrol-origin: margin;"
"}"
"QScrollBar::sub-line:horizontal {"
" border: 0px solid grey;"
" background: rgba(0, 0, 0, 100);"
" width: 0px;"
" subcontrol-position: up;"
" subcontrol-origin: margin;"
"}");
//Update the palette of ground area.
QPalette pal=groundArea->palette();
pal.setColor(QPalette::Window, QColor(0,0,0,0));
groundArea->setPalette(pal);
pal=gridWidget->palette();
pal.setColor(QPalette::Window, GroundGlobal::instance()->baseColor());
gridWidget->setPalette(pal);
//Link the color changed signal.
connect(GroundGlobal::instance(), &GroundGlobal::baseColorChanged,
[=](const QColor &color)
{
QPalette pal=gridWidget->palette();
pal.setColor(QPalette::Window, color);
gridWidget->setPalette(pal);
});
//Set the ground generator.
m_ground->setGenerator(m_groundGenerator);
//Give the ground to elements.
m_panel->setGround(m_ground);
m_robotManagement->setGround(m_ground);
m_enemyManagement->setGround(m_ground);
//Add action to menubar.
m_menuBar->addCategoryAction(MenuBar::Help, m_about);
//Give the menu bar to elements.
m_ground->setMenuBar(m_menuBar);
m_panel->setMenuBar(m_menuBar);
m_robotManagement->setMenuBar(m_menuBar);
m_enemyManagement->setMenuBar(m_menuBar);
LanguageManager::instance()->setMenuBar(m_menuBar);
//Add panel to bottom dock area.
addDockWidget(Qt::RightDockWidgetArea, m_panel);
m_panel->setAllowedAreas(Qt::LeftDockWidgetArea |
Qt::RightDockWidgetArea);
//Configure the about action.
connect(m_about,
static_cast<void (QAction::*)(bool)>(&QAction::triggered),
[=]{About::showAbout(this);});
#ifdef Q_OS_MACX
setWindowTitle("Robot Emulator");
#else
setMenuBar(m_menuBar);
#endif
connect(LanguageManager::instance(), SIGNAL(languageChanged()),
this, SLOT(retranslate()));
retranslate();
}
void MainWindow::closeEvent(QCloseEvent *event)
{
//If the user don't want to close the file, stop close event.
if(!m_ground->closeFile())
{
event->ignore();
return;
}
QMainWindow::closeEvent(event);
}
void MainWindow::retranslate()
{
m_about->setText(tr("About"));
}