cut  1.2.2-pre1
QeLed.hpp
Go to the documentation of this file.
1 #ifndef QELED_H
2 #define QELED_H
3 
4 #include <QWidget>
5 #include <QtSvg>
6 #include <QSvgRenderer>
7 #include <QColor>
8 #include <QXmlStreamReader>
9 
30 class QeLed : public QWidget
31 {
32  Q_OBJECT
33 
41  Q_PROPERTY(QColor colorOn MEMBER m_colorOn READ colorOn WRITE setColorOn NOTIFY colorOnChanged)
42 
43 
50  Q_PROPERTY(QColor colorOff MEMBER m_colorOff READ colorOff WRITE setColorOff NOTIFY colorOffChanged)
51 
52 
56  Q_PROPERTY(bool lit MEMBER m_lit READ isLit WRITE setLit NOTIFY toggled)
57 
58 
62  Q_PROPERTY(bool negate MEMBER m_negate READ isNegated WRITE setNegate NOTIFY negated)
63 
64 public:
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 
71 public slots:
72  void setColorOn(QColor newColorOn){this->m_colorOn = newColorOn; this->updateColor();
73  emit colorOnChanged(newColorOn);}
74  void setColorOff(QColor newColorOff){this->m_colorOff = newColorOff; this->updateColor();
75  emit colorOffChanged(newColorOff);}
76  void setLit(bool newValue){this->m_lit = newValue; this->updateColor();
77  emit toggled(newValue);}
78  void setNegate(bool newValue){this->m_negate = newValue; this->updateColor();
79  emit negated(newValue);}
80 
81 signals:
85  void colorOnChanged(QColor newColorOn);
86 
90  void colorOffChanged(QColor newColorOff);
91 
95  void toggled(bool newValue);
96 
100  void negated(bool newValue);
101 
102 protected:
103  void paintEvent(QPaintEvent *event) override;
104 
105 private:
106  bool m_lit = false;
107  bool m_negate = false;
108  QColor m_colorOn;
109  QColor m_colorOff;
110  QSvgRenderer m_svg;
111  QSvgRenderer m_svg_on;
112  QSvgRenderer m_svg_off;
113  QString m_originalXml;
114  QString m_modifiedXml;
115  const QString c_ledImagePath = ":/led.svg";
116 
117  void updateColor();
118  QColor calculateColor();
119 };
120 
121 #endif // QELED_H
QeLed::setLit
void setLit(bool newValue)
Definition: QeLed.hpp:76
QeLed::isLit
bool isLit()
Definition: QeLed.hpp:68
QeLed::isNegated
bool isNegated()
Definition: QeLed.hpp:69
QeLed::colorOn
QColor colorOn
Color to be used when the LED is lit, or turned on.
Definition: QeLed.hpp:41
QeLed::paintEvent
void paintEvent(QPaintEvent *event) override
Definition: QeLed.cpp:22
QeLed
LED widget.
Definition: QeLed.hpp:31
QeLed::colorOff
QColor colorOff()
Definition: QeLed.hpp:67
QeLed::colorOff
QColor colorOff
Color to be used when the LED is turned off.
Definition: QeLed.hpp:50
QeLed::setColorOff
void setColorOff(QColor newColorOff)
Definition: QeLed.hpp:74
QeLed::toggled
void toggled(bool newValue)
If the lit value changes, the signal send.
QeLed::colorOnChanged
void colorOnChanged(QColor newColorOn)
Communicates a change in on color.
QeLed::negated
void negated(bool newValue)
If the negate value changes, the signal send.
QeLed::setNegate
void setNegate(bool newValue)
Definition: QeLed.hpp:78
QeLed::lit
bool lit
Indicates if the led is to be on or not.
Definition: QeLed.hpp:56
QeLed::colorOffChanged
void colorOffChanged(QColor newColorOff)
Communicates a change in off color.
QeLed::negate
bool negate
Configures the widget to negate the lit value.
Definition: QeLed.hpp:62
QeLed::QeLed
QeLed(QWidget *parent=nullptr)
Definition: QeLed.cpp:7
QeLed::setColorOn
void setColorOn(QColor newColorOn)
Definition: QeLed.hpp:72
QeLed::colorOn
QColor colorOn()
Definition: QeLed.hpp:66