summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel
diff options
context:
space:
mode:
authorMorten Johan Sørvig <morten.sorvig@digia.com>2013-10-02 08:52:26 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-17 15:58:32 +0200
commitfbfc8ffbf39e2e7a540d4d576ec61bea7db63416 (patch)
tree5df0b25a1fae3e88a538075c857e5cc3bcc18a03 /src/gui/kernel
parent73e3d2f6cb002be4ce409c3738db74b61beb12f4 (diff)
Implement native gestures on OS X.
Add QWindowSystemInterface::GestureEvent and QNativeGestureEvent to QtGui. These events are copies of Qt4's QNativeGestureEvent, where it was an implementation detail of QGestureManager. Add gesture message handlers to QNSView and bring back the Mac gesture recognizers for QGestureManager. Task-number: QTBUG-28126 Change-Id: I1304e09e776fa7c44d133d54ca8b895ca2f544c5 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
Diffstat (limited to 'src/gui/kernel')
-rw-r--r--src/gui/kernel/qevent.cpp115
-rw-r--r--src/gui/kernel/qevent.h28
-rw-r--r--src/gui/kernel/qguiapplication.cpp13
-rw-r--r--src/gui/kernel/qguiapplication_p.h1
-rw-r--r--src/gui/kernel/qwindowsysteminterface.cpp29
-rw-r--r--src/gui/kernel/qwindowsysteminterface.h9
-rw-r--r--src/gui/kernel/qwindowsysteminterface_p.h16
7 files changed, 211 insertions, 0 deletions
diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp
index ef9a3a1225..06fa1f3550 100644
--- a/src/gui/kernel/qevent.cpp
+++ b/src/gui/kernel/qevent.cpp
@@ -2263,6 +2263,121 @@ QTabletEvent::~QTabletEvent()
#endif // QT_NO_TABLETEVENT
+/*!
+ \class QNativeGestureEvent
+ \since 5.2
+ \brief The QNativeGestureEvent class contains parameters that describe a gesture event.
+ \inmodule QtGui
+ \ingroup events
+
+ Native gesture events are generated by the operating system, typically by
+ interpreting touch events. Gesture events are high-level events such
+ as zoom or rotate.
+
+ \table
+ \header
+ \li Event Type
+ \li Description
+ \li Touch equence
+ \row
+ \li Qt::ZoomNativeGesture
+ \li Magnification delta in percent.
+ \li OS X: Two-finger pinch.
+ \row
+ \li Qt::SmartZoomNativeGesture
+ \li Boolean magnification state.
+ \li OS X: Two-finger douple tap (trackpad) / One-finger douple tap (magic mouse).
+ \row
+ \li Qt::RotateNativeGesture
+ \li Rotation delta in degrees.
+ \li OS X: Two-finger rotate.
+ \endtable
+
+
+ In addition, BeginNativeGesture and EndNativeGesture are sent before and after
+ gesture event streams:
+
+ BeginNativeGesture
+ ZoomNativeGesture
+ ZoomNativeGesture
+ ZoomNativeGesture
+ EndNativeGesture
+
+ \sa Qt::NativeGestureType, QGestureEvent
+*/
+
+/*!
+ Constructs a native gesture event of type \a type.
+
+ The points \a localPos, \a windowPos and \a screenPos specify the
+ gesture position relative to the receiving widget or item,
+ window, and screen, respectively.
+
+ \a realValue is the OS X event parameter, \a sequenceId and \a intValue are the Windows event parameters.
+*/
+QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPointF &localPos, const QPointF &windowPos,
+ const QPointF &screenPos, qreal realValue, ulong sequenceId, quint64 intValue)
+ : QInputEvent(QEvent::NativeGesture), mGestureType(type),
+ mLocalPos(localPos), mWindowPos(windowPos), mScreenPos(screenPos), mRealValue(realValue),
+ mSequenceId(sequenceId), mIntValue(intValue)
+{ }
+
+/*!
+ \fn QNativeGestureEvent::gestureType() const
+ \since 5.2
+
+ Returns the gesture type.
+*/
+
+/*!
+ \fn QNativeGestureEvent::value() const
+ \since 5.2
+
+ Returns the gesture value. The value should be interpreted based on the
+ gesture type. For example, a Zoom gesture provides a scale factor while a Rotate
+ gesture provides a rotation delta.
+
+ \sa QNativeGestureEvent, gestureType()
+*/
+
+/*!
+ \fn QPoint QNativeGestureEvent::globalPos() const
+ \since 5.2
+
+ Returns the position of the gesture as a QPointF in screen coordinates
+*/
+
+/*!
+ \fn QPoint QNativeGestureEvent::pos() const
+ \since 5.2
+
+ Returns the position of the mouse cursor, relative to the widget
+ or item that received the event.
+*/
+
+/*!
+ \fn QPointF QNativeGestureEvent::localPos() const
+ \since 5.2
+
+ Returns the position of the gesture as a QPointF, relative to the
+ widget or item that received the event.
+*/
+
+/*!
+ \fn QPointF QNativeGestureEvent::screenPos() const
+ \since 5.2
+
+ Returns the position of the gesture as a QPointF in screen coordinates.
+*/
+
+/*!
+ \fn QPointF QNativeGestureEvent::windowPos() const
+ \since 5.2
+
+ Returns the position of the gesture as a QPointF, relative to the
+ window that received the event.
+*/
+
#ifndef QT_NO_DRAGANDDROP
/*!
Creates a QDragMoveEvent of the required \a type indicating
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index 0c1cf70420..d22e423248 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -268,6 +268,34 @@ protected:
};
#endif // QT_NO_TABLETEVENT
+#ifndef QT_NO_GESTURES
+class Q_GUI_EXPORT QNativeGestureEvent : public QInputEvent
+{
+public:
+ QNativeGestureEvent(Qt::NativeGestureType type, const QPointF &localPos, const QPointF &windowPos,
+ const QPointF &screenPos, qreal value, ulong sequenceId, quint64 intArgument);
+ Qt::NativeGestureType gestureType() const { return mGestureType; }
+ qreal value() const { return mRealValue; }
+
+#ifndef QT_NO_INTEGER_EVENT_COORDINATES
+ inline const QPoint pos() const { return mLocalPos.toPoint(); }
+ inline const QPoint globalPos() const { return mScreenPos.toPoint(); }
+#endif
+ const QPointF &localPos() const { return mLocalPos; }
+ const QPointF &windowPos() const { return mWindowPos; }
+ const QPointF &screenPos() const { return mScreenPos; }
+
+protected:
+ Qt::NativeGestureType mGestureType;
+ QPointF mLocalPos;
+ QPointF mWindowPos;
+ QPointF mScreenPos;
+ qreal mRealValue;
+ ulong mSequenceId;
+ quint64 mIntValue;
+};
+#endif // QT_NO_GESTURES
+
class Q_GUI_EXPORT QKeyEvent : public QInputEvent
{
public:
diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp
index 1e3ea3092f..d254f7c9bc 100644
--- a/src/gui/kernel/qguiapplication.cpp
+++ b/src/gui/kernel/qguiapplication.cpp
@@ -1473,6 +1473,10 @@ void QGuiApplicationPrivate::processWindowSystemEvent(QWindowSystemInterfacePriv
QGuiApplicationPrivate::processTabletLeaveProximityEvent(
static_cast<QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *>(e));
break;
+ case QWindowSystemInterfacePrivate::Gesture:
+ QGuiApplicationPrivate::processGestureEvent(
+ static_cast<QWindowSystemInterfacePrivate::GestureEvent *>(e));
+ break;
case QWindowSystemInterfacePrivate::PlatformPanel:
QGuiApplicationPrivate::processPlatformPanelEvent(
static_cast<QWindowSystemInterfacePrivate::PlatformPanelEvent *>(e));
@@ -1958,6 +1962,15 @@ void QGuiApplicationPrivate::processTabletLeaveProximityEvent(QWindowSystemInter
#endif
}
+#ifndef QT_NO_GESTURES
+void QGuiApplicationPrivate::processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e)
+{
+ QNativeGestureEvent ev(e->type, e->pos, e->pos, e->globalPos, e->realValue, e->sequenceId, e->intValue);
+ ev.setTimestamp(e->timestamp);
+ QGuiApplication::sendSpontaneousEvent(e->window, &ev);
+}
+#endif // QT_NO_GESTURES
+
void QGuiApplicationPrivate::processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e)
{
if (!e->window)
diff --git a/src/gui/kernel/qguiapplication_p.h b/src/gui/kernel/qguiapplication_p.h
index d1716a6e28..65c6d814e6 100644
--- a/src/gui/kernel/qguiapplication_p.h
+++ b/src/gui/kernel/qguiapplication_p.h
@@ -148,6 +148,7 @@ public:
static void processTabletEvent(QWindowSystemInterfacePrivate::TabletEvent *e);
static void processTabletEnterProximityEvent(QWindowSystemInterfacePrivate::TabletEnterProximityEvent *e);
static void processTabletLeaveProximityEvent(QWindowSystemInterfacePrivate::TabletLeaveProximityEvent *e);
+ static void processGestureEvent(QWindowSystemInterfacePrivate::GestureEvent *e);
static void processPlatformPanelEvent(QWindowSystemInterfacePrivate::PlatformPanelEvent *e);
#ifndef QT_NO_CONTEXTMENU
diff --git a/src/gui/kernel/qwindowsysteminterface.cpp b/src/gui/kernel/qwindowsysteminterface.cpp
index d62330083e..902c32419d 100644
--- a/src/gui/kernel/qwindowsysteminterface.cpp
+++ b/src/gui/kernel/qwindowsysteminterface.cpp
@@ -669,6 +669,35 @@ void QWindowSystemInterface::handleTabletLeaveProximityEvent(int device, int poi
handleTabletLeaveProximityEvent(time, device, pointerType, uid);
}
+#ifndef QT_NO_GESTURES
+void QWindowSystemInterface::handleGestureEvent(QWindow *window, ulong timestamp, Qt::NativeGestureType type,
+ QPointF &local, QPointF &global)
+{
+ QWindowSystemInterfacePrivate::GestureEvent *e =
+ new QWindowSystemInterfacePrivate::GestureEvent(window, timestamp, type, local, global);
+ QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+}
+
+void QWindowSystemInterface::handleGestureEventWithRealValue(QWindow *window, ulong timestamp, Qt::NativeGestureType type,
+ qreal value, QPointF &local, QPointF &global)
+{
+ QWindowSystemInterfacePrivate::GestureEvent *e =
+ new QWindowSystemInterfacePrivate::GestureEvent(window, timestamp, type, local, global);
+ e->realValue = value;
+ QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+}
+
+void QWindowSystemInterface::handleGestureEventWithSequenceIdAndValue(QWindow *window, ulong timestamp, Qt::NativeGestureType type,
+ ulong sequenceId, quint64 value, QPointF &local, QPointF &global)
+{
+ QWindowSystemInterfacePrivate::GestureEvent *e =
+ new QWindowSystemInterfacePrivate::GestureEvent(window, timestamp, type, local, global);
+ e->sequenceId = sequenceId;
+ e->intValue = value;
+ QWindowSystemInterfacePrivate::handleWindowSystemEvent(e);
+}
+#endif // QT_NO_GESTURES
+
void QWindowSystemInterface::handlePlatformPanelEvent(QWindow *w)
{
QWindowSystemInterfacePrivate::PlatformPanelEvent *e =
diff --git a/src/gui/kernel/qwindowsysteminterface.h b/src/gui/kernel/qwindowsysteminterface.h
index c8e464f985..d8d0922b96 100644
--- a/src/gui/kernel/qwindowsysteminterface.h
+++ b/src/gui/kernel/qwindowsysteminterface.h
@@ -177,6 +177,15 @@ public:
static void handleTabletLeaveProximityEvent(ulong timestamp, int device, int pointerType, qint64 uid);
static void handleTabletLeaveProximityEvent(int device, int pointerType, qint64 uid);
+#ifndef QT_NO_GESTURES
+ static void handleGestureEvent(QWindow *window, ulong timestamp, Qt::NativeGestureType type,
+ QPointF &local, QPointF &global);
+ static void handleGestureEventWithRealValue(QWindow *window, ulong timestamp, Qt::NativeGestureType type,
+ qreal value, QPointF &local, QPointF &global);
+ static void handleGestureEventWithSequenceIdAndValue(QWindow *window, ulong timestamp,Qt::NativeGestureType type,
+ ulong sequenceId, quint64 value, QPointF &local, QPointF &global);
+#endif // QT_NO_GESTURES
+
static void handlePlatformPanelEvent(QWindow *w);
#ifndef QT_NO_CONTEXTMENU
static void handleContextMenuEvent(QWindow *w, bool mouseTriggered,
diff --git a/src/gui/kernel/qwindowsysteminterface_p.h b/src/gui/kernel/qwindowsysteminterface_p.h
index 46479701cc..03e2d420f0 100644
--- a/src/gui/kernel/qwindowsysteminterface_p.h
+++ b/src/gui/kernel/qwindowsysteminterface_p.h
@@ -91,6 +91,7 @@ public:
PlatformPanel = UserInputEvent | 0x17,
ContextMenu = UserInputEvent | 0x18,
EnterWhatsThisMode = UserInputEvent | 0x19,
+ Gesture = UserInputEvent | 0x1a,
ApplicationStateChanged = 0x19,
FlushEvents = 0x20,
WindowScreenChanged = 0x21
@@ -398,6 +399,21 @@ public:
};
#endif
+ class GestureEvent : public InputEvent {
+ public:
+ GestureEvent(QWindow *window, ulong time, Qt::NativeGestureType type, QPointF pos, QPointF globalPos)
+ : InputEvent(window, time, Gesture, Qt::NoModifier), type(type), pos(pos), globalPos(globalPos),
+ realValue(0), sequenceId(0), intValue(0) { }
+ Qt::NativeGestureType type;
+ QPointF pos;
+ QPointF globalPos;
+ // Mac
+ qreal realValue;
+ // Windows
+ ulong sequenceId;
+ quint64 intValue;
+ };
+
class WindowSystemEventList {
QList<WindowSystemEvent *> impl;
mutable QMutex mutex;