on xenial help sign in
Expose color, onMillisec and offMillisec properties to QML.
commit7cd27f20666a81942ebfc108eff3dc1103e0a7b6 authorRenato Araujo Oliveira Filho <renato.filho@canonical.com> dateWed 2 Jul 2014, 20:15 (12 years ago) parent5c90c06
3 files changed+70−7
plugins/Lights/CMakeLists.txt+1−1 plugins/Lights/Lights.cpp+49−5 plugins/Lights/Lights.h+20−1
plugins/Lights/CMakeLists.txt+1−1
@@ -12,7 +12,7 @@ add_library(Lights-qml MODULE
1212 Lights.cpp
1313 )
1414
15−qt5_use_modules(Lights-qml Qml)
15+qt5_use_modules(Lights-qml Qml Gui)
1616target_link_libraries(Lights-qml ${ANDROID_HARDWARE_LIBRARIES})
1717
1818add_unity8_plugin(Lights 0.1 Lights TARGETS Lights-qml)
plugins/Lights/Lights.cpp+49−5
@@ -27,12 +27,14 @@ extern "C" {
2727
2828Lights::Lights(QObject* parent)
2929 : QObject(parent),
30+ m_lightDevice(0),
31+ m_color("blue"),
3032 m_state(Lights::Off),
31− m_lightDevice(0)
33+ m_onMs(1000),
34+ m_offMs(3000)
3235{
3336}
3437
35−
3638Lights::~Lights()
3739{
3840 if (m_lightDevice) {
@@ -57,6 +59,48 @@ Lights::State Lights::state() const
5759 return m_state;
5860}
5961
62+void Lights::setColor(const QColor &color)
63+{
64+ if (m_color != color) {
65+ m_color = color;
66+ Q_EMIT colorChanged(m_color);
67+ // FIXME: update the collor if the light is already on
68+ }
69+}
70+
71+QColor Lights::color() const
72+{
73+ return m_color;
74+}
75+
76+int Lights::onMillisec() const
77+{
78+ return m_onMs;
79+}
80+
81+void Lights::setOnMillisec(int onMs)
82+{
83+ if (m_onMs != onMs) {
84+ m_onMs = onMs;
85+ Q_EMIT onMillisecChanged(m_onMs);
86+ // FIXME: update the property if the light is already on
87+ }
88+}
89+
90+int Lights::offMillisec() const
91+{
92+ return m_offMs;
93+}
94+
95+void Lights::setOffMillisec(int offMs)
96+{
97+ if (m_offMs != offMs) {
98+ m_offMs = offMs;
99+ Q_EMIT offMillisecChanged(m_offMs);
100+ // FIXME: update the property if the light is already on
101+ }
102+}
103+
60104bool Lights::init()
61105{
62106 if (m_lightDevice) {
@@ -96,10 +140,10 @@ void Lights::turnOn()
96140 // pulse
97141 light_state_t state;
98142 memset(&state, 0, sizeof(light_state_t));
99− state.color = 0xff0000ff; // blue
143+ state.color = m_color.rgba();
100144 state.flashMode = LIGHT_FLASH_TIMED;
101− state.flashOnMS = 1000;
102− state.flashOffMS = 1000;
145+ state.flashOnMS = m_onMs;
146+ state.flashOffMS = m_offMs;
103147 state.brightnessMode = BRIGHTNESS_MODE_USER;
104148
105149 if (m_lightDevice->set_light(m_lightDevice, &state) != 0) {
plugins/Lights/Lights.h+20−1
@@ -20,6 +20,7 @@
2020#define UNITY_LIGHTS_H
2121
2222#include <QtCore/QObject>
23+#include <QtGui/QColor>
2324
2425struct light_device_t;
2526
@@ -28,6 +29,9 @@ class Lights: public QObject
2829 Q_OBJECT
2930 Q_ENUMS(State)
3031 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)
3135
3236public:
3337 enum State {
@@ -41,12 +45,27 @@ public:
4145 void setState(State newState);
4246 State state() const;
4347
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+
4457Q_SIGNALS:
4558 void stateChanged(State newState);
59+ void colorChanged(const QColor &color);
60+ void onMillisecChanged(int onMs);
61+ void offMillisecChanged(int offMs);
4662
4763private:
48− State m_state;
4964 light_device_t* m_lightDevice;
65+ QColor m_color;
66+ State m_state;
67+ int m_onMs;
68+ int m_offMs;
5069
5170 bool init();
5271 void turnOff();