Repository navigation
Expand file tree
/
Copy pathindicatorled.cpp
More file actions
85 lines (70 loc) · 1.86 KB
/
Copy pathindicatorled.cpp
File metadata and controls
85 lines (70 loc) · 1.86 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
#include "indicatorled.h"
IndicatorLED::IndicatorLED(QWidget *parent)
: QWidget(parent)
{
Layout = new QHBoxLayout(this);
Layout->setSpacing(6);
Layout->setContentsMargins(0,0,0,0);
DefaultImage = new QImage(":/images/LED-Black.png");
IconOnImage = DefaultImage;
IconOffImage = DefaultImage;
Icon = new QLabel(this);
Icon->setFixedWidth(20);
Icon->setPixmap(QPixmap::fromImage(*IconOffImage));
Identifier = new QLabel(this);
Identifier->setMinimumWidth(40);
Layout->addWidget(Icon);
Layout->addWidget(Identifier);
setLayout(Layout);
connect(this, &IndicatorLED::objectNameChanged, Identifier, &QLabel::setText);
}
void IndicatorLED::setText(QString s)
{
Identifier->setText(s);
}
void IndicatorLED::setOnColour(Qt::GlobalColor Colour)
{
if(IconOnImage != DefaultImage)
delete(IconOnImage);
IconOnImage = SelectImage(Colour);
}
void IndicatorLED::setOffColour(Qt::GlobalColor Colour)
{
if(IconOffImage != DefaultImage)
delete(IconOffImage);
IconOffImage = SelectImage(Colour);
}
void IndicatorLED::operator=(bool f)
{
State = f;
Icon->setPixmap(QPixmap::fromImage(State ? *IconOnImage : *IconOffImage));
}
IndicatorLED::operator bool()
{
return State;
}
IndicatorLED::~IndicatorLED()
{
if(IconOnImage != DefaultImage)
delete IconOnImage;
if(IconOffImage != DefaultImage)
delete IconOffImage;
delete Layout;
delete DefaultImage;
delete Icon;
delete Identifier;
}
QImage * IndicatorLED::SelectImage(Qt::GlobalColor Colour)
{
switch(Colour)
{
case Qt::red:
return new QImage(":/images/LED-Red.png");
case Qt::blue:
return new QImage(":/images/LED-Blue.png");
case Qt::green:
return new QImage(":/images/LED-Green.png");
default:
return new QImage(":/images/LED-Black.png");
}
}