diff options
author | Thomas McGuire <thomas.mcguire.qnx@kdab.com> | 2012-07-19 15:46:09 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-07-24 11:23:25 +0200 |
commit | 1760d541f35c851b6c08bc617a89cb16a1d8f975 (patch) | |
tree | 752b016c18fb5628e2c4b1b6ce5e16ab318c814b /src/plugins/sensors/blackberry/bbrotationsensor.cpp | |
parent | 0de0ead684a322103ec9cff3dcf5153ef4c1545c (diff) |
Blackberry: Remove QtGui dependency
In the Blackberry backend, we can't depend on QtGui and especially
not on the Blackberry QPA plugin, as Cascades uses
QCoreApplication, not QGuiApplication.
All QtGui functions are replaced with a new GuiHelper class, that
internally uses BPS.
Change-Id: Ia508e8b397050676c68612340d33cdbf57041076
Reviewed-by: Adam Parco <aparco@rim.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src/plugins/sensors/blackberry/bbrotationsensor.cpp')
-rw-r--r-- | src/plugins/sensors/blackberry/bbrotationsensor.cpp | 50 |
1 files changed, 20 insertions, 30 deletions
diff --git a/src/plugins/sensors/blackberry/bbrotationsensor.cpp b/src/plugins/sensors/blackberry/bbrotationsensor.cpp index 0ed1495b..f64844ae 100644 --- a/src/plugins/sensors/blackberry/bbrotationsensor.cpp +++ b/src/plugins/sensors/blackberry/bbrotationsensor.cpp @@ -40,21 +40,18 @@ ****************************************************************************/ #include "bbrotationsensor.h" +#include "bbguihelper.h" #include "bbutil.h" #include <QtCore/qmath.h> -#include <QGuiApplication> -#include <QScreen> -#include <qpa/qplatformscreen.h> using namespace BbUtil; BbRotationSensor::BbRotationSensor(QSensor *sensor) - : BbSensorBackend<QRotationReading>(devicePath(), SENSOR_TYPE_ROTATION_MATRIX, sensor), - m_orientation(Qt::PrimaryOrientation), - m_nativeOrientation(Qt::PrimaryOrientation) + : BbSensorBackend<QRotationReading>(devicePath(), SENSOR_TYPE_ROTATION_MATRIX, sensor) { - updateOrientation(); setDescription(QLatin1String("Device rotation in degrees")); + m_mappingMatrix[0] = m_mappingMatrix[2] = 1; + m_mappingMatrix[1] = m_mappingMatrix[3] = 0; } QString BbRotationSensor::devicePath() @@ -62,6 +59,13 @@ QString BbRotationSensor::devicePath() return QLatin1String("/dev/sensor/rotMatrix"); } +void BbRotationSensor::setGuiHelper(BbGuiHelper *guiHelper) +{ + BbSensorBackend<QRotationReading>::setGuiHelper(guiHelper); + connect(guiHelper, SIGNAL(orientationChanged()), this, SLOT(updateOrientation())); + updateOrientation(); +} + void BbRotationSensor::additionalDeviceInit() { addOutputRange(-180, 180, 0 /* ? */); @@ -94,7 +98,6 @@ static void remapMatrix(const float inputMatrix[3*3], } } - bool BbRotationSensor::updateReadingFromEvent(const sensor_event_t &event, QRotationReading *reading) { // sensor_event_t has euler angles for a Z-Y'-X'' system, but the QtMobility API @@ -102,7 +105,7 @@ bool BbRotationSensor::updateReadingFromEvent(const sensor_event_t &event, QRota // So extract the euler angles using the Z-X'-Y'' system from the matrix. float xRad, yRad, zRad; - if (isAutoAxisRemappingEnabled() && m_orientation!=m_nativeOrientation) { + if (isAutoAxisRemappingEnabled() && guiHelper()->currentOrientation() != 0) { float mappedRotationMatrix[3*3]; remapMatrix(event.rotation_matrix, m_mappingMatrix, mappedRotationMatrix); matrixToEulerZXY(mappedRotationMatrix, xRad, yRad, zRad); @@ -127,27 +130,14 @@ bool BbRotationSensor::isAutoAxisRemappingEnabled() const return sensor()->property("automaticAxisRemapping").toBool(); } -bool BbRotationSensor::eventFilter(QObject *object, QEvent *event) -{ - if (object == QCoreApplication::instance() && event->type() == QEvent::OrientationChange) - updateOrientation(); - - return BbSensorBackend<QRotationReading>::eventFilter(object, event); -} - void BbRotationSensor::updateOrientation() { - QScreen *screen = QGuiApplication::primaryScreen(); - if (screen) { - const QPlatformScreen * const platformScreen = screen->handle(); - m_nativeOrientation = platformScreen->nativeOrientation(); - m_orientation = screen->orientation(); - - const int rotationAngle = screen->angleBetween(m_nativeOrientation, m_orientation); - - m_mappingMatrix[0] = cos(rotationAngle*M_PI/180); - m_mappingMatrix[1] = sin(rotationAngle*M_PI/180); - m_mappingMatrix[2] = -sin(rotationAngle*M_PI/180); - m_mappingMatrix[3] = cos(rotationAngle*M_PI/180); - } + // ### I can't really test this, the rotation matrix has too many glitches and drifts over time, + // making any measurement quite hard + const int rotationAngle = guiHelper()->currentOrientation(); + + m_mappingMatrix[0] = cos(rotationAngle*M_PI/180); + m_mappingMatrix[1] = sin(rotationAngle*M_PI/180); + m_mappingMatrix[2] = -sin(rotationAngle*M_PI/180); + m_mappingMatrix[3] = cos(rotationAngle*M_PI/180); } |