SEPIA
Software documentation for the APEX SEPIA receivers
led.h
1 /* Copyright 2017 Michael Olberg <michael.olberg@chalmers.se> */
2 #ifndef _LED_H_
3 #define _LED_H_
4 
5 #include <QWidget>
6 
7 class QTimer;
8 
9 class LED : public QWidget
10 {
11  Q_OBJECT
12 
13  Q_PROPERTY(double diameter READ diameter WRITE setDiameter) // mm
14  Q_PROPERTY(QColor color READ color WRITE setColor)
15  Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment)
16  Q_PROPERTY(bool state READ state WRITE setState)
17  Q_PROPERTY(bool flashing READ isFlashing WRITE setFlashing)
18  Q_PROPERTY(int flashRate READ flashRate WRITE setFlashRate)
19 
20  public:
21  explicit LED(QWidget* parent = 0);
22  ~LED();
23 
24  double diameter() const;
25  void setDiameter(double diameter);
26 
27  QColor color() const;
28  void setColor(const QColor& color);
29 
30  Qt::Alignment alignment() const;
31  void setAlignment(Qt::Alignment alignment);
32 
33  bool state() const;
34  bool isFlashing() const;
35  int flashRate() const;
36 
37  public slots:
38  void setState(bool state);
39  void toggleState();
40  void setFlashing(bool flashing);
41  void setFlashRate(int rate);
42  void startFlashing();
43  void stopFlashing();
44 
45  public:
46  int heightForWidth(int width) const;
47  QSize sizeHint() const;
48  QSize minimumSizeHint() const;
49 
50  protected:
51  void paintEvent(QPaintEvent* event);
52 
53  private:
54  double diameter_;
55  QColor color_;
56  Qt::Alignment alignment_;
57  bool initialState_;
58  bool state_;
59  int flashRate_;
60  bool flashing_;
61 
62  //
63  // Pixels per mm for x and y...
64  //
65  int pixX_, pixY_;
66 
67  //
68  // Scaled values for x and y diameter.
69  //
70  int diamX_, diamY_;
71 
72  QRadialGradient gradient_;
73  QTimer* timer_;
74 };
75 
76 #endif