summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-09-02 17:59:11 +0200
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-09-03 11:30:55 +0200
commit70f5d838e42b6c34a28de54b5294d18b11529c8a (patch)
tree2f97da0618383deafccae40254313c77fa434bef
parent466bc1ed4bf0c466e54732b2f8f7a16a34b716a8 (diff)
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
-rw-r--r--examples/gestures/imageviewer/imagewidget.cpp4
-rw-r--r--src/gui/kernel/qstandardgestures.cpp16
-rw-r--r--src/gui/kernel/qstandardgestures.h13
-rw-r--r--src/gui/kernel/qstandardgestures_p.h4
4 files changed, 34 insertions, 3 deletions
diff --git a/examples/gestures/imageviewer/imagewidget.cpp b/examples/gestures/imageviewer/imagewidget.cpp
index a4ea238d05..c71c461a75 100644
--- a/examples/gestures/imageviewer/imagewidget.cpp
+++ b/examples/gestures/imageviewer/imagewidget.cpp
@@ -123,9 +123,9 @@ void ImageWidget::panTriggered()
void ImageWidget::pinchTriggered()
{
QPinchGesture *pg = qobject_cast<QPinchGesture*>(sender());
- if (pg->rotationAngle() != 0.0)
+ if (pg->whatChanged() & QPinchGesture::RotationAngleChanged)
rotationAngle += pg->rotationAngle() - pg->lastRotationAngle();
- if (pg->scaleFactor() != 1.0)
+ if (pg->whatChanged() & QPinchGesture::ScaleFactorChanged)
scaleFactor += pg->scaleFactor() - pg->lastScaleFactor();
update();
}
diff --git a/src/gui/kernel/qstandardgestures.cpp b/src/gui/kernel/qstandardgestures.cpp
index 783c1d3e28..8e76715ba7 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 c6dfa925eb..53c4416abf 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 9e235155cf..354ebeeaa7 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.