summaryrefslogtreecommitdiffstats
path: root/tests/manual/gestures
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/gestures')
-rw-r--r--tests/manual/gestures/graphicsview/gestures.cpp24
-rw-r--r--tests/manual/gestures/graphicsview/gestures.h8
-rw-r--r--tests/manual/gestures/graphicsview/main.cpp10
-rw-r--r--tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp25
-rw-r--r--tests/manual/gestures/graphicsview/mousepangesturerecognizer.h4
-rw-r--r--tests/manual/gestures/scrollarea/main.cpp20
-rw-r--r--tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp25
-rw-r--r--tests/manual/gestures/scrollarea/mousepangesturerecognizer.h4
8 files changed, 55 insertions, 65 deletions
diff --git a/tests/manual/gestures/graphicsview/gestures.cpp b/tests/manual/gestures/graphicsview/gestures.cpp
index 5416457..4c21712 100644
--- a/tests/manual/gestures/graphicsview/gestures.cpp
+++ b/tests/manual/gestures/graphicsview/gestures.cpp
@@ -45,41 +45,41 @@
Qt::GestureType ThreeFingerSlideGesture::Type = Qt::CustomGesture;
-QGesture *ThreeFingerSlideGestureRecognizer::createGesture(QObject *)
+QGesture *ThreeFingerSlideGestureRecognizer::create(QObject *)
{
return new ThreeFingerSlideGesture;
}
-QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event)
+QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
ThreeFingerSlideGesture *d = static_cast<ThreeFingerSlideGesture *>(state);
QGestureRecognizer::Result result;
switch (event->type()) {
case QEvent::TouchBegin:
- result = QGestureRecognizer::MaybeGesture;
+ result = QGestureRecognizer::MayBeGesture;
case QEvent::TouchEnd:
if (d->gestureFired)
- result = QGestureRecognizer::GestureFinished;
+ result = QGestureRecognizer::FinishGesture;
else
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
case QEvent::TouchUpdate:
if (d->state() != Qt::NoGesture) {
QTouchEvent *ev = static_cast<QTouchEvent*>(event);
if (ev->touchPoints().size() == 3) {
d->gestureFired = true;
- result = QGestureRecognizer::GestureTriggered;
+ result = QGestureRecognizer::TriggerGesture;
} else {
- result = QGestureRecognizer::MaybeGesture;
+ result = QGestureRecognizer::MayBeGesture;
for (int i = 0; i < ev->touchPoints().size(); ++i) {
const QTouchEvent::TouchPoint &pt = ev->touchPoints().at(i);
const int distance = (pt.pos().toPoint() - pt.startPos().toPoint()).manhattanLength();
if (distance > 20) {
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
}
}
}
} else {
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
}
break;
@@ -89,7 +89,7 @@ QGestureRecognizer::Result ThreeFingerSlideGestureRecognizer::filterEvent(QGestu
if (d->state() != Qt::NoGesture)
result = QGestureRecognizer::Ignore;
else
- result = QGestureRecognizer::NotGesture;
+ result = QGestureRecognizer::CancelGesture;
break;
default:
result = QGestureRecognizer::Ignore;
@@ -105,12 +105,12 @@ void ThreeFingerSlideGestureRecognizer::reset(QGesture *state)
}
-QGesture *RotateGestureRecognizer::createGesture(QObject *)
+QGesture *RotateGestureRecognizer::create(QObject *)
{
return new QGesture;
}
-QGestureRecognizer::Result RotateGestureRecognizer::filterEvent(QGesture *, QObject *, QEvent *event)
+QGestureRecognizer::Result RotateGestureRecognizer::recognize(QGesture *, QObject *, QEvent *event)
{
switch (event->type()) {
case QEvent::TouchBegin:
diff --git a/tests/manual/gestures/graphicsview/gestures.h b/tests/manual/gestures/graphicsview/gestures.h
index 6140b12..8a31b71 100644
--- a/tests/manual/gestures/graphicsview/gestures.h
+++ b/tests/manual/gestures/graphicsview/gestures.h
@@ -59,8 +59,8 @@ public:
class ThreeFingerSlideGestureRecognizer : public QGestureRecognizer
{
private:
- QGesture* createGesture(QObject *target);
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ QGesture *create(QObject *target);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
void reset(QGesture *state);
};
@@ -70,8 +70,8 @@ public:
RotateGestureRecognizer();
private:
- QGesture* createGesture(QObject *target);
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ QGesture *create(QObject *target);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
void reset(QGesture *state);
};
diff --git a/tests/manual/gestures/graphicsview/main.cpp b/tests/manual/gestures/graphicsview/main.cpp
index de92afe..f8433b5 100644
--- a/tests/manual/gestures/graphicsview/main.cpp
+++ b/tests/manual/gestures/graphicsview/main.cpp
@@ -66,11 +66,11 @@ protected:
default: qDebug("view: Pan: <unknown state>"); break;
}
- const QPointF offset = pan->offset();
+ const QPointF delta = pan->delta();
QScrollBar *vbar = verticalScrollBar();
QScrollBar *hbar = horizontalScrollBar();
- vbar->setValue(vbar->value() - offset.y());
- hbar->setValue(hbar->value() - offset.x());
+ vbar->setValue(vbar->value() - delta.y());
+ hbar->setValue(hbar->value() - delta.x());
ge->accept(pan);
return true;
}
@@ -152,8 +152,8 @@ private:
MainWindow::MainWindow()
{
- (void)QApplication::registerGestureRecognizer(new MousePanGestureRecognizer);
- ThreeFingerSlideGesture::Type = QApplication::registerGestureRecognizer(new ThreeFingerSlideGestureRecognizer);
+ (void)QGestureRecognizer::registerRecognizer(new MousePanGestureRecognizer);
+ ThreeFingerSlideGesture::Type = QGestureRecognizer::registerRecognizer(new ThreeFingerSlideGestureRecognizer);
tabWidget = new QTabWidget;
diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp
index 6cdbe12..82adfbd 100644
--- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp
+++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.cpp
@@ -51,12 +51,12 @@ MousePanGestureRecognizer::MousePanGestureRecognizer()
{
}
-QGesture* MousePanGestureRecognizer::createGesture(QObject *)
+QGesture* MousePanGestureRecognizer::create(QObject *)
{
return new QPanGesture;
}
-QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event)
+QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
QPoint globalPos;
@@ -78,23 +78,19 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonDblClick
|| event->type() == QEvent::GraphicsSceneMousePress || event->type() == QEvent::GraphicsSceneMouseDoubleClick) {
g->setHotSpot(globalPos);
- g->setProperty("lastPos", globalPos);
+ g->setProperty("startPos", globalPos);
g->setProperty("pressed", QVariant::fromValue<bool>(true));
- return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
} else if (event->type() == QEvent::MouseMove || event->type() == QEvent::GraphicsSceneMouseMove) {
if (g->property("pressed").toBool()) {
- QPoint pos = globalPos;
- QPoint lastPos = g->property("lastPos").toPoint();
+ QPoint offset = globalPos - g->property("startPos").toPoint();
g->setLastOffset(g->offset());
- lastPos = pos - lastPos;
- g->setOffset(QPointF(lastPos.x(), lastPos.y()));
- g->setTotalOffset(g->totalOffset() + QPointF(lastPos.x(), lastPos.y()));
- g->setProperty("lastPos", pos);
- return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ g->setOffset(QPointF(offset.x(), offset.y()));
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
}
- return QGestureRecognizer::NotGesture;
+ return QGestureRecognizer::CancelGesture;
} else if (event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::GraphicsSceneMouseRelease) {
- return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint;
+ return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::Ignore;
}
@@ -102,11 +98,10 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat
void MousePanGestureRecognizer::reset(QGesture *state)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
- g->setTotalOffset(QPointF());
g->setLastOffset(QPointF());
g->setOffset(QPointF());
g->setAcceleration(0);
- g->setProperty("lastPos", QVariant());
+ g->setProperty("startPos", QVariant());
g->setProperty("pressed", QVariant::fromValue<bool>(false));
QGestureRecognizer::reset(state);
}
diff --git a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h
index b062fd0..6e04621 100644
--- a/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h
+++ b/tests/manual/gestures/graphicsview/mousepangesturerecognizer.h
@@ -49,8 +49,8 @@ class MousePanGestureRecognizer : public QGestureRecognizer
public:
MousePanGestureRecognizer();
- QGesture* createGesture(QObject *target);
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ QGesture* create(QObject *target);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
void reset(QGesture *state);
};
diff --git a/tests/manual/gestures/scrollarea/main.cpp b/tests/manual/gestures/scrollarea/main.cpp
index 9a5eb02..4f33b28 100644
--- a/tests/manual/gestures/scrollarea/main.cpp
+++ b/tests/manual/gestures/scrollarea/main.cpp
@@ -50,7 +50,7 @@ public:
ScrollArea(QWidget *parent = 0)
: QScrollArea(parent), outside(false)
{
- viewport()->grabGesture(Qt::PanGesture);
+ viewport()->grabGesture(Qt::PanGesture, Qt::ReceivePartialGestures);
}
protected:
@@ -87,8 +87,8 @@ protected:
if (outside)
return;
- const QPointF offset = pan->offset();
- const QPointF totalOffset = pan->totalOffset();
+ const QPointF delta = pan->delta();
+ const QPointF totalOffset = pan->offset();
QScrollBar *vbar = verticalScrollBar();
QScrollBar *hbar = horizontalScrollBar();
@@ -102,8 +102,8 @@ protected:
outside = true;
return;
}
- vbar->setValue(vbar->value() - offset.y());
- hbar->setValue(hbar->value() - offset.x());
+ vbar->setValue(vbar->value() - delta.y());
+ hbar->setValue(hbar->value() - delta.x());
event->accept(pan);
}
}
@@ -147,8 +147,8 @@ protected:
event->ignore(pan);
if (outside)
return;
- const QPointF offset = pan->offset();
- const QPointF totalOffset = pan->totalOffset();
+ const QPointF delta = pan->delta();
+ const QPointF totalOffset = pan->offset();
if (orientation() == Qt::Horizontal) {
if ((value() == minimum() && totalOffset.x() < -10) ||
(value() == maximum() && totalOffset.x() > 10)) {
@@ -156,7 +156,7 @@ protected:
return;
}
if (totalOffset.y() < 40 && totalOffset.y() > -40) {
- setValue(value() + offset.x());
+ setValue(value() + delta.x());
event->accept(pan);
} else {
outside = true;
@@ -168,7 +168,7 @@ protected:
return;
}
if (totalOffset.x() < 40 && totalOffset.x() > -40) {
- setValue(value() - offset.y());
+ setValue(value() - delta.y());
event->accept(pan);
} else {
outside = true;
@@ -232,7 +232,7 @@ private:
int main(int argc, char **argv)
{
QApplication app(argc, argv);
- app.registerGestureRecognizer(new MousePanGestureRecognizer);
+ QGestureRecognizer::registerRecognizer(new MousePanGestureRecognizer);
MainWindow w;
w.show();
return app.exec();
diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
index ce5ef57..66fcf18 100644
--- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
+++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.cpp
@@ -49,12 +49,12 @@ MousePanGestureRecognizer::MousePanGestureRecognizer()
{
}
-QGesture* MousePanGestureRecognizer::createGesture(QObject *)
+QGesture *MousePanGestureRecognizer::create(QObject *)
{
return new QPanGesture;
}
-QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *state, QObject *, QEvent *event)
+QGestureRecognizer::Result MousePanGestureRecognizer::recognize(QGesture *state, QObject *, QEvent *event)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
if (event->type() == QEvent::TouchBegin) {
@@ -68,24 +68,20 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat
if (g->property("ignoreMousePress").toBool())
return QGestureRecognizer::Ignore;
g->setHotSpot(me->globalPos());
- g->setProperty("lastPos", me->globalPos());
+ g->setProperty("startPos", me->globalPos());
g->setProperty("pressed", QVariant::fromValue<bool>(true));
- return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
} else if (event->type() == QEvent::MouseMove) {
if (g->property("pressed").toBool()) {
- QPoint pos = me->globalPos();
- QPoint lastPos = g->property("lastPos").toPoint();
+ QPoint offset = me->globalPos() - g->property("startPos").toPoint();
g->setLastOffset(g->offset());
- lastPos = pos - lastPos;
- g->setOffset(QPointF(lastPos.x(), lastPos.y()));
- g->setTotalOffset(g->totalOffset() + QPointF(lastPos.x(), lastPos.y()));
- g->setProperty("lastPos", pos);
- return QGestureRecognizer::GestureTriggered | QGestureRecognizer::ConsumeEventHint;
+ g->setOffset(QPointF(offset.x(), offset.y()));
+ return QGestureRecognizer::TriggerGesture | QGestureRecognizer::ConsumeEventHint;
}
- return QGestureRecognizer::NotGesture;
+ return QGestureRecognizer::CancelGesture;
} else if (event->type() == QEvent::MouseButtonRelease) {
if (g->property("pressed").toBool())
- return QGestureRecognizer::GestureFinished | QGestureRecognizer::ConsumeEventHint;
+ return QGestureRecognizer::FinishGesture | QGestureRecognizer::ConsumeEventHint;
}
return QGestureRecognizer::Ignore;
}
@@ -93,11 +89,10 @@ QGestureRecognizer::Result MousePanGestureRecognizer::filterEvent(QGesture *stat
void MousePanGestureRecognizer::reset(QGesture *state)
{
QPanGesture *g = static_cast<QPanGesture *>(state);
- g->setTotalOffset(QPointF());
g->setLastOffset(QPointF());
g->setOffset(QPointF());
g->setAcceleration(0);
- g->setProperty("lastPos", QVariant());
+ g->setProperty("startPos", QVariant());
g->setProperty("pressed", QVariant::fromValue<bool>(false));
g->setProperty("ignoreMousePress", QVariant::fromValue<bool>(false));
QGestureRecognizer::reset(state);
diff --git a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h
index b062fd0..6e04621 100644
--- a/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h
+++ b/tests/manual/gestures/scrollarea/mousepangesturerecognizer.h
@@ -49,8 +49,8 @@ class MousePanGestureRecognizer : public QGestureRecognizer
public:
MousePanGestureRecognizer();
- QGesture* createGesture(QObject *target);
- QGestureRecognizer::Result filterEvent(QGesture *state, QObject *watched, QEvent *event);
+ QGesture* create(QObject *target);
+ QGestureRecognizer::Result recognize(QGesture *state, QObject *watched, QEvent *event);
void reset(QGesture *state);
};