-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
385 lines (303 loc) · 9.64 KB
/
mainwindow.cpp
File metadata and controls
385 lines (303 loc) · 9.64 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
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "securitysystem.h"
#include "introduction.h"
#include<QPropertyAnimation>
#include<QPainter>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
,currentIndex(0)
{
ui->setupUi(this);
setFixedSize(1132,770);
ui->anouncementtextEdit->setStyleSheet("background-color: rgba(255, 255, 255, 128);");
images << ":/imgs/Image/fengyuan.jpg"<< ":/imgs/Image/luojiashan.jpg"<< ":/imgs/Image/yingyuan.jpg"<< ":/imgs/Image/guiyuancaochang.jpg";
backgroundLabel = new QLabel(this);
backgroundLabel->setGeometry(0, 0, this->width(), this->height());
backgroundLabel->setScaledContents(true);
backgroundLabel->lower(); // 将标签置于底层
// 设置透明度
QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect;
opacityEffect->setOpacity(0.3); // 30%透明度
backgroundLabel->setGraphicsEffect(opacityEffect);
// 设置定时器
QTimer *timer = new QTimer(this);
connect(timer, &QTimer::timeout, this, &MainWindow::changeBackground);
timer->start(20000); // 每20秒触发一次
// 初始设置背景图片
changeBackground();
//主界面切换
ui->stackedWidget->setCurrentIndex((0));
//退出功能实现
connect(ui->actionexit,&QAction::triggered,this,[=](){
this->close();
});
connect(ui->enterSecurity,&QPushButton::clicked,this,[=](){
ui->stackedWidget->setCurrentIndex((1));
});
connect(ui->enterTourist,&QPushButton::clicked,this,[=](){
ui->stackedWidget->setCurrentIndex((2));
});
connect(ui->exitTourist,&QPushButton::clicked,this,[=](){
ui->stackedWidget->setCurrentIndex((0));
updateAnnouncementTextEdit();
});
connect(ui->exitSecurity,&QPushButton::clicked,this,[=](){
ui->stackedWidget->setCurrentIndex((0));
updateAnnouncementTextEdit();
});
// 初始化图
graph = new Graph(20);
changes= new QString("");
// 添加顶点和边
graph->addVertex(0, "南2门");
graph->addVertex(1, "珞瑜门");
graph->addVertex(2, "信息学部1教");
graph->addVertex(3, "10舍");
graph->addVertex(4, "国软c3");
graph->addVertex(5, "网安小操场");
graph->addVertex(6, "信操");
graph->addVertex(7, "信图");
graph->addVertex(8, "星湖体育场");
graph->addVertex(9, "珞珈门");
graph->addVertex(10, "珞珈广场");
graph->addVertex(11, "珞珈山");
graph->addVertex(12, "雷军科技楼");
graph->addVertex(13, "桂园操场");
graph->addVertex(14, "九一二操场");
graph->addVertex(15, "枫园");
graph->addVertex(16, "松园操场");
graph->addVertex(17, "樱园");
graph->addVertex(18, "计算机学院");
graph->addVertex(19, "工主教");
// 添加边
graph->addEdge(0, 3, 228);
graph->addEdge(3, 0, 228);
graph->addEdge(1, 2, 270);
graph->addEdge(2, 1, 270);
graph->addEdge(2, 3, 293);
graph->addEdge(3, 2, 293);
graph->addEdge(4, 3, 455);
graph->addEdge(3, 4, 455);
graph->addEdge(5, 4, 96);
graph->addEdge(4, 5, 96);
graph->addEdge(8, 3, 312);
graph->addEdge(3, 8, 312);
graph->addEdge(6, 2, 162);
graph->addEdge(2, 6, 162);
graph->addEdge(6, 7, 185);
graph->addEdge(7, 6, 185);
graph->addEdge(8, 7, 229);
graph->addEdge(7, 8, 229);
graph->addEdge(9, 8, 302);
graph->addEdge(8, 9, 302);
graph->addEdge(7, 11, 1300);
graph->addEdge(11, 7, 1300);
graph->addEdge(10, 9, 575);
graph->addEdge(9, 10, 575);
graph->addEdge(11, 10, 998);
graph->addEdge(10, 11, 998);
graph->addEdge(12, 9, 592);
graph->addEdge(9, 12, 592);
graph->addEdge(13, 10, 393);
graph->addEdge(10, 13, 393);
graph->addEdge(14, 11, 969);
graph->addEdge(11, 14, 969);
graph->addEdge(11, 15, 812);
graph->addEdge(15, 11, 812);
graph->addEdge(13, 18, 252);
graph->addEdge(18, 13, 252);
graph->addEdge(14, 13, 728);
graph->addEdge(13, 14, 728);
graph->addEdge(17, 18, 626);
graph->addEdge(18, 17, 626);
graph->addEdge(13, 17, 205);
graph->addEdge(17, 13, 205);
graph->addEdge(17, 14, 570);
graph->addEdge(14, 17, 570);
graph->addEdge(16, 14, 587);
graph->addEdge(14, 16, 587);
graph->addEdge(16, 15, 630);
graph->addEdge(15, 16, 630);
graph->addEdge(16, 17, 968);
graph->addEdge(17, 16, 968);
graph->addEdge(19, 17, 952);
graph->addEdge(17, 19, 952);
graph->addEdge(16, 19, 620);
graph->addEdge(19, 16, 620);
connect(ui->searchButton, &QPushButton::clicked, this, &MainWindow::openTouristWindow);
connect(ui->changeMap, &QPushButton::clicked,this,&MainWindow::openSecurityWindow);
}
void MainWindow::openSecurityWindow(){
securityWindow = new SecuritySystem(graph,this,changes);
securityWindow->setAttribute(Qt::WA_DeleteOnClose);
securityWindow->show();
}
MainWindow::~MainWindow()
{
delete ui;
delete graph;
delete changes;
delete backgroundLabel;
}
void MainWindow::updateAnnouncementTextEdit() {
ui->anouncementtextEdit->setText(*changes);
}
void MainWindow::changeBackground() {
if (currentIndex >= images.size()) {
currentIndex = 0;
}
// 创建新的 QPixmap
QPixmap newPixmap(images[currentIndex]);
// 创建 QGraphicsOpacityEffect
QGraphicsOpacityEffect *opacityEffect = new QGraphicsOpacityEffect(backgroundLabel);
backgroundLabel->setGraphicsEffect(opacityEffect);
// 创建动画对象
QPropertyAnimation *animation = new QPropertyAnimation(opacityEffect, "opacity");
animation->setDuration(2000); // 渐变时间
animation->setStartValue(0.0); // 开始时完全不透明
animation->setEndValue(0.3); // 渐变
QPropertyAnimation *animationWait = new QPropertyAnimation(opacityEffect, "opacity");
animationWait->setDuration(16000);
animationWait->setStartValue(0.3);
animationWait->setEndValue(0.3);
QPropertyAnimation *animationFade = new QPropertyAnimation(opacityEffect, "opacity");
animationFade->setDuration(2000);
animationFade->setStartValue(0.3);
animationFade->setEndValue(0.0);
// 切换背景图片
QSequentialAnimationGroup *animationGroup = new QSequentialAnimationGroup;
animationGroup->addAnimation(animation);
animationGroup->addAnimation(animationWait);
animationGroup->addAnimation(animationFade);
animationGroup->start(QAbstractAnimation::DeleteWhenStopped);
backgroundLabel->setPixmap(newPixmap);
currentIndex++;
}
void MainWindow::openTouristWindow()
{
touristWindow = new TouristWindow(graph, this);
touristWindow->setAttribute(Qt::WA_DeleteOnClose);
touristWindow->show();
}
void MainWindow::on_gongzhujiao_clicked()
{
introwindow = new Introduction(this);
introwindow->showFirstLayer();
introwindow->show();
}
void MainWindow::on_yingyuan_clicked()
{
introwindow = new Introduction(this);
introwindow->showSecondLayer();
introwindow->show();
}
void MainWindow::on_songyuancaochang_clicked()
{
introwindow = new Introduction(this);
introwindow->showThirdLayer();
introwindow->show();
}
void MainWindow::on_jisuanjixueyuan_clicked()
{
introwindow = new Introduction(this);
introwindow->showFourthLayer();
introwindow->show();
}
void MainWindow::on_guiyuancaochang_clicked()
{
introwindow = new Introduction(this);
introwindow->showFifthLayer();
introwindow->show();
}
void MainWindow::on_jiuyiercaochang_clicked()
{
introwindow = new Introduction(this);
introwindow->showSixthLayer();
introwindow->show();
}
void MainWindow::on_fengyuan_clicked()
{
introwindow = new Introduction(this);
introwindow->showSeventhLayer();
introwindow->show();
}
void MainWindow::on_leijunkejilou_clicked()
{
introwindow = new Introduction(this);
introwindow->showEighthLayer();
introwindow->show();
}
void MainWindow::on_luojiaguangchang_clicked()
{
introwindow = new Introduction(this);
introwindow->showNinthLayer();
introwindow->show();
}
void MainWindow::on_luojiashan_clicked()
{
introwindow = new Introduction(this);
introwindow->showTenthLayer();
introwindow->show();
}
void MainWindow::on_luojiamen_clicked()
{
introwindow = new Introduction(this);
introwindow->showEleventhLayer();
introwindow->show();
}
void MainWindow::on_xinghutiyuchang_clicked()
{
introwindow = new Introduction(this);
introwindow->showTwelfthLayer();
introwindow->show();
}
void MainWindow::on_xintu_clicked()
{
introwindow = new Introduction(this);
introwindow->showThirteenthLayer();
introwindow->show();
}
void MainWindow::on_wanganxiaocaochang_clicked()
{
introwindow = new Introduction(this);
introwindow->showFourteenthLayer();
introwindow->show();
}
void MainWindow::on_xincao_clicked()
{
introwindow = new Introduction(this);
introwindow->showFifteenthLayer();
introwindow->show();
}
void MainWindow::on_shishe_clicked()
{
introwindow = new Introduction(this);
introwindow->showSixteenthLayer();
introwindow->show();
}
void MainWindow::on_guoruanc3_clicked()
{
introwindow = new Introduction(this);
introwindow->showSeventeenthLayer();
introwindow->show();
}
void MainWindow::on_xinxixuebuyijiao_clicked()
{
introwindow = new Introduction(this);
introwindow->showEighteenthLayer();
introwindow->show();
}
void MainWindow::on_nanermen_clicked()
{
introwindow = new Introduction(this);
introwindow->showNineteenthLayer();
introwindow->show();
}
void MainWindow::on_luoyumen_clicked()
{
introwindow = new Introduction(this);
introwindow->showTwentiethLayer();
introwindow->show();
}