summaryrefslogtreecommitdiffstats
path: root/examples/gestures
diff options
context:
space:
mode:
authorDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-08-06 11:14:52 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2009-08-06 11:51:00 (GMT)
commit576af5e57831c7065d621f468c067fca8ebc2fe5 (patch)
tree00dcc829356aa9e440921acd91829b6fce21123e /examples/gestures
parent504866ffcf57461774bc39357b23954df3a2d9ee (diff)
downloadQt-576af5e57831c7065d621f468c067fca8ebc2fe5.zip
Qt-576af5e57831c7065d621f468c067fca8ebc2fe5.tar.gz
Qt-576af5e57831c7065d621f468c067fca8ebc2fe5.tar.bz2
Fixed compilation of the gestures/imagewidget example.
Also improved an example a bit to optionally support TapAndHold gesture with plain mouse events. Reviewed-by: trustme
Diffstat (limited to 'examples/gestures')
-rw-r--r--examples/gestures/imageviewer/imagewidget.cpp13
-rw-r--r--examples/gestures/imageviewer/tapandholdgesture.cpp33
-rw-r--r--examples/gestures/imageviewer/tapandholdgesture.h1
3 files changed, 35 insertions, 12 deletions
diff --git a/examples/gestures/imageviewer/imagewidget.cpp b/examples/gestures/imageviewer/imagewidget.cpp
index 99889ed..c0d1e2d 100644
--- a/examples/gestures/imageviewer/imagewidget.cpp
+++ b/examples/gestures/imageviewer/imagewidget.cpp
@@ -67,6 +67,7 @@ ImageWidget::ImageWidget(QWidget *parent)
tapAndHoldGesture = new TapAndHoldGesture(this);
connect(tapAndHoldGesture, SIGNAL(triggered()), this, SLOT(gestureTriggered()));
+ connect(tapAndHoldGesture, SIGNAL(finished()), this, SLOT(gestureTriggered()));
}
void ImageWidget::paintEvent(QPaintEvent*)
@@ -112,7 +113,7 @@ void ImageWidget::paintEvent(QPaintEvent*)
touchFeedback.position + QPoint(-10, 10),
touchFeedback.position + QPoint(-15, 0)
};
- for (int i = 0; i < (touchFeedback.tapAndHoldState-20)/10; ++i)
+ for (int i = 0; i < touchFeedback.tapAndHoldState/5; ++i)
p.drawEllipse(pts[i], 3, 3);
}
} else if (touchFeedback.sliding) {
@@ -156,10 +157,9 @@ void ImageWidget::mouseDoubleClickEvent(QMouseEvent *event)
void ImageWidget::gestureTriggered()
{
- touchFeedback.tapped = false;
- touchFeedback.doubleTapped = false;
-
if (sender() == panGesture) {
+ touchFeedback.tapped = false;
+ touchFeedback.doubleTapped = false;
QPanGesture *pg = qobject_cast<QPanGesture*>(sender());
if (zoomedIn) {
#ifndef QT_NO_CURSOR
@@ -174,7 +174,6 @@ void ImageWidget::gestureTriggered()
#endif
horizontalOffset += pg->lastOffset().width();
verticalOffset += pg->lastOffset().height();
- update();
} else {
// only slide gesture should be accepted
if (pg->state() == Qt::GestureFinished) {
@@ -187,6 +186,7 @@ void ImageWidget::gestureTriggered()
updateImage();
}
}
+ update();
feedbackFadeOutTimer.start(500, this);
} else if (sender() == tapAndHoldGesture) {
if (tapAndHoldGesture->state() == Qt::GestureFinished) {
@@ -199,6 +199,9 @@ void ImageWidget::gestureTriggered()
menu.addAction("Action 2");
menu.addAction("Action 3");
menu.exec(mapToGlobal(tapAndHoldGesture->pos()));
+ } else {
+ ++touchFeedback.tapAndHoldState;
+ update();
}
feedbackFadeOutTimer.start(500, this);
}
diff --git a/examples/gestures/imageviewer/tapandholdgesture.cpp b/examples/gestures/imageviewer/tapandholdgesture.cpp
index ff5284e..5fe52cc 100644
--- a/examples/gestures/imageviewer/tapandholdgesture.cpp
+++ b/examples/gestures/imageviewer/tapandholdgesture.cpp
@@ -43,6 +43,8 @@
#include <QtGui/qevent.h>
+// #define TAPANDHOLD_USING_MOUSE
+
/*!
\class TapAndHoldGesture
\since 4.6
@@ -95,6 +97,26 @@ bool TapAndHoldGesture::filterEvent(QEvent *event)
case QEvent::TouchEnd:
reset();
break;
+#ifdef TAPANDHOLD_USING_MOUSE
+ case QEvent::MouseButtonPress: {
+ if (timer.isActive())
+ timer.stop();
+ timer.start(TapAndHoldGesture::iterationTimeout, this);
+ const QPoint p = static_cast<QMouseEvent*>(event)->pos();
+ position = startPosition = p;
+ break;
+ }
+ case QEvent::MouseMove: {
+ const QPoint startPos = startPosition;
+ const QPoint pos = static_cast<QMouseEvent*>(event)->pos();
+ if ((startPos - pos).manhattanLength() > 15)
+ reset();
+ break;
+ }
+ case QEvent::MouseButtonRelease:
+ reset();
+ break;
+#endif // TAPANDHOLD_USING_MOUSE
default:
break;
}
@@ -108,11 +130,9 @@ void TapAndHoldGesture::timerEvent(QTimerEvent *event)
return;
if (iteration == TapAndHoldGesture::iterationCount) {
timer.stop();
- setState(Qt::GestureFinished);
- emit triggered();
+ updateState(Qt::GestureFinished);
} else {
- setState(Qt::GestureStarted);
- emit triggered();
+ updateState(Qt::GestureUpdated);
}
++iteration;
}
@@ -120,11 +140,10 @@ void TapAndHoldGesture::timerEvent(QTimerEvent *event)
/*! \internal */
void TapAndHoldGesture::reset()
{
- if (state() != Qt::NoGesture)
- emit cancelled();
- setState(Qt::NoGesture);
timer.stop();
iteration = 0;
+ position = startPosition = QPoint();
+ updateState(Qt::NoGesture);
}
/*!
diff --git a/examples/gestures/imageviewer/tapandholdgesture.h b/examples/gestures/imageviewer/tapandholdgesture.h
index e0d50b5..61fabc2 100644
--- a/examples/gestures/imageviewer/tapandholdgesture.h
+++ b/examples/gestures/imageviewer/tapandholdgesture.h
@@ -66,6 +66,7 @@ private:
QBasicTimer timer;
int iteration;
QPoint position;
+ QPoint startPosition;
static const int iterationCount;
static const int iterationTimeout;
};