-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgraph.cpp
191 lines (141 loc) · 2.85 KB
/
graph.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
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
#include "graph.h"
Graph::Graph(int x, int y, int w , int h, QWidget *parent) :
QWidget(parent)
{
painter = new QPainter;
graph_x = x;
graph_y = y;
graph_w = w;
graph_h = h;
_x = 0;
_y = 0;
canvas = new Canvas(x, y ,w, h, this);
axis = new Axis(x, y, w, h, this);
line = new Line(x, y, w, h, this);
grid = new Grid(x, y, w ,h, this);
refreshFrequency = 1000;
//funkcje timera
refreshTimer = new QTimer(this);
connect(refreshTimer, SIGNAL(timeout()), this, SLOT(UpdateGraph()));
connect(line, SIGNAL(minMaxValues(double,double,double,double)), axis, SLOT(getMinMax(double,double,double,double)));
connect(axis, SIGNAL(unitsSetted(double,double)), grid, SLOT(setDensitiy(double,double)));
refreshTimer->start(refreshFrequency);
}
Graph::~Graph()
{
delete axis;
delete painter;
}
void Graph::paintEvent(QPaintEvent *e)
{
painter->begin(this);
canvas->drawCanvas(painter, this);
axis->showAxis(painter);
grid->drawGrid(painter);
line->DrawLine(painter);
painter->end();
}
void Graph::setGeometry(int x, int y, int w, int h)
{
graph_x = x;
graph_y = y;
graph_w = w;
graph_h = h;
}
void Graph::UpdateGraph()
{
update();
}
void Graph::axisOff()
{
}
void Graph::axisOn()
{
}
void Graph::axisSetXunits()
{
}
void Graph::axisSetYunits()
{
}
void Graph::gridOff()
{
}
void Graph::gridOn()
{
}
void Graph::gridSetXdensity()
{
}
void Graph::gridSetYdensity()
{
}
bool Graph::getShiftPressed() const
{
return shiftPressed;
}
void Graph::setShiftPressed(bool value)
{
shiftPressed = value;
}
void Graph::setCanvasVisible()
{
visible_canvas = true;
}
Line* Graph::getLine()
{
return line;
}
Axis * Graph::getAxis()
{
return axis;
}
void Graph::mouseMoveEvent(QMouseEvent *ev)
{
int dx, dy;
mouseMovePoint.setX(ev->x());
mouseMovePoint.setY(ev->y());
//inicjalizacja zmiennych
if(_x == 0 && _y == 0)
{
_x = ev->x();
_y = ev->y();
}
dx = _x - ev->x();
dy = _y - ev->y();
_x = ev->x();
_y = ev->y();
qDebug() << __FILE__ << __LINE__ << __func__ << _x << _y ;
line->MoveLine(dx, dy);
update();
}
void Graph::mousePressEvent(QMouseEvent *ev)
{
mousePressPoint.setX(ev->x());
mousePressPoint.setY(ev->y());
}
void Graph::mouseReleaseEvent(QMouseEvent *ev)
{
mouseReleasePoint.setX(ev->x());
mouseReleasePoint.setY(ev->y());
_x = 0;
_y = 0;
}
void Graph::wheelEvent(QWheelEvent *ev)
{
float scX, scY;
scX = line->GetXscale();
scY = line->GetYscale();
if(shiftPressed == true)
{
if(ev->delta() > 0) scY = scY - 0.1;
else scY = scY + 0.1;
line->SetScale(scX, scY);
}
else
{
if(ev->delta() > 0 ) scX = scX - 0.1;
else scX = scX + 0.1;
line->SetScale(scX, scY);
}
}