diff options
author | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2009-08-06 10:10:16 (GMT) |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@nokia.com> | 2009-08-06 14:09:04 (GMT) |
commit | c53004694b49d8e4e6c4cfd294efb6589559c2f3 (patch) | |
tree | a50a3daeb441f795def11b62b48d27e9d4088052 /src | |
parent | 443a7b6f3eb1191b20240b5068da386d669045fc (diff) | |
download | Qt-c53004694b49d8e4e6c4cfd294efb6589559c2f3.zip Qt-c53004694b49d8e4e6c4cfd294efb6589559c2f3.tar.gz Qt-c53004694b49d8e4e6c4cfd294efb6589559c2f3.tar.bz2 |
Cocoa: Add support for native gestures
Cocoa: Add support for native gestures
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qcocoaview_mac.mm | 54 | ||||
-rw-r--r-- | src/gui/kernel/qevent_p.h | 10 |
2 files changed, 51 insertions, 13 deletions
diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 1d352cb..8c6f394 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -50,6 +50,7 @@ #include <private/qdnd_p.h> #include <private/qmacinputcontext_p.h> #include <private/qmultitouch_mac_p.h> +#include <private/qevent_p.h> #include <qscrollarea.h> #include <qhash.h> @@ -868,32 +869,65 @@ extern "C" { - (void)magnifyWithEvent:(NSEvent *)event; { - Q_UNUSED(event); -// qDebug() << "magnifyWithEvent"; + if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) + return; + + QNativeGestureEvent qNGEvent; + qNGEvent.gestureType = QNativeGestureEvent::Zoom; + NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; + qNGEvent.position = flipPoint(p).toPoint(); + qNGEvent.percentage = [event magnification]; + qApp->sendEvent(qwidget, &qNGEvent); } - (void)rotateWithEvent:(NSEvent *)event; { - Q_UNUSED(event); -// qDebug() << "rotateWithEvent"; + if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) + return; + + QNativeGestureEvent qNGEvent; + qNGEvent.gestureType = QNativeGestureEvent::Rotate; + NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; + qNGEvent.position = flipPoint(p).toPoint(); + qNGEvent.percentage = [event rotation]; + qApp->sendEvent(qwidget, &qNGEvent); } - (void)swipeWithEvent:(NSEvent *)event; { - Q_UNUSED(event); -// qDebug() << "swipeWithEvent"; + if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) + return; + + QNativeGestureEvent qNGEvent; + qNGEvent.gestureType = QNativeGestureEvent::Swipe; + NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; + qNGEvent.position = flipPoint(p).toPoint(); + qNGEvent.direction = QSize(-[event deltaX], -[event deltaY]); + qApp->sendEvent(qwidget, &qNGEvent); } - (void)beginGestureWithEvent:(NSEvent *)event; { - Q_UNUSED(event); -// qDebug() << "beginGestureWithEvent"; + if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) + return; + + QNativeGestureEvent qNGEvent; + qNGEvent.gestureType = QNativeGestureEvent::GestureBegin; + NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; + qNGEvent.position = flipPoint(p).toPoint(); + qApp->sendEvent(qwidget, &qNGEvent); } - (void)endGestureWithEvent:(NSEvent *)event; { - Q_UNUSED(event); -// qDebug() << "endGestureWithEvent"; + if (!QApplicationPrivate::tryModalHelper(qwidget, 0)) + return; + + QNativeGestureEvent qNGEvent; + qNGEvent.gestureType = QNativeGestureEvent::GestureEnd; + NSPoint p = [[event window] convertBaseToScreen:[event locationInWindow]]; + qNGEvent.position = flipPoint(p).toPoint(); + qApp->sendEvent(qwidget, &qNGEvent); } #endif // MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 92c4fc1..b21b35c 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -127,11 +127,13 @@ public: GestureBegin, GestureEnd, Pan, - Pinch + Zoom, + Rotate, + Swipe }; QNativeGestureEvent() - : QEvent(QEvent::NativeGesture), gestureType(None) + : QEvent(QEvent::NativeGesture), gestureType(None), percentage(0), direction(0, 0) #ifdef Q_WS_WIN , sequenceId(0) #endif @@ -139,8 +141,10 @@ public: } Type gestureType; -#ifdef Q_WS_WIN + float percentage; QPoint position; + QSize direction; +#ifdef Q_WS_WIN ulong sequenceId; #endif }; |