-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmapform.cpp
102 lines (92 loc) · 2.43 KB
/
mapform.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
#include "mapform.h"
#include "ui_mapform.h"
#include<QPainter>
#include<QFont>
MapForm::MapForm(QWidget *parent) :
QWidget(parent),
ui(new Ui::MapForm)
{
ui->setupUi(this);
setWindowFlags(Qt::CustomizeWindowHint|Qt::FramelessWindowHint);
//初始化matrix
for(int i = 0; i < 14; i++)
{
for(int j = 0; j < 14; j++)
{
if(i == j)
matrix[i][j] = 0;
else
matrix[i][j] = 0x3f3f3f3f;
}
}
//填充matrix
for(int i = 0; i < 18; i++)
{
matrix[roads[i].city1.name-1][roads[i].city2.name-1] = roads[i].length;
matrix[roads[i].city2.name-1][roads[i].city1.name-1] = roads[i].length;
}
}
MapForm::~MapForm()
{
delete ui;
}
void MapForm::paintEvent(QPaintEvent *)
{
//绘制地点
QPainter painter(this);
for(int i = 0; i < 14; i++)
{
QPen pen;
if(citys[i].color == "black")
pen.setColor(Qt::black);
else
{
if(citys[i].color == "red")
pen.setColor(Qt::red);
else if(citys[i].color == "yellow")
pen.setColor(Qt::yellow);
}
pen.setWidth(8);
painter.setPen(pen);
painter.drawPoint(citys[i].addr);
//painter.drawText(citys[i].addr.x()-2,citys[i].addr.y()-10,QString::number(i+1));
}
//绘制地名
QPainter painter2(this);
QFont font;
font.setPointSize(10);
font.setFamily("Microsoft YaHei");
font.setLetterSpacing(QFont::AbsoluteSpacing,0);
painter2.setFont(font);
for(int i = 0; i < 14; i++)
{
painter2.drawText(citys[i].addr.x()-2,citys[i].addr.y()-10,QString::number(i+1));
}
//绘制路线
QPainter painter1(this);
for(int i = 0; i < 18; i++)
{
QPen pen1;
if(roads[i].color == "black")
{
pen1.setColor(Qt::black);
pen1.setWidth(2);
}
else
{
if(roads[i].color == "red")
pen1.setColor(Qt::red);
else if(roads[i].color == "yellow")
pen1.setColor(Qt::yellow);
pen1.setWidth(5);
}
painter1.setPen(pen1);
painter1.drawLine(roads[i].city1.addr, roads[i].city2.addr);
}
//绘制拥堵标记,蓝色小点标记
QPainter painter3(this);
QPen pen2(Qt::red);
pen2.setWidth(7);
painter3.setPen(pen2);
painter3.drawPoints(jamroads, 3);
}