-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwidget.cpp
More file actions
528 lines (468 loc) · 17.4 KB
/
widget.cpp
File metadata and controls
528 lines (468 loc) · 17.4 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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
/*===================================================
*主窗口模块
*功能说明:创建主窗口,显示窗口中各功能按钮以及功能面板切换效果
*模块重要性:重要
*作者:杨飞
*
*---------------------------------------------------
*变更履历:
*2013.3.19 增加拖动主界面窗口鼠标指针呈收放手形状
*==================================================*/
#include "widget.h"
#include "ui_widget.h"
#include "dlgabout.h"
#include "dlgsetup.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
dingWei = true;
chaZhao = true;
m_isSilenced = false;
isshowShortestRoute = true;
ui->xunluWidget->setVisible(false);
ui->locatingLabel->setVisible(false);
}
Widget::~Widget()
{
delete ui;
}
MapTilesFrame *Widget::getMapFrame()
{
return ui->mapFrame;
}
RouteWidget *Widget::getRouteWidget()
{
return ui->routeWidget;
}
//使主窗口可以拖拽
void Widget::mousePressEvent(QMouseEvent *event)
{
ui->windowWidget->setCursor(Qt::ClosedHandCursor);
if (event->button() == Qt::LeftButton) {
dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}
void Widget::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() & Qt::LeftButton) {
move(event->globalPos() - dragPosition);
event->accept();
}
}
void Widget::mouseReleaseEvent(QMouseEvent *)
{
qDebug() << "mouseRelease called";
ui->windowWidget->setCursor(Qt::OpenHandCursor);
}
//关闭系统
void Widget::on_exitPushButton_clicked()
{
QPropertyAnimation *animation = new QPropertyAnimation(this, "geometry"); //关闭软件的卷轴闭合效果
animation->setDuration(1000);
animation->setStartValue(QRect(0, 0, 1210, 770));
animation->setEndValue(QRect(605, 0, 0, 770));
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start();
//让程序等待1秒关闭,实现关闭卷轴效果
QTime t;
t.start();
while(t.elapsed()<1000)
QCoreApplication::processEvents();
QCoreApplication::quit();
}
//放大地图按钮
void Widget::on_enlargeToolButton_clicked()
{
ui->mapFrame->zoomIn();
}
//缩小地图按钮
void Widget::on_shrinkToolButton_clicked()
{
ui->mapFrame->zoomOut();
}
//关于“道听途说”按钮
void Widget::on_aboutDlgToolButton_clicked()
{
DlgAbout *dlg = new DlgAbout(this);
dlg->setWindowFlags(Qt::FramelessWindowHint);
dlg->setAttribute(Qt::WA_TranslucentBackground);
dlg->exec();
}
/*=======================================================================================
*当点击“查找”按钮时,如果在寻路功能面板,查找功能的sousuoLineEdiit跟sousuoToolButton就会自左向右出现,
*形成一种将寻路功能面板推出去的效果
*
=======================================================================================*/
void Widget::on_searchToolButton_clicked()
{
chaZhao = true;
if(xunLu == true)
{
//搜索面板向右移入
QPropertyAnimation *animation = new QPropertyAnimation(ui->sousuoLineEdit, "geometry");
animation->setDuration(1000);
animation->setStartValue(QRect(875, 300, 0, 40));
animation->setEndValue(QRect(875, 300, 170, 40));
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start();
QPropertyAnimation *animation1 = new QPropertyAnimation(ui->sousuoToolButton, "geometry");
animation1->setDuration(1000);
animation1->setStartValue(QRect(1045, 295, 0, 50));
animation1->setEndValue(QRect(1045, 295, 70, 50));
animation1->setEasingCurve(QEasingCurve::InOutQuad);
animation1->start();
//寻路面板向右移出
ui->xunluWidget->setVisible(true);
QPropertyAnimation *animation4 = new QPropertyAnimation(ui->xunluWidget, "geometry");
animation4->setDuration(1000);
animation4->setStartValue(QRect(880, 210, 220, 480));
animation4->setEndValue(QRect(1100, 210, 0, 480));
animation4->setEasingCurve(QEasingCurve::InOutQuad);
animation4->start();
}
else
{
//搜索面版向右移入
QPropertyAnimation *animation = new QPropertyAnimation(ui->sousuoLineEdit, "geometry");
animation->setDuration(1000);
animation->setStartValue(QRect(875, 300, 0, 40));
animation->setEndValue(QRect(875, 300, 170, 40));
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start();
QPropertyAnimation *animation1 = new QPropertyAnimation(ui->sousuoToolButton, "geometry");
animation1->setDuration(1000);
animation1->setStartValue(QRect(1045, 295, 0, 50));
animation1->setEndValue(QRect(1045, 295, 70, 50));
animation1->setEasingCurve(QEasingCurve::InOutQuad);
animation1->start();
}
xunLu = false;
}
void Widget::on_locateToolButton_clicked()
{
if(xunLu == true)
{
//定位面板向右移入
QPropertyAnimation *animation = new QPropertyAnimation(ui->wozaiLabel, "geometry");
animation->setDuration(1000);
animation->setStartValue(QRect(860, 215, 0, 70));
animation->setEndValue(QRect(860, 215, 70, 70));
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start();
QPropertyAnimation *animation1 = new QPropertyAnimation(ui->locationLabel, "geometry");
animation1->setDuration(1000);
animation1->setStartValue(QRect(930, 230, 0, 40));
animation1->setEndValue(QRect(930, 230, 170, 40));
animation1->setEasingCurve(QEasingCurve::InOutQuad);
animation1->start();
//寻路面板向右移出
ui->xunluWidget->setVisible(true);
QPropertyAnimation *animation4 = new QPropertyAnimation(ui->xunluWidget, "geometry");
animation4->setDuration(1000);
animation4->setStartValue(QRect(880, 210, 220, 480));
animation4->setEndValue(QRect(1100, 210, 0, 480));
animation4->setEasingCurve(QEasingCurve::InOutQuad);
animation4->start();
}
else
{//定位面板向右移入
QPropertyAnimation *animation = new QPropertyAnimation(ui->wozaiLabel, "geometry");
animation->setDuration(1000);
animation->setStartValue(QRect(860, 215, 0, 70));
animation->setEndValue(QRect(860, 215, 60, 70));
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start();
QPropertyAnimation *animation1 = new QPropertyAnimation(ui->locationLabel, "geometry");
animation1->setDuration(1000);
animation1->setStartValue(QRect(930, 230, 0, 40));
animation1->setEndValue(QRect(930, 230, 170, 40));
animation1->setEasingCurve(QEasingCurve::InOutQuad);
animation1->start();
}
dingWei = true;
xunLu = false;
ui->locatingLabel->setVisible(true);
QTime t;
t.start();
while(t.elapsed()<2000)
QCoreApplication::processEvents();
ui->locatingLabel->setVisible(false);
if(ui->routeWidget->userLocationWidget)
{
delete ui->routeWidget->userLocationWidget;
ui->routeWidget->userLocationWidget = NULL;
}
ui->routeWidget->userLocationWidget = new LocationWidget(ui->mapFrame);
connect(ui->routeWidget->userLocationWidget,
SIGNAL(serverCoordinateChanged(QPoint,QPoint)),
ui->routeWidget->sm,
SLOT(userLocationChangedSlot(QPoint)));
ui->routeWidget->userLocationWidget->setRandomPos();
ui->locationLabel->setText(ui->routeWidget->findNearestSpotName(ui->routeWidget->userLocationWidget->getServerCoordinate()) + " 附近");
}
void Widget::on_xunluToolButton_clicked()
{
if (dingWei==true&&chaZhao==true)
{
//搜索面板向右移出
QPropertyAnimation *animation = new QPropertyAnimation(ui->sousuoLineEdit, "geometry");
animation->setDuration(1000);
animation->setStartValue(QRect(875, 300, 170, 40));
animation->setEndValue(QRect(1100, 300, 0, 40));
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start();
QPropertyAnimation *animation1 = new QPropertyAnimation(ui->sousuoToolButton, "geometry");
animation1->setDuration(1000);
animation1->setStartValue(QRect(1045, 295, 70, 50));
animation1->setEndValue(QRect(1100, 295, 0, 50));
animation1->setEasingCurve(QEasingCurve::InOutQuad);
animation1->start();
//定位面板向右移出
QPropertyAnimation *animation2 = new QPropertyAnimation(ui->wozaiLabel, "geometry");
animation2->setDuration(1000);
animation2->setStartValue(QRect(860, 215, 70, 70));
animation2->setEndValue(QRect(1100, 215, 0, 70));
animation2->setEasingCurve(QEasingCurve::InOutQuad);
animation2->start();
QPropertyAnimation *animation3 = new QPropertyAnimation(ui->locationLabel, "geometry");
animation3->setDuration(1000);
animation3->setStartValue(QRect(930, 230, 170, 40));
animation3->setEndValue(QRect(1100, 230, 0, 40));
animation3->setEasingCurve(QEasingCurve::InOutQuad);
animation3->start();
//寻路面板向右移入
ui->xunluWidget->setVisible(true);
ui->zizhuxunluWidget->setVisible(false);
QPropertyAnimation *animation4 = new QPropertyAnimation(ui->xunluWidget, "geometry");
animation4->setDuration(1000);
animation4->setStartValue(QRect(880, 210, 0, 480));
animation4->setEndValue(QRect(880, 210, 220, 480));
animation4->setEasingCurve(QEasingCurve::InOutQuad);
animation4->start();
}
else if(dingWei == false && chaZhao == true)
{
//搜索面板向右移出
QPropertyAnimation *animation = new QPropertyAnimation(ui->sousuoLineEdit, "geometry");
animation->setDuration(1000);
animation->setStartValue(QRect(875, 300, 170, 40));
animation->setEndValue(QRect(1100, 300, 0, 40));
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start();
QPropertyAnimation *animation1 = new QPropertyAnimation(ui->sousuoToolButton, "geometry");
animation1->setDuration(1000);
animation1->setStartValue(QRect(1045, 295, 70, 50));
animation1->setEndValue(QRect(1100, 295, 0, 50));
animation1->setEasingCurve(QEasingCurve::InOutQuad);
animation1->start();
//寻路面板向右移入
ui->xunluWidget->setVisible(true);
ui->zizhuxunluWidget->setVisible(false);
QPropertyAnimation *animation4 = new QPropertyAnimation(ui->xunluWidget, "geometry");
animation4->setDuration(1000);
animation4->setStartValue(QRect(880, 210, 0, 480));
animation4->setEndValue(QRect(880, 210, 220, 480));
animation4->setEasingCurve(QEasingCurve::InOutQuad);
animation4->start();
}
else if(dingWei == true && chaZhao == false)
{
//定位面板向右移出
QPropertyAnimation *animation2 = new QPropertyAnimation(ui->wozaiLabel, "geometry");
animation2->setDuration(1000);
animation2->setStartValue(QRect(860, 215, 70, 70));
animation2->setEndValue(QRect(1100, 215, 0, 70));
animation2->setEasingCurve(QEasingCurve::InOutQuad);
animation2->start();
QPropertyAnimation *animation3 = new QPropertyAnimation(ui->locationLabel, "geometry");
animation3->setDuration(1000);
animation3->setStartValue(QRect(930, 230, 170, 40));
animation3->setEndValue(QRect(1100, 230, 0, 40));
animation3->setEasingCurve(QEasingCurve::InOutQuad);
animation3->start();
//寻路面板向右移入
ui->xunluWidget->setVisible(true);
ui->zizhuxunluWidget->setVisible(false);
QPropertyAnimation *animation4 = new QPropertyAnimation(ui->xunluWidget, "geometry");
animation4->setDuration(1000);
animation4->setStartValue(QRect(880, 210, 0, 480));
animation4->setEndValue(QRect(880, 210, 220, 480));
animation4->setEasingCurve(QEasingCurve::InOutQuad);
animation4->start();
}
xunLu = true;
dingWei = false;
chaZhao = false;
}
void Widget::on_qidianToolButton_clicked()
{
QCursor my(QPixmap(":/images/start.png"));//更改鼠标图标为绿色起点图标
ui->routeWidget->setCursor(my);
ui->routeWidget->raise();
ui->routeWidget->isPlacingStartLocation = true;
}
void Widget::on_zhongdianToolButton_clicked()
{
QCursor my(QPixmap(":/images/end.png"));//更改鼠标图标为红色终点图标
ui->routeWidget->setCursor(my);
ui->routeWidget->raise();
ui->routeWidget->isPlacingEndLocation = true;
}
void Widget::on_volumeToolButton_clicked()
{
if(m_isSilenced == false)
{
ui->routeWidget->sm->setSilenced(true);
ui->volumeToolButton->setIcon(QIcon(":/images/jingyin.png"));
m_isSilenced = true;
}
else
{
ui->routeWidget->sm->setSilenced(false);
ui->volumeToolButton->setIcon(QIcon(":/images/shengyin.png"));
m_isSilenced = false;
}
}
/*创建设置对话框
*将背景色设为透明
*/
void Widget::on_setupDlgToolButton_clicked()
{
DlgSetup *dlgset = new DlgSetup(this);
dlgset->setWindowFlags(Qt::FramelessWindowHint);
dlgset->setAttribute(Qt::WA_TranslucentBackground);
dlgset->exec();
}
void Widget::on_pushButton_clicked()
{
showMinimized();
}
void Widget::on_quedingToolButton_clicked()
{
bool ok = false;
QPoint startPos(ui->routeWidget->findSpotLocation(ui->qidianLineEdit->text(), &ok));
if(!ok)
return;
QPoint endPos(ui->routeWidget->findSpotLocation(ui->zhongdianLineEdit->text(), &ok));
if(!ok)
return;
if(ui->routeWidget->startWidget != NULL)
{
delete ui->routeWidget->startWidget;
ui->routeWidget->startWidget = NULL;
}
ui->routeWidget->startWidget = new LocationWidget(ui->mapFrame);
ui->routeWidget->startWidget->setPixmap(QPixmap(":/images/start.png"));
ui->routeWidget->startWidget->setServerCoordinate(startPos);
if(ui->routeWidget->endWidget != NULL)
{
delete ui->routeWidget->endWidget;
ui->routeWidget->endWidget = NULL;
}
ui->routeWidget->endWidget = new LocationWidget(ui->mapFrame);
ui->routeWidget->endWidget->setPixmap(QPixmap(":/images/end.png"));
ui->routeWidget->endWidget->setServerCoordinate(endPos);
ui->routeWidget->locationSet(false);
}
void Widget::on_zizhuxunluToolButton_clicked()
{
if(isshowShortestRoute == true)
{
QPropertyAnimation *animation = new QPropertyAnimation(ui->zizhuxunluWidget, "geometry");
animation->setDuration(1000);
animation->setStartValue(QRect(0, 210, 0, 280));
animation->setEndValue(QRect(0, 210, 220, 280));
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start();
isshowShortestRoute = false;
}
else
{
QPropertyAnimation *animation = new QPropertyAnimation(ui->zizhuxunluWidget, "geometry");
animation->setDuration(1000);
animation->setStartValue(QRect(0, 210, 220, 280));
animation->setEndValue(QRect(0, 210, 0, 280));
animation->setEasingCurve(QEasingCurve::InOutQuad);
animation->start();
isshowShortestRoute = true;
}
ui->zizhuxunluWidget->setVisible(true);
}
void Widget::on_sousuoToolButton_clicked()
{
if(ui->routeWidget->searchResultWidget)
{
delete ui->routeWidget->searchResultWidget;
ui->routeWidget->searchResultWidget = NULL;
}
if(ui->sousuoLineEdit->text().isEmpty())
{
return;
}
bool isFound = false;
QPoint pos = ui->routeWidget->findSpotLocation(ui->sousuoLineEdit->text(), &isFound);
if(!isFound)
{
return;
}
ui->routeWidget->searchResultWidget = new LocationWidget(ui->mapFrame, pos);
}
void Widget::on_recommendRouteToolButton_clicked()
{
static bool isSet = false;
if(!isSet)
{
isSet = true;
ui->mapFrame->provider().setMapType("/SuggestedRouteMap/");
//ui->recommendRouteToolButton->setText(tr("取消设置"));
}
else
{
isSet = false;
ui->mapFrame->provider().setMapType("/NormalMap/");
}
}
void Widget::on_beautifulRouteToolButton_clicked()
{
static bool isSet = false;
if(!isSet)
{
isSet = true;
ui->mapFrame->provider().setMapType("/ScenicRouteMap/");
//ui->recommendRouteToolButton->setText(tr("取消设置"));
}
else
{
isSet = false;
ui->mapFrame->provider().setMapType("/NormalMap/");
}
}
void Widget::on_quxiaoButton_clicked()
{
ui->routeWidget->isRoute = false;
ui->routeWidget->m_isRouteByCoor = false;
ui->routeWidget->update();
if(ui->routeWidget->startWidget != NULL)
{
delete ui->routeWidget->startWidget;
ui->routeWidget->startWidget = NULL;
}
if(ui->routeWidget->endWidget != NULL)
{
delete ui->routeWidget->endWidget;
ui->routeWidget->endWidget = NULL;
}
if(ui->routeWidget->userLocationWidget != NULL)
{
delete ui->routeWidget->userLocationWidget;
ui->routeWidget->userLocationWidget = NULL;
}
if(ui->routeWidget->searchResultWidget != NULL)
{
delete ui->routeWidget->searchResultWidget;
ui->routeWidget->searchResultWidget = NULL;
}
}