rotationsensor.cpp Example File
imagerotation/src/rotationsensor.cpp
#include "rotationsensor.hpp"
#include <bb/cascades/OrientationSupport>
#include <QDebug>
using namespace bb::cascades;
RotationSensor::RotationSensor(QObject *parent)
: QObject(parent)
, m_rotation(0)
{
OrientationSupport::instance()->setSupportedDisplayOrientation(SupportedDisplayOrientation::CurrentLocked);
if (!m_rotationSensor.connectToBackend()) {
qWarning() << "Cannot connect to rotation sensor backend!";
}
m_rotationSensor.addFilter(this);
m_rotationSensor.start();
}
qreal RotationSensor::rotation() const
{
return m_rotation;
}
bool RotationSensor::filter(QRotationReading *reading)
{
const qreal x = reading->x();
const qreal y = reading->y();
if (x > 0 && x < 90) {
if (y > 0) {
m_rotation = (x - 90);
} else {
m_rotation = (90 - x);
}
} else {
if (y > 0) {
m_rotation = (-90 + x);
} else {
m_rotation = (90 - x);
}
}
emit rotationChanged();
return false;
}