1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qorientationsensor.h" |
5 | #include "qorientationsensor_p.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | IMPLEMENT_READING(QOrientationReading) |
10 | |
11 | /*! |
12 | \class QOrientationReading |
13 | \ingroup sensors_reading |
14 | \inmodule QtSensors |
15 | \since 5.1 |
16 | |
17 | \brief The QOrientationReading class represents one reading from the |
18 | orientation sensor. |
19 | |
20 | The orientation sensor reports the orientation of the device. As it operates below |
21 | the UI level it does not report on or even know how the UI is rotated. Most importantly |
22 | this means that this sensor cannot be used to detect if a device is in portrait or |
23 | landscape mode. |
24 | |
25 | This sensor is useful to detect that a particular side of the device is pointing up. |
26 | |
27 | \section2 QOrientationReading Units |
28 | The orientation sensor returns the orientation of the device using |
29 | the pre-defined values found in the QOrientationReading::Orientation |
30 | enum. |
31 | */ |
32 | |
33 | /*! |
34 | \enum QOrientationReading::Orientation |
35 | |
36 | This enum represents the orientation of the device. |
37 | |
38 | To explain the meaning of each value it is helpful to refer to the following diagram. |
39 | |
40 | \image sensors-sides.jpg |
41 | |
42 | The orientations are shown here in order: TopUp, TopDown, LeftUp, RightUp, FaceUp, FaceDown. |
43 | |
44 | \image sensors-orientation.jpg |
45 | |
46 | \value Undefined The orientation is unknown. |
47 | \value TopUp The Top edge of the device is pointing up. |
48 | \value TopDown The Top edge of the device is pointing down. |
49 | \value LeftUp The Left edge of the device is pointing up. |
50 | \value RightUp The Right edge of the device is pointing up. |
51 | \value FaceUp The Face of the device is pointing up. |
52 | \value FaceDown The Face of the device is pointing down. |
53 | |
54 | It should be noted that the orientation sensor reports the orientation of the device |
55 | and not the UI. The orientation of the device will not change just because the UI is |
56 | rotated. This means this sensor cannot be used to detect if a device is in portrait |
57 | or landscape mode. |
58 | */ |
59 | |
60 | /*! |
61 | \property QOrientationReading::orientation |
62 | \brief the orientation of the device. |
63 | |
64 | The unit is an enumeration describing the orientation of the device. |
65 | |
66 | \sa {QOrientationReading Units} |
67 | */ |
68 | |
69 | QOrientationReading::Orientation QOrientationReading::orientation() const |
70 | { |
71 | return static_cast<QOrientationReading::Orientation>(d->orientation); |
72 | } |
73 | |
74 | /*! |
75 | Sets the \a orientation for the reading. |
76 | */ |
77 | void QOrientationReading::setOrientation(QOrientationReading::Orientation orientation) |
78 | { |
79 | switch (orientation) { |
80 | case TopUp: |
81 | case TopDown: |
82 | case LeftUp: |
83 | case RightUp: |
84 | case FaceUp: |
85 | case FaceDown: |
86 | d->orientation = orientation; |
87 | break; |
88 | default: |
89 | d->orientation = Undefined; |
90 | break; |
91 | } |
92 | } |
93 | |
94 | // ===================================================================== |
95 | |
96 | /*! |
97 | \class QOrientationFilter |
98 | \ingroup sensors_filter |
99 | \inmodule QtSensors |
100 | \since 5.1 |
101 | |
102 | \brief The QOrientationFilter class is a convenience wrapper around QSensorFilter. |
103 | |
104 | The only difference is that the filter() method features a pointer to QOrientationReading |
105 | instead of QSensorReading. |
106 | */ |
107 | |
108 | /*! |
109 | \fn QOrientationFilter::filter(QOrientationReading *reading) |
110 | |
111 | Called when \a reading changes. Returns false to prevent the reading from propagating. |
112 | |
113 | \sa QSensorFilter::filter() |
114 | */ |
115 | |
116 | bool QOrientationFilter::filter(QSensorReading *reading) |
117 | { |
118 | return filter(reading: static_cast<QOrientationReading*>(reading)); |
119 | } |
120 | |
121 | char const * const QOrientationSensor::sensorType("QOrientationSensor" ); |
122 | |
123 | /*! |
124 | \class QOrientationSensor |
125 | \ingroup sensors_type |
126 | \inmodule QtSensors |
127 | \since 5.1 |
128 | |
129 | \brief The QOrientationSensor class is a convenience wrapper around QSensor. |
130 | |
131 | The only behavioural difference is that this class sets the type properly. |
132 | |
133 | This class also features a reading() function that returns a QOrientationReading instead of a QSensorReading. |
134 | |
135 | For details about how the sensor works, see \l QOrientationReading. |
136 | |
137 | \sa QOrientationReading |
138 | */ |
139 | |
140 | /*! |
141 | Construct the sensor as a child of \a parent. |
142 | */ |
143 | QOrientationSensor::QOrientationSensor(QObject *parent) |
144 | : QSensor(QOrientationSensor::sensorType, parent) |
145 | { |
146 | } |
147 | |
148 | /*! |
149 | Destroy the sensor. Stops the sensor if it has not already been stopped. |
150 | */ |
151 | QOrientationSensor::~QOrientationSensor() |
152 | { |
153 | } |
154 | |
155 | /*! |
156 | \fn QOrientationSensor::reading() const |
157 | |
158 | Returns the reading class for this sensor. |
159 | |
160 | \sa QSensor::reading() |
161 | */ |
162 | |
163 | QOrientationReading *QOrientationSensor::reading() const |
164 | { |
165 | return static_cast<QOrientationReading*>(QSensor::reading()); |
166 | } |
167 | |
168 | QT_END_NAMESPACE |
169 | |
170 | #include "moc_qorientationsensor.cpp" |
171 | |