Unity 8
Lights.h
1 /*
2  * Copyright (C) 2014 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Author: Renato Araujo Oliveira Filho <renato.filho@canonical.com>
17  */
18 
19 #ifndef UNITY_LIGHTS_H
20 #define UNITY_LIGHTS_H
21 
22 #include <QtCore/QObject>
23 #include <QtGui/QColor>
24 
25 struct light_device_t;
26 
27 class Lights: public QObject
28 {
29  Q_OBJECT
30  Q_ENUMS(State)
31  Q_PROPERTY(State state READ state WRITE setState NOTIFY stateChanged)
32  Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged)
33  Q_PROPERTY(int onMillisec READ onMillisec WRITE setOnMillisec NOTIFY onMillisecChanged)
34  Q_PROPERTY(int offMillisec READ offMillisec WRITE setOffMillisec NOTIFY offMillisecChanged)
35 
36 public:
37  enum State {
38  Off,
39  On,
40  };
41 
42  explicit Lights(QObject *parent = 0);
43  ~Lights();
44 
45  void setState(State newState);
46  State state() const;
47 
48  void setColor(const QColor &color);
49  QColor color() const;
50 
51  int onMillisec() const;
52  void setOnMillisec(int onMs);
53 
54  int offMillisec() const;
55  void setOffMillisec(int offMs);
56 
57 Q_SIGNALS:
58  void stateChanged(State newState);
59  void colorChanged(const QColor &color);
60  void onMillisecChanged(int onMs);
61  void offMillisecChanged(int offMs);
62 
63 private:
64  light_device_t* m_lightDevice;
65  QColor m_color;
66  State m_state;
67  int m_onMs;
68  int m_offMs;
69 
70  bool init();
71  void turnOff();
72  void turnOn();
73 };
74 
75 #endif