1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 #include "xqdeviceorientation.h" |
|
19 #include "cxesensoreventhandlersymbian.h" |
|
20 #include "cxutils.h" |
|
21 |
|
22 |
|
23 CxeSensorEventHandlerSymbian::CxeSensorEventHandlerSymbian() |
|
24 : mOrientationSensor(NULL) |
|
25 { |
|
26 CX_DEBUG_ENTER_FUNCTION(); |
|
27 CX_DEBUG_EXIT_FUNCTION(); |
|
28 } |
|
29 |
|
30 CxeSensorEventHandlerSymbian::~CxeSensorEventHandlerSymbian() |
|
31 { |
|
32 CX_DEBUG_ENTER_FUNCTION(); |
|
33 CX_DEBUG_EXIT_FUNCTION(); |
|
34 } |
|
35 |
|
36 |
|
37 |
|
38 /* |
|
39 * initializes and enables all supported sensor events |
|
40 */ |
|
41 void CxeSensorEventHandlerSymbian::init() |
|
42 { |
|
43 CX_DEBUG_ENTER_FUNCTION(); |
|
44 enableOrientationSensor(); |
|
45 CX_DEBUG_EXIT_FUNCTION(); |
|
46 } |
|
47 |
|
48 |
|
49 /* |
|
50 * closes all supported sensors. |
|
51 */ |
|
52 void CxeSensorEventHandlerSymbian::deinit() |
|
53 { |
|
54 CX_DEBUG_ENTER_FUNCTION(); |
|
55 disableOrientationSensor(); |
|
56 CX_DEBUG_EXIT_FUNCTION(); |
|
57 } |
|
58 |
|
59 |
|
60 /* |
|
61 * Initializes and opens connection to recieve orientation sensor events |
|
62 */ |
|
63 void CxeSensorEventHandlerSymbian::enableOrientationSensor() |
|
64 { |
|
65 CX_DEBUG_ENTER_FUNCTION(); |
|
66 |
|
67 if( mOrientationSensor == NULL) { |
|
68 mOrientationSensor = new XQDeviceOrientation(this); |
|
69 if (mOrientationSensor) { |
|
70 |
|
71 // connect signals from orientationsensor, so we recieve events when orientation changes |
|
72 QObject::connect( mOrientationSensor, |
|
73 SIGNAL(orientationChanged(XQDeviceOrientation::DisplayOrientation)), |
|
74 this,SLOT(handleOrientationChanged(XQDeviceOrientation::DisplayOrientation)) ); |
|
75 |
|
76 // open the sensor connection |
|
77 mOrientationSensor->open(); |
|
78 } |
|
79 } |
|
80 |
|
81 CX_DEBUG_EXIT_FUNCTION(); |
|
82 } |
|
83 |
|
84 /* |
|
85 * Closes and destroys connection to orientation sensor events. |
|
86 */ |
|
87 void CxeSensorEventHandlerSymbian::disableOrientationSensor() |
|
88 { |
|
89 CX_DEBUG_ENTER_FUNCTION(); |
|
90 |
|
91 if (mOrientationSensor) { |
|
92 mOrientationSensor->close(); |
|
93 delete mOrientationSensor; |
|
94 mOrientationSensor = NULL; |
|
95 } |
|
96 |
|
97 CX_DEBUG_EXIT_FUNCTION(); |
|
98 } |
|
99 |
|
100 |
|
101 /* |
|
102 * Closes and destroys connection to orientation sensor events. |
|
103 */ |
|
104 QVariant CxeSensorEventHandlerSymbian::sensorData(CxeSensorEventHandlerSymbian::SensorType type) |
|
105 { |
|
106 CX_DEBUG_ENTER_FUNCTION(); |
|
107 |
|
108 QVariant data; |
|
109 |
|
110 if (mOrientationSensor && type == CxeSensorEventHandler::OrientationSensor) { |
|
111 data = qVariantFromValue<Cxe::DeviceOrientation > (mapOrientationSensorData(mOrientationSensor->orientation())); |
|
112 } |
|
113 |
|
114 CX_DEBUG_EXIT_FUNCTION(); |
|
115 |
|
116 return data; |
|
117 } |
|
118 |
|
119 |
|
120 /* |
|
121 * Emits signal whenever we receive data from orientation sensor. |
|
122 */ |
|
123 void CxeSensorEventHandlerSymbian::handleOrientationChanged(XQDeviceOrientation::DisplayOrientation sensorData) |
|
124 { |
|
125 CX_DEBUG_ENTER_FUNCTION(); |
|
126 |
|
127 QVariant data = qVariantFromValue<Cxe::DeviceOrientation > (mapOrientationSensorData(sensorData)); |
|
128 emit sensorEvent(CxeSensorEventHandler::OrientationSensor, data); |
|
129 |
|
130 CX_DEBUG_EXIT_FUNCTION(); |
|
131 } |
|
132 |
|
133 |
|
134 /* |
|
135 * Maps sensor data to camera enums |
|
136 */ |
|
137 Cxe::DeviceOrientation |
|
138 CxeSensorEventHandlerSymbian::mapOrientationSensorData(XQDeviceOrientation::DisplayOrientation sensorData) |
|
139 { |
|
140 CX_DEBUG_ENTER_FUNCTION(); |
|
141 |
|
142 Cxe::DeviceOrientation uiOrientation(Cxe::Orientation0); |
|
143 |
|
144 switch (sensorData) { |
|
145 case XQDeviceOrientation::OrientationDisplayUpwards: |
|
146 case XQDeviceOrientation::OrientationDisplayDownwards: |
|
147 uiOrientation = Cxe::OrientationNone; |
|
148 break; |
|
149 case XQDeviceOrientation::OrientationDisplayRightUp: |
|
150 case XQDeviceOrientation::OrientationUndefined: |
|
151 uiOrientation = Cxe::Orientation0; |
|
152 break; |
|
153 case XQDeviceOrientation::OrientationDisplayUp: |
|
154 uiOrientation = Cxe::Orientation90; |
|
155 break; |
|
156 case XQDeviceOrientation::OrientationDisplayLeftUp: |
|
157 uiOrientation = Cxe::Orientation180; |
|
158 break; |
|
159 case XQDeviceOrientation::OrientationDisplayDown: |
|
160 uiOrientation = Cxe::Orientation270; |
|
161 break; |
|
162 default: |
|
163 break; |
|
164 } |
|
165 |
|
166 CX_DEBUG_EXIT_FUNCTION(); |
|
167 |
|
168 return uiOrientation; |
|
169 } |
|
170 |
|
171 |
|
172 // end of file |
|