luna-sysmgr-common
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CustomEvents.h
Go to the documentation of this file.
1 /* @@@LICENSE
2 *
3 * Copyright (c) 2010-2012 Hewlett-Packard Development Company, L.P.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 * LICENSE@@@ */
18 
19 
20 
21 
22 #ifndef CUSTOMEVENTS_H_
23 #define CUSTOMEVENTS_H_
24 
25 #include "Common.h"
26 
27 #include <QEvent>
28 
30 {
34 };
35 
36 
37 static const ushort proximityEventType = QEvent::User + 1000;
38 static const ushort alsEventType = QEvent::User + 1001;
39 static const ushort accelerometerEventType = QEvent::User + 1004;
40 static const ushort accelerationEventType = QEvent::User + 1005;
41 static const ushort angularVelocityEventType = QEvent::User + 1006;
42 static const ushort bearingEventType = QEvent::User + 1007;
43 static const ushort compassEventType = QEvent::User + 1005;
44 static const ushort gravityEventType = QEvent::User + 1008;
45 static const ushort linearAccelerationEventType = QEvent::User + 1009;
46 static const ushort magneticFieldEventType = QEvent::User + 1010;
47 static const ushort orientationEventType = QEvent::User + 1011;
48 static const ushort rotationEventType = QEvent::User + 1012;
49 static const ushort shakeEventType = QEvent::User + 1013;
50 
51 
52 class ProximityEvent: public QEvent {
53 public:
54  ProximityEvent(bool detected) :
55  QEvent((QEvent::Type) proximityEventType), objectDetected(detected) {
56  }
57 
59  return objectDetected;
60  }
61 
62 private:
63  bool objectDetected;
64 };
65 
66 
67 class AlsEvent: public QEvent {
68 public:
69  AlsEvent(int intensity) :
70  QEvent((QEvent::Type) alsEventType), lightIntensity(intensity) {
71  }
72 
74  return lightIntensity;
75  }
76 
77 private:
78  int lightIntensity;
79 };
80 
81 class ShakeEvent : public QEvent
82 {
83 public:
84  enum Shake
85  {
90  Shake_Last = 1 << 31
91  };
92 
93  ShakeEvent(Shake shakeState, float shakeMagnitude) :
94  QEvent((QEvent::Type) shakeEventType),
95  m_shakeState(shakeState),
96  m_shakeMagnitude(shakeMagnitude)
97  {
98  }
99 
100 private:
101  Shake m_shakeState;
102  float m_shakeMagnitude;
103 };
104 
105 class OrientationEvent : public QEvent
106 {
107 public:
109  {
120  };
121 
123  QEvent((QEvent::Type) orientationEventType),
124  m_orientation(orientation),
125  m_pitch(pitch),
126  m_roll(roll)
127  {
128  }
129 
131  QEvent((QEvent::Type) orientationEventType),
132  m_orientation(orientation),
133  m_pitch(0),
134  m_roll(0)
135  {
136  }
137 
138  Orientation orientation() const { return m_orientation; }
139  float pitch() const { return m_pitch; }
140  float roll() const { return m_roll; }
141 
142 private:
143  Orientation m_orientation;
144  float m_pitch;
145  float m_roll;
146 };
147 
154 {
155 public:
156  AccelerometerEvent(float x, float y, float z) :
157  QEvent((QEvent::Type) accelerometerEventType),
158  m_x(x),
159  m_y(y),
160  m_z(z),
161  m_orientation(OrientationEvent::Orientation_Invalid),
162  m_pitch(0),
163  m_roll(0),
164  m_shakeState(ShakeEvent::Shake_Invalid),
165  m_shakeMagnitude(0)
166  {
167  }
168 
170  QEvent((QEvent::Type) accelerometerEventType),
171  m_x(0),
172  m_y(0),
173  m_z(0),
174  m_orientation(orientation),
175  m_pitch(0),
176  m_roll(0),
177  m_shakeState(ShakeEvent::Shake_Invalid),
178  m_shakeMagnitude(0)
179  {
180  }
181 
183  float x, float y, float z,
185  QEvent((QEvent::Type) accelerometerEventType),
186  m_x(x),
187  m_y(y),
188  m_z(z),
189  m_orientation(orientation),
190  m_pitch(pitch),
191  m_roll(roll),
192  m_shakeState(shakeState),
193  m_shakeMagnitude(shakeMagnitude)
194  {
195  }
196 
197  float x() const { return m_x; }
198  float y() const { return m_y; }
199  float z() const { return m_z; }
200  OrientationEvent::Orientation orientation() const { return m_orientation; }
201 
202  float pitch() const { return m_pitch; }
203  float roll() const { return m_roll; }
204  ShakeEvent::Shake shakeState() const { return m_shakeState; }
205  float shakeMagnitude() const { return m_shakeMagnitude; }
206 
207 private:
208  float m_x;
209  float m_y;
210  float m_z;
211 
212  OrientationEvent::Orientation m_orientation;
213  float m_pitch;
214  float m_roll;
215 
216  ShakeEvent::Shake m_shakeState;
217  float m_shakeMagnitude;
218 };
219 
220 
221 class AccelerationEvent : public QEvent
222 {
223 public:
224  AccelerationEvent(float x, float y, float z) :
225  QEvent((QEvent::Type) accelerationEventType),
226  m_x(x),
227  m_y(y),
228  m_z(z)
229  {
230  }
231 
232  float x() const { return m_x; }
233  float y() const { return m_y; }
234  float z() const { return m_z; }
235 
236 private:
237  float m_x;
238  float m_y;
239  float m_z;
240 };
241 
242 
244 {
245 public:
246  AngularVelocityEvent(float x, float y, float z) :
247  QEvent((QEvent::Type) angularVelocityEventType),
248  m_x(x),
249  m_y(y),
250  m_z(z)
251  {
252  }
253 
254  float x() const { return m_x; }
255  float y() const { return m_y; }
256  float z() const { return m_z; }
257 
258 private:
259  float m_x;
260  float m_y;
261  float m_z;
262 };
263 
264 
265 class BearingEvent : public QEvent
266 {
267 public:
269  QEvent((QEvent::Type) bearingEventType),
270  m_mag_bearing(mag_bearing),
271  m_true_bearing(true_bearing),
272  m_confidence(confidence)
273  {
274  }
275 
276  float mag_bearing() const { return m_mag_bearing; }
277  float true_bearing() const { return m_true_bearing; }
278  float confidence() const { return m_confidence; }
279 
280 private:
281  float m_mag_bearing;
282  float m_true_bearing;
283  float m_confidence;
284 };
285 
286 
287 class GravityEvent : public QEvent
288 {
289 public:
290  GravityEvent(float x, float y, float z) :
291  QEvent((QEvent::Type) gravityEventType),
292  m_x(x),
293  m_y(y),
294  m_z(z)
295  {
296  }
297 
298  float x() const { return m_x; }
299  float y() const { return m_y; }
300  float z() const { return m_z; }
301 
302 private:
303  float m_x;
304  float m_y;
305  float m_z;
306 };
307 
308 
310 {
311 public:
312  LinearAccelerationEvent(float x, float y, float z, float world_x, float world_y, float world_z) :
313  QEvent((QEvent::Type) gravityEventType),
314  m_x(x),
315  m_y(y),
316  m_z(z),
317  m_world_x(world_x),
318  m_world_y(world_y),
319  m_world_z(world_z)
320  {
321  }
322 
323  float x() const { return m_x; }
324  float y() const { return m_y; }
325  float z() const { return m_z; }
326  float world_x() const { return m_world_x; }
327  float world_y() const { return m_world_y; }
328  float world_z() const { return m_world_z; }
329 
330 private:
331  float m_x;
332  float m_y;
333  float m_z;
334  float m_world_x;
335  float m_world_y;
336  float m_world_z;
337 };
338 
339 
341 {
342 public:
343  MagneticFieldEvent(int x, int y, int z, int raw_x, int raw_y, int raw_z) :
344  QEvent((QEvent::Type) magneticFieldEventType),
345  m_x(x),
346  m_y(y),
347  m_z(z),
348  m_raw_x(raw_x),
349  m_raw_y(raw_y),
350  m_raw_z(raw_z)
351  {
352  }
353 
354  int x() const { return m_x; }
355  int y() const { return m_y; }
356  int z() const { return m_z; }
357  int raw_x() const { return m_raw_x; }
358  int raw_y() const { return m_raw_y; }
359  int raw_z() const { return m_raw_z; }
360 
361 private:
362  int m_x;
363  int m_y;
364  int m_z;
365  int m_raw_x;
366  int m_raw_y;
367  int m_raw_z;
368 };
369 
370 class CompassEvent : public QEvent
371 {
372 public:
373  CompassEvent(float magBearing, float trueBearing, int confidence) :
374  QEvent((QEvent::Type) compassEventType),
375  m_mag_bearing(magBearing),
376  m_true_bearing(trueBearing),
377  m_confidence(confidence)
378 
379  {
380  }
381  int confidence() const { return m_confidence; }
382  float mag_bearing() const { return m_mag_bearing; }
383  float true_bearing() const { return m_true_bearing; }
384 
385 private:
386  float m_mag_bearing;
387  float m_true_bearing;
388  int m_confidence;
389 };
390 
391 class RotationEvent : public QEvent
392 {
393 public:
394  RotationEvent(float pitch, float roll) :
395  QEvent((QEvent::Type) rotationEventType),
396  m_pitch(pitch),
397  m_roll(roll)
398  {
399  }
400 
401  float pitch() const { return m_pitch; }
402  float roll() const { return m_roll; }
403 
404 private:
405  float m_pitch;
406  float m_roll;
407 };
408 
409 #endif /* CUSTOMEVENTS_H_ */