cut 3.4.1-rc1
Loading...
Searching...
No Matches
QeLed.hpp
1#ifndef QELED_H
2#define QELED_H
3
4#include <QWidget>
5#include <QtSvg/QtSvg>
6#include <QtSvg/QSvgRenderer>
7#include <QColor>
8#include <QXmlStreamReader>
9
30class QeLed : public QWidget
31{
32 Q_OBJECT
33
41 Q_PROPERTY(QColor colorOn READ colorOn WRITE setColorOn NOTIFY colorOnChanged)
42
43
50 Q_PROPERTY(QColor colorOff READ colorOff WRITE setColorOff NOTIFY colorOffChanged)
51
56 Q_PROPERTY(bool lit READ isLit WRITE setLit NOTIFY toggled)
57
62 Q_PROPERTY(bool negate READ isNegated WRITE setNegate NOTIFY negated)
63
64public:
65 explicit QeLed(QWidget *parent = nullptr);
66 QColor colorOn(){ return this->m_colorOn;}
67 QColor colorOff(){ return this->m_colorOff;}
68 bool isLit(){ return this->m_lit;}
69 bool isNegated(){ return this->m_negate;}
70 QSize sizeHint() const {
71 return QSize(80,80);
72 }
73
74public slots:
75 void setColorOn(QColor newColorOn){
76 if(this->m_colorOn == newColorOn){
77 return;
78 }
79 this->m_colorOn = newColorOn;
80 this->update();
81 emit colorOnChanged(newColorOn);
82 }
83
84 void setColorOff(QColor newColorOff){
85 if(this->m_colorOff == newColorOff){
86 return;
87 }
88 this->m_colorOff = newColorOff;
89 this->update();
90 emit colorOffChanged(newColorOff);
91 }
92
93 void setLit(bool newValue){
94 if(this->m_lit == newValue){
95 return;
96 }
97 this->m_lit = newValue;
98 this->update();
99 emit toggled(newValue);
100 }
101
102 void setNegate(bool newValue){
103 this->m_negate = newValue;
104 this->update();
105 emit negated(newValue);
106 }
107
108signals:
112 void colorOnChanged(QColor newColorOn);
113
117 void colorOffChanged(QColor newColorOff);
118
122 void toggled(bool newValue);
123
127 void negated(bool newValue);
128
129protected:
130 void paintEvent(QPaintEvent *event) override;
131 void resizeEvent(QResizeEvent *event) override;
132 void changeEvent(QEvent *event) override;
133private:
134 bool m_lit = true;
135 bool m_negate = false;
136 QColor m_colorOn = QColorConstants::Svg::green;
137 QColor m_colorOff = QColorConstants::Svg::green.darker(240);
138
139 void paint_gloss(QPainter &painter, float center_x, float center_y, float gloss_radius, float alpha0, float alpha1, QRectF &target_rect, float mid_stop);
140};
141
142#endif // QELED_H
void negated(bool newValue)
If the negate value changes, the signal send.
void toggled(bool newValue)
If the lit value changes, the signal send.
QColor colorOn
Color to be used when the LED is lit, or turned on.
Definition QeLed.hpp:41
QColor colorOff
Color to be used when the LED is turned off.
Definition QeLed.hpp:50
bool lit
Indicates if the led is to be on or not.
Definition QeLed.hpp:56
void colorOffChanged(QColor newColorOff)
Communicates a change in off color.
bool negate
Configures the widget to negate the lit value.
Definition QeLed.hpp:62
void colorOnChanged(QColor newColorOn)
Communicates a change in on color.