diff options
author | Lasse Holmstedt <lasse.holmstedt@nokia.com> | 2011-07-04 12:08:38 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-07-04 14:32:41 +0200 |
commit | a77ce3301c2035a2aaa3c14e051dceb46ca27924 (patch) | |
tree | 76f0346ee9b2e0978beff9886a0dd0595d8e5eca /src/gui | |
parent | 85869920bb9a4ee45cf4a89e74b1bd3d4ce67eaa (diff) |
Add QScreenOrientationChangeEvent and rotation support to wayland client
Qt Compositor propagates screen orientation changes to wayland, which
are then picked up by the wayland client. The wayland client then sends
a QScreenOrientationChangeEvent to QApplication, which can handle the
orientation change.
Change-Id: Ieb2225e52b7e3c318648f2cb21dab7937f301505
Reviewed-on: http://codereview.qt.nokia.com/1063
Reviewed-by: Matthias Ettrich
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/kernel/qevent.cpp | 98 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 24 | ||||
-rw-r--r-- | src/gui/kernel/qevent_p.h | 11 |
3 files changed, 133 insertions, 0 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 946ab33e80..5d356292fe 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -53,6 +53,7 @@ #include "qevent_p.h" #include "qgesture.h" #include "qgesture_p.h" +#include "qmath.h" #ifdef Q_OS_SYMBIAN #include "private/qcore_symbian_p.h" @@ -4818,4 +4819,101 @@ const QScrollEventPrivate *QScrollEvent::d_func() const return reinterpret_cast<const QScrollEventPrivate *>(d); } +/*! + \enum QScreenOrientationChangeEvent::Orientation + + This enum describes the orientations that a device can have. + + \value Portrait The device is in a position where its top edge is pointing up. + + \value Landscape The device is rotated clockwise 90 degrees, so that its left edge is pointing up. + + \value PortraitInverted The device is rotated 180 degrees, so that its bottom edge is pointing up. + + \value LandscapeInverted The device is counterclockwise 90 degrees, so that its right edge is pointing up. + + \sa QScreenOrientationChangeEvent::orientation() + \sa QScreenOrientationChangeEvent::orientationInDegrees() +*/ + +/*! + Creates a new QScreenOrientationChangeEvent + \a screenOrientationInDegrees is the new screen orientation, expressed in degrees. + The orientation must be expressed in steps of 90 degrees. +*/ +QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(qint32 screenOrientationInDegrees) + : QEvent(QEvent::OrientationChange) +{ + d = reinterpret_cast<QEventPrivate *>(new QScreenOrientationChangeEventPrivate()); + d_func()->orientationInDegrees = screenOrientationInDegrees; + + qint32 orientationIndex = (qAbs(screenOrientationInDegrees) % 360) / 90; + // flip around the negative coords to correct order. + if (screenOrientationInDegrees < 0) { + if (orientationIndex == 1) + orientationIndex = 3; + else if (orientationIndex == 3) + orientationIndex = 1; + } + + orientationIndex = qPow(2, orientationIndex); + d_func()->orientation = (QScreenOrientationChangeEvent::Orientation)(orientationIndex); + d_func()->isValid = (screenOrientationInDegrees % 90 == 0); +} + +/*! + Creates a new QScreenOrientationChangeEvent + \a orientation is the new orientation of the screen. +*/ +QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreenOrientationChangeEvent::Orientation screenOrientation) + : QEvent(QEvent::OrientationChange) +{ + d = reinterpret_cast<QEventPrivate *>(new QScreenOrientationChangeEventPrivate()); + d_func()->orientation = screenOrientation; + d_func()->orientationInDegrees = 90 * ((uint)screenOrientation); + d_func()->isValid = true; +} + +/*! + Destroys QScreenOrientationChangeEvent. +*/ +QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent() +{ + delete reinterpret_cast<QScrollEventPrivate *>(d); +} + +/*! + Returns the orientation of the screen. +*/ +QScreenOrientationChangeEvent::Orientation QScreenOrientationChangeEvent::orientation() const +{ + return d_func()->orientation; +} + +/*! + Returns the screen orientation in degrees. + The orientation is expressed in steps of 90 degrees and depends on the previous value of the orientation. + This is intended to allow for smooth animations from one orientation to the other. +*/ +qint32 QScreenOrientationChangeEvent::orientationInDegrees() const +{ + return d_func()->orientationInDegrees; +} + +/*! + \internal +*/ +QScreenOrientationChangeEventPrivate *QScreenOrientationChangeEvent::d_func() +{ + return reinterpret_cast<QScreenOrientationChangeEventPrivate *>(d); +} + +/*! + \internal +*/ +const QScreenOrientationChangeEventPrivate *QScreenOrientationChangeEvent::d_func() const +{ + return reinterpret_cast<const QScreenOrientationChangeEventPrivate *>(d); +} + QT_END_NAMESPACE diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 0847fd6046..a6196346a7 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -938,6 +938,30 @@ private: const QScrollEventPrivate *d_func() const; }; +class QScreenOrientationChangeEventPrivate; +class Q_GUI_EXPORT QScreenOrientationChangeEvent : public QEvent +{ +public: + enum Orientation { + Portrait = 1, + Landscape = 2, + PortraitInverted = 4, + LandscapeInverted = 8 + }; + QScreenOrientationChangeEvent(qint32 screenOrientationInDegrees); + QScreenOrientationChangeEvent(Orientation screenOrientation); + ~QScreenOrientationChangeEvent(); + + bool isValid() const; + qint32 orientationInDegrees() const; + Orientation orientation() const; + +private: + QScreenOrientationChangeEventPrivate *d_func(); + const QScreenOrientationChangeEventPrivate *d_func() const; + +}; + QT_END_NAMESPACE QT_END_HEADER diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 4dd3d3fbfb..ffe1dfdefc 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -200,6 +200,17 @@ public: QScrollEvent::ScrollState state; }; +class QScreenOrientationChangeEventPrivate +{ +public: + inline QScreenOrientationChangeEventPrivate() + { + } + QScreenOrientationChangeEvent::Orientation orientation; + qint32 orientationInDegrees; + bool isValid; +}; + QT_END_NAMESPACE #endif // QEVENT_P_H |