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 #include "xqdeviceorientation.h" |
|
18 #include "xqdeviceorientation_p.h" |
|
19 |
|
20 /*! |
|
21 \class XQDeviceOrientation |
|
22 |
|
23 \brief The XQDeviceOrientation class is used to determine the orientation |
|
24 of the device. |
|
25 |
|
26 Note that the orientation is calculated from the values received from |
|
27 acceleration sensor so the orientation is reliable only when the speed of |
|
28 the device is constant. |
|
29 |
|
30 Example: |
|
31 \code |
|
32 XQDeviceOrientation* orientation = new XQDeviceOrientation(this); |
|
33 orientation->setResolution(5); //degrees |
|
34 QObject::connect( |
|
35 orientation, SIGNAL(orientationChanged(XQDeviceOrientation::DisplayOrientation)), |
|
36 this, SLOT(updateOrientation(XQDeviceOrientation::DisplayOrientation))); |
|
37 int xRotation = orientation->xRotation(); |
|
38 \endcode |
|
39 */ |
|
40 |
|
41 /*! |
|
42 \enum XQDeviceOrientation::DisplayOrientation |
|
43 |
|
44 This enum defines the possible orientations of the device. |
|
45 */ |
|
46 |
|
47 /*! \var XQDeviceOrientation::DisplayOrientation XQDeviceOrientation::OrientationUndefined |
|
48 The orientation can't be determined. |
|
49 */ |
|
50 |
|
51 /*! \var XQDeviceOrientation::DisplayOrientation XQDeviceOrientation::OrientationDisplayUp |
|
52 The orientation of the device is up, i.e. standing. |
|
53 */ |
|
54 |
|
55 /*! \var XQDeviceOrientation::DisplayOrientation XQDeviceOrientation::OrientationDisplayDown |
|
56 The device is upside down, i.e. bottom up. |
|
57 */ |
|
58 |
|
59 /*! \var XQDeviceOrientation::DisplayOrientation XQDeviceOrientation::OrientationDisplayLeftUp |
|
60 The left side of the device is up. |
|
61 */ |
|
62 |
|
63 /*! \var XQDeviceOrientation::DisplayOrientation XQDeviceOrientation::OrientationDisplayRightUp |
|
64 The right side of the device is up. |
|
65 */ |
|
66 |
|
67 /*! \var XQDeviceOrientation::DisplayOrientation XQDeviceOrientation::OrientationDisplayUpwards |
|
68 The device is laying on its back. |
|
69 */ |
|
70 |
|
71 /*! \var XQDeviceOrientation::DisplayOrientation XQDeviceOrientation::OrientationDisplayDownwards |
|
72 The device is laying on its face. |
|
73 */ |
|
74 |
|
75 |
|
76 /*! |
|
77 Constructs a XQDeviceOrientation object with the given parent |
|
78 */ |
|
79 XQDeviceOrientation::XQDeviceOrientation(QObject* parent): |
|
80 QObject(parent), |
|
81 d(new XQDeviceOrientationPrivate(*this)) |
|
82 { |
|
83 } |
|
84 |
|
85 /*! |
|
86 Destroys the XQDeviceOrientation, deleting all its children. |
|
87 */ |
|
88 XQDeviceOrientation::~XQDeviceOrientation() |
|
89 { |
|
90 } |
|
91 |
|
92 /*! |
|
93 Opens sensor connection |
|
94 */ |
|
95 void XQDeviceOrientation::open() |
|
96 { |
|
97 d->open(); |
|
98 } |
|
99 |
|
100 /*! |
|
101 Closes sensor connection |
|
102 */ |
|
103 void XQDeviceOrientation::close() |
|
104 { |
|
105 d->close(); |
|
106 } |
|
107 |
|
108 /*! |
|
109 Sets the rounding resolution of the rotation angles. For example, say |
|
110 the resolution is set to 10 degrees; if the raw angle is 109 degrees, then |
|
111 110 degrees will be reported, if the raw angle is 93 degrees, then 90 degrees |
|
112 will be reported. |
|
113 |
|
114 Note: If this function is not called, the |
|
115 default rounding resolution of 15 degrees is used. |
|
116 |
|
117 |
|
118 \param resolution Resolution in degrees. |
|
119 */ |
|
120 void XQDeviceOrientation::setResolution(int resolution) |
|
121 { |
|
122 d->setResolution(resolution); |
|
123 } |
|
124 |
|
125 /*! |
|
126 \return Current rotation esolution in degrees |
|
127 */ |
|
128 int XQDeviceOrientation::resolution() const |
|
129 { |
|
130 return d->resolution(); |
|
131 } |
|
132 |
|
133 /*! |
|
134 \return X-axis rotation in degrees (0-359). |
|
135 */ |
|
136 int XQDeviceOrientation::xRotation() const |
|
137 { |
|
138 return d->xRotation(); |
|
139 } |
|
140 |
|
141 /*! |
|
142 \return Y-axis rotation in degrees (0-359). |
|
143 */ |
|
144 int XQDeviceOrientation::yRotation() const |
|
145 { |
|
146 return d->yRotation(); |
|
147 } |
|
148 |
|
149 /*! |
|
150 \return Z-axis rotation in degrees (0-359). |
|
151 */ |
|
152 int XQDeviceOrientation::zRotation() const |
|
153 { |
|
154 return d->zRotation(); |
|
155 } |
|
156 |
|
157 /*! |
|
158 \return Current device orientation |
|
159 */ |
|
160 XQDeviceOrientation::DisplayOrientation XQDeviceOrientation::orientation() const |
|
161 { |
|
162 return d->orientation(); |
|
163 } |
|
164 |
|
165 /*! |
|
166 \fn void XQDeviceOrientation::rotationChanged(int xRotation, int yRotation, int zRotation); |
|
167 |
|
168 This signal is emitted when the angle of rotation of the device has changed. |
|
169 |
|
170 \param xRotation Rotation of x axis in degrees (0-359). |
|
171 \param yRotation Rotation of y axis in degrees (0-359). |
|
172 \param zRotation Rotation of z axis in degrees (0-359). |
|
173 */ |
|
174 |
|
175 /*! |
|
176 \fn void XQDeviceOrientation::orientationChanged(XQDeviceOrientation::DisplayOrientation orientation); |
|
177 |
|
178 This signal is emitted when the orientation of the device has changed. |
|
179 |
|
180 \param orientation Current orientation |
|
181 \sa setResolution() |
|
182 */ |
|