1
/********************************************************************
2
Copyright © 2019 Roman Gilg <subdiff@gmail.com>
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation; either version 2 of the License, or
7
(at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public License
15
along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*********************************************************************/
17
#include "orientation_sensor.h"
19
#include <QOrientationSensor>
21
OrientationSensor::OrientationSensor(QObject *parent)
23
, m_sensor(new QOrientationSensor(this))
25
connect(m_sensor, &QOrientationSensor::activeChanged, this, &OrientationSensor::refresh);
28
OrientationSensor::~OrientationSensor() = default;
30
void OrientationSensor::updateState()
32
const auto orientation = m_sensor->reading()->orientation();
33
if (m_value != orientation) {
34
m_value = orientation;
35
Q_EMIT valueChanged(orientation);
39
void OrientationSensor::refresh()
41
if (m_sensor->isActive()) {
45
Q_EMIT availableChanged(true);
47
Q_EMIT availableChanged(false);
51
QOrientationReading::Orientation OrientationSensor::value() const
56
bool OrientationSensor::available() const
58
return m_sensor->connectToBackend();
61
bool OrientationSensor::enabled() const
63
return m_sensor->isActive();
66
void OrientationSensor::setEnabled(bool enable)
68
if (m_enabled == enable) {
74
connect(m_sensor, &QOrientationSensor::readingChanged,
75
this, &OrientationSensor::updateState);
78
disconnect(m_sensor, &QOrientationSensor::readingChanged,
79
this, &OrientationSensor::updateState);
80
m_value = QOrientationReading::Undefined;
82
Q_EMIT enabledChanged(enable);