| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Contact: https://www.qt.io/licensing/ |
| 5 | ** |
| 6 | ** This file is part of the QtSensors module of the Qt Toolkit. |
| 7 | ** |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 9 | ** Commercial License Usage |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 11 | ** accordance with the commercial license agreement provided with the |
| 12 | ** Software or, alternatively, in accordance with the terms contained in |
| 13 | ** a written agreement between you and The Qt Company. For licensing terms |
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 15 | ** information use the contact form at https://www.qt.io/contact-us. |
| 16 | ** |
| 17 | ** GNU Lesser General Public License Usage |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 19 | ** General Public License version 3 as published by the Free Software |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 21 | ** packaging of this file. Please review the following information to |
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 24 | ** |
| 25 | ** GNU General Public License Usage |
| 26 | ** Alternatively, this file may be used under the terms of the GNU |
| 27 | ** General Public License version 2.0 or (at your option) the GNU General |
| 28 | ** Public license version 3 or any later version approved by the KDE Free |
| 29 | ** Qt Foundation. The licenses are as published by the Free Software |
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 31 | ** included in the packaging of this file. Please review the following |
| 32 | ** information to ensure the GNU General Public License requirements will |
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 35 | ** |
| 36 | ** $QT_END_LICENSE$ |
| 37 | ** |
| 38 | ****************************************************************************/ |
| 39 | |
| 40 | #include "qorientationsensor.h" |
| 41 | #include "qorientationsensor_p.h" |
| 42 | |
| 43 | QT_BEGIN_NAMESPACE |
| 44 | |
| 45 | IMPLEMENT_READING(QOrientationReading) |
| 46 | |
| 47 | /*! |
| 48 | \class QOrientationReading |
| 49 | \ingroup sensors_reading |
| 50 | \inmodule QtSensors |
| 51 | \since 5.1 |
| 52 | |
| 53 | \brief The QOrientationReading class represents one reading from the |
| 54 | orientation sensor. |
| 55 | |
| 56 | The orientation sensor reports the orientation of the device. As it operates below |
| 57 | the UI level it does not report on or even know how the UI is rotated. Most importantly |
| 58 | this means that this sensor cannot be used to detect if a device is in portrait or |
| 59 | landscape mode. |
| 60 | |
| 61 | This sensor is useful to detect that a particular side of the device is pointing up. |
| 62 | |
| 63 | \section2 QOrientationReading Units |
| 64 | The orientation sensor returns the orientation of the device using |
| 65 | the pre-defined values found in the QOrientationReading::Orientation |
| 66 | enum. |
| 67 | */ |
| 68 | |
| 69 | /*! |
| 70 | \enum QOrientationReading::Orientation |
| 71 | |
| 72 | This enum represents the orientation of the device. |
| 73 | |
| 74 | To explain the meaning of each value it is helpful to refer to the following diagram. |
| 75 | |
| 76 | \image sensors-sides.jpg |
| 77 | |
| 78 | The orientations are shown here in order: TopUp, TopDown, LeftUp, RightUp, FaceUp, FaceDown. |
| 79 | |
| 80 | \image sensors-orientation.jpg |
| 81 | |
| 82 | \value Undefined The orientation is unknown. |
| 83 | \value TopUp The Top edge of the device is pointing up. |
| 84 | \value TopDown The Top edge of the device is pointing down. |
| 85 | \value LeftUp The Left edge of the device is pointing up. |
| 86 | \value RightUp The Right edge of the device is pointing up. |
| 87 | \value FaceUp The Face of the device is pointing up. |
| 88 | \value FaceDown The Face of the device is pointing down. |
| 89 | |
| 90 | It should be noted that the orientation sensor reports the orientation of the device |
| 91 | and not the UI. The orientation of the device will not change just because the UI is |
| 92 | rotated. This means this sensor cannot be used to detect if a device is in portrait |
| 93 | or landscape mode. |
| 94 | */ |
| 95 | |
| 96 | /*! |
| 97 | \property QOrientationReading::orientation |
| 98 | \brief the orientation of the device. |
| 99 | |
| 100 | The unit is an enumeration describing the orientation of the device. |
| 101 | |
| 102 | \sa {QOrientationReading Units} |
| 103 | */ |
| 104 | |
| 105 | QOrientationReading::Orientation QOrientationReading::orientation() const |
| 106 | { |
| 107 | return static_cast<QOrientationReading::Orientation>(d->orientation); |
| 108 | } |
| 109 | |
| 110 | /*! |
| 111 | Sets the \a orientation for the reading. |
| 112 | */ |
| 113 | void QOrientationReading::setOrientation(QOrientationReading::Orientation orientation) |
| 114 | { |
| 115 | switch (orientation) { |
| 116 | case TopUp: |
| 117 | case TopDown: |
| 118 | case LeftUp: |
| 119 | case RightUp: |
| 120 | case FaceUp: |
| 121 | case FaceDown: |
| 122 | d->orientation = orientation; |
| 123 | break; |
| 124 | default: |
| 125 | d->orientation = Undefined; |
| 126 | break; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | // ===================================================================== |
| 131 | |
| 132 | /*! |
| 133 | \class QOrientationFilter |
| 134 | \ingroup sensors_filter |
| 135 | \inmodule QtSensors |
| 136 | \since 5.1 |
| 137 | |
| 138 | \brief The QOrientationFilter class is a convenience wrapper around QSensorFilter. |
| 139 | |
| 140 | The only difference is that the filter() method features a pointer to QOrientationReading |
| 141 | instead of QSensorReading. |
| 142 | */ |
| 143 | |
| 144 | /*! |
| 145 | \fn QOrientationFilter::filter(QOrientationReading *reading) |
| 146 | |
| 147 | Called when \a reading changes. Returns false to prevent the reading from propagating. |
| 148 | |
| 149 | \sa QSensorFilter::filter() |
| 150 | */ |
| 151 | |
| 152 | bool QOrientationFilter::filter(QSensorReading *reading) |
| 153 | { |
| 154 | return filter(reading: static_cast<QOrientationReading*>(reading)); |
| 155 | } |
| 156 | |
| 157 | char const * const QOrientationSensor::type("QOrientationSensor" ); |
| 158 | |
| 159 | /*! |
| 160 | \class QOrientationSensor |
| 161 | \ingroup sensors_type |
| 162 | \inmodule QtSensors |
| 163 | \since 5.1 |
| 164 | |
| 165 | \brief The QOrientationSensor class is a convenience wrapper around QSensor. |
| 166 | |
| 167 | The only behavioural difference is that this class sets the type properly. |
| 168 | |
| 169 | This class also features a reading() function that returns a QOrientationReading instead of a QSensorReading. |
| 170 | |
| 171 | For details about how the sensor works, see \l QOrientationReading. |
| 172 | |
| 173 | \sa QOrientationReading |
| 174 | */ |
| 175 | |
| 176 | /*! |
| 177 | Construct the sensor as a child of \a parent. |
| 178 | */ |
| 179 | QOrientationSensor::QOrientationSensor(QObject *parent) |
| 180 | : QSensor(QOrientationSensor::type, parent) |
| 181 | { |
| 182 | } |
| 183 | |
| 184 | /*! |
| 185 | Destroy the sensor. Stops the sensor if it has not already been stopped. |
| 186 | */ |
| 187 | QOrientationSensor::~QOrientationSensor() |
| 188 | { |
| 189 | } |
| 190 | |
| 191 | /*! |
| 192 | \fn QOrientationSensor::reading() const |
| 193 | |
| 194 | Returns the reading class for this sensor. |
| 195 | |
| 196 | \sa QSensor::reading() |
| 197 | */ |
| 198 | |
| 199 | QOrientationReading *QOrientationSensor::reading() const |
| 200 | { |
| 201 | return static_cast<QOrientationReading*>(QSensor::reading()); |
| 202 | } |
| 203 | |
| 204 | QT_END_NAMESPACE |
| 205 | |
| 206 | #include "moc_qorientationsensor.cpp" |
| 207 | |