aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Kapusta <dominik.kapusta@teleca.com>2010-11-08 13:10:53 +0100
committerDominik Kapusta <dominik.kapusta@teleca.com>2010-11-08 13:11:58 +0100
commit2547921347e4ddaa1e0ae7d73dce6b65f21ecc82 (patch)
treed30531ebcc59d9fd4f7faf688701a9c1df03f98f
parente2f3663babe52bd92f2650f01adf4dfd7e516bd6 (diff)
Changes: Adding Tap and Tap And Hold gesture handlers to gesture example app.
RevBy: MichaƂ
-rw-r--r--examples/gestures/mypage.cpp43
-rw-r--r--examples/gestures/mypage.h7
2 files changed, 50 insertions, 0 deletions
diff --git a/examples/gestures/mypage.cpp b/examples/gestures/mypage.cpp
index 7d9da0c1..cb5f716e 100644
--- a/examples/gestures/mypage.cpp
+++ b/examples/gestures/mypage.cpp
@@ -1,5 +1,6 @@
#include <MDebug>
#include <MImageWidget>
+#include <MMessageBox>
#include <QImage>
#include <QPinchGesture>
#include <QSwipeGesture>
@@ -33,6 +34,8 @@ MyPage::MyPage(QGraphicsItem *parent)
// area, even if it holds multiple widgets. In case of multiple widgets,
// you can determine the target of the gesture using the event's hotSpot
// property.
+ grabGesture(Qt::TapGesture);
+ grabGesture(Qt::TapAndHoldGesture);
grabGesture(Qt::PinchGesture);
grabGesture(Qt::SwipeGesture);
@@ -99,8 +102,48 @@ void MyPage::hideImagesExceptCurrent()
}
}
+void MyPage::showImageInfo()
+{
+ MMessageBox *msgBox = new MMessageBox("Image info");
+
+ QString text("Name: %1\nSize: %2");
+ QString size("%1x%2");
+
+ MImageWidget *currentImage = images[currentImageNumber];
+ int width = currentImage->pixmap()->width() * currentImage->scale();
+ int height = currentImage->pixmap()->height() * currentImage->scale();
+
+ msgBox->setText(text.arg(currentImage->imageId()).arg(size.arg(width).arg(height)));
+ msgBox->appear(MMessageBox::DestroyWhenDone);
+}
+
// The gesture handlers:
+// Tap handler
+void MyPage::tapGestureEvent(QGestureEvent *event,
+ QTapGesture *gesture)
+{
+ mDebug("tapGestureEvent")
+ << "State:" << gesture->state()
+ << "Position:" << gesture->position();
+
+ event->accept(Qt::TapGesture);
+}
+
+// Tap And Hold handler
+void MyPage::tapAndHoldGestureEvent(QGestureEvent *event,
+ QTapAndHoldGesture *gesture)
+{
+ mDebug("tapAndHoldGestureEvent")
+ << "State:" << gesture->state()
+ << "Position:" << gesture->position();
+
+ event->accept(Qt::TapAndHoldGesture);
+
+ if (gesture->state() == Qt::GestureFinished)
+ showImageInfo();
+}
+
// Pinch handler
void MyPage::pinchGestureEvent(QGestureEvent *event,
QPinchGesture *gesture)
diff --git a/examples/gestures/mypage.h b/examples/gestures/mypage.h
index 2dbd7d3d..91acd692 100644
--- a/examples/gestures/mypage.h
+++ b/examples/gestures/mypage.h
@@ -23,8 +23,15 @@ public slots:
void showPreviousImage(bool stopCurrentAnimation = false);
void showNextImage(bool stopCurrentAnimation = false);
void hideImagesExceptCurrent();
+ void showImageInfo();
protected:
+ virtual void tapGestureEvent(QGestureEvent *event,
+ QTapGesture *gesture);
+
+ virtual void tapAndHoldGestureEvent(QGestureEvent *event,
+ QTapAndHoldGesture *gesture);
+
virtual void pinchGestureEvent(QGestureEvent *event,
QPinchGesture *gesture);