aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Junnonen <tomas.junnonen@nokia.com>2010-04-21 11:21:07 +0300
committerTomas Junnonen <tomas.junnonen@nokia.com>2010-04-21 11:21:07 +0300
commit051c97adb6a30b3dd7c3e4e86b707d7fa0222e8a (patch)
treecc2fdea13a9aabf1a9e755446d3015235a663aa2
parentc2dbbdcede33dca84027aad4de7b1f84cda126e9 (diff)
Revert "Changes: DuiPannableWidget is now going to use pan gestures"
This reverts commit 6e2ee74ae199a0b254562764a8a7b33904152dbe.
-rw-r--r--src/corelib/core/mcomponentdata.cpp4
-rw-r--r--src/corelib/events/events.pri5
-rw-r--r--src/corelib/events/mpangesture.cpp31
-rw-r--r--src/corelib/events/mpangesture_p.h55
-rw-r--r--src/corelib/events/mpanrecognizer.cpp150
-rw-r--r--src/corelib/events/mpanrecognizer.h74
-rw-r--r--src/corelib/events/mpanrecognizer_p.h43
-rw-r--r--src/corelib/widgets/mpannablewidget.cpp352
-rw-r--r--src/corelib/widgets/mpannablewidget.h28
-rw-r--r--src/corelib/widgets/mpannablewidget_p.h34
-rw-r--r--src/corelib/widgets/mwindow.cpp1
-rw-r--r--tests/stubs/mwidget_stub.h10
-rw-r--r--tests/tests.pro1
-rw-r--r--tests/ut_mapplethandle/ut_mapplethandle.cpp1
-rw-r--r--tests/ut_mextensionhandle/ut_mextensionhandle.cpp1
-rw-r--r--tests/ut_mpannablewidget/ut_mpannablewidget.cpp608
-rw-r--r--tests/ut_mpannablewidget/ut_mpannablewidget.h43
-rw-r--r--tests/ut_mpannablewidget/ut_mpannablewidget.pro18
-rw-r--r--tests/ut_mpanrecognizer/.gitignore1
-rw-r--r--tests/ut_mpanrecognizer/ut_mpanrecognizer.cpp105
-rw-r--r--tests/ut_mpanrecognizer/ut_mpanrecognizer.h44
-rw-r--r--tests/ut_mpanrecognizer/ut_mpanrecognizer.pro16
22 files changed, 693 insertions, 932 deletions
diff --git a/src/corelib/core/mcomponentdata.cpp b/src/corelib/core/mcomponentdata.cpp
index 97bfe13e..69adf8a2 100644
--- a/src/corelib/core/mcomponentdata.cpp
+++ b/src/corelib/core/mcomponentdata.cpp
@@ -41,7 +41,6 @@
#include "mapplicationwindow.h"
#include "mtapandholdrecognizer.h"
#include "mpinchrecognizer.h"
-#include "mpanrecognizer.h"
#include <MDebug>
#ifdef TESTABLE
@@ -586,9 +585,6 @@ void MComponentDataPrivate::init(int &argc, char **argv, const QString &appIdent
QGestureRecognizer::unregisterRecognizer(Qt::PinchGesture);
QGestureRecognizer::registerRecognizer(new MPinchRecognizer());
- QGestureRecognizer::unregisterRecognizer(Qt::PanGesture);
- QGestureRecognizer::registerRecognizer(new MPanRecognizer());
-
q->setShowCursor(showCursor);
}
diff --git a/src/corelib/events/events.pri b/src/corelib/events/events.pri
index 1e3586d9..d6f893df 100644
--- a/src/corelib/events/events.pri
+++ b/src/corelib/events/events.pri
@@ -22,9 +22,6 @@ PRIVATE_HEADERS += \
$$EVENTS_SRC_DIR/mtapandholdrecognizer_p.h \
$$EVENTS_SRC_DIR/mtapandholdgesture_p.h \
$$EVENTS_SRC_DIR/mkeyboardstatetracker_p.h \
- $$EVENTS_SRC_DIR/mpangesture_p.h \
- $$EVENTS_SRC_DIR/mpanrecognizer_p.h \
- $$EVENTS_SRC_DIR/mpanrecognizer.h \
SOURCES += \
$$EVENTS_SRC_DIR/morientationtracker.cpp \
@@ -38,5 +35,3 @@ SOURCES += \
$$EVENTS_SRC_DIR/mtapandholdrecognizer.cpp \
$$EVENTS_SRC_DIR/mkeyboardstatetracker.cpp \
$$EVENTS_SRC_DIR/mpinchrecognizer.cpp \
- $$EVENTS_SRC_DIR/mpanrecognizer.cpp \
- $$EVENTS_SRC_DIR/mpangesture.cpp \
diff --git a/src/corelib/events/mpangesture.cpp b/src/corelib/events/mpangesture.cpp
deleted file mode 100644
index 8f6560c0..00000000
--- a/src/corelib/events/mpangesture.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (directui@nokia.com)
-**
-** This file is part of libdui.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at directui@nokia.com.
-**
-** This library is free software; you can redistribute it and/or
-** modify it under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation
-** and appearing in the file LICENSE.LGPL included in the packaging
-** of this file.
-**
-****************************************************************************/
-
-#include "mpangesture_p.h"
-
-MPanGesture::MPanGesture(QObject *parent) :
- QPanGesture(parent),
- startPos(QPointF()),
- panDirection(0)
-{
-}
-
-MPanGesture::~MPanGesture()
-{
-}
diff --git a/src/corelib/events/mpangesture_p.h b/src/corelib/events/mpangesture_p.h
deleted file mode 100644
index 09b39780..00000000
--- a/src/corelib/events/mpangesture_p.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (directui@nokia.com)
-**
-** This file is part of libdui.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at directui@nokia.com.
-**
-** This library is free software; you can redistribute it and/or
-** modify it under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation
-** and appearing in the file LICENSE.LGPL included in the packaging
-** of this file.
-**
-****************************************************************************/
-
-
-#ifndef MPANGESTURE_P_H
-#define MPANGESTURE_P_H
-
-#include <QPanGesture>
-
-class MPanRecognizer;
-
-/*!
- This class provides Pan gesture state.
- It's objects are delivered to registered handlers when a gesture is initiated.
- */
-class MPanGesture : public QPanGesture
-{
- Q_OBJECT
-
-public:
- /*!
- Default constructor.
- */
- MPanGesture(QObject *parent = 0);
-
- /*!
- Default destructor.
- */
- virtual ~MPanGesture();
-
-private:
-
- QPointF startPos;
- Qt::Orientations panDirection;
-
- friend class MPanRecognizer;
-};
-
-#endif
diff --git a/src/corelib/events/mpanrecognizer.cpp b/src/corelib/events/mpanrecognizer.cpp
deleted file mode 100644
index 3ad00332..00000000
--- a/src/corelib/events/mpanrecognizer.cpp
+++ /dev/null
@@ -1,150 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (directui@nokia.com)
-**
-** This file is part of libdui.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at directui@nokia.com.
-**
-** This library is free software; you can redistribute it and/or
-** modify it under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation
-** and appearing in the file LICENSE.LGPL included in the packaging
-** of this file.
-**
-****************************************************************************/
-
-#include "mpanrecognizer.h"
-#include "mpanrecognizer_p.h"
-
-#include "mpangesture_p.h"
-
-#include <QGraphicsSceneMouseEvent>
-
-//Hardcoded movement threshold used to recognize the panning gesture.
-static const int defaultPanThreshold = 10;
-
-MPanRecognizerPrivate::MPanRecognizerPrivate()
-{
-}
-
-MPanRecognizerPrivate::~MPanRecognizerPrivate()
-{
-}
-
-MPanRecognizer::MPanRecognizer() :
- d_ptr(new MPanRecognizerPrivate())
-{
- Q_D(MPanRecognizer);
- d->movementThreshold = defaultPanThreshold;
-}
-
-MPanRecognizer::~MPanRecognizer()
-{
- delete d_ptr;
-}
-
-QGesture* MPanRecognizer::create(QObject* target)
-{
- Q_UNUSED(target);
- return new MPanGesture;
-}
-
-QGestureRecognizer::Result MPanRecognizer::recognize( QGesture* gesture,
- QObject* watched,
- QEvent* event)
-{
- Q_UNUSED(watched);
- Q_D(MPanRecognizer);
-
- MPanGesture *panGesture = static_cast<MPanGesture*>(gesture);
- const QGraphicsSceneMouseEvent *ev = static_cast<const QGraphicsSceneMouseEvent *>(event);
- QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture;
- qreal distX, distY;
-
- switch (event->type()) {
- case QEvent::GraphicsSceneMousePress:
- panGesture->startPos = ev->pos();
- panGesture->setHotSpot(ev->screenPos());
-
- if (panGesture->state() != Qt::NoGesture) {
- result = QGestureRecognizer::TriggerGesture;
- } else {
- result = QGestureRecognizer::MayBeGesture;
- }
-
- break;
-
- case QEvent::GraphicsSceneMouseRelease:
- if (panGesture->state() != Qt::NoGesture) {
- result = QGestureRecognizer::FinishGesture;
- } else {
- result = QGestureRecognizer::CancelGesture;
- }
-
- break;
-
- case QEvent::GraphicsSceneMouseMove:
- panGesture->setLastOffset(panGesture->offset());
- panGesture->setOffset(ev->pos() - panGesture->startPos);
-
- distX = abs(panGesture->offset().x());
- distY = abs(panGesture->offset().y());
-
- if (panGesture->state() == Qt::NoGesture) {
-
- if (distX > d->movementThreshold) {
- if (panGesture->panDirection.testFlag(Qt::Vertical)) {
- result = QGestureRecognizer::CancelGesture;
- } else {
- panGesture->panDirection = Qt::Horizontal;
- result = QGestureRecognizer::TriggerGesture;
- }
- } else if (distY > d->movementThreshold) {
- if (panGesture->panDirection.testFlag(Qt::Horizontal)) {
- result = QGestureRecognizer::CancelGesture;
- } else {
- panGesture->panDirection = Qt::Vertical;
- result = QGestureRecognizer::TriggerGesture;
- }
- } else {
- result = QGestureRecognizer::MayBeGesture;
- }
-
- } else {
- result = QGestureRecognizer::TriggerGesture;
- }
-
- if (panGesture->panDirection.testFlag(Qt::Vertical)) {
- QPointF zeroedOffset = panGesture->offset();
- zeroedOffset.setX(0);
- panGesture->setOffset(zeroedOffset);
- } else if (panGesture->panDirection.testFlag(Qt::Horizontal)) {
- QPointF zeroedOffset = panGesture->offset();
- zeroedOffset.setY(0);
- panGesture->setOffset(zeroedOffset);
- } else {
- panGesture->setOffset(QPointF());
- }
-
- break;
- default:
- result = QGestureRecognizer::Ignore;
- break;
- }
- return result;
-}
-
-void MPanRecognizer::reset(QGesture* gesture)
-{
- MPanGesture *panGesture = static_cast<MPanGesture*>(gesture);
- panGesture->setOffset(QPointF());
- panGesture->setLastOffset(QPointF());
- panGesture->startPos = QPointF();
- panGesture->panDirection = 0;
-
- QGestureRecognizer::reset(gesture);
-}
diff --git a/src/corelib/events/mpanrecognizer.h b/src/corelib/events/mpanrecognizer.h
deleted file mode 100644
index 161054eb..00000000
--- a/src/corelib/events/mpanrecognizer.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (directui@nokia.com)
-**
-** This file is part of libdui.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at directui@nokia.com.
-**
-** This library is free software; you can redistribute it and/or
-** modify it under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation
-** and appearing in the file LICENSE.LGPL included in the packaging
-** of this file.
-**
-****************************************************************************/
-
-#ifndef MPANRECOGNIZER_H
-#define MPANRECOGNIZER_H
-
-#include <QGestureRecognizer>
-
-class QGesture;
-class MPanRecognizerPrivate;
-
-/*!
- This class provides Pan gesture recognition functionality.
- It provides event based handling of the gestures.
- */
-class MPanRecognizer : public QGestureRecognizer
-{
-public:
-
- /*!
- Default constructor.
- */
- MPanRecognizer();
-
- /*!
- Default destructor.
- */
- virtual ~MPanRecognizer();
-
- /*!
- Method used internally by Qt recognition manager to create a gesture state.
- \sa MPanGesture
- */
- QGesture* create(QObject* target);
-
- /*!
- Event filtering routine, responsible for changing state of the state machine and
- triggering recognition events.
- */
- QGestureRecognizer::Result recognize(QGesture* gesture, QObject* watched, QEvent* event);
-
- /*!
- Method for resetting the gesture recognition state machine.
- */
- void reset(QGesture* gesture);
-
-private:
- /*!
- Private object attribute.
- */
- MPanRecognizerPrivate * const d_ptr;
-
- Q_DECLARE_PRIVATE(MPanRecognizer)
- Q_DISABLE_COPY(MPanRecognizer)
-
-};
-
-#endif // MPANRECOGNIZER_H
diff --git a/src/corelib/events/mpanrecognizer_p.h b/src/corelib/events/mpanrecognizer_p.h
deleted file mode 100644
index 5e9e75db..00000000
--- a/src/corelib/events/mpanrecognizer_p.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (directui@nokia.com)
-**
-** This file is part of libdui.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at directui@nokia.com.
-**
-** This library is free software; you can redistribute it and/or
-** modify it under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation
-** and appearing in the file LICENSE.LGPL included in the packaging
-** of this file.
-**
-****************************************************************************/
-
-#ifndef MPANRECOGNIZER_P_H
-#define MPANRECOGNIZER_P_H
-
-#include "mpanrecognizer.h"
-
-/*!
- Private class used by MPanRecognizer objects to
- store variables during gesture recognition.
- */
-class MPanRecognizerPrivate
-{
-public:
-
- Q_DECLARE_PUBLIC(MPanRecognizer)
- MPanRecognizerPrivate();
- virtual ~MPanRecognizerPrivate();
-
-private:
- int movementThreshold;
-
- MPanRecognizer* q_ptr;
-};
-
-#endif
diff --git a/src/corelib/widgets/mpannablewidget.cpp b/src/corelib/widgets/mpannablewidget.cpp
index e8b6a1ae..a53db8b3 100644
--- a/src/corelib/widgets/mpannablewidget.cpp
+++ b/src/corelib/widgets/mpannablewidget.cpp
@@ -20,7 +20,6 @@
#include <QApplication>
#include <QGraphicsSceneMouseEvent>
#include <QTapAndHoldGesture>
-#include <QPanGesture>
#include "mpannablewidget.h"
#include "mpannablewidget_p.h"
@@ -38,9 +37,8 @@ namespace
const int ResentListMaxSize = 10;
//! Z-value of the glass
const int ZValueGlass = 2;
- //! Hardcoded timeout value for delivering initial press event;
- const int InitialPressDeliveryTimeoutValue = 50;
-
+ //! Hardcoded timeout value for tap&hold gesture;
+ const int TapAndHoldTimeoutValue = 500;
}
/*
@@ -110,11 +108,8 @@ public:
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- virtual void timerEvent(QTimerEvent* event);
-
-protected:
- virtual void tapAndHoldGestureEvent(QGestureEvent *event, QTapAndHoldGesture* state);
- virtual void panGestureEvent(QGestureEvent *event, QPanGesture* state);
+ virtual void ungrabMouseEvent(QEvent *event);
+ virtual void tapAndHoldGestureEvent(QGestureEvent *event, QTapAndHoldGesture* gesture);
MPannableWidget *pannableWidget;
};
@@ -128,15 +123,10 @@ void MPannableWidgetGlass::tapAndHoldGestureEvent(QGestureEvent *event, QTapAndH
event->accept(gesture);
}
-void MPannableWidgetGlass::panGestureEvent(QGestureEvent *event, QPanGesture* gesture)
-{
- pannableWidget->glassPanEvent(event, gesture);
-}
-
MPannableWidgetGlass::MPannableWidgetGlass(QGraphicsItem *parent) :
MWidget(parent)
{
- pannableWidget = dynamic_cast<MPannableWidget *>(parent);
+ this->pannableWidget = dynamic_cast<MPannableWidget *>(parent);
}
@@ -168,17 +158,18 @@ void MPannableWidgetGlass::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
pannableWidget->glassMouseReleaseEvent(event);
}
-void MPannableWidgetGlass::timerEvent(QTimerEvent *event)
+void MPannableWidgetGlass::ungrabMouseEvent(QEvent *event)
{
- pannableWidget->glassTimerEvent(event);
+ pannableWidget->glassUngrabMouseEvent(event);
}
MPannableWidgetPrivate::MPannableWidgetPrivate() :
+ state(MPannableWidgetPrivate::Wait),
+ itemCount(0),
pressEvent(QEvent::GraphicsSceneMousePress),
physics(0),
mouseGrabber(0),
- resentList(),
- pressDeliveryTimerId(0)
+ resentList()
{
}
@@ -195,48 +186,11 @@ void MPannableWidgetPrivate::translateEventToItemCoordinates(const QGraphicsItem
event->setPos(destItem->mapFromItem(srcItem, event->pos()));
}
-void MPannableWidgetPrivate::deliverPressEvent()
-{
- Q_Q(MPannableWidget);
- glass->ungrabMouse();
- q->resendEvent(&pressEvent);
- mouseGrabber = q->scene()->mouseGrabberItem();
-
- MPannableWidgetGlass *otherGlass = dynamic_cast<MPannableWidgetGlass*>(mouseGrabber);
- if (otherGlass) {
- mouseGrabber = 0;
- } else {
- glass->grabMouse();
- }
-}
-
-void MPannableWidgetPrivate::initialPressStartTimer()
-{
- pressDeliveryTimerId = glass->startTimer(InitialPressDeliveryTimeoutValue);
-}
-
-void MPannableWidgetPrivate::initialPressStopTimer()
-{
- if (pressDeliveryTimerId) {
- glass->killTimer(pressDeliveryTimerId);
- pressDeliveryTimerId = 0;
- }
-}
-
-void MPannableWidgetPrivate::resetPhysics()
+void MPannableWidgetPrivate::resetState()
{
physics->pointerRelease();
physics->stop();
-}
-
-void MPannableWidgetPrivate::resetMouseGrabber()
-{
- Q_Q(MPannableWidget);
-
- mouseGrabber = 0;
- if (glass == q->scene()->mouseGrabberItem()) {
- glass->ungrabMouse();
- }
+ state = MPannableWidgetPrivate::Wait;
}
void MPannableWidgetPrivate::deliverMouseEvent(QGraphicsSceneMouseEvent *event)
@@ -279,7 +233,6 @@ void MPannableWidget::init()
d->glass->setObjectName("glass");
d->glass->grabGesture(Qt::TapAndHoldGesture);
- d->glass->grabGesture(Qt::PanGesture);
setPosition(QPointF());
setRange(QRectF());
@@ -324,7 +277,11 @@ void MPannableWidget::setEnabled(bool enabled)
model()->setEnabled(enabled);
if (!enabled) {
- d->resetPhysics();
+ d->physics->pointerRelease();
+
+ d->state = MPannableWidgetPrivate::Wait;
+
+ d->physics->stop();
}
}
@@ -394,6 +351,13 @@ void MPannableWidget::glassMousePressEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(MPannableWidget);
+ if (!isEnabled()) {
+ // Glass: Ignoring, panning disabled
+
+ event->ignore();
+ return;
+ }
+
if (event->button() != Qt::LeftButton) {
// Glass: Ignoring, not a left button
@@ -401,6 +365,13 @@ void MPannableWidget::glassMousePressEvent(QGraphicsSceneMouseEvent *event)
return;
}
+ if (!(panDirection().testFlag(Qt::Horizontal) || panDirection().testFlag(Qt::Vertical))) {
+ // Glass: Ignoring, no enabled panning directions
+
+ event->ignore();
+ return;
+ }
+
if (checkForResent(event)) {
// Glass: Ignoring, already seen
@@ -408,14 +379,31 @@ void MPannableWidget::glassMousePressEvent(QGraphicsSceneMouseEvent *event)
return;
}
- copyGraphicsSceneMouseEvent(d->pressEvent, *event);
- if (!d->physics->inMotion()) {
- // sending it now, we will send "cancel" if it will be needed.
+ switch (d->state) {
+ case MPannableWidgetPrivate::Wait:
+ // Saves the event so it can be passed forward if the
+ // press doesn't end to be a panning action
+
copyGraphicsSceneMouseEvent(d->pressEvent, *event);
- d->initialPressStartTimer();
- } else {
- d->physics->stop();
+ if (!d->physics->inMotion()) {
+ // sending it now, we will send "cancel" if it will be needed.
+
+ d->glass->ungrabMouse();
+ this->resendEvent(&d->pressEvent);
+ d->mouseGrabber = scene()->mouseGrabberItem();
+ d->itemCount = scene()->items().size();
+ d->glass->grabMouse();
+ }
+
+ d->physics->pointerPress(event->pos());
+
+ d->state = MPannableWidgetPrivate::Evaluate;
+ break;
+
+ default:
+ // Evaluate and pan states don't see press events
+ break;
}
}
@@ -423,94 +411,189 @@ void MPannableWidget::glassMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(MPannableWidget);
- if (d->pressDeliveryTimerId) {
- d->deliverPressEvent();
- d->initialPressStopTimer();
+ if (!isEnabled()) {
+ //Widget disabled in the middle of the gesture. We need to deliver
+ //the events to the underlaying widget if we have it.
+ d->deliverMouseEvent(event);
+ d->resetState();
+ //All events from this interaction has been delivered or dropped.
+ //We can now safely become really disabled.
+ d->mouseGrabber = 0;
+ d->glass->ungrabMouse();
+ return;
}
- d->deliverMouseEvent(event);
- d->resetMouseGrabber();
-}
+ switch (d->state) {
+ case MPannableWidgetPrivate::Evaluate: {
+ d->glass->ungrabMouse();
+ //ungrab event handler will ensure that physics is stopped
+ //and pointer is released.
-void MPannableWidget::glassMouseMoveEvent(QGraphicsSceneMouseEvent *event)
-{
- Q_D(MPannableWidget);
- d->deliverMouseEvent(event);
-}
+ QPointF velocity = d->physics->velocity();
-void MPannableWidget::glassLongTapEvent()
-{
- Q_D(MPannableWidget);
-
- QGraphicsSceneContextMenuEvent contextEvent(QEvent::GraphicsSceneContextMenu);
- contextEvent.setPos(d->pressEvent.pos());
- contextEvent.setScenePos(d->pressEvent.scenePos());
- contextEvent.setScreenPos(d->pressEvent.screenPos());
-
- QApplication::sendEvent(scene(), &contextEvent);
+ if (!d->physics->inMotion()) {
+ // If the scene's item count has changed between mouse press and release,
+ // there is a possibility that the mousegrabber pointer points to deleted
+ // object which potentially leads to a crash.
+ if (d->itemCount != scene()->items().size()) {
+ resendEvent(&d->pressEvent); // we need to setup implicit mouse grabber
+ resendEvent(event);
+ } else {
+ d->deliverMouseEvent(event);
+ }
+ } else if (qAbs(velocity.x()) < model()->panClickThreshold() &&
+ qAbs(velocity.y()) < model()->panClickThreshold()) {
+ if (d->mouseGrabber) {
+ resendEvent(&d->pressEvent); // we need to setup implicit mouse grabber
+ resendEvent(event);
+ }
+ } else {
+ sendCancel(&d->pressEvent);
+ }
- if (contextEvent.isAccepted()) {
+ d->state = MPannableWidgetPrivate::Wait;
+ break;
+ }
+ case MPannableWidgetPrivate::Pan:
+ d->physics->pointerRelease();
- sendCancel(&d->pressEvent);
- d->resetPhysics();
+ d->state = MPannableWidgetPrivate::Wait;
+ break;
- //We will still receive mouse release, but
- //we aren't interested in it.
- d->resetMouseGrabber();
+ default:
+ // Wait state sees a release event in case of a press / move
+ // to a passive direction causing a stop of physics because of
+ // physics being inmotion
+ break;
}
}
-void MPannableWidget::glassPanEvent(QGestureEvent *event, QPanGesture* panGesture)
+
+void MPannableWidget::glassMouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
Q_D(MPannableWidget);
+ QPointF delta;
+ qreal distAct, distPass;
if (!isEnabled()) {
- event->ignore(panGesture);
+ //Widget disabled in the middle of the gesture. We need to deliver
+ //the events to the underlaying widget if we have it.
+ d->deliverMouseEvent(event);
+ d->resetState();
+ //We don't ungrab at this point because we want to deliver
+ //rest of the events from this interaction to the underlaying widget.
return;
}
- switch (panGesture->state())
- {
- case Qt::GestureStarted:
- if ((panGesture->offset().x() != 0 && panDirection().testFlag(Qt::Vertical)) ||
- (panGesture->offset().y() != 0 && panDirection().testFlag(Qt::Horizontal)))
- {
- // Panning against the pannable direction, we aren't interested in it.
- event->ignore(panGesture);
- return;
- }
+ switch (d->state) {
+ case MPannableWidgetPrivate::Evaluate:
+
+ // Check if the movement is big enough to justify panning
+
+ delta = event->pos() - d->pressEvent.pos();
+
+ if (panDirection().testFlag(Qt::Horizontal) && !panDirection().testFlag(Qt::Vertical)) {
+ distAct = abs((int)delta.x());
+ distPass = abs((int)delta.y());
+
+ } else if (!panDirection().testFlag(Qt::Horizontal) && panDirection().testFlag(Qt::Vertical)) {
+ distAct = abs((int)delta.y());
+ distPass = abs((int)delta.x());
- if (d->pressDeliveryTimerId) {
- // The initial MousePress event hasn't been delivered yet.
- d->initialPressStopTimer();
} else {
+ // 0.7*(x + y) approximates sqrt(x^2 + y^2)
+
+ distAct = 0.7 * (abs((int)delta.x()) + abs((int)delta.y()));
+ distPass = 0;
+ }
+
+ if (distAct > panThreshold()) {
+
+ // This is panning, cancel the press event.
sendCancel(&d->pressEvent);
- d->mouseGrabber = 0;
+ d->physics->pointerMove(event->pos());
+
+ d->state = MPannableWidgetPrivate::Pan;
+ } else if (distPass > panThreshold()) {
+ d->physics->pointerRelease();
+
+ if (!d->physics->inMotion()) {
+
+ d->glass->ungrabMouse();
+
+ resendEvent(&d->pressEvent); // we need to setup implicit mouse grabber
+ resendEvent(event);
+ } else {
+ d->physics->stop();
+ }
+
+ d->state = MPannableWidgetPrivate::Wait;
}
- d->physics->pointerPress(d->pressEvent.pos() + panGesture->offset());
- break;
- case Qt::GestureUpdated:
- d->physics->pointerMove(d->pressEvent.pos() + panGesture->offset());
break;
- case Qt::GestureFinished:
- case Qt::GestureCanceled:
- d->physics->pointerRelease();
+
+ case MPannableWidgetPrivate::Pan:
+
+ d->physics->pointerMove(event->pos());
+
+ d->state = MPannableWidgetPrivate::Pan;
break;
+
default:
+ // Wait state sees a move event in case of a press / move to a
+ // passive direction causing a stop of physics because of
+ // physics being inmotion
break;
}
+}
+
+void MPannableWidget::glassUngrabMouseEvent(QEvent *event)
+{
+ Q_UNUSED(event);
+ Q_D(MPannableWidget);
- event->accept(panGesture);
+ //We will reset the state so that pannable widget
+ //will be ready to receive next mousePress.
+ switch (d->state) {
+ case MPannableWidgetPrivate::Evaluate:
+ case MPannableWidgetPrivate::Pan:
+ d->resetState();
+ break;
+ default:
+ break;
+ }
}
-void MPannableWidget::glassTimerEvent(QTimerEvent *event)
+void MPannableWidget::glassLongTapEvent()
{
Q_D(MPannableWidget);
- if (event->timerId() == d->pressDeliveryTimerId) {
- d->deliverPressEvent();
- d->initialPressStopTimer();
+
+ //We will reset the state so that pannable widget
+ //will be ready to receive next mousePress.
+ switch (d->state) {
+ case MPannableWidgetPrivate::Evaluate: {
+ QGraphicsSceneContextMenuEvent contextEvent(QEvent::GraphicsSceneContextMenu);
+ contextEvent.setPos(d->pressEvent.pos());
+ contextEvent.setScenePos(d->pressEvent.scenePos());
+ contextEvent.setScreenPos(d->pressEvent.screenPos());
+
+ QApplication::sendEvent(scene(), &contextEvent);
+
+ if (contextEvent.isAccepted()) {
+
+ sendCancel(&d->pressEvent);
+ d->resetState();
+
+ //We will still receive mouse release, but
+ //we aren't interested in it.
+ d->mouseGrabber = 0;
+ d->glass->ungrabMouse();
+ }
+ break;
+ }
+ default:
+ break;
}
}
@@ -541,7 +624,7 @@ void MPannableWidget::resendEvent(QGraphicsSceneMouseEvent *event)
break;
}
- if ((scene() == NULL) || (scene()->views().size() == 0)) {
+ if ((this->scene() == NULL) || (this->scene()->views().size() == 0)) {
// If this widget has been removed from the scene and/or there
// is no view, return
@@ -549,12 +632,21 @@ void MPannableWidget::resendEvent(QGraphicsSceneMouseEvent *event)
}
QMouseEvent mouse_event(type,
- scene()->views().at(0)->mapFromScene(event->scenePos()),
+ this->scene()->views()[0]->mapFromScene(event->scenePos()),
event->screenPos(),
event->button(),
event->buttons(),
event->modifiers());
+ /*
+ mDebug("MPannableWidget") << "Event: " << type
+ << " " << this->scene()->views()[0]->mapFromScene(event->scenePos())
+ << " " << event->screenPos()
+ << " " << event->button()
+ << " " << event->buttons()
+ << " " << event->modifiers();
+ */
+
if (type == QEvent::MouseButtonPress) {
// Puts the event to exclude list
@@ -572,7 +664,7 @@ void MPannableWidget::resendEvent(QGraphicsSceneMouseEvent *event)
d->resentList.append(resentItem);
}
- QApplication::sendEvent(scene()->views().at(0)->viewport(), &mouse_event);
+ QApplication::sendEvent(this->scene()->views()[0]->viewport(), &mouse_event);
}
// onDisplayChangeEvent in MWidget handles MPannableWidgets in a
@@ -617,7 +709,7 @@ void MPannableWidget::sendCancel(QGraphicsSceneMouseEvent *event)
Q_D(MPannableWidget);
Q_UNUSED(event);
- if ((scene() == NULL) || (scene()->views().size() == 0)) {
+ if ((this->scene() == NULL) || (this->scene()->views().size() == 0)) {
// If this widget has been removed from the scene and/or there
// is no view, return
@@ -644,3 +736,13 @@ Qt::Orientations MPannableWidget::panDirection()
{
return model()->panDirection();
}
+
+void MPannableWidget::setPanThreshold(qreal value)
+{
+ model()->setPanThreshold(value);
+}
+
+qreal MPannableWidget::panThreshold()
+{
+ return model()->panThreshold();
+}
diff --git a/src/corelib/widgets/mpannablewidget.h b/src/corelib/widgets/mpannablewidget.h
index 941e5ae9..98ca3a41 100644
--- a/src/corelib/widgets/mpannablewidget.h
+++ b/src/corelib/widgets/mpannablewidget.h
@@ -26,7 +26,6 @@
class QTimerEvent;
class QGraphicsSceneMouseEvent;
-class QPanGesture;
class MPannableWidgetPrivate;
class MOnDisplayChangeEvent;
@@ -55,6 +54,8 @@ class M_EXPORT MPannableWidget : public MWidgetController
Q_PROPERTY(QRectF range READ range WRITE setRange)
//! \brief Panning position
Q_PROPERTY(QPointF position READ position WRITE setPosition NOTIFY positionChanged USER true)
+ //! \brief Panning threshold
+ Q_PROPERTY(qreal panThreshold READ panThreshold WRITE setPanThreshold)
public:
/*!
@@ -141,6 +142,17 @@ public:
*/
Qt::Orientations panDirection();
+ /*!
+ * \brief Sets the panning threshold. This method should be used
+ * only by the view. For setting this value, use css.
+ */
+ void setPanThreshold(qreal value);
+
+ /*!
+ * \brief Returns the current panning threshold.
+ */
+ qreal panThreshold();
+
public Q_SLOTS:
/*!
* \brief Virtual slot for receiving position changes from
@@ -201,19 +213,15 @@ private:
void glassMouseMoveEvent(QGraphicsSceneMouseEvent *event);
/*!
- * \brief Method for delivering tap&hold gesture.
+ * \brief Method for handling situation when some underlying
+ * widget grabs mouse.
*/
- void glassLongTapEvent();
-
- /*!
- * \brief Method for delivering pan gesture.
- */
- void glassPanEvent(QGestureEvent* event, QPanGesture* panGesture);
+ void glassUngrabMouseEvent(QEvent *event);
/*!
- * \brief Method for delivering timer events.
+ * \brief Method for delivering tap&hold gesture.
*/
- void glassTimerEvent(QTimerEvent* event);
+ void glassLongTapEvent();
/*!
* \brief Method for checking if the event is on the resent list
diff --git a/src/corelib/widgets/mpannablewidget_p.h b/src/corelib/widgets/mpannablewidget_p.h
index d99d2029..a7007e78 100644
--- a/src/corelib/widgets/mpannablewidget_p.h
+++ b/src/corelib/widgets/mpannablewidget_p.h
@@ -28,9 +28,11 @@
class QPoint;
class QEvent;
+class QTransform;
class QGraphicsItem;
class QGraphicsSceneMouseEvent;
class MPhysics2DPanning;
+class MStyle;
class MPannableWidgetGlass;
class MPannableWidgetPrivate : public MWidgetControllerPrivate
@@ -40,6 +42,10 @@ public:
explicit MPannableWidgetPrivate();
virtual ~MPannableWidgetPrivate();
+ enum states {Wait, Evaluate, Pan};
+ int state;
+ int itemCount;
+
QGraphicsSceneMouseEvent pressEvent;
MPhysics2DPanning *physics;
@@ -53,8 +59,6 @@ public:
};
QList<struct resentItem> resentList;
-
- int pressDeliveryTimerId;
public:
/*!
@@ -65,36 +69,14 @@ public:
QGraphicsSceneMouseEvent *event);
/*!
- * \brief Method used for resetting state of the physics engine.
+ * \brief Method used for resetting state of the pannable widget.
*/
- void resetPhysics();
-
- /*!
- * \brief Method used for resetting glass and mouse grabber.
- */
- void resetMouseGrabber();
+ void resetState();
/*!
* \brief Method used for delivering event to interested widget.
*/
void deliverMouseEvent(QGraphicsSceneMouseEvent *event);
-
- /*!
- * \brief Method used for delivering initial mouse press. It will set
- * the mouseGrabber if it is necessary at this point.
- */
- void deliverPressEvent();
-
- /*!
- * \brief Method used to start a timer which will trigger the delivery
- * of initial mouse press event.
- */
- void initialPressStartTimer();
-
- /*!
- * \brief Method used for cancelling the mouse press delivery timer.
- */
- void initialPressStopTimer();
};
#endif
diff --git a/src/corelib/widgets/mwindow.cpp b/src/corelib/widgets/mwindow.cpp
index efa961e4..05dcabf4 100644
--- a/src/corelib/widgets/mwindow.cpp
+++ b/src/corelib/widgets/mwindow.cpp
@@ -135,7 +135,6 @@ void MWindowPrivate::init()
q->viewport()->grabGesture(Qt::PinchGesture);
q->setAttribute(Qt::WA_AcceptTouchEvents);
- q->viewport()->grabGesture(Qt::PanGesture);
}
#ifdef Q_WS_X11
diff --git a/tests/stubs/mwidget_stub.h b/tests/stubs/mwidget_stub.h
index 369ac9ee..2d8842c8 100644
--- a/tests/stubs/mwidget_stub.h
+++ b/tests/stubs/mwidget_stub.h
@@ -182,7 +182,7 @@ void MWidgetStub::tapAndHoldGestureEvent(QGestureEvent *event, QTapAndHoldGestur
QList<ParameterBase*> params;
params.append( new Parameter<QGestureEvent * >(event));
params.append( new Parameter<QTapAndHoldGesture * >(gesture));
- stubMethodEntered("tapAndHoldGestureEvent",params);
+ stubMethodEntered("tapAndHoldGesture",params);
}
void MWidgetStub::panGestureEvent(QGestureEvent *event, QPanGesture *gesture)
@@ -190,7 +190,7 @@ void MWidgetStub::panGestureEvent(QGestureEvent *event, QPanGesture *gesture)
QList<ParameterBase*> params;
params.append( new Parameter<QGestureEvent * >(event));
params.append( new Parameter<QPanGesture * >(gesture));
- stubMethodEntered("panGestureEvent",params);
+ stubMethodEntered("panGesture",params);
}
void MWidgetStub::pinchGestureEvent(QGestureEvent *event, QPinchGesture *gesture)
@@ -198,7 +198,7 @@ void MWidgetStub::pinchGestureEvent(QGestureEvent *event, QPinchGesture *gesture
QList<ParameterBase*> params;
params.append( new Parameter<QGestureEvent * >(event));
params.append( new Parameter<QPinchGesture * >(gesture));
- stubMethodEntered("pinchGestureEvent",params);
+ stubMethodEntered("pinchGesture",params);
}
void MWidgetStub::tapGestureEvent(QGestureEvent *event, QTapGesture *gesture)
@@ -206,7 +206,7 @@ void MWidgetStub::tapGestureEvent(QGestureEvent *event, QTapGesture *gesture)
QList<ParameterBase*> params;
params.append( new Parameter<QGestureEvent * >(event));
params.append( new Parameter<QTapGesture * >(gesture));
- stubMethodEntered("tapGestureEvent",params);
+ stubMethodEntered("tapGesture",params);
}
void MWidgetStub::swipeGestureEvent(QGestureEvent *event, QSwipeGesture *gesture)
@@ -214,7 +214,7 @@ void MWidgetStub::swipeGestureEvent(QGestureEvent *event, QSwipeGesture *gesture
QList<ParameterBase*> params;
params.append( new Parameter<QGestureEvent * >(event));
params.append( new Parameter<QSwipeGesture * >(gesture));
- stubMethodEntered("swipeGestureEvent",params);
+ stubMethodEntered("swipeGesture",params);
}
// 3. CREATE A STUB INSTANCE
diff --git a/tests/tests.pro b/tests/tests.pro
index e8af55f8..b697c3d0 100644
--- a/tests/tests.pro
+++ b/tests/tests.pro
@@ -151,7 +151,6 @@ SUBDIRS = \
ut_mvideowidget \
ut_mservicefwgen \
# ut_mstatusbar \ // Unstable. "Randomly" crashes on clean up, when detroying its MApplication instance.
- ut_mpanrecognizer \
# enable only when we have icu available
diff --git a/tests/ut_mapplethandle/ut_mapplethandle.cpp b/tests/ut_mapplethandle/ut_mapplethandle.cpp
index 67369028..c3102257 100644
--- a/tests/ut_mapplethandle/ut_mapplethandle.cpp
+++ b/tests/ut_mapplethandle/ut_mapplethandle.cpp
@@ -18,6 +18,7 @@
****************************************************************************/
#include <QtTest/QtTest>
+#include <QtGui>
#include "ut_mapplethandle.h"
#include <mextensionhandle.h>
diff --git a/tests/ut_mextensionhandle/ut_mextensionhandle.cpp b/tests/ut_mextensionhandle/ut_mextensionhandle.cpp
index 3001191a..1d7f36bb 100644
--- a/tests/ut_mextensionhandle/ut_mextensionhandle.cpp
+++ b/tests/ut_mextensionhandle/ut_mextensionhandle.cpp
@@ -18,6 +18,7 @@
****************************************************************************/
#include <QtTest/QtTest>
+#include <QtGui>
#include <QLocalServer>
#include <QPoint>
#include <QGraphicsSceneMouseEvent>
diff --git a/tests/ut_mpannablewidget/ut_mpannablewidget.cpp b/tests/ut_mpannablewidget/ut_mpannablewidget.cpp
index dab19dea..1f683684 100644
--- a/tests/ut_mpannablewidget/ut_mpannablewidget.cpp
+++ b/tests/ut_mpannablewidget/ut_mpannablewidget.cpp
@@ -18,320 +18,478 @@
****************************************************************************/
#include "ut_mpannablewidget.h"
-#include "mpannablewidget.h"
-#include "mpannablewidget_p.h"
-#include "mcancelevent.h"
-
-#include <QGestureEvent>
-#include <QPanGesture>
-
-#include <QDebug>
-
-class DummyGraphicsItem : public MWidget
+#include "mapplication.h"
+#include <mtheme.h>
+#include <mpannablewidget.h>
+#include "../../src/corelib/widgets/mpannablewidget_p.h"
+#include "../../src/corelib/widgets/mphysics2dpanning_p.h"
+#include <mapplication.h>
+
+#include <QMetaType>
+#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsView>
+
+/** Events that the test widget emits */
+typedef enum {
+// START_TIMER,
+// STOP_TIMER,
+ PHYS_STOP,
+ PHYS_MOUSE_PRESS,
+ PHYS_MOUSE_MOVE,
+ PHYS_MOUSE_RELEASE,
+ MOUSE_BUTTON_PRESS,
+ MOUSE_BUTTON_RELEASE,
+ MOUSE_MOVE,
+ UNGRAB_MOUSE
+} StateTransitionEvent;
+
+/** Class indicating state of the pannable widget after a state transition. */
+class StateTransitionResult
{
public:
- DummyGraphicsItem() {
- mousePressReceived = false;
- mouseMoveReceived = false;
- mouseReleaseReceived = false;
- cancelReceived = false;
+ StateTransitionResult(int targetState = 0) :
+ _targetState(targetState), _outputEvents(QList<StateTransitionEvent>()) {}
+ StateTransitionResult(int targetState, QList<StateTransitionEvent> expectedEvents) :
+ _targetState(targetState), _outputEvents(expectedEvents) {}
+
+ /** Compares this result with another result using QTestLib compare. */
+ void compare(const StateTransitionResult &result) const;
+
+ /** State where the pannable widget should be. */
+ int _targetState;
+ /** List of output events from test widget. */
+ QList<StateTransitionEvent> _outputEvents;
+};
+
+void StateTransitionResult::compare(const StateTransitionResult &result) const
+{
+ // Iterate through the output events and see that they match
+ QCOMPARE(_outputEvents.size(), result._outputEvents.size());
+ QListIterator<StateTransitionEvent> outputEvent(_outputEvents);
+ QListIterator<StateTransitionEvent> resultEvent(result._outputEvents);
+ while (outputEvent.hasNext()) {
+ QCOMPARE(outputEvent.next(), resultEvent.next());
}
+}
- bool mousePressReceived;
- bool mouseMoveReceived;
- bool mouseReleaseReceived;
- bool cancelReceived;
-};
-DummyGraphicsItem *dummyItem = 0;
+// Required to insert StateTransitionResult instances to the test data.
+Q_DECLARE_METATYPE(StateTransitionResult);
-struct PhysicsState {
+static Ut_MPannableWidget *gTester = 0;
- PhysicsState() {
- pointerPressed = false;
- pointerMoved = false;
- pointerReleased = false;
- }
+/* Using the QT timer methods rather than the stubbed ones.
+ *
+// Mock methods of the services required by pannable widget.
+void QTimer::start()
+{
+ qDebug("QTimer::start() - called.");
+ gTester->_currentResult->_outputEvents.push_back(START_TIMER);
+}
- bool pointerPressed;
- bool pointerMoved;
- bool pointerReleased;
-};
-PhysicsState *physicsState = 0;
-//Stubs
+void QTimer::stop()
+{
+ qDebug("QTimer::stop() - called.");
+ gTester->_currentResult->_outputEvents.push_back(STOP_TIMER);
+}
+*/
-//Physics stubs:
void MPhysics2DPanning::start()
{
+ qDebug("Physics2DPanning::start() - called.");
}
-void MPhysics2DPanning::stop()
+void QTimeLine::start()
{
+ qDebug("QTimeLine::start() - called.");
}
-void MPhysics2DPanning::pointerPress(const QPointF& /*pos*/)
+QWidget::QWidget(QWidget* /*parent*/, Qt::WindowFlags /*f*/)
{
- physicsState->pointerPressed = true;
+ qDebug("QWidget::QWidget() - called.");
}
-void MPhysics2DPanning::pointerMove(const QPointF& /*pos*/)
+QFrame::QFrame(QWidget* /*parent*/, Qt::WindowFlags /*f*/)
{
- physicsState->pointerMoved = true;
+ qDebug("QFrame::QFrame() - called.");
}
-void MPhysics2DPanning::pointerRelease()
+QAbstractScrollArea::QAbstractScrollArea(QWidget* /*parent*/)
{
- physicsState->pointerReleased = true;
+ qDebug("QAbstractScrollArea::QAbstractScrollArea() - called.");
}
-//QGraphicsObject stubs:
-void QGraphicsObject::grabGesture(Qt::GestureType, Qt::GestureFlags)
+QGraphicsView::QGraphicsView(QWidget* /*parent*/)
{
+ qDebug("QGraphicsView::QGraphicsView() - called.");
}
-//QGraphicsItem stubs:
-void QGraphicsItem::grabMouse()
+QGraphicsScene *QGraphicsItem::scene() const
{
+ qDebug("QGraphicsItem::scene() - called.");
+ return 0;
}
-void QGraphicsItem::ungrabMouse()
+QGraphicsItem *QGraphicsScene::mouseGrabberItem() const
{
+ qDebug("QGraphicsScene::mouseGrabberItem() - called");
+ return 0;
}
-QGraphicsScene *QGraphicsItem::scene() const
+QList<QGraphicsItem *> QGraphicsScene::items() const
{
- return (QGraphicsScene*)1;
+ qDebug("QGraphicsScene::items() - called");
+ QList<QGraphicsItem *> list;
+ return list;
}
-//QGraphiscScene stubs:
- QGraphicsItem* QGraphicsScene::mouseGrabberItem() const
+QPointF QGraphicsItem::mapFromItem(const QGraphicsItem */*item*/, const QPointF &/*point*/) const
{
- return dummyItem;
+ qDebug("QGraphicsScene::mapFromItem() - called");
+ return QPointF();
}
- QList<QGraphicsItem*> QGraphicsScene::items() const
+QList<QGraphicsView *> QGraphicsScene::views() const
{
- QList<QGraphicsItem*> itemList;
- if (dummyItem) {
- itemList.append(dummyItem);
+ qDebug("QGraphicsScene::views() - called.");
+ return QList<QGraphicsView *>();
+}
+
+QPoint QGraphicsView::mapFromScene(const QPointF& /*point*/) const
+{
+ qDebug("QGraphicsView::mapFromScene() - called.");
+ return QPoint();
+}
+
+QWidget *QAbstractScrollArea::viewport() const
+{
+ qDebug("QAbstractScrollArea::viewport() - called.");
+ return 0;
+}
+
+bool QGraphicsScene::sendEvent(QGraphicsItem *item, QEvent *event)
+{
+ Q_UNUSED(item);
+ Q_UNUSED(event);
+ qDebug("QGraphicsScene::sendEvent() - called.");
+ return true;
+}
+
+void QCoreApplication::postEvent(QObject* /*receiver*/, QEvent *event)
+{
+ qDebug("QCoreApplication::postEvent() - called");
+ if (event->type() == QEvent::MouseButtonPress) {
+ gTester->_currentResult->_outputEvents.push_back(MOUSE_BUTTON_PRESS);
+ }
+ if (event->type() == QEvent::MouseButtonRelease) {
+ gTester->_currentResult->_outputEvents.push_back(MOUSE_BUTTON_RELEASE);
+ }
+ if (event->type() == QEvent::MouseMove) {
+ gTester->_currentResult->_outputEvents.push_back(MOUSE_MOVE);
}
- return itemList;
-}
-
- QList<QGraphicsView *> QGraphicsScene::views() const
- {
- QList<QGraphicsView *> viewList;
- viewList.append(0);
- return viewList;
- }
-
- bool QGraphicsScene::sendEvent(QGraphicsItem *item, QEvent *event)
- {
- if (item == dummyItem) {
-
- if (event->type() == MCancelEvent::eventNumber()) {
- dummyItem->cancelReceived = true;
- }
-
- switch (event->type()) {
- case QEvent::GraphicsSceneMousePress:
- dummyItem->mousePressReceived = true;
- break;
-
- case QEvent::GraphicsSceneMouseRelease:
- dummyItem->mouseReleaseReceived = true;
- break;
-
- case QEvent::GraphicsSceneMouseMove:
- dummyItem->mouseMoveReceived = true;
- break;
-
- default:
- break;
- }
- }
- return true;
- }
-
- QPointF QGraphicsItem::mapFromItem(const QGraphicsItem */*item*/, const QPointF &/*point*/) const
- {
- return QPointF();
- }
-
- QPoint QGraphicsView::mapFromScene(const QPointF& /*point*/) const
- {
- return QPoint();
- }
-
- QWidget *QAbstractScrollArea::viewport() const
- {
- return 0;
- }
-
- void QCoreApplication::postEvent(QObject* /*receiver*/, QEvent */*event*/)
- {
- qDebug("QCoreApplication::postEvent() - called");
- }
-
- Qt::GestureState currentPanState = Qt::NoGesture;
- Qt::GestureState QGesture::state() const
- {
- return currentPanState;
- }
-
- // End of stubs.
+}
+
+void MPhysics2DPanning::stop()
+{
+ gTester->_currentResult->_outputEvents.push_back(PHYS_STOP);
+}
+
+void MPhysics2DPanning::pointerPress(const QPointF& /*pos*/)
+{
+ gTester->_currentResult->_outputEvents.push_back(PHYS_MOUSE_PRESS);
+}
+
+void MPhysics2DPanning::pointerMove(const QPointF& /*pos*/)
+{
+ gTester->_currentResult->_outputEvents.push_back(PHYS_MOUSE_MOVE);
+}
+
+void MPhysics2DPanning::pointerRelease()
+{
+ gTester->_currentResult->_outputEvents.push_back(PHYS_MOUSE_RELEASE);
+}
+
+void MPhysics2DPanningPrivate::_q_integrator(int /*frame*/)
+{
+}
+
+MApplication *app;
+
+void QGraphicsItem::ungrabMouse()
+{
+ gTester->_currentResult->_outputEvents.push_back(UNGRAB_MOUSE);
+}
void Ut_MPannableWidget::initTestCase()
{
+ static int argc = 1;
+ static char *app_name[1] = { (char *) "./ut_pannablewidget" };
+ app = new MApplication(argc, app_name);
+ Q_UNUSED(app);
+
+ gTester = this;
+
}
void Ut_MPannableWidget::cleanupTestCase()
{
+ gTester = 0;
+ delete app;
}
+
void Ut_MPannableWidget::init()
{
- dummyItem = new DummyGraphicsItem;
- physicsState = new PhysicsState();
- widget = new MPannableWidget();
+ _widget = new MPannableWidget();
+ _currentResult = new StateTransitionResult();
}
void Ut_MPannableWidget::cleanup()
{
- delete widget;
- delete physicsState;
- delete dummyItem;
+ delete _currentResult;
+ delete _widget;
+ _widget = 0;
+ _currentResult = 0;
}
-void Ut_MPannableWidget::mousePressAndReleaseAreDeliveredToGrabber()
+void Ut_MPannableWidget::testWaitState_data()
{
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- QTimerEvent timerEvent(1);
+ QList<StateTransitionEvent> expectedEvents;
- widget->glassMousePressEvent(&pressEvent);
+ // Create a list of results that the widget should reach to
+ // when receiving events.
+ QList<StateTransitionResult> results;
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
+ // Result after no events
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Wait)));
- widget->d_func()->pressDeliveryTimerId = 1;
- widget->glassTimerEvent(&timerEvent);
+ // Result after mouse press event
+ expectedEvents.push_back(UNGRAB_MOUSE);
+ expectedEvents.push_back(PHYS_MOUSE_PRESS);
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Evaluate), expectedEvents));
+ expectedEvents.clear();
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
- QVERIFY2(widget->d_func()->resentList.at(0).type == QEvent::GraphicsSceneMousePress, "Mouse press was not sent");
+ // Result after mouse release event
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Wait), expectedEvents));
- widget->glassMouseReleaseEvent(&releaseEvent);
+ // Result after mouse move event
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Wait), expectedEvents));
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
- QCOMPARE(dummyItem->mouseReleaseReceived, true);
+ // Result after move over passive threshold event
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Wait), expectedEvents));
+
+ // Result after move over active threshold event
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Wait), expectedEvents));
+
+ createTestData(results);
+}
+
+void Ut_MPannableWidget::testWaitState()
+{
+ // Set the pannable widget into wait state
+ static_cast<MPannableWidgetPrivate *>(_widget->d_ptr)->state = MPannableWidgetPrivate::Wait;
+
+ testStateTransitions();
}
-void Ut_MPannableWidget::mouseMoveIsDelieveredToGrabberIfNoPanningIsRecognized()
+void Ut_MPannableWidget::testEvaluateState_data()
{
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove);
- QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- QTimerEvent timerEvent(1);
+ QList<StateTransitionEvent> expectedEvents;
+
+ // Create a list of results that the widget should reach to
+ // when receiving events.
+ QList<StateTransitionResult> results;
- widget->glassMousePressEvent(&pressEvent);
+ // Result after no events
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Evaluate)));
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
+ // Result after mouse press event
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Evaluate)));
- widget->d_func()->pressDeliveryTimerId = 1;
- widget->glassTimerEvent(&timerEvent);
+ // Result after mouse release event
+ expectedEvents.push_back(UNGRAB_MOUSE);
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Wait), expectedEvents));
+ expectedEvents.clear();
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
- QVERIFY2(widget->d_func()->resentList.at(0).type == QEvent::GraphicsSceneMousePress, "Mouse press was not sent");
+ // Result after mouse move event
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Evaluate)));
- widget->glassMouseMoveEvent(&moveEvent);
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
- QCOMPARE(dummyItem->mouseMoveReceived, true);
- QCOMPARE(dummyItem->mouseReleaseReceived, false);
+ // Result after move over passive threshold event
+ expectedEvents.push_back(PHYS_MOUSE_RELEASE);
+ expectedEvents.push_back(UNGRAB_MOUSE);
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Wait), expectedEvents));
+ expectedEvents.clear();
- widget->glassMouseReleaseEvent(&releaseEvent);
+ // Result after move over active threshold event
+ expectedEvents.push_back(PHYS_MOUSE_MOVE);
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Pan), expectedEvents));
+ expectedEvents.clear();
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
- QCOMPARE(dummyItem->mouseReleaseReceived, true);
+ createTestData(results);
}
-void Ut_MPannableWidget::panGestureMovesPhysicsPointer()
+void Ut_MPannableWidget::testEvaluateState()
{
- QPanGesture panGesture;
-
- QList<QGesture*> gestureList;
- gestureList.append(&panGesture);
- QGestureEvent event(gestureList);
+ // Set the pannable widget into evaluate state
+ static_cast<MPannableWidgetPrivate *>(_widget->d_ptr)->state = MPannableWidgetPrivate::Evaluate;
- currentPanState = Qt::GestureStarted;
- widget->glassPanEvent(&event, &panGesture);
- QCOMPARE(physicsState->pointerPressed, true);
- QCOMPARE(physicsState->pointerMoved, false);
- QCOMPARE(physicsState->pointerReleased, false);
+ testStateTransitions();
+}
- physicsState->pointerPressed = false;
+void Ut_MPannableWidget::testPanState_data()
+{
+ QList<StateTransitionEvent> expectedEvents;
- currentPanState = Qt::GestureUpdated;
- widget->glassPanEvent(&event, &panGesture);
- QCOMPARE(physicsState->pointerPressed, false);
- QCOMPARE(physicsState->pointerMoved, true);
- QCOMPARE(physicsState->pointerReleased, false);
+ // Create a list of results that the widget should reach to
+ // when receiving events.
+ QList<StateTransitionResult> results;
- physicsState->pointerMoved = false;
+ // Result after no events
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Pan)));
- currentPanState = Qt::GestureFinished;
- widget->glassPanEvent(&event, &panGesture);
- QCOMPARE(physicsState->pointerPressed, false);
- QCOMPARE(physicsState->pointerMoved, false);
- QCOMPARE(physicsState->pointerReleased, true);
+ // Result after mouse press event
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Pan)));
-}
+ // Result after mouse release event
+ expectedEvents.push_back(PHYS_MOUSE_RELEASE);
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Wait), expectedEvents));
+ expectedEvents.clear();
-void Ut_MPannableWidget::panGestureAgainstPanningDirectionIsIgnored()
-{
- QPanGesture panGesture;
+ // Result after mouse move event
+ expectedEvents.push_back(PHYS_MOUSE_MOVE);
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Pan), expectedEvents));
+ expectedEvents.clear();
- QList<QGesture*> gestureList;
- gestureList.append(&panGesture);
- QGestureEvent event(gestureList);
+ // Result after move over passive threshold event
+ expectedEvents.push_back(PHYS_MOUSE_MOVE);
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Pan), expectedEvents));
+ expectedEvents.clear();
- currentPanState = Qt::GestureStarted;
- panGesture.setOffset(QPointF(100,0));
+ // Result after move over active threshold event
+ expectedEvents.push_back(PHYS_MOUSE_MOVE);
+ results.push_back(StateTransitionResult(int(MPannableWidgetPrivate::Pan), expectedEvents));
+ expectedEvents.clear();
- widget->glassPanEvent(&event, &panGesture);
- QCOMPARE(physicsState->pointerPressed, false);
- QCOMPARE(physicsState->pointerMoved, false);
- QCOMPARE(physicsState->pointerReleased, false);
- QCOMPARE(event.isAccepted(&panGesture), false);
+ createTestData(results);
}
-void Ut_MPannableWidget::panGestureCancelsMouseEvents()
+void Ut_MPannableWidget::testPanState()
{
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- QTimerEvent timerEvent(1);
-
- widget->glassMousePressEvent(&pressEvent);
+ // Set the pannable widget into pan state
+ static_cast<MPannableWidgetPrivate *>(_widget->d_ptr)->state = MPannableWidgetPrivate::Pan;
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
+ testStateTransitions();
+}
- widget->d_func()->pressDeliveryTimerId = 1;
- widget->glassTimerEvent(&timerEvent);
+void Ut_MPannableWidget::createTestData(QList<StateTransitionResult> results)
+{
+ qRegisterMetaType< QList<QEvent *> >();
+ qRegisterMetaType< StateTransitionResult >();
+
+ Q_ASSERT(results.size() == 6);
+
+ QTest::addColumn< QList<QEvent *> >("events");
+ QTest::addColumn<StateTransitionResult>("result");
+
+ // Sequence of events to be passed to the test widget.
+ QList<QEvent *> sequence;
+
+ // Iterator to results that the widget should reach when
+ // input events are send to the test widget.
+ QListIterator<StateTransitionResult> resIt(results);
+
+ // No events sent to the widget
+ QTest::newRow("initial") << sequence << resIt.next();
+
+ QGraphicsSceneMouseEvent *mouseEvent;
+
+ // Send a mouse press event
+ mouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMousePress);
+ mouseEvent->setButton(Qt::LeftButton);
+ sequence.push_back(mouseEvent);
+ QTest::newRow("left mouse button pressed") << sequence << resIt.next();
+ sequence.clear();
+
+ // Send a mouse release event
+ mouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseRelease);
+ mouseEvent->setButton(Qt::LeftButton);
+ sequence.push_back(mouseEvent);
+ QTest::newRow("left mouse button released") << sequence << resIt.next();
+ sequence.clear();
+
+ // Send a mouse move event
+ mouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseMove);
+ mouseEvent->setButton(Qt::LeftButton);
+ mouseEvent->setScreenPos(QPoint(0, 1));
+ sequence.push_back(mouseEvent);
+ QTest::newRow("mouse move") << sequence << resIt.next();
+ sequence.clear();
+
+ // Send a mouse move over passive threshold
+ mouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseMove);
+ mouseEvent->setButton(Qt::LeftButton);
+ mouseEvent->setPos(QPoint(31, 0));
+ sequence.push_back(mouseEvent);
+ QTest::newRow("mouse move over passive") << sequence << resIt.next();
+ sequence.clear();
+
+ // Send a mouse move over active threshold
+ mouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseMove);
+ mouseEvent->setButton(Qt::LeftButton);
+ mouseEvent->setPos(QPoint(0, 31));
+ sequence.push_back(mouseEvent);
+ QTest::newRow("mouse move over active") << sequence << resIt.next();
+ sequence.clear();
+}
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
- QVERIFY2(widget->d_func()->resentList.at(0).type == QEvent::GraphicsSceneMousePress, "Mouse press was not sent");
- QPanGesture panGesture;
+void Ut_MPannableWidget::testStateTransitions()
+{
+ QFETCH(QList<QEvent *>, events);
+ QFETCH(StateTransitionResult, result);
+
+ // Iterate through the events in the event list
+ QListIterator<QEvent *> i(events);
+ while (i.hasNext()) {
+ QEvent *event = i.next();
+ switch (event->type()) {
+ case QEvent::GraphicsSceneMousePress:
+ _widget->glassMousePressEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
+ break;
+ case QEvent::GraphicsSceneMouseMove:
+ _widget->glassMouseMoveEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
+ break;
+ case QEvent::GraphicsSceneMouseRelease:
+ _widget->glassMouseReleaseEvent(static_cast<QGraphicsSceneMouseEvent *>(event));
+ break;
+ default:
+ break;
+ }
+ }
- QList<QGesture*> gestureList;
- gestureList.append(&panGesture);
- QGestureEvent event(gestureList);
+ QCOMPARE(static_cast<MPannableWidgetPrivate *>(_widget->d_ptr)->state, result._targetState);
- currentPanState = Qt::GestureStarted;
- widget->glassPanEvent(&event, &panGesture);
- QCOMPARE(physicsState->pointerPressed, true);
- QCOMPARE(physicsState->pointerMoved, false);
- QCOMPARE(physicsState->pointerReleased, false);
+ _currentResult->compare(result);
+}
- QCOMPARE(dummyItem->cancelReceived, true);
+void Ut_MPannableWidget::testRightMouseButton()
+{
+ QGraphicsSceneMouseEvent *mouseEvent;
+ mouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMousePress);
+ mouseEvent->setButton(Qt::RightButton);
+ mouseEvent->setScenePos(QPoint(100, 100));
+ _widget->glassMousePressEvent(mouseEvent);
+ delete mouseEvent;
+ // State should not change with right mousebutton
+ QVERIFY(static_cast<MPannableWidgetPrivate *>(_widget->d_ptr)->state == MPannableWidgetPrivate::Wait);
+
+ mouseEvent = new QGraphicsSceneMouseEvent(QEvent::GraphicsSceneMouseRelease);
+ mouseEvent->setButton(Qt::RightButton);
+ mouseEvent->setScenePos(QPoint(100, 100));
+ _widget->glassMouseReleaseEvent(mouseEvent);
+ delete mouseEvent;
+ // State should stay the same after button release
+ QVERIFY(static_cast<MPannableWidgetPrivate *>(_widget->d_ptr)->state == MPannableWidgetPrivate::Wait);
}
class CustomPhysics : public MPhysics2DPanning
@@ -344,32 +502,32 @@ public:
void Ut_MPannableWidget::usingCustomPhysics()
{
- CustomPhysics *customPhysics = new CustomPhysics(widget);
- widget->setPhysics(customPhysics);
+ CustomPhysics *customPhysics = new CustomPhysics(_widget);
+ _widget->setPhysics(customPhysics);
- QVERIFY(static_cast<MPannableWidgetPrivate *>(widget->d_ptr)->physics == customPhysics);
+ QVERIFY(static_cast<MPannableWidgetPrivate *>(_widget->d_ptr)->physics == customPhysics);
- widget->setPhysics(new MPhysics2DPanning(widget));
+ _widget->setPhysics(new MPhysics2DPanning(_widget));
}
void Ut_MPannableWidget::settingNewPhysicsShouldEmitPhysicsChangeSignal()
{
- CustomPhysics *customPhysics = new CustomPhysics(widget);
+ CustomPhysics *customPhysics = new CustomPhysics(_widget);
- QSignalSpy spyPhysicsChange(widget, SIGNAL(physicsChanged()));
+ QSignalSpy spyPhysicsChange(_widget, SIGNAL(physicsChanged()));
- widget->setPhysics(customPhysics);
+ _widget->setPhysics(customPhysics);
QCOMPARE(spyPhysicsChange.count(),1);
- widget->setPhysics(new MPhysics2DPanning(widget));
+ _widget->setPhysics(new MPhysics2DPanning(_widget));
}
void Ut_MPannableWidget::settingPhysicsToNULLShouldNotBreakTheWidget()
{
- widget->setPhysics(NULL);
- QVERIFY(static_cast<MPannableWidgetPrivate *>(widget->d_ptr)->physics != NULL);
+ _widget->setPhysics(NULL);
+ QVERIFY(static_cast<MPannableWidgetPrivate *>(_widget->d_ptr)->physics != NULL);
}
diff --git a/tests/ut_mpannablewidget/ut_mpannablewidget.h b/tests/ut_mpannablewidget/ut_mpannablewidget.h
index ad0f610f..e15e6e09 100644
--- a/tests/ut_mpannablewidget/ut_mpannablewidget.h
+++ b/tests/ut_mpannablewidget/ut_mpannablewidget.h
@@ -25,7 +25,11 @@
#include <QObject>
#include "mapplication.h"
class MPannableWidget;
-class DummyGraphicsItem;
+class QGraphicsWidget;
+class StateTransitionResult;
+
+// Required to insert QList<QEvent*> instances to the test data.
+Q_DECLARE_METATYPE(QList<QEvent *>);
class Ut_MPannableWidget : public QObject
{
@@ -33,7 +37,17 @@ class Ut_MPannableWidget : public QObject
public:
+ /** Result generated by running a test case. */
+ StateTransitionResult *_currentResult;
+
private:
+ MApplication *app;
+
+ /** Pannable widget instance under testing. */
+ MPannableWidget *_widget;
+
+// /** Event enumerator for timeout events. */
+// int _timeoutType;
private slots:
void initTestCase();
@@ -42,19 +56,32 @@ private slots:
void init();
void cleanup();
- void mousePressAndReleaseAreDeliveredToGrabber();
- void mouseMoveIsDelieveredToGrabberIfNoPanningIsRecognized();
+ void testWaitState_data();
+ void testEvaluateState_data();
+ void testPanState_data();
+ void testWaitState();
+ void testEvaluateState();
+ void testPanState();
+ void testRightMouseButton();
void usingCustomPhysics();
void settingNewPhysicsShouldEmitPhysicsChangeSignal();
void settingPhysicsToNULLShouldNotBreakTheWidget();
- void panGestureMovesPhysicsPointer();
- void panGestureAgainstPanningDirectionIsIgnored();
- void panGestureCancelsMouseEvents();
-
private:
- MPannableWidget *widget;
+
+ /**
+ * Helper method to create test data with all possible input events
+ * @param results List of results that the test widget should reach
+ * when events are triggered.
+ */
+ void createTestData(QList<StateTransitionResult> results);
+
+ /**
+ * Helper method which tests state transitions using the already set-up
+ * test data and already set-up test widget.
+ */
+ void testStateTransitions();
};
diff --git a/tests/ut_mpannablewidget/ut_mpannablewidget.pro b/tests/ut_mpannablewidget/ut_mpannablewidget.pro
index a3190bfb..d049999f 100644
--- a/tests/ut_mpannablewidget/ut_mpannablewidget.pro
+++ b/tests/ut_mpannablewidget/ut_mpannablewidget.pro
@@ -1,11 +1,23 @@
include(../common_top.pri)
-INCLUDEPATH += $$MSRCDIR/corelib/widgets
+
TARGET = ut_mpannablewidget
+support_files.files += \
+ ut_mpannablewidget_image.svg \
+ ut_mpannablewidget_template.css \
+
+# Input
HEADERS += \
ut_mpannablewidget.h \
+# $$STUBSDIR/mpannableviewport_stub.h \
+# $$STUBSDIR/mstyledescription_stub.h \
+# $$STUBSDIR/mstyle_stub.h \
+# $$STUBSDIR/mtheme_stub.h \
+
+TEST_SOURCES += \
+# $$MSRCDIR/mpannablewidget.cpp \
-SOURCES += \
- ut_mpannablewidget.cpp \
+SOURCES += ut_mpannablewidget.cpp \
+# stubbase.cpp \
include(../common_bot.pri)
diff --git a/tests/ut_mpanrecognizer/.gitignore b/tests/ut_mpanrecognizer/.gitignore
deleted file mode 100644
index 16b6704e..00000000
--- a/tests/ut_mpanrecognizer/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-ut_mpanrecognizer
diff --git a/tests/ut_mpanrecognizer/ut_mpanrecognizer.cpp b/tests/ut_mpanrecognizer/ut_mpanrecognizer.cpp
deleted file mode 100644
index 2ae67b06..00000000
--- a/tests/ut_mpanrecognizer/ut_mpanrecognizer.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (directui@nokia.com)
-**
-** This file is part of libdui.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at directui@nokia.com.
-**
-** This library is free software; you can redistribute it and/or
-** modify it under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation
-** and appearing in the file LICENSE.LGPL included in the packaging
-** of this file.
-**
-****************************************************************************/
-
-#include "ut_mpanrecognizer.h"
-#include "mpanrecognizer.h"
-#include "mpanrecognizer_p.h"
-
-#include "mpangesture_p.h"
-
-#include <QGraphicsSceneMouseEvent>
-#include <QtTest/QtTest>
-
-// QGesture stubs:
-Qt::GestureState currentGestureState = Qt::NoGesture;
-Qt::GestureState QGesture::state() const
-{
- return currentGestureState;
-}
-
-
-void Ut_MPanRecognizer::init()
-{
- currentGestureState = Qt::NoGesture;
- recognizer = new MPanRecognizer();
-}
-
-void Ut_MPanRecognizer::cleanup()
-{
- delete recognizer;
-}
-
-void Ut_MPanRecognizer::testCreateGesture()
-{
- PanGesture = static_cast<MPanGesture*>(recognizer->create(this));
-}
-
-void Ut_MPanRecognizer::testRecognize()
-{
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- pressEvent.setPos(QPointF(0,0));
- pressEvent.setScenePos(QPointF(0,0));
- pressEvent.setScreenPos(QPoint(0,0));
-
- QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove);
- moveEvent.setPos(QPointF(0,100));
- moveEvent.setScenePos(QPointF(0,100));
- moveEvent.setScreenPos(QPoint(0,100));
-
- QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- releaseEvent.setPos(QPointF(0,100));
- releaseEvent.setScenePos(QPointF(0,100));
- releaseEvent.setScreenPos(QPoint(0,100));
-
- QGestureRecognizer::Result currentState;
- currentState = recognizer->recognize(PanGesture, 0, &pressEvent);
- QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
-
- currentState = recognizer->recognize(PanGesture, 0, &moveEvent);
- QCOMPARE( currentState, QGestureRecognizer::TriggerGesture);
-
- //Artificially setting state of QGesture object.
- currentGestureState = Qt::GestureUpdated;
-
- currentState = recognizer->recognize(PanGesture, 0, &releaseEvent);
- QCOMPARE( currentState, QGestureRecognizer::FinishGesture);
-}
-
-void Ut_MPanRecognizer::testTapIsNotRecognizedAsPan()
-{
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- pressEvent.setPos(QPointF(0,0));
- pressEvent.setScenePos(QPointF(0,0));
- pressEvent.setScreenPos(QPoint(0,0));
-
- QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- pressEvent.setPos(QPointF(0,0));
- pressEvent.setScenePos(QPointF(0,0));
- pressEvent.setScreenPos(QPoint(0,0));
-
- QGestureRecognizer::Result currentState;
- currentState = recognizer->recognize(PanGesture, 0, &pressEvent);
- QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
-
- currentState = recognizer->recognize(PanGesture, 0, &releaseEvent);
- QCOMPARE( currentState, QGestureRecognizer::CancelGesture);
-}
-
-QTEST_APPLESS_MAIN(Ut_MPanRecognizer)
-
diff --git a/tests/ut_mpanrecognizer/ut_mpanrecognizer.h b/tests/ut_mpanrecognizer/ut_mpanrecognizer.h
deleted file mode 100644
index 9ebb5ecb..00000000
--- a/tests/ut_mpanrecognizer/ut_mpanrecognizer.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/***************************************************************************
-**
-** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
-** All rights reserved.
-** Contact: Nokia Corporation (directui@nokia.com)
-**
-** This file is part of libdui.
-**
-** If you have questions regarding the use of this file, please contact
-** Nokia at directui@nokia.com.
-**
-** This library is free software; you can redistribute it and/or
-** modify it under the terms of the GNU Lesser General Public
-** License version 2.1 as published by the Free Software Foundation
-** and appearing in the file LICENSE.LGPL included in the packaging
-** of this file.
-**
-****************************************************************************/
-
-#ifndef UT_MPANRECOGNIZER_H
-#define UT_MPANRECOGNIZER_H
-
-#include <QObject>
-
-class MPanRecognizer;
-class MPanGesture;
-
-class Ut_MPanRecognizer : public QObject
-{
- Q_OBJECT
-
-private:
- MPanRecognizer* recognizer;
- MPanGesture* PanGesture;
-private slots:
- void init();
- void cleanup();
-
- void testCreateGesture();
- void testRecognize();
- void testTapIsNotRecognizedAsPan();
-};
-
-#endif // UT_MPANRECOGNIZER_H
diff --git a/tests/ut_mpanrecognizer/ut_mpanrecognizer.pro b/tests/ut_mpanrecognizer/ut_mpanrecognizer.pro
deleted file mode 100644
index c083b280..00000000
--- a/tests/ut_mpanrecognizer/ut_mpanrecognizer.pro
+++ /dev/null
@@ -1,16 +0,0 @@
-include(../common_top.pri)
-INCLUDEPATH += $$MSRCDIR/corelib/events
-TARGET = ut_mpanrecognizer
-
-# unit test and unit classes
-SOURCES += \
- ut_mpanrecognizer.cpp \
- ../../src/corelib/events/mpanrecognizer.cpp \
- ../../src/corelib/events/mpangesture.cpp \
-
-# unit test and unit classes
-HEADERS += \
- ut_mpanrecognizer.h \
- ../../src/corelib/events/mpangesture_p.h \
-
-include(../common_bot.pri)