-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathled.cpp
83 lines (72 loc) · 1.45 KB
/
led.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
/*! \file led.cpp
* \brief This is a simple coloured circle that can indicate a binary state.
* \details
* \author Csaba Hegedűs
* \copyright Csaba Hegedűs
* \date 2016
*/
#include <QWidget>
#include <QtGui>
#include <QtCore>
#include <QColor>
#include "led.h"
/*!
* \brief The constructor of the led widget.
* \details The constructor sets the circle color to red and shows it.
* \param parent
*/
Led::Led(QWidget *parent) : QWidget(parent)
{
/*!
* Set the size of the widget.
*/
setMinimumWidth(24);
setMinimumHeight(24);
setMaximumWidth(24);
setMaximumHeight(24);
/*!
* Set the color of the circle to red.
*/
ledColor = QColor(130,21,0);
/*!
* Show the widget.
*/
show();
}
/*!
* \brief Led::setState
* \param state
*/
void Led::setState(bool state)
{
/*!
* If \p<state> is true, set the color of the circle to green,
* if \p<state> is false, set the color of the circle to red.
*/
if(state)
ledColor = QColor(255,40,0);
else
ledColor = QColor(130,21,0);
/*!
* Update the widget, which triggers a paintEvent(QPaintEvent *e).
*/
update();
}
/*!
* \brief Led::paintEvent
* \param e
*/
void Led::paintEvent(QPaintEvent *e)
{
// draw circle
QPainter painter(this);
painter.setBrush(ledColor);
painter.setPen(Qt::black);
painter.drawEllipse(QRect(2,2,20,20));
}
/*!
* \brief Led::~Led
*/
Led::~Led()
{
}