diff options
author | Shawn Rutledge <shawn.rutledge@digia.com> | 2014-12-09 10:28:25 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@digia.com> | 2015-02-13 14:03:47 +0000 |
commit | 5b31071e56ef6e241e27b66ff91f4e9222f2cddb (patch) | |
tree | 6f87fffdc4225cff1ac97f87ef3ab045c4c1e2e1 | |
parent | 3f3be0fa64f8745b05a417d3e9c8c20da74d5fa9 (diff) |
PinchArea: handle smart zoom gesture
This is the double-finger double-tap trackpad gesture on OS X.
Change-Id: Ie79dc533adf382170867318bc9b61b367f819e9b
Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
-rw-r--r-- | examples/quick/demos/photosurface/photosurface.qml | 21 | ||||
-rw-r--r-- | src/quick/items/qquickitemsmodule.cpp | 2 | ||||
-rw-r--r-- | src/quick/items/qquickpincharea.cpp | 37 | ||||
-rw-r--r-- | src/quick/items/qquickpincharea_p.h | 1 |
4 files changed, 60 insertions, 1 deletions
diff --git a/examples/quick/demos/photosurface/photosurface.qml b/examples/quick/demos/photosurface/photosurface.qml index c7d59ffa9b..fc3b505bcf 100644 --- a/examples/quick/demos/photosurface/photosurface.qml +++ b/examples/quick/demos/photosurface/photosurface.qml @@ -37,7 +37,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -import QtQuick 2.4 +import QtQuick 2.5 import QtQuick.Dialogs 1.0 import QtQuick.Window 2.1 import Qt.labs.folderlistmodel 1.0 @@ -104,6 +104,25 @@ Window { pinch.maximumScale: 10 pinch.dragAxis: Pinch.XAndYAxis onPinchStarted: setFrameColor(); + property real zRestore: 0 + onSmartZoom: { + if (pinch.scale > 0) { + photoFrame.rotation = 0; + photoFrame.scale = Math.min(root.width, root.height) / Math.max(image.sourceSize.width, image.sourceSize.height) * 0.85 + photoFrame.x = flick.contentX + (flick.width - photoFrame.width) / 2 + photoFrame.y = flick.contentY + (flick.height - photoFrame.height) / 2 + zRestore = photoFrame.z + photoFrame.z = ++root.highestZ; + } else { + photoFrame.rotation = pinch.previousAngle + photoFrame.scale = pinch.previousScale + photoFrame.x = pinch.previousCenter.x - photoFrame.width / 2 + photoFrame.y = pinch.previousCenter.y - photoFrame.height / 2 + photoFrame.z = zRestore + --root.highestZ + } + } + MouseArea { id: dragArea hoverEnabled: true diff --git a/src/quick/items/qquickitemsmodule.cpp b/src/quick/items/qquickitemsmodule.cpp index 48e9290cbe..b1116bdb64 100644 --- a/src/quick/items/qquickitemsmodule.cpp +++ b/src/quick/items/qquickitemsmodule.cpp @@ -265,6 +265,8 @@ static void qt_quickitems_defineModule(const char *uri, int major, int minor) qmlRegisterType<QQuickMouseArea, 1>(uri, 2, 4, "MouseArea"); qmlRegisterType<QQuickShaderEffect, 1>(uri, 2, 4, "ShaderEffect"); qmlRegisterUncreatableType<QQuickOpenGLInfo>(uri, 2, 4,"OpenGLInfo", QQuickOpenGLInfo::tr("OpenGLInfo is only available via attached properties")); + + qmlRegisterType<QQuickPinchArea, 1>(uri, 2, 5,"PinchArea"); } static void initResources() diff --git a/src/quick/items/qquickpincharea.cpp b/src/quick/items/qquickpincharea.cpp index 667a988cba..5c3916cfc4 100644 --- a/src/quick/items/qquickpincharea.cpp +++ b/src/quick/items/qquickpincharea.cpp @@ -234,6 +234,22 @@ QQuickPinchAreaPrivate::~QQuickPinchAreaPrivate() The corresponding handler is \c onPinchFinished. */ +/*! + \qmlsignal QtQuick::PinchArea::smartZoom() + \since 5.5 + + This signal is emitted when the pinch area detects the smart zoom gesture. + This gesture occurs only on certain operating systems such as OS X. + + The \l {PinchEvent}{pinch} parameter provides information about the pinch + gesture, including the location where the gesture occurred. \c pinch.scale + will be greater than zero when the gesture indicates that the user wishes to + enter smart zoom, and zero when exiting (even though typically the same gesture + is used to toggle between the two states). + + The corresponding handler is \c onSmartZoom. +*/ + /*! \qmlpropertygroup QtQuick::PinchArea::pinch @@ -663,6 +679,27 @@ bool QQuickPinchArea::event(QEvent *event) d->inPinch = true; updatePinchTarget(); } break; + case Qt::SmartZoomNativeGesture: { + if (gesture->value() > 0.0 && d->pinch && d->pinch->target()) { + d->pinchStartPos = pinch()->target()->position(); + d->pinchStartCenter = mapToItem(pinch()->target()->parentItem(), pinch()->target()->boundingRect().center()); + d->pinchStartScale = d->pinch->target()->scale(); + d->pinchStartRotation = d->pinch->target()->rotation(); + d->pinchLastScale = d->pinchStartScale = d->pinch->target()->scale(); + d->pinchLastAngle = d->pinchStartRotation = d->pinch->target()->rotation(); + } + QQuickPinchEvent pe(gesture->localPos(), gesture->value(), d->pinchLastAngle, 0.0); + pe.setStartCenter(gesture->localPos()); + pe.setPreviousCenter(d->pinchStartCenter); + pe.setPreviousAngle(d->pinchLastAngle); + pe.setPreviousScale(d->pinchLastScale); + pe.setStartPoint1(gesture->localPos()); + pe.setStartPoint2(gesture->localPos()); + pe.setPoint1(mapFromScene(gesture->windowPos())); + pe.setPoint2(mapFromScene(gesture->windowPos())); + pe.setPointCount(2); + emit smartZoom(&pe); + } break; case Qt::RotateNativeGesture: { qreal angle = d->pinchLastAngle + gesture->value(); QQuickPinchEvent pe(d->pinchStartCenter, d->pinchLastScale, angle, 0.0); diff --git a/src/quick/items/qquickpincharea_p.h b/src/quick/items/qquickpincharea_p.h index ebb5f44379..57f9a87e07 100644 --- a/src/quick/items/qquickpincharea_p.h +++ b/src/quick/items/qquickpincharea_p.h @@ -266,6 +266,7 @@ Q_SIGNALS: void pinchStarted(QQuickPinchEvent *pinch); void pinchUpdated(QQuickPinchEvent *pinch); void pinchFinished(QQuickPinchEvent *pinch); + Q_REVISION(1) void smartZoom(QQuickPinchEvent *pinch); protected: bool childMouseEventFilter(QQuickItem *i, QEvent *e) Q_DECL_OVERRIDE; |