-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathledindicator.cpp
More file actions
186 lines (151 loc) · 4.29 KB
/
Copy pathledindicator.cpp
File metadata and controls
186 lines (151 loc) · 4.29 KB
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
#include "ledindicator.h"
// Constructor
LedIndicator::LedIndicator(QWidget *parent) : QWidget(parent) {
}
LedIndicator::LedIndicator(const QString& name, const double& x, const double& y, int ledSize, QWidget *parent) :
QWidget(parent)
{
threshold.push_back(5);
threshold.push_back(10);
lit = gray;
ledHighImpedance=Qt::red;
ledLowImpedance=Qt::green;
ledMidImpedance=Qt::yellow;
ledNotConnected=Qt::gray;
ledHighPattern = Qt::SolidPattern;
ledLowPattern = Qt::SolidPattern;
ledMidPattern = Qt::SolidPattern;
ledNotConnectedPattern = Qt::SolidPattern;
highlighted = false;
// Assign the name label displayed below the led
this->name = new QLabel(this);
this->name->setText(name);
// Led's relative positions to the parent picture.
this->relativePos_x = x;
this->relativePos_y = y;
this->ledSize = ledSize;
}
//-----------------------------------------------------------------------------------------------------
// PaintEvent overload
//-----------------------------------------------------------------------------------------------------
void LedIndicator::paintEvent(QPaintEvent *) {
QPainter p(this);
switch(lit) {
case gray:
p.setBrush(QBrush(ledNotConnected, ledNotConnectedPattern));
break;
case red:
p.setBrush(QBrush(ledHighImpedance, ledHighPattern));
break;
case yellow:
p.setBrush(QBrush(ledMidImpedance, ledMidPattern));
break;
case green:
p.setBrush(QBrush(ledLowImpedance, ledLowPattern));
break;
}
if (highlighted == true) {
QPen* pen = new QPen();
pen->setWidth(3);
pen->setColor(Qt::blue);
p.setPen(*pen);
}
else
p.setPen(Qt::NoPen);
p.drawEllipse(1,1,ledSize,ledSize);
}
//-----------------------------------------------------------------------------------------------------
// Getters and Setters
//-----------------------------------------------------------------------------------------------------
void LedIndicator::setState(color state)
{
lit = state;
repaint();
}
void LedIndicator::setHighImpColor(QColor highColor)
{
ledHighImpedance=highColor;
repaint();
}
void LedIndicator::setLowImpColor(QColor lowColor)
{
ledLowImpedance=lowColor;
repaint();
}
void LedIndicator::setMidImpColor(QColor midColor)
{
ledMidImpedance=midColor;
repaint();
}
void LedIndicator::setHighPattern(Qt::BrushStyle highPattern)
{
ledHighPattern=highPattern;
repaint();
}
void LedIndicator::setLowPattern(Qt::BrushStyle lowPattern)
{
ledLowPattern=lowPattern;
repaint();
}
void LedIndicator::setMidPattern(Qt::BrushStyle midPattern)
{
ledMidPattern=midPattern;
repaint();
}
void LedIndicator::setLedThreshold(int impThreshold) {
switch(impThreshold) {
case(0):
threshold.at(0) = 5.0;
threshold.at(1) = 10.0;
break;
case(1):
threshold.at(0) = 10.0;
threshold.at(1) = 20.0;
break;
case(2):
threshold.at(0) = 20.0;
threshold.at(1) = 50.0;
break;
case(3):
threshold.at(0) = 50.0;
threshold.at(1) = 100.0;
break;
}
}
void LedIndicator::setHighLighted(bool highLight) {
this->highlighted = highLight;
repaint();
}
void LedIndicator::setLedSize(int size)
{
ledSize=size;
setFixedSize(size+25, size+25);
repaint();
}
int LedIndicator::getLedSize(void) const {
return this->ledSize;
}
void LedIndicator::setRelativePosX(double x) {
this->relativePos_x = x;
}
double LedIndicator::getRelativePosX(void) const {
return this->relativePos_x;
}
void LedIndicator::setRelativePosY(double y) {
this->relativePos_y = y;
}
double LedIndicator::getRelativePosY(void) const {
return this->relativePos_y;
}
//-----------------------------------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------------------------------
void LedIndicator::displayImpedance(double impValue) {
if ( (impValue < threshold.at(0)) )
lit = green;
else if ( impValue > threshold.at(1) )
lit = red;
else
lit = yellow;
repaint();
}