From e3172080a2e39ce0f76764ce1aef873642666a79 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 27 Jun 2011 13:36:03 +0200 Subject: Use floating point coordinates in events Use FP coordinates in Mouse, Wheel and Hover events. Change-Id: I8b43ca257620b4653ae5d6b6122c516384db1e48 Reviewed-on: http://codereview.qt.nokia.com/766 Reviewed-by: Qt Sanity Bot Reviewed-by: Paul Olav Tvete --- src/gui/kernel/qevent.cpp | 44 +++++++------------------------------------- 1 file changed, 7 insertions(+), 37 deletions(-) (limited to 'src/gui/kernel/qevent.cpp') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 8426198614..aba848258b 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -166,7 +166,7 @@ QInputEvent::~QInputEvent() position explicitly. */ -QMouseEvent::QMouseEvent(Type type, const QPoint &position, Qt::MouseButton button, +QMouseEvent::QMouseEvent(Type type, const QPointF &position, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) : QInputEvent(type, modifiers), p(position), b(button), mouseState(buttons) { @@ -228,28 +228,20 @@ QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos, modifiers. */ -QMouseEvent::QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos, +QMouseEvent::QMouseEvent(Type type, const QPointF &pos, const QPointF &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) : QInputEvent(type, modifiers), p(pos), g(globalPos), b(button), mouseState(buttons) {} -/*! - \internal -*/ -QMouseEvent *QMouseEvent::createExtendedMouseEvent(Type type, const QPointF &pos, - const QPoint &globalPos, Qt::MouseButton button, - Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers) -{ - return new QMouseEventEx(type, pos, globalPos, button, buttons, modifiers); -} - /*! \fn bool QMouseEvent::hasExtendedInfo() const \internal */ /*! + \fn QPointF QMouseEvent::posF() const + \since 4.4 Returns the position of the mouse cursor as a QPointF, relative to the @@ -261,28 +253,6 @@ QMouseEvent *QMouseEvent::createExtendedMouseEvent(Type type, const QPointF &pos \sa x() y() pos() globalPos() */ -QPointF QMouseEvent::posF() const -{ - return hasExtendedInfo() ? reinterpret_cast(this)->posF : QPointF(pos()); -} - -/*! - \internal -*/ -QMouseEventEx::QMouseEventEx(Type type, const QPointF &pos, const QPoint &globalPos, - Qt::MouseButton button, Qt::MouseButtons buttons, - Qt::KeyboardModifiers modifiers) - : QMouseEvent(type, pos.toPoint(), globalPos, button, buttons, modifiers), posF(pos) -{ - d = reinterpret_cast(this); -} - -/*! - \internal -*/ -QMouseEventEx::~QMouseEventEx() -{ -} /*! \fn const QPoint &QMouseEvent::pos() const @@ -475,7 +445,7 @@ QMouseEventEx::~QMouseEventEx() receiving widget, while \a oldPos is the previous mouse cursor's position relative to the receiving widget. */ -QHoverEvent::QHoverEvent(Type type, const QPoint &pos, const QPoint &oldPos) +QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos) : QEvent(type), p(pos), op(oldPos) { } @@ -542,7 +512,7 @@ QHoverEvent::~QHoverEvent() \sa pos() delta() state() */ #ifndef QT_NO_WHEELEVENT -QWheelEvent::QWheelEvent(const QPoint &pos, int delta, +QWheelEvent::QWheelEvent(const QPointF &pos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient) : QInputEvent(Wheel, modifiers), p(pos), d(delta), mouseState(buttons), o(orient) @@ -581,7 +551,7 @@ QWheelEvent::QWheelEvent(const QPoint &pos, int delta, int state, Qt::Orientatio \sa pos() globalPos() delta() state() */ -QWheelEvent::QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, +QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient) : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), d(delta), mouseState(buttons), o(orient) -- cgit v1.2.3 From 13b83d896de8b00d6a373c97917ce52553a7e451 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Wed, 29 Jun 2011 10:16:34 +0200 Subject: make QHoverEvent inherit from QInputEvent QHoverEvent is an input event and as such should also contain the current keyboard modifiers. Change-Id: Ic403a8511eb991a9c6b5132908af1d5900869361 Reviewed-on: http://codereview.qt.nokia.com/937 Reviewed-by: Qt Sanity Bot Reviewed-by: Paul Olav Tvete --- src/gui/kernel/qevent.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui/kernel/qevent.cpp') diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index aba848258b..946ab33e80 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -445,8 +445,8 @@ QMouseEvent::QMouseEvent(Type type, const QPointF &pos, const QPointF &globalPos receiving widget, while \a oldPos is the previous mouse cursor's position relative to the receiving widget. */ -QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos) - : QEvent(type), p(pos), op(oldPos) +QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers) + : QInputEvent(type, modifiers), p(pos), op(oldPos) { } -- cgit v1.2.3 From a77ce3301c2035a2aaa3c14e051dceb46ca27924 Mon Sep 17 00:00:00 2001 From: Lasse Holmstedt Date: Mon, 4 Jul 2011 12:08:38 +0200 Subject: 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 --- src/gui/kernel/qevent.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) (limited to 'src/gui/kernel/qevent.cpp') 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(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(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(new QScreenOrientationChangeEventPrivate()); + d_func()->orientation = screenOrientation; + d_func()->orientationInDegrees = 90 * ((uint)screenOrientation); + d_func()->isValid = true; +} + +/*! + Destroys QScreenOrientationChangeEvent. +*/ +QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent() +{ + delete reinterpret_cast(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(d); +} + +/*! + \internal +*/ +const QScreenOrientationChangeEventPrivate *QScreenOrientationChangeEvent::d_func() const +{ + return reinterpret_cast(d); +} + QT_END_NAMESPACE -- cgit v1.2.3