diff options
author | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-09-02 15:59:11 (GMT) |
---|---|---|
committer | Denis Dzyubenko <denis.dzyubenko@nokia.com> | 2009-09-03 09:30:55 (GMT) |
commit | 70f5d838e42b6c34a28de54b5294d18b11529c8a (patch) | |
tree | 2f97da0618383deafccae40254313c77fa434bef /src | |
parent | 466bc1ed4bf0c466e54732b2f8f7a16a34b716a8 (diff) | |
download | Qt-70f5d838e42b6c34a28de54b5294d18b11529c8a.zip Qt-70f5d838e42b6c34a28de54b5294d18b11529c8a.tar.gz Qt-70f5d838e42b6c34a28de54b5294d18b11529c8a.tar.bz2 |
Added a property to QPinchGesture to specify what exactly changed.
Added QPinchGesture::whatChanged() which specifies which property in the pinch
gesture changed - the scale factor or rotation angle or both.
Reviewed-by: Bradley T. Hughes
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qstandardgestures.cpp | 16 | ||||
-rw-r--r-- | src/gui/kernel/qstandardgestures.h | 13 | ||||
-rw-r--r-- | src/gui/kernel/qstandardgestures_p.h | 4 |
3 files changed, 32 insertions, 1 deletions
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp index 783c1d3..8e76715 100644 --- a/src/gui/kernel/qstandardgestures.cpp +++ b/src/gui/kernel/qstandardgestures.cpp @@ -413,6 +413,7 @@ bool QPinchGesture::eventFilter(QObject *receiver, QEvent *event) // next we might receive the first gesture update event, so we // prepare for it. d->state = Qt::NoGesture; + d->changes = 0; d->totalScaleFactor = d->scaleFactor = d->lastScaleFactor = 1.; d->totalRotationAngle = d->rotationAngle = d->lastRotationAngle = 0.; d->startCenterPoint = d->centerPoint = d->lastCenterPoint = QPointF(); @@ -460,6 +461,7 @@ bool QPinchGesture::eventFilter(QObject *receiver, QEvent *event) if (!windowsRotateWorkaround) nextState = Qt::GestureUpdated; #endif + d->changes = QPinchGesture::RotationAngleChanged; event->accept(); break; } @@ -484,6 +486,7 @@ bool QPinchGesture::eventFilter(QObject *receiver, QEvent *event) d->scaleFactor += ev->percentage; #endif nextState = Qt::GestureUpdated; + d->changes = QPinchGesture::ScaleFactorChanged; event->accept(); break; case QNativeGestureEvent::GestureEnd: @@ -498,6 +501,8 @@ bool QPinchGesture::eventFilter(QObject *receiver, QEvent *event) d->startCenterPoint = d->centerPoint; d->lastCenterPoint = d->centerPoint; d->centerPoint = static_cast<QWidget*>(receiver)->mapFromGlobal(ev->position); + if (d->lastCenterPoint != d->centerPoint) + d->changes |= QPinchGesture::CenterPointChanged; updateState(nextState); return true; } @@ -523,6 +528,7 @@ bool QPinchGesture::filterEvent(QEvent *event) void QPinchGesture::reset() { Q_D(QPinchGesture); + d->changes = 0; d->totalScaleFactor = d->scaleFactor = d->lastScaleFactor = 1.; d->totalRotationAngle = d->rotationAngle = d->lastRotationAngle = 0.; d->startCenterPoint = d->centerPoint = d->lastCenterPoint = QPointF(); @@ -530,6 +536,16 @@ void QPinchGesture::reset() } /*! + \property QPinchGesture::whatChanged + + Specifies which values were changed in the gesture. +*/ +QPinchGesture::WhatChanged QPinchGesture::whatChanged() const +{ + return d_func()->changes; +} + +/*! \property QPinchGesture::totalScaleFactor Specifies a total scale factor of the pinch gesture since the gesture diff --git a/src/gui/kernel/qstandardgestures.h b/src/gui/kernel/qstandardgestures.h index c6dfa92..53c4416 100644 --- a/src/gui/kernel/qstandardgestures.h +++ b/src/gui/kernel/qstandardgestures.h @@ -89,6 +89,16 @@ class Q_GUI_EXPORT QPinchGesture : public QGesture Q_OBJECT Q_DECLARE_PRIVATE(QPinchGesture) +public: + enum WhatChange { + ScaleFactorChanged = 0x1, + RotationAngleChanged = 0x2, + CenterPointChanged = 0x4 + }; + Q_DECLARE_FLAGS(WhatChanged, WhatChange) + + Q_PROPERTY(WhatChanged whatChanged READ whatChanged) + Q_PROPERTY(qreal totalScaleFactor READ totalScaleFactor) Q_PROPERTY(qreal lastScaleFactor READ lastScaleFactor) Q_PROPERTY(qreal scaleFactor READ scaleFactor) @@ -102,11 +112,14 @@ class Q_GUI_EXPORT QPinchGesture : public QGesture Q_PROPERTY(QPointF centerPoint READ centerPoint) public: + QPinchGesture(QWidget *gestureTarget, QObject *parent = 0); bool filterEvent(QEvent *event); void reset(); + WhatChanged whatChanged() const; + QPointF startCenterPoint() const; QPointF lastCenterPoint() const; QPointF centerPoint() const; diff --git a/src/gui/kernel/qstandardgestures_p.h b/src/gui/kernel/qstandardgestures_p.h index 9e23515..354ebee 100644 --- a/src/gui/kernel/qstandardgestures_p.h +++ b/src/gui/kernel/qstandardgestures_p.h @@ -89,7 +89,7 @@ class QPinchGesturePrivate : public QGesturePrivate public: QPinchGesturePrivate() - : totalScaleFactor(0.), lastScaleFactor(0.), scaleFactor(0.), + : changes(0), totalScaleFactor(0.), lastScaleFactor(0.), scaleFactor(0.), totalRotationAngle(0.), lastRotationAngle(0.), rotationAngle(0.) #ifdef Q_WS_WIN ,initialDistance(0), lastSequenceId(0) @@ -99,6 +99,8 @@ public: void setupGestureTarget(QObject *o); + QPinchGesture::WhatChanged changes; + qreal totalScaleFactor; // total scale factor, excluding the current sequence. qreal lastScaleFactor; qreal scaleFactor; // scale factor in the current sequence. |