Berkeley Nuclear Data Software
LightWidget.h
Go to the documentation of this file.
1 #ifndef _LIGHT_WIDGET_H_
2 #define _LIGHT_WIDGET_H_
3 
4 
5 #include <QWidget>
6 #include <QPainter>
7 
8 
9 
10 class LightWidget : public QWidget
11 {
12  Q_OBJECT
13  Q_PROPERTY(bool on READ isOn WRITE setOn)
14 public:
15  LightWidget(const QColor &color, QWidget *parent = 0)
16  : QWidget(parent), m_colorOff(Qt::red),m_colorOn(Qt::green),
17  m_on(false) {}
18 
19  bool isOn() const
20  { return m_on; }
21  void setOn(bool on)
22  {
23  if (on == m_on)
24  return;
25  m_on = on;
26  update();
27  }
28 
29 public slots:
30  void turnOff() { setOn(false); }
31  void turnOn() { setOn(true); }
32 
33 protected:
34  void paintEvent(QPaintEvent *) override
35  {
36  if (!m_on)
37  {
38  QPainter painter(this);
39  painter.setRenderHint(QPainter::Antialiasing);
40  painter.setBrush(m_colorOff);
41  painter.drawEllipse(0, 0, width(), height());
42 
43  return;
44  }
45  QPainter painter(this);
46  painter.setRenderHint(QPainter::Antialiasing);
47  painter.setBrush(m_colorOn);
48  painter.drawEllipse(0, 0, width(), height());
49  }
50 
51 private:
52  QColor m_colorOff;
53  QColor m_colorOn;
54  bool m_on;
55 };
56 
57 #endif
Definition: LightWidget.h:11
void paintEvent(QPaintEvent *) override
Definition: LightWidget.h:34
bool isOn() const
Definition: LightWidget.h:19
void turnOn()
Definition: LightWidget.h:31
LightWidget(const QColor &color, QWidget *parent=0)
Definition: LightWidget.h:15
void turnOff()
Definition: LightWidget.h:30
void setOn(bool on)
Definition: LightWidget.h:21
bool on
Definition: LightWidget.h:13