From 3a18ec30f030d52026880c67d928654822eede8f Mon Sep 17 00:00:00 2001 From: Fabian Bumberger Date: Thu, 27 Mar 2014 16:18:11 +0100 Subject: [PATCH] BlackBerry: Fix the rotation of the viewfinder This fixes the rotation of the viewfinder. We have to adjust the orientation depending on the primary screen orientation. On a keyboard device, the viewfinder would not rotate at all (same if auto orientation is turned off). Task-number: QTBUG-37894 Change-Id: I2bf955fb3303ed236d3234154ded94fe78607455 Reviewed-by: Yoann Lopes Reviewed-by: Bernd Weimer Reviewed-by: Rafael Roquetto --- src/plugins/qnx/camera/bbcameraorientationhandler.cpp | 18 +++++++++++++++++- src/plugins/qnx/camera/bbcameraorientationhandler.h | 2 ++ src/plugins/qnx/camera/bbcamerasession.cpp | 11 ++++++++--- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/plugins/qnx/camera/bbcameraorientationhandler.cpp b/src/plugins/qnx/camera/bbcameraorientationhandler.cpp index b715249..393c9e6 100644 --- a/src/plugins/qnx/camera/bbcameraorientationhandler.cpp +++ b/src/plugins/qnx/camera/bbcameraorientationhandler.cpp @@ -41,7 +41,8 @@ #include "bbcameraorientationhandler.h" #include -#include +#include +#include #include #include @@ -87,6 +88,10 @@ bool BbCameraOrientationHandler::nativeEventFilter(const QByteArray&, void *mess const int angle = orientation_event_get_angle(event); if (angle != m_orientation) { +#ifndef Q_OS_BLACKBERRY_TABLET + if (angle == 180) // The screen does not rotate at 180 degrees + return false; +#endif m_orientation = angle; emit orientationChanged(m_orientation); } @@ -94,6 +99,17 @@ bool BbCameraOrientationHandler::nativeEventFilter(const QByteArray&, void *mess return false; // do not drop the event } +int BbCameraOrientationHandler::viewfinderOrientation() const +{ + // On a keyboard device we do not rotate the screen at all + if (qGuiApp->primaryScreen()->nativeOrientation() + != qGuiApp->primaryScreen()->primaryOrientation()) { + return m_orientation; + } + + return 0; +} + int BbCameraOrientationHandler::orientation() const { return m_orientation; diff --git a/src/plugins/qnx/camera/bbcameraorientationhandler.h b/src/plugins/qnx/camera/bbcameraorientationhandler.h index 3d236b8..42d6891 100644 --- a/src/plugins/qnx/camera/bbcameraorientationhandler.h +++ b/src/plugins/qnx/camera/bbcameraorientationhandler.h @@ -57,6 +57,8 @@ public: int orientation() const; + int viewfinderOrientation() const; + Q_SIGNALS: void orientationChanged(int degree); diff --git a/src/plugins/qnx/camera/bbcamerasession.cpp b/src/plugins/qnx/camera/bbcamerasession.cpp index 618aca5..c5309b0 100644 --- a/src/plugins/qnx/camera/bbcamerasession.cpp +++ b/src/plugins/qnx/camera/bbcamerasession.cpp @@ -772,11 +772,16 @@ void BbCameraSession::viewfinderFrameGrabbed(const QImage &image) { QTransform transform; + // subtract out the native rotation transform.rotate(m_nativeCameraOrientation); + // subtract out the current device orientation + if (m_device == cameraIdentifierRear()) + transform.rotate(360 - m_orientationHandler->viewfinderOrientation()); + else + transform.rotate(m_orientationHandler->viewfinderOrientation()); + QImage frame = image.copy().transformed(transform); - if (m_device == cameraIdentifierFront()) - frame = frame.mirrored(true, false); QMutexLocker locker(&m_surfaceMutex); if (m_surface) { @@ -896,7 +901,7 @@ bool BbCameraSession::startViewFinder() return false; } - const int angle = m_orientationHandler->orientation(); + const int angle = m_orientationHandler->viewfinderOrientation(); const QSize rotatedSize = ((angle == 0 || angle == 180) ? viewfinderResolution : viewfinderResolution.transposed()); -- 2.7.4