-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgrid.cpp
83 lines (67 loc) · 1.42 KB
/
grid.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
#include "grid.h"
Grid::Grid(int x, int y, int w, int h, QObject *parent) : QObject(parent)
{
graph_x = x;
graph_y = y;
graph_w = w;
graph_h = h;
xGridDensity = 50;
yGridDensity = 50;
setGridLineProperties();
}
int Grid::getXGridDensity() const
{
return xGridDensity;
}
void Grid::setXGridDensity(double value)
{
xGridDensity = value;
}
int Grid::getYGridDensity() const
{
return yGridDensity;
}
void Grid::setYGridDensity(double value)
{
yGridDensity = value;
}
void Grid::drawGrid(QPainter *painter)
{
painter->setPen(gridLineProperties);
drawXgridLine(painter);
drawYgridLine(painter);
visible = true;
}
QPen Grid::getGridLineProperties() const
{
return gridLineProperties;
}
void Grid::setGridLineProperties()
{
}
void Grid::drawXgridLine(QPainter *painter)
{
for(int x = xGridDensity + graph_x; x <= graph_w + graph_x; x+= xGridDensity)
{
painter->drawLine(x, graph_y , x, graph_w + graph_y);
}
}
void Grid::drawYgridLine(QPainter *painter)
{
for(int y = yGridDensity; y <= graph_h + graph_y; y += yGridDensity)
{
painter->drawLine(graph_x, y + graph_y, graph_h + graph_x, y + graph_y);
}
}
void Grid::setGeometry(int x, int y, int w, int h)
{
graph_x = x;
graph_y = y;
graph_w = w;
graph_h = h;
}
void Grid::setDensitiy(double xDensity, double yDensity)
{
xGridDensity = xDensity;
yGridDensity = yDensity;
}