diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2011-07-06 13:55:40 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2011-07-06 14:08:02 +0200 |
commit | 314fdbce8ce473eb3610be3658c61fab2fac0efb (patch) | |
tree | 98a24a6f53ea8d6a7f3fc6ad60ab84dd66ae2863 /src/gui/kernel | |
parent | 8d7647e286e07690de15a6ff9189307ee1a3517c (diff) | |
parent | 83736a8d06a6ca2a1f165d6119ddaca90646e1f8 (diff) |
Merge remote branch 'gerrit/master' into refactor
Conflicts:
config.tests/unix/opengldesktop/opengldesktop.cpp
examples/itemviews/interview/interview.pro
examples/mainwindows/mainwindow/mainwindow.pro
examples/openvg/README
examples/richtext/textedit/textedit.pro
examples/tools/undo/undo.pro
src/corelib/global/qglobal.h
src/corelib/kernel/qcoreapplication.h
src/corelib/kernel/qcoreevent.h
src/corelib/kernel/qmetatype.h
src/gui/kernel/qevent.cpp
src/gui/kernel/qevent.h
src/gui/painting/qpaintengine_raster.cpp
src/gui/painting/qpaintengine_raster_p.h
src/gui/text/qfontdatabase.cpp
src/opengl/qgl.h
src/openvg/qpaintengine_vg.cpp
src/plugins/platforms/wayland/qwaylandwindow.cpp
tests/auto/qmainwindow/qmainwindow.pro
Change-Id: I6bfb586740a68379bb99f4612ec993393a5f3234
Diffstat (limited to 'src/gui/kernel')
-rw-r--r-- | src/gui/kernel/qevent.cpp | 144 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 77 | ||||
-rw-r--r-- | src/gui/kernel/qevent_p.h | 25 |
3 files changed, 169 insertions, 77 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 9e6a8d6e52..fff27cd908 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -48,6 +48,7 @@ #include "qmime.h" #include "private/qdnd_p.h" #include "qevent_p.h" +#include "qmath.h" #ifdef Q_OS_SYMBIAN #include "private/qcore_symbian_p.h" @@ -161,7 +162,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) { @@ -193,28 +194,20 @@ QMouseEvent::~QMouseEvent() 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 @@ -226,28 +219,6 @@ QMouseEvent *QMouseEvent::createExtendedMouseEvent(Type type, const QPointF &pos \sa x() y() pos() globalPos() */ -QPointF QMouseEvent::posF() const -{ - return hasExtendedInfo() ? reinterpret_cast<const QMouseEventEx *>(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<QEventPrivate *>(this); -} - -/*! - \internal -*/ -QMouseEventEx::~QMouseEventEx() -{ -} /*! \fn const QPoint &QMouseEvent::pos() const @@ -440,8 +411,8 @@ 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) - : 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) { } @@ -507,7 +478,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) @@ -533,7 +504,7 @@ QWheelEvent::~QWheelEvent() \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) @@ -4355,4 +4326,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 59d50df268..de0d6b3793 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -84,62 +84,62 @@ protected: class Q_GUI_EXPORT QMouseEvent : public QInputEvent { public: - QMouseEvent(Type type, const QPoint &pos, Qt::MouseButton button, + QMouseEvent(Type type, const QPointF &pos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); - QMouseEvent(Type type, const QPoint &pos, const QPoint &globalPos, + QMouseEvent(Type type, const QPointF &pos, const QPointF &globalPos, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); ~QMouseEvent(); - inline const QPoint &pos() const { return p; } - inline const QPoint &globalPos() const { return g; } - inline int x() const { return p.x(); } - inline int y() const { return p.y(); } - inline int globalX() const { return g.x(); } - inline int globalY() const { return g.y(); } + inline QPoint pos() const { return p.toPoint(); } + inline QPoint globalPos() const { return g.toPoint(); } + inline int x() const { return qRound(p.x()); } + inline int y() const { return qRound(p.y()); } + inline int globalX() const { return qRound(g.x()); } + inline int globalY() const { return qRound(g.y()); } inline Qt::MouseButton button() const { return b; } inline Qt::MouseButtons buttons() const { return mouseState; } - static QMouseEvent *createExtendedMouseEvent(Type type, const QPointF &pos, - const QPoint &globalPos, Qt::MouseButton button, - Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); - inline bool hasExtendedInfo() const { return reinterpret_cast<const QMouseEvent *>(d) == this; } - QPointF posF() const; + const QPointF &posF() const { return p; } + const QPointF &globalPosF() const { return g; } protected: - QPoint p, g; + QPointF p, g; Qt::MouseButton b; Qt::MouseButtons mouseState; }; -class Q_GUI_EXPORT QHoverEvent : public QEvent +class Q_GUI_EXPORT QHoverEvent : public QInputEvent { public: - QHoverEvent(Type type, const QPoint &pos, const QPoint &oldPos); + QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier); ~QHoverEvent(); - inline const QPoint &pos() const { return p; } - inline const QPoint &oldPos() const { return op; } + inline QPoint pos() const { return p.toPoint(); } + inline QPoint oldPos() const { return op.toPoint(); } + + inline const QPointF &posF() const { return p; } + inline const QPointF &oldPosF() const { return op; } protected: - QPoint p, op; + QPointF p, op; }; #ifndef QT_NO_WHEELEVENT class Q_GUI_EXPORT QWheelEvent : public QInputEvent { public: - QWheelEvent(const QPoint &pos, int delta, + QWheelEvent(const QPointF &pos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient = Qt::Vertical); - QWheelEvent(const QPoint &pos, const QPoint& globalPos, int delta, + QWheelEvent(const QPointF &pos, const QPointF& globalPos, int delta, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::Orientation orient = Qt::Vertical); ~QWheelEvent(); inline int delta() const { return d; } - inline const QPoint &pos() const { return p; } - inline const QPoint &globalPos() const { return g; } + inline QPoint pos() const { return p.toPoint(); } + inline QPoint globalPos() const { return g.toPoint(); } inline int x() const { return p.x(); } inline int y() const { return p.y(); } inline int globalX() const { return g.x(); } @@ -148,9 +148,12 @@ public: inline Qt::MouseButtons buttons() const { return mouseState; } Qt::Orientation orientation() const { return o; } + inline const QPointF &posF() const { return p; } + inline const QPointF &globalPosF() const { return g; } + protected: - QPoint p; - QPoint g; + QPointF p; + QPointF g; int d; Qt::MouseButtons mouseState; Qt::Orientation o; @@ -819,6 +822,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 731cfc97f2..59eb270230 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -81,20 +81,6 @@ protected: friend class QKeyEvent; }; -// ### Qt 5: remove -class QMouseEventEx : public QMouseEvent -{ -public: - QMouseEventEx(Type type, const QPointF &pos, const QPoint &globalPos, - Qt::MouseButton button, Qt::MouseButtons buttons, - Qt::KeyboardModifiers modifiers); - ~QMouseEventEx(); - -protected: - QPointF posF; - friend class QMouseEvent; -}; - class QTouchEventTouchPointPrivate { public: @@ -167,6 +153,17 @@ public: QScrollEvent::ScrollState state; }; +class QScreenOrientationChangeEventPrivate +{ +public: + inline QScreenOrientationChangeEventPrivate() + { + } + QScreenOrientationChangeEvent::Orientation orientation; + qint32 orientationInDegrees; + bool isValid; +}; + QT_END_NAMESPACE #endif // QEVENT_P_H |