forked from challinan/pmd-demo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.cpp
140 lines (109 loc) · 3.21 KB
/
helper.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
#include <QPainter>
#include <QPaintEvent>
#include <QWidget>
#include <QDebug>
#include "helper.h"
Helper::Helper()
{
}
void Helper::initialized(const int gW, const int gH, TGraphType gType, float gXScale)
{
graphBgImage = new QImage(":/images/grid.png");
graphType = gType;
if (graphType == GraphECG)
{
graphColor.setRgb(0,255,0);
}
else if (graphType == GraphABP)
{
graphColor.setRgb(255,0,0);
}
else if (graphType == GraphPLETH)
{
graphColor.setRgb(0,255,245);
}
// Graph widthxheight
graphHeight = gH;
graphWidth = gW;
/* Calculating y-axis offset value needed to shift the graph
to the middle of the plugin area. */
//the zero line will be at %80 of height
graphYOffset = graphHeight * 0.20;
// Setup graph scales
setGraphXScale(gXScale);
setGraphYScale(1);
//set the initial values to be same
graphPoint2=graphPoint1;
}
void Helper::setGraphXScale(float xScale)
{
graphXScale = xScale;
/* Number of units in plug-in area on x-axis. */
graphXMaxUnit = graphWidth / graphXScale;
/* Calculating # of pixels in x-axis per unit. */
graphXPerUnit = graphWidth / graphXMaxUnit;
// Initialize graph cell width
graphCellWidth = graphXScale + 10.0f;
// Initialize graph previous point
graphPoint1.setX(0);
graphPoint1.setY(graphYMaxUnit - graphYOffset);
}
float Helper::getGraphXScale()
{
return graphXScale;
}
void Helper::setGraphYScale(float yScale)
{
graphYScale = yScale;
/* Number of units in plug-in area on y-axis. */
graphYMaxUnit = graphHeight / graphYScale;
/* Calculating # of pixels in y-axis per unit. */
graphYPerUnit = graphHeight / graphYMaxUnit;
// Initialize graph previous point
graphPoint1.setY(graphYMaxUnit - graphYOffset);
}
float Helper::getGraphYScale()
{
return graphYScale;
}
void Helper::clearGraph(QPainter *painter)
{
//qDebug() << "Graph has been cleared";
painter->drawImage(0, 0, *graphBgImage);
}
void Helper::paintGraph(QPainter *painter)
{
// Erase the old graph line
painter->drawImage(getGraphRectEraser(), *graphBgImage, getGraphRectEraser());
// Draw line to previous to the new point
painter->setPen(QPen (graphColor, 1, Qt::SolidLine));
painter->drawLine(graphPoint1, graphPoint2);
// Save for later reference
graphPoint1 = graphPoint2;
// Wrap the line
if (graphPoint1.x() + graphXPerUnit >= graphWidth)
graphPoint1.setX(0);
}
QRect Helper::animate(signed short int xGraphData)
{
// Save new graph data
graphData = xGraphData;
// Calculate new point
graphPoint2.setY((graphYMaxUnit - (graphData + graphYOffset)));
graphPoint2.setX(graphPoint1.x() + graphXPerUnit);
// Calculate dirty rect
return getGraphRectDirty().toRect();
}
QRectF Helper::getGraphRectDirty()
{
return getGraphRectEraser();
}
QRectF Helper::getGraphRectEraser()
{
return QRectF(graphPoint1.x(), 0.0, graphCellWidth, graphHeight);
}
void Helper::resetValues()
{
graphPoint1.setX(0);
graphPoint2=graphPoint1;
}