cut 3.3.0
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
71public slots:
72 void setColorOn(QColor newColorOn){
73 this->m_colorOn = newColorOn;
74 this->updateColor();
75 emit colorOnChanged(newColorOn);
76 }
77 void setColorOff(QColor newColorOff){
78 this->m_colorOff = newColorOff;
79 this->updateColor();
80 emit colorOffChanged(newColorOff);
81 }
82 void setLit(bool newValue){
83 this->m_lit = newValue;
84 this->updateColor();
85 emit toggled(newValue);
86 }
87 void setNegate(bool newValue){
88 this->m_negate = newValue;
89 this->updateColor();
90 emit negated(newValue);
91 }
92
93signals:
97 void colorOnChanged(QColor newColorOn);
98
102 void colorOffChanged(QColor newColorOff);
103
107 void toggled(bool newValue);
108
112 void negated(bool newValue);
113
114protected:
115 void paintEvent(QPaintEvent *event) override;
116 void resizeEvent(QResizeEvent *event) override;
117
118private:
119 bool m_lit = false;
120 bool m_negate = false;
121 QColor m_colorOn;
122 QColor m_colorOff;
123 QSvgRenderer m_svg;
124 QSvgRenderer m_svg_on;
125 QSvgRenderer m_svg_off;
126 QString m_originalXml;
127 QString m_modifiedXml;
128 const QString c_ledImagePath = ":/led.svg";
129
130 void updateColor();
131 QColor calculateColor();
132};
133
134#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.