-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRoad.cpp
95 lines (84 loc) · 1.64 KB
/
Road.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
#include "Road.h"
#include <QPainter>
#include <QPaintEvent>
Road::Road(ParkingLotWidget* parent, const int length, const direction dir)
:QWidget(parent), length(length), dir(dir)
{
switch(dir)
{
case horizontal:
resize(length, 50);
setMinimumSize(length, 50);
setMaximumSize(length, 50);
break;
case vertical:
resize(50, length);
setMinimumSize(50, length);
setMaximumSize(50, length);
break;
}
// setContentsMargins(0, 0, 0, 0);
number = parent->addRoad(this);
QObject::connect(parent, &ParkingLotWidget::showMargain, [this](bool b){
this->m_showMargin = b;
update();
});
}
void Road::paintEvent(QPaintEvent * event)
{
event->ignore();
QPainter painter(this);
/*painter.setPen(Qt::blue);
painter.drawRect(0, 0, width() - 1, height() - 1);*/
painter.setBrush(Qt::white);
painter.setPen(Qt::white);
auto x = 0, y = 0;
if (dir == horizontal) {
while (x < length) {
painter.drawRect(x + 5, 20, 40, 10);
x += 50;
}
}
else {
while (y < length) {
painter.drawRect(20, y + 5, 10, 40);
y += 50;
}
}
if (m_showMargin) {
painter.setPen(Qt::blue);
painter.setBrush(Qt::NoBrush);
painter.drawRect(0, 0, width() - 1, height() - 1);
}
}
Road::~Road()
{
}
Road::Action Road::getAction() const
{
return action;
}
void Road::setAction(const Action &value)
{
action = value;
}
short Road::getActionPos() const
{
return actionPos;
}
void Road::setActionPos(short value)
{
actionPos = value;
}
uint Road::getNumber() const
{
return number;
}
int Road::getLength() const
{
return length;
}
Road::direction Road::getDir() const
{
return dir;
}