diff options
Diffstat (limited to 'src/gui/kernel/qevent.cpp')
-rw-r--r-- | src/gui/kernel/qevent.cpp | 344 |
1 files changed, 210 insertions, 134 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index 60e7b97f12..11f7f13552 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -1,7 +1,7 @@ /**************************************************************************** ** -** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/legal +** Copyright (C) 2015 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ ** ** This file is part of the QtGui module of the Qt Toolkit. ** @@ -10,9 +10,9 @@ ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and Digia. For licensing terms and -** conditions see http://qt.digia.com/licensing. For further information -** use the contact form at http://qt.digia.com/contact-us. +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser @@ -23,8 +23,8 @@ ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** -** In addition, as a special exception, Digia gives you certain additional -** rights. These rights are described in the Digia Qt LGPL Exception +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** $QT_END_LICENSE$ @@ -37,13 +37,13 @@ #include "qpa/qplatformintegration.h" #include "qpa/qplatformdrag.h" #include "private/qevent_p.h" -#include "qdebug.h" #include "qmetaobject.h" #include "qmimedata.h" #include "private/qdnd_p.h" #include "qevent_p.h" #include "qmath.h" +#include <private/qdebug_p.h> QT_BEGIN_NAMESPACE @@ -575,7 +575,8 @@ QHoverEvent::~QHoverEvent() wheel event delta: angleDelta() returns the delta in wheel degrees. This value is always provided. pixelDelta() returns the delta in screen pixels and is available on platforms that - have high-resolution trackpads, such as Mac OS X. + have high-resolution trackpads, such as Mac OS X. If that is the + case, source() will return Qt::MouseEventSynthesizedBySystem. The functions pos() and globalPos() return the mouse cursor's location at the time of the event. @@ -600,6 +601,22 @@ QHoverEvent::~QHoverEvent() */ /*! + \fn Qt::MouseEventSource QWheelEvent::source() const + \since 5.5 + + Returns information about the wheel event source. + + The source can be used to distinguish between events that come from a mouse + with a physical wheel and events that are generated by some other means, + such as a flick gesture on a touchpad. + + \note Many platforms provide no such information. On such platforms + \l Qt::MouseEventNotSynthesized is returned always. + + \sa Qt::MouseEventSource +*/ + +/*! \fn Qt::Orientation QWheelEvent::orientation() const \obsolete @@ -731,7 +748,44 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase) : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta), - angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase) + angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase), + src(Qt::MouseEventNotSynthesized) +{} + +/*! + Constructs a wheel event object. + + The \a pos provides the location of the mouse cursor + within the window. The position in global coordinates is specified + by \a globalPos. + + \a pixelDelta contains the scrolling distance in pixels on screen, while + \a angleDelta contains the wheel rotation distance. \a pixelDelta is + optional and can be null. + + The mouse and keyboard states at the time of the event are specified by + \a buttons and \a modifiers. + + For backwards compatibility, the event can also hold monodirectional wheel + event data: \a qt4Delta specifies the rotation, and \a qt4Orientation the + direction. + + The scrolling phase of the event is specified by \a phase. + + If the wheel event comes from a physical mouse wheel, \a source is set to + Qt::MouseEventNotSynthesized. If it comes from a gesture detected by the + operating system, or from a non-mouse hardware device, such that \a pixelDelta is + directly related to finger movement, \a source is set to Qt::MouseEventSynthesizedBySystem. + If it comes from Qt, source would be set to Qt::MouseEventSynthesizedByQt. + + \sa posF(), globalPosF(), angleDelta(), pixelDelta(), phase() +*/ + +QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF& globalPos, + QPoint pixelDelta, QPoint angleDelta, int qt4Delta, Qt::Orientation qt4Orientation, + Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, Qt::MouseEventSource source) + : QInputEvent(Wheel, modifiers), p(pos), g(globalPos), pixelD(pixelDelta), + angleD(angleDelta), qt4D(qt4Delta), qt4O(qt4Orientation), mouseState(buttons), ph(phase), src(source) {} #endif // QT_NO_WHEELEVENT @@ -1324,6 +1378,55 @@ QExposeEvent::~QExposeEvent() } /*! + \class QPlatformSurfaceEvent + \since 5.5 + \brief The QPlatformSurfaceEvent class is used to notify about native platform surface events. + \inmodule QtGui + + \ingroup events + + Platform window events are synchronously sent to windows and offscreen surfaces when their + underlying native surfaces are created or are about to be destroyed. + + Applications can respond to these events to know when the underlying platform + surface exists. +*/ + +/*! + \enum QPlatformSurfaceEvent::SurfaceEventType + + This enum describes the type of platform surface event. The possible types are: + + \value SurfaceCreated The underlying native surface has been created + \value SurfaceAboutToBeDestroyed The underlying native surface will be destroyed immediately after this event + + The \c SurfaceAboutToBeDestroyed event type is useful as a means of stopping rendering to + a platform window before it is destroyed. +*/ + +/*! + \fn QPlatformSurfaceEvent::SurfaceEventType QPlatformSurfaceEvent::surfaceEventType() const + + Returns the specific type of platform surface event. +*/ + +/*! + Constructs a platform surface event for the given \a surfaceEventType. +*/ +QPlatformSurfaceEvent::QPlatformSurfaceEvent(SurfaceEventType surfaceEventType) + : QEvent(PlatformSurface) + , m_surfaceEventType(surfaceEventType) +{ +} + +/*! + \internal +*/ +QPlatformSurfaceEvent::~QPlatformSurfaceEvent() +{ +} + +/*! \fn const QRegion &QExposeEvent::region() const Returns the window area that has been exposed. The region is given in local coordinates. @@ -3358,29 +3461,12 @@ QShortcutEvent::~QShortcutEvent() #ifndef QT_NO_DEBUG_STREAM -static inline void formatTouchPoint(QDebug d, const QTouchEvent::TouchPoint &tp) +static inline void formatTouchEvent(QDebug d, const QTouchEvent &t) { - d << "TouchPoint(" << tp.id() << ' ' << tp.rect(); - switch (tp.state()) { - case Qt::TouchPointPressed: - d << " pressed"; - break; - case Qt::TouchPointReleased: - d << " released"; - break; - case Qt::TouchPointMoved: - d << " moved"; - break; - case Qt::TouchPointStationary: - d << " stationary"; - break; - } - d << ')'; -} - -static inline void formatTouchEvent(QDebug d, const char *name, const QTouchEvent &t) -{ - d << "QTouchEvent(" << name << " states: " << t.touchPointStates(); + d << "QTouchEvent("; + QtDebugUtils::formatQEnum(d, t.type()); + d << " states: "; + QtDebugUtils::formatQFlags(d, t.touchPointStates()); d << ", " << t.touchPoints().size() << " points: " << t.touchPoints() << ')'; } @@ -3439,14 +3525,6 @@ static inline void formatInputMethodQueryEvent(QDebug d, const QInputMethodQuery d << "})"; } -static const char *eventTypeName(QEvent::Type t) -{ - static const int enumIdx = QEvent::staticMetaObject.indexOfEnumerator("Type"); - return t <= QEvent::User - ? QEvent::staticMetaObject.enumerator(enumIdx).valueToKey(t) - : "User"; -} - static const char *eventClassName(QEvent::Type t) { switch (t) { @@ -3556,74 +3634,33 @@ static const char *eventClassName(QEvent::Type t) return "QGraphicsSceneEvent"; case QEvent::Timer: return "QTimerEvent"; + case QEvent::PlatformSurface: + return "QPlatformSurfaceEvent"; default: break; } return "QEvent"; } -namespace { -// Make protected QObject::staticQtMetaObject accessible for formatting enums. -class DebugHelper : public QObject { -public: - static const char *mouseButtonToString(Qt::MouseButton button) - { - static const int enumIdx = QObject::staticQtMetaObject.indexOfEnumerator("MouseButtons"); - return QObject::staticQtMetaObject.enumerator(enumIdx).valueToKey(button); - } - - static QByteArray mouseButtonsToString(Qt::MouseButtons buttons) - { - QByteArray result; - for (int i = 0; (uint)(1 << i) <= Qt::MaxMouseButton; ++i) { - const Qt::MouseButton button = static_cast<Qt::MouseButton>(1 << i); - if (buttons.testFlag(button)) { - if (!result.isEmpty()) - result.append('|'); - result.append(mouseButtonToString(button)); - } - } - if (result.isEmpty()) - result.append("NoButton"); - return result; - } - - static const char *mouseEventSourceToString(Qt::MouseEventSource source) - { - static const int enumIdx = QObject::staticQtMetaObject.indexOfEnumerator("MouseEventSource"); - return QObject::staticQtMetaObject.enumerator(enumIdx).valueToKey(source); - } - - static const char *focusReasonToString(Qt::FocusReason reason) - { - static const int enumIdx = QObject::staticQtMetaObject.indexOfEnumerator("FocusReason"); - return QObject::staticQtMetaObject.enumerator(enumIdx).valueToKey(reason); - } - -# ifndef QT_NO_GESTURES - static const char *nativeGestureTypeToString(Qt::NativeGestureType type) - { - static const int enumIdx = QObject::staticQtMetaObject.indexOfEnumerator("NativeGestureType"); - return QObject::staticQtMetaObject.enumerator(enumIdx).valueToKey(type); - } -# endif // !QT_NO_GESTURES -}; -} // namespace - # ifndef QT_NO_DRAGANDDROP static void formatDropEvent(QDebug d, const QDropEvent *e) { const QEvent::Type type = e->type(); - d << eventClassName(type) << "(dropAction=" << e->dropAction() << ", proposedAction=" - << e->proposedAction() << ", possibleActions=" << e->possibleActions() - << ", posF=" << e->posF(); + d << eventClassName(type) << "(dropAction="; + QtDebugUtils::formatQEnum(d, e->dropAction()); + d << ", proposedAction="; + QtDebugUtils::formatQEnum(d, e->proposedAction()); + d << ", possibleActions="; + QtDebugUtils::formatQFlags(d, e->possibleActions()); + d << ", posF="; + QtDebugUtils::formatQPoint(d, e->posF()); if (type == QEvent::DragMove || type == QEvent::DragEnter) d << ", answerRect=" << static_cast<const QDragMoveEvent *>(e)->answerRect(); d << ", formats=" << e->mimeData()->formats(); - if (const Qt::KeyboardModifiers mods = e->keyboardModifiers()) - d << ", keyboardModifiers=" << mods; - d << ", " << DebugHelper::mouseButtonsToString(e->mouseButtons()).constData(); + QtDebugUtils::formatNonNullQFlags(d, ", keyboardModifiers=", e->keyboardModifiers()); + d << ", "; + QtDebugUtils::formatQFlags(d, e->mouseButtons()); } # endif // !QT_NO_DRAGANDDROP @@ -3634,20 +3671,19 @@ static void formatTabletEvent(QDebug d, const QTabletEvent *e) { const QEvent::Type type = e->type(); - static const int deviceEnumIdx = QTabletEvent::staticMetaObject.indexOfEnumerator("TabletDevice"); - static const int pointerTypeEnumIdx = QTabletEvent::staticMetaObject.indexOfEnumerator("PointerType"); - const char* device = QTabletEvent::staticMetaObject.enumerator(deviceEnumIdx).valueToKey(e->device()); - const char* pointerType = QTabletEvent::staticMetaObject.enumerator(pointerTypeEnumIdx).valueToKey(e->pointerType()); - - d << eventClassName(type) << '(' << eventTypeName(type) - << ", device=" << device - << ", pointerType=" << pointerType - << ", uniqueId=" << e->uniqueId() + d << eventClassName(type) << '('; + QtDebugUtils::formatQEnum(d, type); + d << ", device="; + QtDebugUtils::formatQEnum(d, e->device()); + d << ", pointerType="; + QtDebugUtils::formatQEnum(d, e->pointerType()); + d << ", uniqueId=" << e->uniqueId() << ", pos=" << e->posF() << ", z=" << e->z() << ", xTilt=" << e->xTilt() << ", yTilt=" << e->yTilt() - << ", " << DebugHelper::mouseButtonsToString(e->buttons()).constData(); + << ", "; + QtDebugUtils::formatQFlags(d, e->buttons()); if (type == QEvent::TabletPress || type == QEvent::TabletMove) d << ", pressure=" << e->pressure(); if (e->device() == QTabletEvent::RotationStylus || e->device() == QTabletEvent::FourDMouse) @@ -3662,7 +3698,18 @@ QDebug operator<<(QDebug dbg, const QTouchEvent::TouchPoint &tp) { QDebugStateSaver saver(dbg); dbg.nospace(); - formatTouchPoint(dbg, tp); + dbg << "TouchPoint(" << tp.id() << " ("; + QtDebugUtils::formatQRect(dbg, tp.rect()); + dbg << ") "; + QtDebugUtils::formatQEnum(dbg, tp.state()); + dbg << " press " << tp.pressure() << " vel " << tp.velocity() + << " start ("; + QtDebugUtils::formatQPoint(dbg, tp.startPos()); + dbg << ") last ("; + QtDebugUtils::formatQPoint(dbg, tp.lastPos()); + dbg << ") delta ("; + QtDebugUtils::formatQPoint(dbg, tp.pos() - tp.lastPos()); + dbg << ')'; return dbg; } @@ -3692,18 +3739,23 @@ QDebug operator<<(QDebug dbg, const QEvent *e) const QMouseEvent *me = static_cast<const QMouseEvent*>(e); const Qt::MouseButton button = me->button(); const Qt::MouseButtons buttons = me->buttons(); - dbg << "QMouseEvent(" << eventTypeName(type); - if (type != QEvent::MouseMove && type != QEvent::NonClientAreaMouseMove) - dbg << ", " << DebugHelper::mouseButtonToString(button); - if (buttons && button != buttons) - dbg << ", buttons=" << DebugHelper::mouseButtonsToString(buttons).constData(); - if (const int mods = int(me->modifiers())) - dbg << ", modifiers=0x" << hex << mods << dec; - dbg << ", localPos=" << me->localPos() << ", screenPos=" << me->screenPos(); - if (me->source()) - dbg << ", " << DebugHelper::mouseEventSourceToString(me->source()); - if (const Qt::MouseEventFlags flags = me->flags()) - dbg << ", flags = " << hex << int(flags) << dec; + dbg << "QMouseEvent("; + QtDebugUtils::formatQEnum(dbg, type); + if (type != QEvent::MouseMove && type != QEvent::NonClientAreaMouseMove) { + dbg << ", "; + QtDebugUtils::formatQEnum(dbg, button); + } + if (buttons && button != buttons) { + dbg << ", buttons="; + QtDebugUtils::formatQFlags(dbg, buttons); + } + QtDebugUtils::formatNonNullQFlags(dbg, ", ", me->modifiers()); + dbg << ", localPos="; + QtDebugUtils::formatQPoint(dbg, me->localPos()); + dbg << ", screenPos="; + QtDebugUtils::formatQPoint(dbg, me->screenPos()); + QtDebugUtils::formatNonNullQEnum(dbg, ", ", me->source()); + QtDebugUtils::formatNonNullQFlags(dbg, ", flags=", me->flags()); dbg << ')'; } break; @@ -3719,10 +3771,11 @@ QDebug operator<<(QDebug dbg, const QEvent *e) case QEvent::ShortcutOverride: { const QKeyEvent *ke = static_cast<const QKeyEvent *>(e); - dbg << "QKeyEvent(" << eventTypeName(type) - << ", key=0x" << hex << ke->key() << dec; - if (const int mods = ke->modifiers()) - dbg << ", modifiers=0x" << hex << mods << dec; + dbg << "QKeyEvent("; + QtDebugUtils::formatQEnum(dbg, type); + dbg << ", "; + QtDebugUtils::formatQEnum(dbg, static_cast<Qt::Key>(ke->key())); + QtDebugUtils::formatNonNullQFlags(dbg, ", ", ke->modifiers()); if (!ke->text().isEmpty()) dbg << ", text=" << ke->text(); if (ke->isAutoRepeat()) @@ -3741,13 +3794,16 @@ QDebug operator<<(QDebug dbg, const QEvent *e) case QEvent::FocusAboutToChange: case QEvent::FocusIn: case QEvent::FocusOut: - dbg << "QFocusEvent(" << eventTypeName(type) << ", " - << DebugHelper::focusReasonToString(static_cast<const QFocusEvent *>(e)->reason()) - << ')'; + dbg << "QFocusEvent("; + QtDebugUtils::formatQEnum(dbg, type); + dbg << ", "; + QtDebugUtils::formatQEnum(dbg, static_cast<const QFocusEvent *>(e)->reason()); + dbg << ')'; break; case QEvent::Move: { const QMoveEvent *me = static_cast<const QMoveEvent *>(e); - dbg << "QMoveEvent(" << me->pos(); + dbg << "QMoveEvent("; + QtDebugUtils::formatQPoint(dbg, me->pos()); if (!me->spontaneous()) dbg << ", non-spontaneous"; dbg << ')'; @@ -3755,7 +3811,8 @@ QDebug operator<<(QDebug dbg, const QEvent *e) break; case QEvent::Resize: { const QResizeEvent *re = static_cast<const QResizeEvent *>(e); - dbg << "QResizeEvent(" << re->size(); + dbg << "QResizeEvent("; + QtDebugUtils::formatQSize(dbg, re->size()); if (!re->spontaneous()) dbg << ", non-spontaneous"; dbg << ')'; @@ -3777,24 +3834,30 @@ QDebug operator<<(QDebug dbg, const QEvent *e) case QEvent::TouchBegin: case QEvent::TouchUpdate: case QEvent::TouchEnd: - formatTouchEvent(dbg, eventTypeName(type), *static_cast<const QTouchEvent*>(e)); + formatTouchEvent(dbg, *static_cast<const QTouchEvent*>(e)); break; case QEvent::ChildAdded: case QEvent::ChildPolished: case QEvent::ChildRemoved: - dbg << "QChildEvent(" << eventTypeName(type) << ", " << (static_cast<const QChildEvent*>(e))->child() << ')'; + dbg << "QChildEvent("; + QtDebugUtils::formatQEnum(dbg, type); + dbg << ", " << (static_cast<const QChildEvent*>(e))->child() << ')'; break; # ifndef QT_NO_GESTURES case QEvent::NativeGesture: { const QNativeGestureEvent *ne = static_cast<const QNativeGestureEvent *>(e); - dbg << "QNativeGestureEvent(" << DebugHelper::nativeGestureTypeToString(ne->gestureType()) - << "localPos=" << ne->localPos() << ", value=" << ne->value() << ')'; + dbg << "QNativeGestureEvent("; + QtDebugUtils::formatQEnum(dbg, ne->gestureType()); + dbg << "localPos="; + QtDebugUtils::formatQPoint(dbg, ne->localPos()); + dbg << ", value=" << ne->value() << ')'; } break; # endif // !QT_NO_GESTURES case QEvent::ApplicationStateChange: - dbg << "QApplicationStateChangeEvent(" - << static_cast<const QApplicationStateChangeEvent *>(e)->applicationState() << ')'; + dbg << "QApplicationStateChangeEvent("; + QtDebugUtils::formatQEnum(dbg, static_cast<const QApplicationStateChangeEvent *>(e)->applicationState()); + dbg << ')'; break; case QEvent::ContextMenu: dbg << "QContextMenuEvent(" << static_cast<const QContextMenuEvent *>(e)->pos() << ')'; @@ -3814,9 +3877,22 @@ QDebug operator<<(QDebug dbg, const QEvent *e) case QEvent::Timer: dbg << "QTimerEvent(id=" << static_cast<const QTimerEvent *>(e)->timerId() << ')'; break; + case QEvent::PlatformSurface: + dbg << "QPlatformSurfaceEvent(surfaceEventType="; + switch (static_cast<const QPlatformSurfaceEvent *>(e)->surfaceEventType()) { + case QPlatformSurfaceEvent::SurfaceCreated: + dbg << "SurfaceCreated"; + break; + case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: + dbg << "SurfaceAboutToBeDestroyed"; + break; + } + dbg << ')'; + break; default: - dbg << eventClassName(type) << '(' << eventTypeName(type) << ", " - << (const void *)e << ", type = " << e->type() << ')'; + dbg << eventClassName(type) << '('; + QtDebugUtils::formatQEnum(dbg, type); + dbg << ", " << (const void *)e << ')'; break; } return dbg; |