aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Guminiak <michal.guminiak@teleca.com>2010-10-19 15:52:24 +0200
committerDominik Kapusta <dominik.kapusta@teleca.com>2010-12-08 16:05:04 +0100
commit46fea17d494761ec6b40b424c2f3be88781df31a (patch)
tree23913c1121adc34548b2d99012dd05faa238f0df
parentadac4f3fb70f524c4cf3df842db1317b4d2d3ea1 (diff)
Fixes: NB#182815 - Pannable widget is not transparent wrt. passing focus to child widgets
RevBy: Jarno Malmari, Michael Hasselmann, Dominik Kapusta Details: This patch completely removes mouse event replaying functionality in the pannable widget and moves necessary pieces to mscene. This should allow better focus handling in the scene and also should remove all crashes related to mouse event being bounced between pannable widgets when two of them are placed on the scene. It also introduces one new method, an overloaded version of grabGesture, which can be used to control the cancel event handling in libmeegotouch applications. See documentation of MWidget::grabGesture for details.
-rw-r--r--src/corelib/events/mpangesture.cpp3
-rw-r--r--src/corelib/events/mpangesture_p.h1
-rw-r--r--src/corelib/events/mpanrecognizer.cpp50
-rw-r--r--src/corelib/events/mswiperecognizer.cpp20
-rw-r--r--src/corelib/events/mswiperecognizer_p.h6
-rw-r--r--src/corelib/events/mtapandholdrecognizer.cpp1
-rw-r--r--src/corelib/scene/mscene.cpp213
-rw-r--r--src/corelib/scene/mscene.h2
-rw-r--r--src/corelib/scene/mscene_p.h35
-rw-r--r--src/corelib/widgets/core/mwidget.cpp33
-rw-r--r--src/corelib/widgets/core/mwidget.h38
-rw-r--r--src/corelib/widgets/core/mwidget_p.h3
-rw-r--r--src/corelib/widgets/mcontentitem.cpp2
-rw-r--r--src/corelib/widgets/mlabel.cpp4
-rw-r--r--src/corelib/widgets/mlistitem.cpp2
-rw-r--r--src/corelib/widgets/mpannablewidget.cpp435
-rw-r--r--src/corelib/widgets/mpannablewidget.h40
-rw-r--r--src/corelib/widgets/mpannablewidget_p.h74
-rw-r--r--src/corelib/widgets/mscenewindow.cpp13
-rw-r--r--tests/ut_mappletinventory/ut_mappletinventory.pro5
-rw-r--r--tests/ut_mappletinventoryview/ut_mappletinventoryview.pro5
-rw-r--r--tests/ut_mextensionarea/ut_mextensionarea.pro9
-rw-r--r--tests/ut_mmashupcanvas/ut_mmashupcanvas.pro9
-rw-r--r--tests/ut_mpannableviewport/ut_mpannableviewport.pro6
-rw-r--r--tests/ut_mpannablewidget/ut_mpannablewidget.cpp382
-rw-r--r--tests/ut_mpannablewidget/ut_mpannablewidget.h12
-rw-r--r--tests/ut_mpanrecognizer/ut_mpanrecognizer.cpp63
-rw-r--r--tests/ut_mscene/ut_mscene.cpp396
-rw-r--r--tests/ut_mscene/ut_mscene.h14
-rw-r--r--tests/ut_mscene/ut_mscene.pro19
-rw-r--r--tests/ut_mswiperecognizer/ut_mswiperecognizer.cpp92
-rw-r--r--tests/ut_mtoolbar/ut_mtoolbar.pro9
32 files changed, 842 insertions, 1154 deletions
diff --git a/src/corelib/events/mpangesture.cpp b/src/corelib/events/mpangesture.cpp
index 8f6560c0..98bfaf56 100644
--- a/src/corelib/events/mpangesture.cpp
+++ b/src/corelib/events/mpangesture.cpp
@@ -22,7 +22,8 @@
MPanGesture::MPanGesture(QObject *parent) :
QPanGesture(parent),
startPos(QPointF()),
- panDirection(0)
+ panDirection(0),
+ pressed(false)
{
}
diff --git a/src/corelib/events/mpangesture_p.h b/src/corelib/events/mpangesture_p.h
index 2bb34c55..1504ea49 100644
--- a/src/corelib/events/mpangesture_p.h
+++ b/src/corelib/events/mpangesture_p.h
@@ -51,6 +51,7 @@ private:
*/
QPointF startPos;
Qt::Orientations panDirection;
+ bool pressed;
friend class MPanRecognizer;
};
diff --git a/src/corelib/events/mpanrecognizer.cpp b/src/corelib/events/mpanrecognizer.cpp
index 3376f077..b577083a 100644
--- a/src/corelib/events/mpanrecognizer.cpp
+++ b/src/corelib/events/mpanrecognizer.cpp
@@ -58,7 +58,11 @@ MPanRecognizer::~MPanRecognizer()
QGesture* MPanRecognizer::create(QObject* target)
{
- Q_UNUSED(target);
+ if (target && target->isWidgetType() == false) {
+ return 0; // this assumes the target is a QGraphicsObject, so we return
+ // NULL to indicate that the recognizer doesn't support graphicsobject and
+ // graphicsscene events.
+ }
return new MPanGesture;
}
@@ -70,7 +74,7 @@ QGestureRecognizer::Result MPanRecognizer::recognize( QGesture* gesture,
Q_D(MPanRecognizer);
MPanGesture *panGesture = static_cast<MPanGesture*>(gesture);
- const QGraphicsSceneMouseEvent *ev = static_cast<const QGraphicsSceneMouseEvent *>(event);
+ const QMouseEvent *ev = static_cast<const QMouseEvent *>(event);
const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event);
QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture;
qreal distX, distY;
@@ -87,47 +91,49 @@ QGestureRecognizer::Result MPanRecognizer::recognize( QGesture* gesture,
}
break;
- case QEvent::GraphicsSceneMousePress:
-
- panGesture->startPos = ev->scenePos();
- panGesture->setHotSpot(ev->screenPos());
+ case QEvent::MouseButtonPress:
+ panGesture->startPos = ev->pos();
+ panGesture->setHotSpot(ev->globalPos());
+ panGesture->pressed = true;
if (panGesture->state() != Qt::NoGesture) {
result = QGestureRecognizer::TriggerGesture;
} else {
result = QGestureRecognizer::MayBeGesture;
}
-
break;
- case QEvent::GraphicsSceneMouseRelease:
+ case QEvent::MouseButtonRelease:
+ panGesture->pressed = false;
if (panGesture->state() != Qt::NoGesture) {
result = QGestureRecognizer::FinishGesture;
} else {
result = QGestureRecognizer::CancelGesture;
}
-
break;
- case QEvent::GraphicsSceneMouseMove:
+ case QEvent::MouseMove:
+
+ if (panGesture->pressed == false) {
+ //Stray mouse move received;
+ result = QGestureRecognizer::Ignore;
+ break;
+ }
panGesture->setLastOffset(panGesture->offset());
- panGesture->setOffset(ev->scenePos() - panGesture->startPos);
+ panGesture->setOffset(ev->pos() - panGesture->startPos);
distX = abs(panGesture->offset().x());
distY = abs(panGesture->offset().y());
- if (panGesture->state() == Qt::NoGesture) {
-
- if (distX > d->style->distanceThreshold() || distY > d->style->distanceThreshold()) {
- panGesture->panDirection = (distX > distY ? Qt::Horizontal : Qt::Vertical);
- result = QGestureRecognizer::TriggerGesture;
- } else {
- result = QGestureRecognizer::MayBeGesture;
- }
-
- } else {
+ if (panGesture->state() != Qt::NoGesture) {
+ result = QGestureRecognizer::TriggerGesture;
+ } else if (distX > d->style->distanceThreshold() ||
+ distY > d->style->distanceThreshold()) {
+ panGesture->panDirection = (distX > distY ? Qt::Horizontal : Qt::Vertical);
result = QGestureRecognizer::TriggerGesture;
+ } else {
+ result = QGestureRecognizer::MayBeGesture;
}
if (panGesture->panDirection.testFlag(Qt::Vertical)) {
@@ -143,6 +149,7 @@ QGestureRecognizer::Result MPanRecognizer::recognize( QGesture* gesture,
}
break;
+
default:
result = QGestureRecognizer::Ignore;
break;
@@ -157,6 +164,7 @@ void MPanRecognizer::reset(QGesture* gesture)
panGesture->setLastOffset(QPointF());
panGesture->startPos = QPointF();
panGesture->panDirection = 0;
+ panGesture->pressed = false;
QGestureRecognizer::reset(gesture);
}
diff --git a/src/corelib/events/mswiperecognizer.cpp b/src/corelib/events/mswiperecognizer.cpp
index 5c2469d7..ab69cd10 100644
--- a/src/corelib/events/mswiperecognizer.cpp
+++ b/src/corelib/events/mswiperecognizer.cpp
@@ -67,22 +67,22 @@ void MSwipeRecognizerPrivate::snapToRightAngle(MSwipeGesture *swipeGesture)
swipeGesture->setSwipeAngle(270);
}
-QGestureRecognizer::Result MSwipeRecognizerPrivate::startRecognition(MSwipeGesture *swipeGesture, const QGraphicsSceneMouseEvent *mouseEvent)
+QGestureRecognizer::Result MSwipeRecognizerPrivate::startRecognition(MSwipeGesture *swipeGesture, const QMouseEvent *mouseEvent)
{
swipeGesture->time = QTime::currentTime();
- swipeGesture->startPosition = mouseEvent->scenePos();
- swipeGesture->setHotSpot(mouseEvent->screenPos());
+ swipeGesture->startPosition = mouseEvent->globalPos();
+ swipeGesture->setHotSpot(mouseEvent->globalPos());
return QGestureRecognizer::MayBeGesture;
}
-QGestureRecognizer::Result MSwipeRecognizerPrivate::updateRecognition(MSwipeGesture *swipeGesture, const QGraphicsSceneMouseEvent *mouseEvent)
+QGestureRecognizer::Result MSwipeRecognizerPrivate::updateRecognition(MSwipeGesture *swipeGesture, const QMouseEvent *mouseEvent)
{
QGestureRecognizer::Result result = QGestureRecognizer::CancelGesture;
- qreal currentDistance = vectorLength(mouseEvent->scenePos() - swipeGesture->startPosition);
+ qreal currentDistance = vectorLength(mouseEvent->globalPos() - swipeGesture->startPosition);
//Swipe angle is equal to the angle of a line between starting position and current position.
- swipeGesture->setSwipeAngle(QLineF(swipeGesture->startPosition, mouseEvent->scenePos()).angle());
+ swipeGesture->setSwipeAngle(QLineF(swipeGesture->startPosition, mouseEvent->globalPos()).angle());
int elapsedTime = swipeGesture->time.msecsTo(QTime::currentTime());
if (swipeGesture->state() != Qt::NoGesture) {
@@ -146,7 +146,7 @@ QGestureRecognizer::Result MSwipeRecognizer::recognize(QGesture *state, QObject
{
Q_D(MSwipeRecognizer);
- const QGraphicsSceneMouseEvent *mouseEvent = static_cast<const QGraphicsSceneMouseEvent*>(event);
+ const QMouseEvent *mouseEvent = static_cast<const QMouseEvent*>(event);
const QTouchEvent *touchEvent = static_cast<const QTouchEvent *>(event);
QGestureRecognizer::Result result;
@@ -162,15 +162,15 @@ QGestureRecognizer::Result MSwipeRecognizer::recognize(QGesture *state, QObject
result = swipeGesture->state() != Qt::NoGesture && touchEvent->touchPoints().count() > 1 ? CancelGesture : Ignore;
break;
- case QEvent::GraphicsSceneMousePress:
+ case QEvent::MouseButtonPress:
result = d->startRecognition(swipeGesture, mouseEvent);
break;
- case QEvent::GraphicsSceneMouseMove:
+ case QEvent::MouseMove:
result = d->updateRecognition(swipeGesture, mouseEvent);
break;
- case QEvent::GraphicsSceneMouseRelease:
+ case QEvent::MouseButtonRelease:
result = d->finishRecognition(swipeGesture);
break;
diff --git a/src/corelib/events/mswiperecognizer_p.h b/src/corelib/events/mswiperecognizer_p.h
index cfe0f1aa..23251823 100644
--- a/src/corelib/events/mswiperecognizer_p.h
+++ b/src/corelib/events/mswiperecognizer_p.h
@@ -26,7 +26,7 @@
class MSwipeGesture;
class QPointF;
-class QGraphicsSceneMouseEvent;
+class QMouseEvent;
/*!
Private class used by MSwipeRecognizer objects to
@@ -48,8 +48,8 @@ protected:
bool isAngleDeltaBelowThreshold(qreal angle, qreal threshold);
void snapToRightAngle(MSwipeGesture *swipeGesture);
- QGestureRecognizer::Result startRecognition(MSwipeGesture *swipeGesture, const QGraphicsSceneMouseEvent *mouseEvent);
- QGestureRecognizer::Result updateRecognition(MSwipeGesture *swipeGesture, const QGraphicsSceneMouseEvent *mouseEvent);
+ QGestureRecognizer::Result startRecognition(MSwipeGesture *swipeGesture, const QMouseEvent *mouseEvent);
+ QGestureRecognizer::Result updateRecognition(MSwipeGesture *swipeGesture, const QMouseEvent *mouseEvent);
QGestureRecognizer::Result finishRecognition(MSwipeGesture *swipeGesture);
MSwipeRecognizer* q_ptr;
diff --git a/src/corelib/events/mtapandholdrecognizer.cpp b/src/corelib/events/mtapandholdrecognizer.cpp
index d077c006..d357f3cd 100644
--- a/src/corelib/events/mtapandholdrecognizer.cpp
+++ b/src/corelib/events/mtapandholdrecognizer.cpp
@@ -60,7 +60,6 @@ MTapAndHoldRecognizer::~MTapAndHoldRecognizer()
QGesture* MTapAndHoldRecognizer::create(QObject* target)
{
- Q_UNUSED(target);
if (target && target->isWidgetType() == false) {
return 0; // this assumes the target is a QGraphicsObject, so we return
// NULL to indicate that the recognizer doesn't support graphicsobject and
diff --git a/src/corelib/scene/mscene.cpp b/src/corelib/scene/mscene.cpp
index 3dc1e950..624cc3e7 100644
--- a/src/corelib/scene/mscene.cpp
+++ b/src/corelib/scene/mscene.cpp
@@ -19,6 +19,7 @@
#include <QList>
#include <QGraphicsItem>
+#include <QGraphicsWidget>
#include <QPainter>
#include <QTime>
#include <QTimer>
@@ -38,24 +39,61 @@
#include "mdeviceprofile.h"
#include "mcancelevent.h"
-const QFont TextFont = QFont("Sans", 10);
-const QSize FpsBoxSize = QSize(100, 40);
-const QColor FpsTextColor = QColor(0xFFFF00);
-const QFont FpsFont = QFont("Sans", 15);
-const int FpsRefreshInterval = 1000;
-const QString FpsBackgroundColor = "#000000";
-const qreal FpsBackgroundOpacity = 0.35;
-const QString BoundingRectLineColor = "#00F000";
-const QString BoundingRectFillColor = "#00F000";
-const qreal BoundingRectOpacity = 0.1;
-const qreal MarginBackgroundOpacity = 0.4;
-const QColor MarginColor = QColor(Qt::red);
-const int MarginBorderWidth = 2;
+static const QFont TextFont = QFont("Sans", 10);
+static const QSize FpsBoxSize = QSize(100, 40);
+static const QColor FpsTextColor = QColor(0xFFFF00);
+static const QFont FpsFont = QFont("Sans", 15);
+static const int FpsRefreshInterval = 1000;
+static const QString FpsBackgroundColor = "#000000";
+static const qreal FpsBackgroundOpacity = 0.35;
+static const QString BoundingRectLineColor = "#00F000";
+static const QString BoundingRectFillColor = "#00F000";
+static const qreal BoundingRectOpacity = 0.1;
+static const qreal MarginBackgroundOpacity = 0.4;
+static const QColor MarginColor = QColor(Qt::red);
+static const int MarginBorderWidth = 2;
+static const int InitialPressTimeout = 140; //msec
+
+void copyGraphicsSceneMouseEvent(QGraphicsSceneMouseEvent &target, const QGraphicsSceneMouseEvent &source)
+{
+ target.setPos(source.pos());
+ target.setScenePos(source.scenePos());
+ target.setScreenPos(source.screenPos());
+
+ target.setButtons(source.buttons());
+ Qt::MouseButtons buttons = source.buttons();
+ Qt::MouseButton buttonbit = (Qt::MouseButton)0x1;
+ while (buttons != 0x0) {
+ if (buttons & buttonbit) {
+ // Button pressed
+ target.setButtonDownPos(buttonbit, source.buttonDownPos(buttonbit));
+ target.setButtonDownScenePos(buttonbit, source.buttonDownScenePos(buttonbit));
+ target.setButtonDownScreenPos(buttonbit, source.buttonDownScreenPos(buttonbit));
+
+ // Unset button
+ buttons = buttons & ~buttonbit;
+ }
+ buttonbit = (Qt::MouseButton)(buttonbit << 1);
+ }
+
+ target.setLastPos(source.lastPos());
+ target.setLastScenePos(source.lastScenePos());
+ target.setLastScreenPos(source.lastScreenPos());
+ target.setButton(source.button());
+ target.setModifiers(source.modifiers());
+}
MScenePrivate::MScenePrivate() :
q_ptr(0),
manager(0),
+ eventEater(new QGraphicsWidget),
+ cancelSent(false),
+ initialPressTimer(0),
+ mousePressEvent(QEvent::GraphicsSceneMousePress),
+ touchBeginEvent(QEvent::TouchBegin),
+ pressPending(false),
+ touchPending(false),
emuPoint1(1),
emuPoint2(2),
pinchEmulationEnabled(false)
@@ -400,43 +438,85 @@ void MScenePrivate::fillMarginRectWithPattern(QPainter *painter, const QRectF& r
painter->fillRect(rect, QBrush(Qt::black, Qt::BDiagPattern));
}
-void MScenePrivate::handleGestureEvent(QEvent* event)
+void MScenePrivate::notifyChildRequestedMouseCancel()
+{
+ if (!cancelSent)
+ sendCancelEvent();
+}
+
+
+void MScenePrivate::resetMouseGrabber()
+{
+ if (cancelSent) {
+ eventEater->ungrabMouse();
+ cancelSent = false;
+ }
+}
+
+void MScenePrivate::sendCancelEvent()
{
Q_Q(MScene);
- QGestureEvent *gestureEvent = static_cast<QGestureEvent*>(event);
-
- foreach(QGesture* gesture, gestureEvent->gestures()) {
-
- switch (gesture->state()) {
- case Qt::GestureStarted:
- if (panelAcceptedGestures.contains(gesture->gestureType()))
- panelAcceptedGestures.removeAt(panelAcceptedGestures.indexOf(gesture->gestureType()));
- else if (gestureEvent->isAccepted(gesture))
- childrenAcceptedGestures.append(gesture->gestureType());
- break;
- case Qt::GestureCanceled:
- if (childrenAcceptedGestures.contains(gesture->gestureType()))
- childrenAcceptedGestures.removeAt(childrenAcceptedGestures.indexOf(gesture->gestureType()));
- break;
- case Qt::GestureFinished:
- if (childrenAcceptedGestures.contains(gesture->gestureType())) {
- if (q->mouseGrabberItem()) {
- MCancelEvent cancelEvent;
- q->sendEvent(q->mouseGrabberItem(),&cancelEvent);
- }
- childrenAcceptedGestures.removeAt(childrenAcceptedGestures.indexOf(gesture->gestureType()));
- }
- default:
- break;
- }
+ if (initialPressTimer->isActive()) {
+ //We still didn't send the initial press and touch.
+ //We can stop the timer and forget about them.
+ initialPressTimer->stop();
+ pressPending = false;
+ touchPending = false;
+ return;
+ }
+
+ if (q->mouseGrabberItem()) {
+ MCancelEvent cancelEvent;
+ q->sendEvent(q->mouseGrabberItem(),&cancelEvent);
}
+
+ if (q->mouseGrabberItem() != eventEater)
+ eventEater->grabMouse();
+
+ cancelSent = true;
}
-void MScenePrivate::notifyGestureCaughtByPanel(Qt::GestureType gestureType)
+void MScenePrivate::delayMousePressEvent(QGraphicsSceneMouseEvent* mouseEvent)
{
- if (!panelAcceptedGestures.contains(gestureType))
- panelAcceptedGestures.append(gestureType);
+ copyGraphicsSceneMouseEvent(mousePressEvent, *mouseEvent);
+
+ if (!initialPressTimer->isActive())
+ initialPressTimer->start();
+
+ pressPending = true;
+}
+
+void MScenePrivate::delayTouchEvent(QTouchEvent* touchEvent)
+{
+ touchBeginEvent = *touchEvent;
+
+ if (!initialPressTimer->isActive())
+ initialPressTimer->start();
+
+ touchPending = true;
+}
+
+void MScenePrivate::forceSendingInitialEvents()
+{
+ if (initialPressTimer->isActive()) {
+ //Didn't send the press yet...
+ initialPressTimer->stop();
+ _q_initialPressDeliveryTimeout();
+ }
+}
+
+void MScenePrivate::_q_initialPressDeliveryTimeout()
+{
+ Q_Q(MScene);
+ if (touchPending) {
+ q->QGraphicsScene::event(&touchBeginEvent);
+ touchPending = false;
+ }
+ if (pressPending) {
+ q->QGraphicsScene::event(&mousePressEvent);
+ pressPending = false;
+ }
}
MScene::MScene(QObject *parent)
@@ -458,6 +538,13 @@ MScene::MScene(QObject *parent)
d->boundingRectFillBrush = QBrush(boundingRectFillColor);
setItemIndexMethod(QGraphicsScene::NoIndex);
+
+ d->eventEater->setParent(this);
+ addItem(d->eventEater);
+ d->initialPressTimer = new QTimer(this);
+ d->initialPressTimer->setSingleShot(true);
+ d->initialPressTimer->setInterval(InitialPressTimeout);
+ connect(d->initialPressTimer, SIGNAL(timeout()), this, SLOT(_q_initialPressDeliveryTimeout()));
}
MScene::~MScene()
@@ -476,14 +563,42 @@ bool MScene::event(QEvent *event)
{
Q_D(MScene);
- if (d->eventEmulateTwoFingerGestures(event)) {
+ if (d->eventEmulateTwoFingerGestures(event))
return true;
- }
- bool retValue = QGraphicsScene::event(event);
+ bool retValue = false;
- if (event->type() == QEvent::Gesture)
- d->handleGestureEvent(event);
+ switch (event->type())
+ {
+
+ case QEvent::TouchBegin:
+ d->delayTouchEvent(static_cast<QTouchEvent*>(event));
+ retValue = true;
+ break;
+ case QEvent::TouchUpdate:
+ retValue = (d->touchPending ? true : QGraphicsScene::event(event));
+ break;
+ case QEvent::TouchEnd:
+ d->forceSendingInitialEvents();
+ retValue = QGraphicsScene::event(event);
+ break;
+
+ case QEvent::GraphicsSceneMousePress:
+ d->delayMousePressEvent(static_cast<QGraphicsSceneMouseEvent*>(event));
+ retValue = true;
+ break;
+ case QEvent::GraphicsSceneMouseMove:
+ retValue = (d->pressPending ? true : QGraphicsScene::event(event));
+ break;
+ case QEvent::GraphicsSceneMouseRelease:
+ d->forceSendingInitialEvents();
+ retValue = QGraphicsScene::event(event);
+ d->resetMouseGrabber();
+ break;
+
+ default:
+ retValue = QGraphicsScene::event(event);
+ }
return retValue;
}
@@ -635,3 +750,5 @@ void MScene::drawForeground(QPainter *painter, const QRectF &rect)
painter->drawPixmap(d->emuPoint2.scenePos() - pixmapCenterDelta, *tapPixmap);
}
}
+
+#include "moc_mscene.cpp"
diff --git a/src/corelib/scene/mscene.h b/src/corelib/scene/mscene.h
index fd911e50..eff50946 100644
--- a/src/corelib/scene/mscene.h
+++ b/src/corelib/scene/mscene.h
@@ -93,6 +93,7 @@ protected:
private:
Q_DISABLE_COPY(MScene)
Q_DECLARE_PRIVATE(MScene)
+ Q_PRIVATE_SLOT(d_func(), void _q_initialPressDeliveryTimeout())
#ifdef UNIT_TEST
friend class Ut_MScene;
@@ -101,6 +102,7 @@ private:
friend class MSceneManager;
friend class MWindowPrivate;
friend class MSceneWindow;
+ friend class MWidget;
};
#endif
diff --git a/src/corelib/scene/mscene_p.h b/src/corelib/scene/mscene_p.h
index 326d6792..c923ba6f 100644
--- a/src/corelib/scene/mscene_p.h
+++ b/src/corelib/scene/mscene_p.h
@@ -27,6 +27,8 @@
class MSceneManager;
class MOnDisplayChangeEvent;
+class QGraphicsSceneMouseEvent;
+class QTouchEvent;
class MScenePrivate
{
@@ -71,23 +73,29 @@ public:
bool eventEmulatePinch(QEvent *event);
void fillMarginRectWithPattern(QPainter *painter, const QRectF& rect, int thickness);
- void handleGestureEvent(QEvent* event);
+ void resetMouseGrabber();
+ void delayMousePressEvent(QGraphicsSceneMouseEvent* mouseEvent);
+ void delayTouchEvent(QTouchEvent* touchEvent);
+ void forceSendingInitialEvents();
+ void sendCancelEvent();
- /*
- MeegoTouch needs to have widgets that stop
- propagation of gestures. We implement that using
- MSceneWindows, which are supposed to swallow all
- gesture events. The scene windows on the other hand
- need to inform the scene that they swallowed gesture
- event and they use the notifyGestureCaughtByPanel
- method.
- */
- void notifyGestureCaughtByPanel(Qt::GestureType gestureType);
+ void notifyChildRequestedMouseCancel();
+
+public Q_SLOTS:
+ void _q_initialPressDeliveryTimeout();
protected:
MScene *q_ptr;
MSceneManager *manager;
+ QGraphicsWidget* eventEater;
+ bool cancelSent;
+ QTimer *initialPressTimer;
+ QGraphicsSceneMouseEvent mousePressEvent;
+ QTouchEvent touchBeginEvent;
+ bool pressPending;
+ bool touchPending;
+
//Two finger gestures emulation variables
QTouchEvent::TouchPoint emuPoint1, emuPoint2;
bool pinchEmulationEnabled;
@@ -95,8 +103,9 @@ protected:
Fps fps;
FpsLog fpsLog;
- QList<Qt::GestureType> childrenAcceptedGestures;
- QList<Qt::GestureType> panelAcceptedGestures;
+#ifdef UNIT_TEST
+ friend class Ut_MScene;
+#endif // UNIT_TEST
};
#endif // MSCENE_P_H
diff --git a/src/corelib/widgets/core/mwidget.cpp b/src/corelib/widgets/core/mwidget.cpp
index 0d8258a2..ab7f2928 100644
--- a/src/corelib/widgets/core/mwidget.cpp
+++ b/src/corelib/widgets/core/mwidget.cpp
@@ -42,7 +42,8 @@
#include <mcancelevent.h>
#include <mondisplaychangeevent.h>
#include <morientationchangeevent.h>
-#include <mscene.h>
+#include "mscene.h"
+#include "mscene_p.h"
#include <mscenemanager.h>
#include "mobjectmenu.h"
@@ -340,8 +341,18 @@ void MWidget::contextMenuEvent(QGraphicsSceneContextMenuEvent *event)
}
}
+void MWidget::grabGesture(Qt::GestureType type, Qt::GestureFlags flags, MouseEventCancelPolicy cancelPolicy)
+{
+ Q_D(MWidget);
+ QGraphicsWidget::grabGesture(type, flags);
+ if (cancelPolicy != MouseEventNoCancel)
+ d->cancelPolicies.insert(type,cancelPolicy);
+}
+
void MWidget::gestureEvent(QGestureEvent *event)
{
+ Q_D(MWidget);
+
foreach(QGesture* gesture, event->gestures()) {
if (Qt::TapAndHoldGesture == gesture->gestureType()) {
QTapAndHoldGesture* tapAndHoldState = static_cast<QTapAndHoldGesture *>(gesture);
@@ -359,6 +370,26 @@ void MWidget::gestureEvent(QGestureEvent *event)
QSwipeGesture* swipeState = static_cast<QSwipeGesture *>(gesture);
swipeGestureEvent(event,swipeState);
}
+
+ if (gesture->state() != Qt::GestureStarted || event->isAccepted(gesture)) {
+ // Gesture was accepted, let's see if we should cancel mouse event at this time.
+
+ bool initiateMouseCancel = false;
+
+ if (gesture->state() == Qt::GestureStarted &&
+ d->cancelPolicies.value(gesture->gestureType()) == MouseEventCancelOnGestureStarted)
+ initiateMouseCancel = true;
+
+ if (gesture->state() == Qt::GestureFinished &&
+ d->cancelPolicies.value(gesture->gestureType()) == MouseEventCancelOnGestureFinished)
+ initiateMouseCancel = true;
+
+ if (initiateMouseCancel) {
+ MScene *mScene = qobject_cast<MScene *>(scene());
+ if (mScene)
+ mScene->d_func()->notifyChildRequestedMouseCancel();
+ }
+ }
}
}
diff --git a/src/corelib/widgets/core/mwidget.h b/src/corelib/widgets/core/mwidget.h
index 837eefed..c3bea238 100644
--- a/src/corelib/widgets/core/mwidget.h
+++ b/src/corelib/widgets/core/mwidget.h
@@ -115,6 +115,44 @@ public:
*/
void setPaintOffset(const QPointF & offset);
+ /*!
+ * This enum contains possible values of a mouse event cancel policy.
+ *
+ * \li MouseEventNoCancel - the cancel event will not be sent if this widget receives a gesture.
+ * \li MouseEventCancelOnGestureStarted - the cancel event will be sent when
+ * a gesture is being started and accepted by this widget.
+ * \li MouseEventCancelOnGestureFinished - the cancel event will be sent when
+ * a gesture is being finished and was accepted by this widget.
+ *
+ * \sa grabGesture.
+ */
+ enum MouseEventCancelPolicy {
+ MouseEventNoCancel,
+ MouseEventCancelOnGestureStarted,
+ MouseEventCancelOnGestureFinished
+ };
+
+ /*!
+ Subscribes the widget to gestures events of a specific \a type. Allows definition
+ of cancel event handling policy for that gesture.
+
+ The meegotouch library can send cancel event to the current mouse grabber and
+ stop processing mouse events. This allows the UI to react to situation when
+ the user starts a gesture on top of interactive elements like buttons. In
+ a typical example, the user starts panning gesture over a button, which will
+ initially reach the pressed state. Then the user moves his finger and the button
+ will then be moved back to un-pressed state, without triggering actions connected
+ to it. Internally, the button will receive a cancel event and it will not receive
+ the release event.
+
+ This method is an overloaded version of grabGesture defined in QGraphicsWidget
+ which introduces \a cancelPolicy argument. It can be used to define the reaction
+ to started or finished gesture when it reaches the object of the MWidget.
+
+ \sa MouseEventCancelPolicy
+ */
+ void grabGesture(Qt::GestureType type, Qt::GestureFlags flags = Qt::GestureFlags(), MouseEventCancelPolicy cancelPolicy = MouseEventNoCancel);
+
/*! \reimp
* We reimplement these to distinguish between the user hiding items
* explicitly, and the layout hiding them.
diff --git a/src/corelib/widgets/core/mwidget_p.h b/src/corelib/widgets/core/mwidget_p.h
index 69fd34ca..10809ea7 100644
--- a/src/corelib/widgets/core/mwidget_p.h
+++ b/src/corelib/widgets/core/mwidget_p.h
@@ -21,6 +21,7 @@
#define MWIDGET_P_H
#include <mwidget.h>
+#include <QMap>
class M_CORE_EXPORT MWidgetPrivate
{
@@ -45,6 +46,8 @@ protected:
bool onDisplay;
bool onDisplaySet;
bool selected;
+
+ QMap<Qt::GestureType, MWidget::MouseEventCancelPolicy> cancelPolicies;
};
#endif // MWIDGET_P_H
diff --git a/src/corelib/widgets/mcontentitem.cpp b/src/corelib/widgets/mcontentitem.cpp
index 0eb450bc..2dfa2e6d 100644
--- a/src/corelib/widgets/mcontentitem.cpp
+++ b/src/corelib/widgets/mcontentitem.cpp
@@ -46,7 +46,7 @@ void MContentItemPrivate::updateLongTapConnections()
Q_Q(MContentItem);
if (q->receivers(SIGNAL(longTapped(QPointF))) > 0)
- q->grabGesture(Qt::TapAndHoldGesture);
+ q->grabGesture(Qt::TapAndHoldGesture, Qt::GestureFlags(), MWidget::MouseEventCancelOnGestureFinished);
else
q->ungrabGesture(Qt::TapAndHoldGesture);
}
diff --git a/src/corelib/widgets/mlabel.cpp b/src/corelib/widgets/mlabel.cpp
index aa62ec1d..8b80b106 100644
--- a/src/corelib/widgets/mlabel.cpp
+++ b/src/corelib/widgets/mlabel.cpp
@@ -32,13 +32,13 @@ M_REGISTER_WIDGET(MLabel)
MLabel::MLabel(QGraphicsItem *parent, MLabelModel *model) :
MWidgetController(new MLabelPrivate, model == NULL ? new MLabelModel : model, parent)
{
- grabGesture(Qt::TapAndHoldGesture);
+ grabGesture(Qt::TapAndHoldGesture, Qt::GestureFlags(), MWidget::MouseEventCancelOnGestureFinished);
}
MLabel::MLabel(QString const &text, QGraphicsItem *parent) :
MWidgetController(new MLabelPrivate, new MLabelModel, parent)
{
- grabGesture(Qt::TapAndHoldGesture);
+ grabGesture(Qt::TapAndHoldGesture, Qt::GestureFlags(), MWidget::MouseEventCancelOnGestureFinished);
setText(text);
}
diff --git a/src/corelib/widgets/mlistitem.cpp b/src/corelib/widgets/mlistitem.cpp
index a08168cb..5283ec77 100644
--- a/src/corelib/widgets/mlistitem.cpp
+++ b/src/corelib/widgets/mlistitem.cpp
@@ -37,7 +37,7 @@ void MListItemPrivate::updateLongTapConnections()
{
Q_Q(MListItem);
if (q->receivers(SIGNAL(longTapped(QPointF))) > 0)
- q->grabGesture(Qt::TapAndHoldGesture);
+ q->grabGesture(Qt::TapAndHoldGesture, Qt::GestureFlags(), MWidget::MouseEventCancelOnGestureFinished);
else
q->ungrabGesture(Qt::TapAndHoldGesture);
}
diff --git a/src/corelib/widgets/mpannablewidget.cpp b/src/corelib/widgets/mpannablewidget.cpp
index bfbeab8f..a2e889a8 100644
--- a/src/corelib/widgets/mpannablewidget.cpp
+++ b/src/corelib/widgets/mpannablewidget.cpp
@@ -29,115 +29,25 @@
#include "mondisplaychangeevent.h"
#include "mwidgetcreator.h"
+#include "mscene.h"
M_REGISTER_WIDGET(MPannableWidget)
-namespace
-{
- //! Limiter for the resent list
- const int ResentListMaxSize = 10;
- //! Z-value of the glass
- const int ZValueGlass = 2;
- //! Hardcoded timeout value for delivering initial press event;
- const int InitialPressDeliveryTimeoutValue = 140;
-
-}
-
-/*
- * MPannableWidget handles the event interception by setting up a
- * 'glass' widget on top of the pannable widget and its possible
- * children. Glass forwards all mouse events to pannable widget which
- * interprets them. The press event is just stored first and in case
- * the gesture turns out to be not a panning one, the press is resend
- * to scene. It is also put to the exclude list and when seen for the
- * second time in mouse press handler, it is ignored. For this to
- * work, just before the resending the mouse is ungrabbed in the glass
- * which enables Qt to forward the event deeper after ignoring.
- * After the forwarded press, all events go directly to the possible
- * widget under the glass.
- *
- * If debugging of glass events is needed, it is recommend to override
- * sceneEvent since also the mouse grabs and ungrabs are seen on that
- * level.
- */
-
-/**
- * Copies QGraphicsSceneMouseEvent data from one instance to another.
- * Note that this function copies only data defined in QGraphicsSceneMouseEvent.
- * Target event will keep its event type and other properties defined in QGraphicsSceneMouseEvent
- * subclasses.
- */
-void copyGraphicsSceneMouseEvent(QGraphicsSceneMouseEvent &target, const QGraphicsSceneMouseEvent &source)
-{
- target.setPos(source.pos());
- target.setScenePos(source.scenePos());
- target.setScreenPos(source.screenPos());
-
- target.setButtons(source.buttons());
- Qt::MouseButtons buttons = source.buttons();
- Qt::MouseButton buttonbit = (Qt::MouseButton)0x1;
- while (buttons != 0x0) {
- if (buttons & buttonbit) {
- // Button pressed
- target.setButtonDownPos(buttonbit, source.buttonDownPos(buttonbit));
- target.setButtonDownScenePos(buttonbit, source.buttonDownScenePos(buttonbit));
- target.setButtonDownScreenPos(buttonbit, source.buttonDownScreenPos(buttonbit));
-
- // Unset button
- buttons = buttons & ~buttonbit;
- }
- buttonbit = (Qt::MouseButton)(buttonbit << 1);
- }
-
- target.setLastPos(source.lastPos());
- target.setLastScenePos(source.lastScenePos());
- target.setLastScreenPos(source.lastScreenPos());
- target.setButton(source.button());
- target.setModifiers(source.modifiers());
-}
-
-MPannableWidgetGlass::MPannableWidgetGlass(QGraphicsItem *parent) :
- MWidget(parent)
-{
- pannableWidget = dynamic_cast<MPannableWidget *>(parent);
-}
-
+static const int ZValueGlass = 2;
-MPannableWidgetGlass::~MPannableWidgetGlass()
+MPannableWidgetGlass::MPannableWidgetGlass(MPannableWidget *pannableWidget) :
+ MWidget(pannableWidget),
+ pannableWidget(pannableWidget)
{
}
-
QRectF MPannableWidgetGlass::boundingRect() const
{
return QRectF(QPointF(), pannableWidget->size());
}
-
void MPannableWidgetGlass::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
- pannableWidget->glassMousePressEvent(event);
-}
-
-
-void MPannableWidgetGlass::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
-{
- pannableWidget->glassMouseMoveEvent(event);
-}
-
-
-void MPannableWidgetGlass::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
-{
- pannableWidget->glassMouseReleaseEvent(event);
-}
-
-void MPannableWidgetGlass::timerEvent(QTimerEvent *event)
-{
- pannableWidget->glassTimerEvent(event);
-}
-
-void MPannableWidgetGlass::cancelEvent(MCancelEvent *event)
-{
- pannableWidget->cancelEvent(event);
+ pannableWidget->d_func()->glassMousePressEvent(event);
}
void MPannableWidgetGlass::tapAndHoldGestureEvent(QGestureEvent *event, QTapAndHoldGesture *gesture)
@@ -146,12 +56,7 @@ void MPannableWidgetGlass::tapAndHoldGestureEvent(QGestureEvent *event, QTapAndH
}
MPannableWidgetPrivate::MPannableWidgetPrivate() :
- pressEvent(QEvent::GraphicsSceneMousePress),
- physics(0),
- mouseGrabber(0),
- resentList(),
- pressDeliveryTimerId(0),
- panGestureCausedCancelEvent(false)
+ physics(0)
{
}
@@ -160,136 +65,69 @@ MPannableWidgetPrivate::~MPannableWidgetPrivate()
delete physics;
}
-void MPannableWidgetPrivate::translateEventToItemCoordinates(const QGraphicsItem *srcItem, const QGraphicsItem *destItem, QGraphicsSceneMouseEvent *event)
-{
- event->setLastPos(destItem->mapFromItem(srcItem, event->lastPos()));
- event->setPos(destItem->mapFromItem(srcItem, event->pos()));
-}
-
-void MPannableWidgetPrivate::deliverPressEvent()
+void MPannableWidgetPrivate::init()
{
Q_Q(MPannableWidget);
- if (physics->inMotion())
- {
- physics->stop();
- return;
- }
+ physics = new MPhysics2DPanning(q);
- if (q->scene() == NULL) {
- // We have been removed from the scene
- // while waiting for timer to expire.
- // Reset the states and wait for next events.
- resetPhysics();
- resetMouseGrabber();
- return;
- }
+ q->connect(physics, SIGNAL(positionChanged(QPointF)),
+ q, SLOT(updatePosition(QPointF)));
- glass->ungrabMouse();
- q->resendEvent(&pressEvent);
- mouseGrabber = q->scene()->mouseGrabberItem();
- glass->grabMouse();
-}
-
-void MPannableWidgetPrivate::initialPressStartTimer()
-{
- pressDeliveryTimerId = glass->startTimer(InitialPressDeliveryTimeoutValue);
-}
+ q->connect(physics, SIGNAL(panningStopped()),
+ q, SIGNAL(panningStopped()));
-void MPannableWidgetPrivate::initialPressStopTimer()
-{
- if (pressDeliveryTimerId) {
- glass->killTimer(pressDeliveryTimerId);
- pressDeliveryTimerId = 0;
- }
-}
+ glass = new MPannableWidgetGlass(q);
+ glass->setZValue(ZValueGlass);
-void MPannableWidgetPrivate::resetPhysics()
-{
- physics->pointerRelease();
- physics->stop();
-}
+ glass->setObjectName("glass");
+ glass->grabGesture(Qt::TapAndHoldGesture);
-void MPannableWidgetPrivate::resetMouseGrabber()
-{
- Q_Q(MPannableWidget);
+ q->grabGesture(Qt::PanGesture, Qt::GestureFlags(), MWidget::MouseEventCancelOnGestureStarted);
- mouseGrabber = 0;
- if (q->scene() && glass == q->scene()->mouseGrabberItem()) {
- glass->ungrabMouse();
- }
+ q->setPosition(QPointF());
+ q->setRange(QRectF());
}
-void MPannableWidgetPrivate::deliverMouseEvent(QGraphicsSceneMouseEvent *event)
+void MPannableWidgetPrivate::glassMousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
{
Q_Q(MPannableWidget);
- if (mouseGrabber && q->scene()->items().contains(mouseGrabber)) {
- translateEventToItemCoordinates(glass, mouseGrabber, event);
- q->scene()->sendEvent(mouseGrabber, event);
+ // This handler is called by the glass tapAndHoldGestureEvent method.
+ if (q->isEnabled() && physics->inMotion()) {
+ // The viewport is still moving,
+ // let's swallow this event
+ resetPhysics();
+ mouseEvent->accept();
+ } else {
+ mouseEvent->ignore();
}
}
-MPannableWidget* MPannableWidgetPrivate::parentPannableWidget()
+void MPannableWidgetPrivate::resetPhysics()
{
- Q_Q(MPannableWidget);
-
- QGraphicsWidget* parentWidget = q->parentWidget();
- MPannableWidget* parentPannableWidget = 0;
-
- // Looking for topmost enabled pannablewidget.
- while(parentWidget) {
- MPannableWidget* candidate = qobject_cast<MPannableWidget*>(parentWidget);
- if (candidate && candidate->panDirection() != 0)
- parentPannableWidget = candidate;
- parentWidget = parentWidget->parentWidget();
- }
-
- return parentPannableWidget;
+ physics->pointerRelease();
+ physics->stop();
}
MPannableWidget::MPannableWidget(MPannableWidgetPrivate *dd, MPannableWidgetModel *model,
QGraphicsItem *parent)
: MWidgetController(dd, model, parent)
{
- init();
+ Q_D(MPannableWidget);
+ d->init();
}
-
MPannableWidget::MPannableWidget(QGraphicsItem *parent) :
MWidgetController(new MPannableWidgetPrivate(), new MPannableWidgetModel, parent)
{
- init();
-}
-
-void MPannableWidget::init()
-{
Q_D(MPannableWidget);
-
- d->physics = new MPhysics2DPanning(this);
-
- connect(d->physics, SIGNAL(positionChanged(QPointF)),
- this, SLOT(updatePosition(QPointF)));
-
- connect(d->physics, SIGNAL(panningStopped()),
- this, SIGNAL(panningStopped()));
-
- d->glass = new MPannableWidgetGlass(this);
- d->glass->setZValue(ZValueGlass);
-
- d->glass->setObjectName("glass");
- d->glass->grabGesture(Qt::TapAndHoldGesture);
-
- grabGesture(Qt::PanGesture);
-
- setPosition(QPointF());
- setRange(QRectF());
+ d->init();
}
MPannableWidget::~MPannableWidget()
{
}
-
MPhysics2DPanning *MPannableWidget::physics() const
{
Q_D(const MPannableWidget);
@@ -322,7 +160,6 @@ void MPannableWidget::setEnabled(bool enabled)
MWidgetController::setEnabled(enabled);
}
-
bool MPannableWidget::isEnabled()
{
return MWidgetController::isEnabled();
@@ -333,12 +170,10 @@ void MPannableWidget::setVerticalPanningPolicy(PanningPolicy policy)
Q_D(MPannableWidget);
model()->setVerticalPanningPolicy(policy);
-
d->physics->setPanDirection(panDirection());
- if (policy == PanningAlwaysOff) {
+ if (policy == PanningAlwaysOff)
d->resetPhysics();
- }
}
MPannableWidget::PanningPolicy MPannableWidget::verticalPanningPolicy() const
@@ -351,12 +186,10 @@ void MPannableWidget::setHorizontalPanningPolicy(PanningPolicy policy)
Q_D(MPannableWidget);
model()->setHorizontalPanningPolicy(policy);
-
d->physics->setPanDirection(panDirection());
- if (policy == PanningAlwaysOff) {
+ if (policy == PanningAlwaysOff)
d->resetPhysics();
- }
}
MPannableWidget::PanningPolicy MPannableWidget::horizontalPanningPolicy() const
@@ -367,116 +200,34 @@ MPannableWidget::PanningPolicy MPannableWidget::horizontalPanningPolicy() const
void MPannableWidget::setRange(const QRectF &r)
{
Q_D(const MPannableWidget);
+
d->physics->setRange(r);
}
-
QRectF MPannableWidget::range() const
{
Q_D(const MPannableWidget);
+
return d->physics->range();
}
-
void MPannableWidget::setPosition(const QPointF &p)
{
Q_D(const MPannableWidget);
+
d->physics->setPosition(p);
emit positionChanged(p);
}
-
QPointF MPannableWidget::position() const
{
Q_D(const MPannableWidget);
- return d->physics->position();
-}
-
-
-bool MPannableWidget::checkForResent(QEvent *event)
-{
- Q_D(MPannableWidget);
-
- const int size = d->resentList.size();
- for (int i = 0; i < size; ++i) {
- const MPannableWidgetPrivate::resentItem &item = d->resentList.at(i);
- if (item.type == (static_cast<QGraphicsSceneMouseEvent *>(event))->type() &&
- item.screenPos == (static_cast<QGraphicsSceneMouseEvent *>(event))->screenPos() &&
- item.button == (static_cast<QGraphicsSceneMouseEvent *>(event))->button()) {
-
- d->resentList.removeAt(i);
-
- return true;
- }
- }
-
- return false;
-}
-
-void MPannableWidget::updatePosition(const QPointF &position)
-{
- Q_UNUSED(position);
-}
-
-
-void MPannableWidget::glassMousePressEvent(QGraphicsSceneMouseEvent *event)
-{
- Q_D(MPannableWidget);
-
- if (event->button() != Qt::LeftButton) {
- // Glass: Ignoring, not a left button
-
- event->ignore();
- return;
- }
-
- if (checkForResent(event)) {
- // Glass: Ignoring, already seen
- event->ignore();
- return;
- }
-
- if (panDirection() == 0) {
- // Glass: Ignoring, I'm disabled
- event->ignore();
- return;
- }
-
- MPannableWidget *parentPannableWidget = d->parentPannableWidget();
- if (parentPannableWidget) {
-
- //We are stopping here, because if there is a parent pannable widget
- //then the initial press timeout has already happened.
- d->physics->stop();
-
- //My parent will handle this mouse press.
- event->ignore();
- return;
- }
-
- copyGraphicsSceneMouseEvent(d->pressEvent, *event);
- d->initialPressStartTimer();
-}
-
-void MPannableWidget::glassMouseReleaseEvent(QGraphicsSceneMouseEvent *event)
-{
- Q_D(MPannableWidget);
-
- if (d->pressDeliveryTimerId) {
- d->deliverPressEvent();
- d->initialPressStopTimer();
- }
-
- d->deliverMouseEvent(event);
- d->resetMouseGrabber();
+ return d->physics->position();
}
-
-void MPannableWidget::glassMouseMoveEvent(QGraphicsSceneMouseEvent *event)
+void MPannableWidget::updatePosition(const QPointF &/*position*/)
{
- Q_D(MPannableWidget);
- d->deliverMouseEvent(event);
}
void MPannableWidget::panGestureEvent(QGestureEvent *event, QPanGesture* panGesture)
@@ -492,7 +243,6 @@ void MPannableWidget::panGestureEvent(QGestureEvent *event, QPanGesture* panGest
(horizontalPanningPolicy() == PanningAsNeeded && range().height() == 0) ) {
event->ignore(panGesture);
- d->panGestureCausedCancelEvent = true;
return;
}
}
@@ -502,7 +252,6 @@ void MPannableWidget::panGestureEvent(QGestureEvent *event, QPanGesture* panGest
(verticalPanningPolicy() == PanningAsNeeded && range().height() == 0) ) {
event->ignore(panGesture);
- d->panGestureCausedCancelEvent = true;
return;
}
}
@@ -510,19 +259,6 @@ void MPannableWidget::panGestureEvent(QGestureEvent *event, QPanGesture* panGest
switch (panGesture->state())
{
case Qt::GestureStarted:
-
- //If we have parent pannable widget, then it is the parent
- //who handles the cancelling of mouse press. We need to inform
- //it that this needs to be done.
- {
- MPannableWidget *parentPannableWidget = d->parentPannableWidget();
- if (parentPannableWidget) {
- parentPannableWidget->sendCancel();
- } else {
- sendCancel();
- }
- }
-
d->physics->pointerPress(QPointF());
//Fallthrough is intentional, we need to handle the movement that
//is delivered with a started gesture.
@@ -530,7 +266,6 @@ void MPannableWidget::panGestureEvent(QGestureEvent *event, QPanGesture* panGest
d->physics->pointerMove(itemSpaceOffset);
break;
case Qt::GestureFinished:
- d->panGestureCausedCancelEvent = true;
case Qt::GestureCanceled:
d->physics->pointerRelease();
break;
@@ -555,72 +290,9 @@ void MPannableWidget::tapAndHoldGestureEvent(QGestureEvent *event, QTapAndHoldGe
}
}
-void MPannableWidget::orientationChangeEvent(MOrientationChangeEvent *event)
-{
- Q_D(MPannableWidget);
- d->resetPhysics();
-
- MWidgetController::orientationChangeEvent(event);
-}
-
-void MPannableWidget::glassTimerEvent(QTimerEvent *event)
-{
- Q_D(MPannableWidget);
- if (event->timerId() == d->pressDeliveryTimerId) {
- d->deliverPressEvent();
- d->initialPressStopTimer();
- }
-}
-
-void MPannableWidget::resendEvent(QGraphicsSceneMouseEvent *event)
-{
- Q_D(MPannableWidget);
-
- struct MPannableWidgetPrivate::resentItem resentItem;
-
- if ((scene() == NULL) || (scene()->views().size() == 0)) {
-
- // If this widget has been removed from the scene and/or there
- // is no view, return
- return;
- }
-
- if (event->type() == QEvent::GraphicsSceneMousePress) {
- // Puts the event to exclude list
-
- resentItem.type = event->type();
- resentItem.screenPos = event->screenPos();
- resentItem.button = event->button();
-
- // Size limiter for the list. Prevents the list from growing in
- // unlimited fashion in case of an unexpected loss of events
-
- while (d->resentList.size() > ResentListMaxSize) {
- d->resentList.removeLast();
- }
-
- d->resentList.append(resentItem);
- }
-
- QApplication::sendEvent(scene(), event);
-}
-
void MPannableWidget::cancelEvent(MCancelEvent *event)
{
Q_UNUSED(event);
- Q_D(MPannableWidget);
-
- if (d->panGestureCausedCancelEvent) {
- d->panGestureCausedCancelEvent = false;
- return;
- }
-
- sendCancel();
- d->resetPhysics();
-
- //We will still receive mouse release, but
- //we aren't interested in it.
- d->resetMouseGrabber();
}
// onDisplayChangeEvent in MWidget handles MPannableWidgets in a
@@ -660,27 +332,12 @@ void MPannableWidget::onDisplayChangeEvent(MOnDisplayChangeEvent *event)
}
}
-void MPannableWidget::sendCancel()
+void MPannableWidget::orientationChangeEvent(MOrientationChangeEvent *event)
{
Q_D(MPannableWidget);
- MCancelEvent cancelEvent;
-
- if ((scene() == NULL) || (scene()->views().size() == 0)) {
-
- // If this widget has been removed from the scene and/or there
- // is no view, return
- return;
- }
-
- if (d->pressDeliveryTimerId) {
- // The initial MousePress event hasn't been delivered yet.
- d->initialPressStopTimer();
- } else if (d->mouseGrabber && scene()->items().contains(d->mouseGrabber)) {
- scene()->sendEvent(d->mouseGrabber, &cancelEvent);
- d->mouseGrabber = 0;
- }
-
+ d->resetPhysics();
+ MWidgetController::orientationChangeEvent(event);
}
void MPannableWidget::setPanDirection(const Qt::Orientations &panDirection)
@@ -698,7 +355,7 @@ void MPannableWidget::setPanDirection(const Qt::Orientations &panDirection)
Qt::Orientations MPannableWidget::panDirection()
{
- return static_cast<const MPannableWidget *>(this)->panDirection();
+ return const_cast<const MPannableWidget*>(this)->panDirection();
}
Qt::Orientations MPannableWidget::panDirection() const
diff --git a/src/corelib/widgets/mpannablewidget.h b/src/corelib/widgets/mpannablewidget.h
index 437747c2..8f91e334 100644
--- a/src/corelib/widgets/mpannablewidget.h
+++ b/src/corelib/widgets/mpannablewidget.h
@@ -293,46 +293,6 @@ private:
Q_DISABLE_COPY(MPannableWidget)
Q_DECLARE_PRIVATE(MPannableWidget)
- /*!
- * \brief Method for handling the press events from the glass.
- */
- void glassMousePressEvent(QGraphicsSceneMouseEvent *event);
-
- /*!
- * \brief Method for handling the release events from the glass.
- */
- void glassMouseReleaseEvent(QGraphicsSceneMouseEvent *event);
-
- /*!
- * \brief Method for handling the move events from the glass.
- */
- void glassMouseMoveEvent(QGraphicsSceneMouseEvent *event);
-
- /*!
- * \brief Method for delivering timer events.
- */
- void glassTimerEvent(QTimerEvent* event);
-
- /*!
- * \brief Method for checking if the event is on the resent list
- * and should pass the glass when it hits it the second time.
- */
- bool checkForResent(QEvent *event);
-
- /*!
- * \brief Method for posting a captured event back to viewport.
- */
- void resendEvent(QGraphicsSceneMouseEvent *event);
-
- /*!
- * \brief Method for sending cancel event to viewport.
- */
- void sendCancel();
-
- /*!
- * \brief Init method.
- */
- void init();
#ifdef UNIT_TEST
// Test unit is defined as a friend of production code to access private members
diff --git a/src/corelib/widgets/mpannablewidget_p.h b/src/corelib/widgets/mpannablewidget_p.h
index 6129623b..b853783a 100644
--- a/src/corelib/widgets/mpannablewidget_p.h
+++ b/src/corelib/widgets/mpannablewidget_p.h
@@ -37,16 +37,11 @@ class MPannableWidgetGlass;
class MPannableWidgetGlass : public MWidget
{
public:
- MPannableWidgetGlass(QGraphicsItem *parent = 0);
- virtual ~MPannableWidgetGlass();
+ MPannableWidgetGlass(MPannableWidget *pannableWidget = 0);
virtual QRectF boundingRect() const;
virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
- virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
- virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
- virtual void timerEvent(QTimerEvent* event);
- virtual void cancelEvent(MCancelEvent *event);
virtual void tapAndHoldGestureEvent(QGestureEvent *event, QTapAndHoldGesture *gesture);
protected:
@@ -61,67 +56,20 @@ public:
explicit MPannableWidgetPrivate();
virtual ~MPannableWidgetPrivate();
- QGraphicsSceneMouseEvent pressEvent;
- MPhysics2DPanning *physics;
- MPannableWidgetGlass *glass;
- QGraphicsItem *mouseGrabber;
-
- struct resentItem {
- QEvent::Type type;
- QPoint screenPos;
- Qt::MouseButton button;
- };
-
- QList<struct resentItem> resentList;
-
- int pressDeliveryTimerId;
- bool panGestureCausedCancelEvent;
-public:
+ void init();
+ void resetPhysics();
+ void glassMousePressEvent(QGraphicsSceneMouseEvent *event);
- /*!
- * \brief Internal method necessary to correctly handle event positions.
- */
- void translateEventToItemCoordinates(const QGraphicsItem *srcItem,
- const QGraphicsItem *destItem,
- QGraphicsSceneMouseEvent *event);
+private:
- /*!
- * \brief Method used for resetting state of the physics engine.
- */
- void resetPhysics();
+ MPhysics2DPanning *physics;
+ MPannableWidgetGlass *glass;
- /*!
- * \brief Method used for resetting glass and mouse grabber.
- */
- void resetMouseGrabber();
-
- /*!
- * \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();
-
- /*!
- * \brief Method used for getting an enabled parent pannable widget.
- */
- MPannableWidget* parentPannableWidget();
+#ifdef UNIT_TEST
+ // Test unit is defined as a friend of production code to access private members
+ friend class Ut_MPannableWidget;
+#endif
};
#endif
diff --git a/src/corelib/widgets/mscenewindow.cpp b/src/corelib/widgets/mscenewindow.cpp
index 4509c703..4822f2bc 100644
--- a/src/corelib/widgets/mscenewindow.cpp
+++ b/src/corelib/widgets/mscenewindow.cpp
@@ -304,12 +304,7 @@ void MSceneWindow::tapAndHoldGestureEvent(QGestureEvent *event, QTapAndHoldGestu
{
Q_D(MSceneWindow);
- if (gesture->state() == Qt::GestureStarted) {
- // We will send cancel event on our own, unregistering this gesture from mscene.
- MScene *mScene = qobject_cast<MScene *>(scene());
- if (mScene)
- mScene->d_func()->notifyGestureCaughtByPanel(gesture->gestureType());
- } else if (gesture->state() == Qt::GestureFinished) {
+ if (gesture->state() == Qt::GestureFinished) {
QGraphicsSceneContextMenuEvent contextEvent(QEvent::GraphicsSceneContextMenu);
contextEvent.setPos(gesture->position());
@@ -370,16 +365,10 @@ bool MSceneWindow::event(QEvent *event)
void MSceneWindow::gestureEvent(QGestureEvent *event)
{
-
MWidgetController::gestureEvent(event);
- MScene *mScene = qobject_cast<MScene *>(scene());
- if (!mScene)
- return;
-
foreach(QGesture* gesture, event->gestures()) {
if (gesture->state() == Qt::GestureStarted && !event->isAccepted(gesture->gestureType())) {
- mScene->d_func()->notifyGestureCaughtByPanel(gesture->gestureType());
event->accept(gesture);
}
}
diff --git a/tests/ut_mappletinventory/ut_mappletinventory.pro b/tests/ut_mappletinventory/ut_mappletinventory.pro
index e09b4c76..9817f348 100644
--- a/tests/ut_mappletinventory/ut_mappletinventory.pro
+++ b/tests/ut_mappletinventory/ut_mappletinventory.pro
@@ -4,6 +4,7 @@ include(../common_mextensions.pri)
INCLUDEPATH += \
$$MSRCDIR/include \
$$MSRCDIR/corelib/widgets \
+ $$MSRCDIR/corelib/scene \
$$MSRCDIR/events
MODEL_HEADERS += \
@@ -16,7 +17,8 @@ SOURCES += \
$$MSRCDIR/extensions/mashup/appletinstallation/mappletinstantiator.cpp \
$$MSRCDIR/corelib/widgets/core/mwidgetcontroller.cpp \
$$MSRCDIR/corelib/widgets/core/mwidget.cpp \
- $$MSRCDIR/corelib/widgets/mwidgetmodel.cpp
+ $$MSRCDIR/corelib/widgets/mwidgetmodel.cpp \
+ $$MSRCDIR/corelib/scene/mscene.cpp \
# service classes
SOURCES += \
@@ -36,6 +38,7 @@ HEADERS += \
$$MSRCDIR/corelib/widgets/core/mwidget_p.h \
$$MSRCDIR/corelib/widgets/mwidgetmodel_p.h \
$$MSRCDIR/corelib/widgets/mobjectmenu.h \
+ $$MSRCDIR/corelib/scene/mscene.h \
$$MODEL_HEADERS
include(../common_bot.pri)
diff --git a/tests/ut_mappletinventoryview/ut_mappletinventoryview.pro b/tests/ut_mappletinventoryview/ut_mappletinventoryview.pro
index 8e1195b1..cc0ab64a 100644
--- a/tests/ut_mappletinventoryview/ut_mappletinventoryview.pro
+++ b/tests/ut_mappletinventoryview/ut_mappletinventoryview.pro
@@ -7,6 +7,7 @@ INCLUDEPATH += $$MSRCDIR/corelib/style
INCLUDEPATH += $$MSRCDIR/corelib/widgets
INCLUDEPATH += $$MSRCDIR/corelib/widgets/core
INCLUDEPATH += $$MSRCDIR/corelib/core
+INCLUDEPATH += $$MSRCDIR/corelib/scene
STYLE_HEADERS += $$MSRCDIR/extensions/style/mappletinventorystyle.h
MODEL_HEADERS += $$MSRCDIR/corelib/widgets/mwidgetmodel.h \
@@ -22,7 +23,8 @@ SOURCES += \
SOURCES += \
$$MSRCDIR/corelib/widgets/core/mwidgetcontroller.cpp \
$$MSRCDIR/corelib/widgets/core/mwidget.cpp \
- $$MSRCDIR/corelib/widgets/mwidgetmodel.cpp
+ $$MSRCDIR/corelib/widgets/mwidgetmodel.cpp \
+ $$MSRCDIR/corelib/scene/mscene.cpp \
# service classes
SOURCES += \
@@ -42,6 +44,7 @@ HEADERS += \
$$MSRCDIR/extensions/style/mappletinventorystyle.h \
$$MSRCDIR/corelib/widgets/mwidgetmodel_p.h \
$$MSRCDIR/corelib/widgets/mobjectmenu.h \
+ $$MSRCDIR/corelib/scene/mscene.h \
$$MODEL_HEADERS \
$$STYLE_HEADERS
diff --git a/tests/ut_mextensionarea/ut_mextensionarea.pro b/tests/ut_mextensionarea/ut_mextensionarea.pro
index 40989dfe..8e700160 100644
--- a/tests/ut_mextensionarea/ut_mextensionarea.pro
+++ b/tests/ut_mextensionarea/ut_mextensionarea.pro
@@ -3,14 +3,16 @@ include(../common_mextensions.pri)
INCLUDEPATH += \
$$MSRCDIR/corelib/widgets \
- $$MSRCDIR/corelib/style
+ $$MSRCDIR/corelib/style \
+ $$MSRCDIR/corelib/scene \
# unit test and unit classes
SOURCES += \
ut_mextensionarea.cpp \
$$MSRCDIR/extensions/applicationextension/mextensionarea.cpp \
$$MSRCDIR/corelib/widgets/core/mwidgetcontroller.cpp \
- $$MSRCDIR/corelib/widgets/core/mwidget.cpp
+ $$MSRCDIR/corelib/widgets/core/mwidget.cpp \
+ $$MSRCDIR/corelib/scene/mscene.cpp \
# service classes
SOURCES += \
@@ -24,6 +26,7 @@ HEADERS += \
$$MSRCDIR/extensions/mashup/mashup/mappletid.h \
$$MSRCDIR/corelib/widgets/core/mwidgetcontroller_p.h \
$$MSRCDIR/corelib/widgets/core/mwidget_p.h \
- $$MSRCDIR/corelib/widgets/mobjectmenu.h
+ $$MSRCDIR/corelib/widgets/mobjectmenu.h \
+ $$MSRCDIR/corelib/scene/mscene.h \
include(../common_bot.pri)
diff --git a/tests/ut_mmashupcanvas/ut_mmashupcanvas.pro b/tests/ut_mmashupcanvas/ut_mmashupcanvas.pro
index 13bfe8a4..a7680525 100644
--- a/tests/ut_mmashupcanvas/ut_mmashupcanvas.pro
+++ b/tests/ut_mmashupcanvas/ut_mmashupcanvas.pro
@@ -3,7 +3,8 @@ include(../common_mextensions.pri)
INCLUDEPATH += \
$$MSRCDIR/corelib/widgets \
- $$MSRCDIR/corelib/style
+ $$MSRCDIR/corelib/style \
+ $$MSRCDIR/corelib/scene \
# unit test and unit classes
SOURCES += \
@@ -11,7 +12,8 @@ SOURCES += \
$$MSRCDIR/extensions/mashup/mashup/mmashupcanvas.cpp \
$$MSRCDIR/corelib/widgets/core/mwidgetcontroller.cpp \
$$MSRCDIR/corelib/widgets/core/mwidget.cpp \
- $$MSRCDIR/extensions/applicationextension/mextensionarea.cpp
+ $$MSRCDIR/extensions/applicationextension/mextensionarea.cpp \
+ $$MSRCDIR/corelib/scene/mscene.cpp \
# service classes
SOURCES += \
@@ -25,6 +27,7 @@ HEADERS += \
$$MSRCDIR/extensions/mashup/mashup/mappletid.h \
$$MSRCDIR/corelib/widgets/core/mwidgetcontroller_p.h \
$$MSRCDIR/corelib/widgets/core/mwidget_p.h \
- $$MSRCDIR/corelib/widgets/mobjectmenu.h
+ $$MSRCDIR/corelib/widgets/mobjectmenu.h \
+ $$MSRCDIR/corelib/scene/mscene.h \
include(../common_bot.pri)
diff --git a/tests/ut_mpannableviewport/ut_mpannableviewport.pro b/tests/ut_mpannableviewport/ut_mpannableviewport.pro
index dc94aa5b..688d15bc 100644
--- a/tests/ut_mpannableviewport/ut_mpannableviewport.pro
+++ b/tests/ut_mpannableviewport/ut_mpannableviewport.pro
@@ -1,5 +1,7 @@
include(../common_top.pri)
-INCLUDEPATH += $$MSRCDIR/corelib/widgets
+INCLUDEPATH += \
+ $$MSRCDIR/corelib/widgets \
+ $$MSRCDIR/corelib/scene \
TARGET = ut_mpannableviewport
@@ -17,6 +19,7 @@ SOURCES += \
$$MSRCDIR/corelib/widgets/mpannablewidget.cpp \
$$MSRCDIR/corelib/widgets/mpannableviewportlayout.cpp \
$$MSRCDIR/corelib/widgets/mpannableviewport.cpp \
+ $$MSRCDIR/corelib/scene/mscene.cpp \
# unit test and unit classes
HEADERS += \
@@ -26,5 +29,6 @@ HEADERS += \
$$MSRCDIR/corelib/widgets/mpannableviewport.h \
$$MSRCDIR/corelib/widgets/core/mwidgetcontroller_p.h \
$$MSRCDIR/corelib/widgets/core/mwidget_p.h \
+ $$MSRCDIR/corelib/scene/mscene.h \
include(../common_bot.pri)
diff --git a/tests/ut_mpannablewidget/ut_mpannablewidget.cpp b/tests/ut_mpannablewidget/ut_mpannablewidget.cpp
index abbc11ec..3821daf6 100644
--- a/tests/ut_mpannablewidget/ut_mpannablewidget.cpp
+++ b/tests/ut_mpannablewidget/ut_mpannablewidget.cpp
@@ -62,20 +62,6 @@ struct PhysicsState {
};
PhysicsState *physicsState = 0;
-struct MouseGrabberState {
-
- MouseGrabberState() {
- grabbedMouse = false;
- ungrabbedMouse = false;
- }
-
- bool grabbedMouse;
- bool ungrabbedMouse;
-};
-MouseGrabberState *mouseGrabberState = 0;
-
-//Stubs
-
//Physics stubs:
void MPhysics2DPanning::start()
{
@@ -101,102 +87,6 @@ void MPhysics2DPanning::pointerRelease()
physicsState->pointerReleased = true;
}
-bool MPhysics2DPanning::inMotion() const
-{
- return physicsState->physicsIsMoving;
-}
-
-//QGraphicsObject stubs:
-void QGraphicsObject::grabGesture(Qt::GestureType, Qt::GestureFlags)
-{
-}
-
-//QGraphicsItem stubs:
-void QGraphicsItem::grabMouse()
-{
- mouseGrabberState->grabbedMouse = true;
-}
-
-void QGraphicsItem::ungrabMouse()
-{
- mouseGrabberState->ungrabbedMouse = true;
-}
-
-QGraphicsScene *QGraphicsItem::scene() const
-{
- return (QGraphicsScene*)1;
-}
-
-//QGraphiscScene stubs:
- QGraphicsItem* QGraphicsScene::mouseGrabberItem() const
-{
- return dummyItem;
-}
-
- QList<QGraphicsItem*> QGraphicsScene::items() const
-{
- QList<QGraphicsItem*> itemList;
- if (dummyItem) {
- itemList.append(dummyItem);
- }
- 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
{
@@ -217,7 +107,6 @@ void Ut_MPannableWidget::init()
{
dummyItem = new DummyGraphicsItem;
physicsState = new PhysicsState;
- mouseGrabberState = new MouseGrabberState;
widget = new MPannableWidget;
}
@@ -225,174 +114,9 @@ void Ut_MPannableWidget::cleanup()
{
delete widget;
delete physicsState;
- delete mouseGrabberState;
delete dummyItem;
}
-void Ut_MPannableWidget::mousePressAndReleaseAreDeliveredToGrabber()
-{
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- pressEvent.setButton(Qt::LeftButton);
- QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- releaseEvent.setButton(Qt::LeftButton);
-
- QTimerEvent timerEvent(1);
-
- widget->d_func()->glass->mousePressEvent(&pressEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
-
- widget->d_func()->pressDeliveryTimerId = 1;
- widget->d_func()->glass->timerEvent(&timerEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
- QVERIFY2(widget->d_func()->resentList.at(0).type == QEvent::GraphicsSceneMousePress, "Mouse press was not sent");
-
- widget->d_func()->glass->mouseReleaseEvent(&releaseEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
- QCOMPARE(dummyItem->mouseReleaseReceived, true);
-}
-
-void Ut_MPannableWidget::mouseMoveIsDelieveredToGrabberIfNoPanningIsRecognized()
-{
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- pressEvent.setButton(Qt::LeftButton);
- QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove);
- moveEvent.setButton(Qt::LeftButton);
- QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- releaseEvent.setButton(Qt::LeftButton);
-
- QTimerEvent timerEvent(1);
-
- widget->d_func()->glass->mousePressEvent(&pressEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
-
- widget->d_func()->pressDeliveryTimerId = 1;
- widget->d_func()->glass->timerEvent(&timerEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
- QVERIFY2(widget->d_func()->resentList.at(0).type == QEvent::GraphicsSceneMousePress, "Mouse press was not sent");
-
- widget->d_func()->glass->mouseMoveEvent(&moveEvent);
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
- QCOMPARE(dummyItem->mouseMoveReceived, true);
- QCOMPARE(dummyItem->mouseReleaseReceived, false);
-
- widget->d_func()->glass->mouseReleaseEvent(&releaseEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
- QCOMPARE(dummyItem->mouseReleaseReceived, true);
-}
-
-void Ut_MPannableWidget::mousePressWithNoLeftButtonIsIgnored()
-{
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- pressEvent.setButton(Qt::RightButton);
-
- widget->d_func()->glass->mousePressEvent(&pressEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
- QCOMPARE(widget->d_func()->pressDeliveryTimerId, 0);
- QVERIFY(pressEvent.isAccepted() == false);
-}
-
-void Ut_MPannableWidget::pannableViewportInsidePannableViewportIgnoresMousePress()
-{
- MPannableWidget *innerWidget = new MPannableWidget(widget);
-
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- pressEvent.setButton(Qt::LeftButton);
-
- innerWidget->d_func()->glass->mousePressEvent(&pressEvent);
-
- QCOMPARE(innerWidget->d_func()->mouseGrabber, (QGraphicsItem*)0);
- QCOMPARE(innerWidget->d_func()->pressDeliveryTimerId, 0);
- QVERIFY(pressEvent.isAccepted() == false);
-}
-
-void Ut_MPannableWidget::cancelEventStopPhysicsAndResetsStateOfWidget()
-{
- QPanGesture panGesture;
-
- QList<QGesture*> gestureList;
- gestureList.append(&panGesture);
- QGestureEvent event(gestureList);
-
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- pressEvent.setButton(Qt::LeftButton);
-
- QTimerEvent timerEvent(1);
-
-
- widget->d_func()->glass->mousePressEvent(&pressEvent); //mousePress delivered to glass,
- //delivery timer is started.
- widget->d_func()->pressDeliveryTimerId = 1;
- widget->d_func()->glass->timerEvent(&timerEvent); //timer expired, mouse press should be delivered to
- //the widget inside pannable widget.
-
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
-
- currentPanState = Qt::GestureStarted;
- widget->panGestureEvent(&event, &panGesture);
- QCOMPARE(physicsState->pointerPressed, true);
- QCOMPARE(physicsState->pointerMoved, true);
- QCOMPARE(physicsState->pointerReleased, false);
-
- QCOMPARE(mouseGrabberState->ungrabbedMouse, true); //pannable widget ungrabbed mouse;
- QCOMPARE(mouseGrabberState->grabbedMouse, true); //and grabbed it again later.
-
- MCancelEvent cancelEvent; //Sending cancel event
- widget->cancelEvent(&cancelEvent);
-
- mouseGrabberState->grabbedMouse = false;
- mouseGrabberState->ungrabbedMouse = false;
-
- QCOMPARE(physicsState->pointerReleased, true); //Pannable widget should reset it's state
- QCOMPARE(physicsState->physicsStopped, true); //after cancel event.
- QCOMPARE(mouseGrabberState->grabbedMouse, false);
-}
-
-void Ut_MPannableWidget::disabledWidgetShouldIgnoreMousePressAndPanEvents()
-{
- widget->setVerticalPanningPolicy(MPannableWidget::PanningAlwaysOff);
- widget->setHorizontalPanningPolicy(MPannableWidget::PanningAlwaysOff);
-
- QCOMPARE(physicsState->pointerPressed, false);
- QCOMPARE(physicsState->pointerMoved, false);
- QCOMPARE(physicsState->pointerReleased, true); //Disabling widget resets the state of physics.
- physicsState->pointerReleased = false; //Cleaning up the state tracker.
-
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- pressEvent.setButton(Qt::LeftButton);
-
- widget->d_func()->glass->mousePressEvent(&pressEvent);
-
- QCOMPARE(physicsState->pointerPressed, false);
- QCOMPARE(physicsState->pointerMoved, false);
- QCOMPARE(physicsState->pointerReleased, false);
-
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
- QCOMPARE(widget->d_func()->pressDeliveryTimerId, 0);
- QVERIFY(pressEvent.isAccepted() == false);
-
- QPanGesture panGesture;
-
- QList<QGesture*> gestureList;
- gestureList.append(&panGesture);
- QGestureEvent event(gestureList);
-
- currentPanState = Qt::GestureStarted;
- panGesture.setOffset(QPointF(100,0));
-
- widget->panGestureEvent(&event, &panGesture);
- QCOMPARE(physicsState->pointerPressed, false);
- QCOMPARE(physicsState->pointerMoved, false);
- QCOMPARE(physicsState->pointerReleased, false);
- QCOMPARE(event.isAccepted(&panGesture), false);
-}
-
void Ut_MPannableWidget::panGestureMovesPhysicsPointer()
{
QPanGesture panGesture;
@@ -443,37 +167,6 @@ void Ut_MPannableWidget::panGestureAgainstPanningDirectionIsIgnored()
QCOMPARE(event.isAccepted(&panGesture), false);
}
-void Ut_MPannableWidget::panGestureCancelsMouseEvents()
-{
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- QTimerEvent timerEvent(1);
-
- widget->glassMousePressEvent(&pressEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
-
- widget->d_func()->pressDeliveryTimerId = 1;
- widget->glassTimerEvent(&timerEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
- QVERIFY2(widget->d_func()->resentList.at(0).type == QEvent::GraphicsSceneMousePress, "Mouse press was not sent");
-
- QPanGesture panGesture;
-
- QList<QGesture*> gestureList;
- gestureList.append(&panGesture);
- QGestureEvent event(gestureList);
-
- currentPanState = Qt::GestureStarted;
- widget->panGestureEvent(&event, &panGesture);
- QCOMPARE(physicsState->pointerPressed, true);
- QCOMPARE(physicsState->pointerMoved, true);
- QCOMPARE(physicsState->pointerReleased, false);
-
- QCOMPARE(dummyItem->cancelReceived, true);
-}
-
class CustomPhysics : public MPhysics2DPanning
{
public:
@@ -513,79 +206,4 @@ void Ut_MPannableWidget::settingPhysicsToNULLShouldNotBreakTheWidget()
}
-void Ut_MPannableWidget::ignoredPanGestureShouldNotCancelMouseEvents()
-{
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- pressEvent.setButton(Qt::LeftButton);
- QGraphicsSceneMouseEvent moveEvent(QEvent::GraphicsSceneMouseMove);
- moveEvent.setButton(Qt::LeftButton);
- QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- releaseEvent.setButton(Qt::LeftButton);
-
- QTimerEvent timerEvent(1);
-
- widget->d_func()->glass->mousePressEvent(&pressEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
-
- widget->d_func()->pressDeliveryTimerId = 1;
- widget->d_func()->glass->timerEvent(&timerEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
- QVERIFY2(widget->d_func()->resentList.at(0).type == QEvent::GraphicsSceneMousePress, "Mouse press was not sent");
-
- QPanGesture panGesture;
- panGesture.setOffset(QPointF(50,0));
-
- QList<QGesture*> gestureList;
- gestureList.append(&panGesture);
- QGestureEvent event(gestureList);
-
- currentPanState = Qt::GestureStarted;
- widget->panGestureEvent(&event, &panGesture);
- QCOMPARE(physicsState->pointerPressed, false);
- QCOMPARE(physicsState->pointerMoved, false);
- QCOMPARE(physicsState->pointerReleased, false);
-
- widget->d_func()->glass->mouseMoveEvent(&moveEvent);
- QCOMPARE(widget->d_func()->mouseGrabber, dummyItem);
- QCOMPARE(dummyItem->mouseMoveReceived, true);
- QCOMPARE(dummyItem->mouseReleaseReceived, false);
-
- widget->d_func()->glass->cancelEvent(new MCancelEvent());
- widget->d_func()->glass->mouseReleaseEvent(&releaseEvent);
-
- QCOMPARE(widget->d_func()->mouseGrabber, (QGraphicsItem*)0);
- QCOMPARE(dummyItem->mouseReleaseReceived, true);
-
- QCOMPARE(dummyItem->cancelReceived, false);
-}
-
-void Ut_MPannableWidget::tapAndHoldGestureShouldBeGrabbedIfViewportIsMoving()
-{
- QTapAndHoldGesture tapAndHoldGesture;
-
- QList<QGesture*> gestureList;
- gestureList.append(&tapAndHoldGesture);
- QGestureEvent gestureEvent(gestureList);
-
- physicsState->physicsIsMoving = true;
-
- widget->d_func()->glass->tapAndHoldGestureEvent(&gestureEvent, &tapAndHoldGesture);
-
- QCOMPARE(gestureEvent.isAccepted(&tapAndHoldGesture), true);
-
- physicsState->physicsIsMoving = false;
-
- widget->d_func()->glass->tapAndHoldGestureEvent(&gestureEvent, &tapAndHoldGesture);
-
- QCOMPARE(gestureEvent.isAccepted(&tapAndHoldGesture), false);
-}
-
-void Ut_MPannableWidget::testPanThreshold()
-{
- widget->setPanThreshold(100);
- QCOMPARE(widget->panThreshold(), qreal(0));
-}
-
QTEST_APPLESS_MAIN(Ut_MPannableWidget);
diff --git a/tests/ut_mpannablewidget/ut_mpannablewidget.h b/tests/ut_mpannablewidget/ut_mpannablewidget.h
index f2ad56c1..88ac8a17 100644
--- a/tests/ut_mpannablewidget/ut_mpannablewidget.h
+++ b/tests/ut_mpannablewidget/ut_mpannablewidget.h
@@ -42,24 +42,12 @@ private slots:
void init();
void cleanup();
- void mousePressAndReleaseAreDeliveredToGrabber();
- void mouseMoveIsDelieveredToGrabberIfNoPanningIsRecognized();
- void mousePressWithNoLeftButtonIsIgnored();
- void cancelEventStopPhysicsAndResetsStateOfWidget();
- void pannableViewportInsidePannableViewportIgnoresMousePress();
- void disabledWidgetShouldIgnoreMousePressAndPanEvents();
-
void usingCustomPhysics();
void settingNewPhysicsShouldEmitPhysicsChangeSignal();
void settingPhysicsToNULLShouldNotBreakTheWidget();
void panGestureMovesPhysicsPointer();
void panGestureAgainstPanningDirectionIsIgnored();
- void panGestureCancelsMouseEvents();
- void ignoredPanGestureShouldNotCancelMouseEvents();
-
- void tapAndHoldGestureShouldBeGrabbedIfViewportIsMoving();
- void testPanThreshold();
private:
MPannableWidget *widget;
diff --git a/tests/ut_mpanrecognizer/ut_mpanrecognizer.cpp b/tests/ut_mpanrecognizer/ut_mpanrecognizer.cpp
index d2c056d7..f3d7b05f 100644
--- a/tests/ut_mpanrecognizer/ut_mpanrecognizer.cpp
+++ b/tests/ut_mpanrecognizer/ut_mpanrecognizer.cpp
@@ -23,7 +23,8 @@
#include "mpangesture_p.h"
-#include <QGraphicsSceneMouseEvent>
+#include <QGraphicsView>
+#include <QMouseEvent>
#include <QtTest/QtTest>
#include <MApplication>
@@ -67,11 +68,15 @@ Qt::GestureState QGesture::state() const
}
MApplication *app;
+QGraphicsView *view;
void Ut_MPanRecognizer::initTestCase()
{
static int argc = 1;
static char *app_name[1] = { (char *) "./ut_mpanrecognizer" };
app = new MApplication(argc, app_name);
+
+ view = new QGraphicsView();
+ view->show();
}
void Ut_MPanRecognizer::cleanupTestCase()
@@ -92,25 +97,14 @@ void Ut_MPanRecognizer::cleanup()
void Ut_MPanRecognizer::testCreateGesture()
{
- panGesture = static_cast<MPanGesture*>(recognizer->create(this));
+ panGesture = static_cast<MPanGesture*>(recognizer->create(view));
}
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));
+ QMouseEvent pressEvent(QEvent::MouseButtonPress,QPoint(0,0), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent(QEvent::MouseMove,QPoint(0,100), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent releaseEvent(QEvent::MouseButtonRelease,QPoint(0,100), Qt::LeftButton, Qt::LeftButton, 0);
QGestureRecognizer::Result currentState;
currentState = recognizer->recognize(panGesture, 0, &pressEvent);
@@ -128,15 +122,8 @@ void Ut_MPanRecognizer::testRecognize()
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));
+ QMouseEvent pressEvent(QEvent::MouseButtonPress,QPoint(0,0), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent releaseEvent(QEvent::MouseButtonRelease,QPoint(0,0), Qt::LeftButton, Qt::LeftButton, 0);
QGestureRecognizer::Result currentState;
currentState = recognizer->recognize(panGesture, 0, &pressEvent);
@@ -148,36 +135,20 @@ void Ut_MPanRecognizer::testTapIsNotRecognizedAsPan()
void Ut_MPanRecognizer::testTheMovementInDirectionOtherThanRecognizedIsZeroed()
{
- 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));
+ QMouseEvent pressEvent(QEvent::MouseButtonPress,QPoint(0,0), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent1(QEvent::MouseMove,QPoint(0,100), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent2(QEvent::MouseMove,QPoint(30,100), Qt::LeftButton, Qt::LeftButton, 0);
QGestureRecognizer::Result currentState;
currentState = recognizer->recognize(panGesture, 0, &pressEvent);
QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
- currentState = recognizer->recognize(panGesture, 0, &moveEvent);
+ currentState = recognizer->recognize(panGesture, 0, &moveEvent1);
QCOMPARE( currentState, QGestureRecognizer::TriggerGesture);
//Artificially setting state of QGesture object.
currentGestureState = Qt::GestureUpdated;
-
- moveEvent.setPos(QPointF(30,100));
- moveEvent.setScenePos(QPointF(30,100));
- moveEvent.setScreenPos(QPoint(30,100));
-
- recognizer->recognize(panGesture, 0, &moveEvent);
+ recognizer->recognize(panGesture, 0, &moveEvent2);
QCOMPARE( panGesture->offset().x(), 0.0);
}
diff --git a/tests/ut_mscene/ut_mscene.cpp b/tests/ut_mscene/ut_mscene.cpp
index 31c97509..99659c82 100644
--- a/tests/ut_mscene/ut_mscene.cpp
+++ b/tests/ut_mscene/ut_mscene.cpp
@@ -18,23 +18,94 @@
****************************************************************************/
#include <QtTest/QtTest>
-#include <QList>
-#include <QGraphicsItem>
#include <QPainter>
-#include <QTime>
-#include <mapplication.h>
-#include <mdeviceprofile.h>
-#include <mtheme.h>
-#include "ut_mscene.h"
-#include <MButton>
+#include <QImage>
+#include <QGraphicsSceneMouseEvent>
+#include <QGesture>
+#include <QGestureEvent>
+#include "mwidget.h"
+#include "mbutton.h"
+#include "ut_mscene.h"
+#include "mscene_p.h"
#define MAX_PARAMS 10
-void Ut_MScene::initTestCase()
+class EventTester : public MWidget
{
+public:
+ EventTester() {
+ mousePressReceived = false;
+ mouseMoveReceived = false;
+ mouseReleaseReceived = false;
+ cancelReceived = false;
+ touchBeginReceived = false;
+ touchUpdateReceived = false;
+ touchEndReceived = false;
+
+ setAcceptTouchEvents(true);
+ }
+
+ bool mousePressReceived;
+ bool mouseMoveReceived;
+ bool mouseReleaseReceived;
+ bool cancelReceived;
+ bool touchBeginReceived;
+ bool touchUpdateReceived;
+ bool touchEndReceived;
+
+ void mousePressEvent(QGraphicsSceneMouseEvent */*event*/)
+ {
+ mousePressReceived = true;
+ }
+
+ void mouseMoveEvent(QGraphicsSceneMouseEvent */*event*/)
+ {
+ mouseMoveReceived = true;
+ }
+
+ void mouseReleaseEvent(QGraphicsSceneMouseEvent */*event*/)
+ {
+ mouseReleaseReceived = true;
+ }
+
+ void cancelEvent(MCancelEvent */*event*/)
+ {
+ cancelReceived = true;
+ }
+
+ bool event(QEvent *event)
+ {
+ switch (event->type())
+ {
+ case QEvent::TouchBegin:
+ touchBeginReceived = true;
+ event->accept();
+ return true;
+ case QEvent::TouchUpdate:
+ touchUpdateReceived = true;
+ event->accept();
+ return true;
+ case QEvent::TouchEnd:
+ touchEndReceived = true;
+ event->accept();
+ return true;
+ default:
+ return MWidget::event(event);
+ }
+ }
+};
+EventTester *eventTester = 0;
+Qt::GestureState currentPanState = Qt::NoGesture;
+Qt::GestureState QGesture::state() const
+{
+ return currentPanState;
+}
+
+void Ut_MScene::initTestCase()
+{
}
void Ut_MScene::cleanupTestCase()
{
@@ -56,7 +127,11 @@ void Ut_MScene::init()
x = 6;
app = new MApplication(x, argv);
+ eventTester = new EventTester;
m_subject = new MScene();
+
+ m_subject->addItem(eventTester);
+ eventTester->resize(1000,1000);
}
void Ut_MScene::cleanup()
@@ -86,4 +161,307 @@ void Ut_MScene::drawForeground()
QVERIFY(img1 == img1);
}
+void Ut_MScene::mousePressIsDelayed()
+{
+ QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress);
+ mousePress.setButton(Qt::LeftButton);
+ mousePress.setPos(QPointF(100,100));
+ mousePress.setScreenPos(QPoint(100,100));
+ mousePress.setScenePos(QPointF(100,100));
+
+ QGraphicsSceneMouseEvent mouseRelease(QEvent::GraphicsSceneMouseRelease);
+ mouseRelease.setButton(Qt::LeftButton);
+ mouseRelease.setPos(QPointF(100,100));
+ mouseRelease.setScreenPos(QPoint(100,100));
+ mouseRelease.setScenePos(QPointF(100,100));
+
+ QApplication::sendEvent(m_subject,&mousePress);
+
+ QCOMPARE(eventTester->mousePressReceived, false);
+ QCOMPARE(eventTester->mouseMoveReceived, false);
+ QCOMPARE(eventTester->mouseReleaseReceived, false);
+
+ // Initial press timer has been started.
+ QVERIFY(m_subject->d_func()->initialPressTimer->isActive());
+ m_subject->d_func()->initialPressTimer->stop();
+ m_subject->d_func()->_q_initialPressDeliveryTimeout();
+
+ QCOMPARE(eventTester->mousePressReceived, true);
+ QCOMPARE(eventTester->mouseMoveReceived, false);
+ QCOMPARE(eventTester->mouseReleaseReceived, false);
+ eventTester->mousePressReceived = false;
+}
+
+void Ut_MScene::touchBeginIsDelayed()
+{
+ QList<QTouchEvent::TouchPoint> touchList;
+ QTouchEvent::TouchPoint touchPoint;
+ touchPoint.setState(Qt::TouchPointPressed);
+ touchPoint.setPos(QPointF(100,100));
+ touchPoint.setScenePos(QPointF(100,100));
+ touchPoint.setScreenPos(QPoint(100,100));
+
+ touchList.append(touchPoint);
+
+ QTouchEvent touchEvent(QEvent::TouchBegin, QTouchEvent::TouchPad, Qt::NoModifier, Qt::TouchPointPressed, touchList);
+
+ QApplication::sendEvent(m_subject,&touchEvent);
+
+ QCOMPARE(eventTester->touchBeginReceived, false);
+ QCOMPARE(eventTester->touchUpdateReceived, false);
+ QCOMPARE(eventTester->touchEndReceived, false);
+
+ // Initial press timer has been started.
+ QVERIFY(m_subject->d_func()->initialPressTimer->isActive());
+ m_subject->d_func()->initialPressTimer->stop();
+ m_subject->d_func()->_q_initialPressDeliveryTimeout();
+
+ QCOMPARE(eventTester->touchBeginReceived, true);
+ QCOMPARE(eventTester->touchUpdateReceived, false);
+ QCOMPARE(eventTester->touchEndReceived, false);
+}
+
+void Ut_MScene::mousePressAndReleaseAreDeliveredToGrabber()
+{
+ QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress);
+ mousePress.setButton(Qt::LeftButton);
+ mousePress.setPos(QPointF(100,100));
+ mousePress.setScreenPos(QPoint(100,100));
+ mousePress.setScenePos(QPointF(100,100));
+
+ QGraphicsSceneMouseEvent mouseRelease(QEvent::GraphicsSceneMouseRelease);
+ mouseRelease.setButton(Qt::LeftButton);
+ mouseRelease.setPos(QPointF(100,100));
+ mouseRelease.setScreenPos(QPoint(100,100));
+ mouseRelease.setScenePos(QPointF(100,100));
+
+ QApplication::sendEvent(m_subject,&mousePress);
+
+ // Initial press timer has been started.
+ QVERIFY(m_subject->d_func()->initialPressTimer->isActive());
+ m_subject->d_func()->initialPressTimer->stop();
+ m_subject->d_func()->_q_initialPressDeliveryTimeout();
+
+ QCOMPARE(eventTester->mousePressReceived, true);
+ QCOMPARE(eventTester->mouseMoveReceived, false);
+ QCOMPARE(eventTester->mouseReleaseReceived, false);
+ eventTester->mousePressReceived = false;
+
+ QApplication::sendEvent(m_subject,&mouseRelease);
+
+ QCOMPARE(eventTester->mousePressReceived, false);
+ QCOMPARE(eventTester->mouseMoveReceived, false);
+ QCOMPARE(eventTester->mouseReleaseReceived, true);
+
+}
+
+void Ut_MScene::touchBeginAndEndAreDeliveredToGrabber()
+{
+ QList<QTouchEvent::TouchPoint> touchBeginList;
+ QTouchEvent::TouchPoint touchPointBegin;
+ touchPointBegin.setState(Qt::TouchPointPressed);
+ touchPointBegin.setPos(QPointF(100,100));
+ touchPointBegin.setScenePos(QPointF(100,100));
+ touchPointBegin.setScreenPos(QPoint(100,100));
+ touchBeginList.append(touchPointBegin);
+ QTouchEvent touchBeginEvent(QEvent::TouchBegin, QTouchEvent::TouchPad, Qt::NoModifier, Qt::TouchPointPressed, touchBeginList);
+
+ QList<QTouchEvent::TouchPoint> touchEndList;
+ QTouchEvent::TouchPoint touchPointEnd;
+ touchPointEnd.setState(Qt::TouchPointReleased);
+ touchPointEnd.setPos(QPointF(100,100));
+ touchPointEnd.setScenePos(QPointF(100,100));
+ touchPointEnd.setScreenPos(QPoint(100,100));
+ touchEndList.append(touchPointEnd);
+ QTouchEvent touchEndEvent(QEvent::TouchEnd, QTouchEvent::TouchPad, Qt::NoModifier, Qt::TouchPointReleased, touchEndList);
+
+ QApplication::sendEvent(m_subject,&touchBeginEvent);
+
+ // Initial press timer has been started.
+ QVERIFY(m_subject->d_func()->initialPressTimer->isActive());
+ m_subject->d_func()->initialPressTimer->stop();
+ m_subject->d_func()->_q_initialPressDeliveryTimeout();
+
+ QCOMPARE(eventTester->touchBeginReceived, true);
+ QCOMPARE(eventTester->touchUpdateReceived, false);
+ QCOMPARE(eventTester->touchEndReceived, false);
+ eventTester->touchBeginReceived = false;
+
+ QApplication::sendEvent(m_subject,&touchEndEvent);
+
+ QCOMPARE(eventTester->touchBeginReceived, false);
+ QCOMPARE(eventTester->touchUpdateReceived, false);
+ QCOMPARE(eventTester->touchEndReceived, true);
+}
+
+void Ut_MScene::mouseMoveIsDelieveredToGrabberIfNoGestureIsRecognized()
+{
+ QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress);
+ mousePress.setButton(Qt::LeftButton);
+ mousePress.setPos(QPointF(100,100));
+ mousePress.setScreenPos(QPoint(100,100));
+ mousePress.setScenePos(QPointF(100,100));
+
+ QGraphicsSceneMouseEvent mouseMove(QEvent::GraphicsSceneMouseMove);
+ mouseMove.setButton(Qt::LeftButton);
+ mouseMove.setPos(QPointF(150,100));
+ mouseMove.setScreenPos(QPoint(150,100));
+ mouseMove.setScenePos(QPointF(150,100));
+
+ QApplication::sendEvent(m_subject,&mousePress);
+
+ //Initial press timer has been started.
+ QVERIFY(m_subject->d_func()->initialPressTimer->isActive());
+ m_subject->d_func()->initialPressTimer->stop();
+ m_subject->d_func()->_q_initialPressDeliveryTimeout();
+
+ QCOMPARE(eventTester->mousePressReceived, true);
+ QCOMPARE(eventTester->mouseMoveReceived, false);
+ QCOMPARE(eventTester->mouseReleaseReceived, false);
+ eventTester->mousePressReceived = false;
+
+ QApplication::sendEvent(m_subject,&mouseMove);
+
+ QCOMPARE(eventTester->mousePressReceived, false);
+ QCOMPARE(eventTester->mouseMoveReceived, true);
+ QCOMPARE(eventTester->mouseReleaseReceived, false);
+}
+
+void Ut_MScene::mouseReleaseResetsStateOfEventEater()
+{
+ QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress);
+ mousePress.setButton(Qt::LeftButton);
+ mousePress.setPos(QPointF(100,100));
+ mousePress.setScreenPos(QPoint(100,100));
+ mousePress.setScenePos(QPointF(100,100));
+
+ QGraphicsSceneMouseEvent mouseRelease(QEvent::GraphicsSceneMouseRelease);
+ mouseRelease.setButton(Qt::LeftButton);
+ mouseRelease.setPos(QPointF(100,100));
+ mouseRelease.setScreenPos(QPoint(100,100));
+ mouseRelease.setScenePos(QPointF(100,100));
+
+ QApplication::sendEvent(m_subject,&mousePress);
+
+ //Initial press timer has been started.
+ QVERIFY(m_subject->d_func()->initialPressTimer->isActive());
+ m_subject->d_func()->initialPressTimer->stop();
+ m_subject->d_func()->_q_initialPressDeliveryTimeout();
+
+ QCOMPARE(eventTester->mousePressReceived, true);
+ QCOMPARE(eventTester->mouseMoveReceived, false);
+ QCOMPARE(eventTester->mouseReleaseReceived, false);
+ eventTester->mousePressReceived = false;
+
+ QPanGesture panGesture;
+ QList<QGesture*> gestureList;
+ gestureList.append(&panGesture);
+ QGestureEvent gestureEvent(gestureList);
+ currentPanState = Qt::GestureStarted;
+
+ QApplication::sendEvent(m_subject,&gestureEvent);
+ m_subject->d_func()->notifyChildRequestedMouseCancel();
+
+ currentPanState = Qt::GestureFinished;
+ QApplication::sendEvent(m_subject,&gestureEvent);
+
+ QCOMPARE(m_subject->mouseGrabberItem(), m_subject->d_func()->eventEater);
+
+ QApplication::sendEvent(m_subject,&mouseRelease);
+
+ QVERIFY(m_subject->mouseGrabberItem() != m_subject->d_func()->eventEater);
+}
+
+void Ut_MScene::panGestureCancelsMouseEvents()
+{
+ QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress);
+ mousePress.setButton(Qt::LeftButton);
+ mousePress.setPos(QPointF(100,100));
+ mousePress.setScreenPos(QPoint(100,100));
+ mousePress.setScenePos(QPointF(100,100));
+
+ QGraphicsSceneMouseEvent mouseRelease(QEvent::GraphicsSceneMouseRelease);
+ mouseRelease.setButton(Qt::LeftButton);
+ mouseRelease.setPos(QPointF(100,100));
+ mouseRelease.setScreenPos(QPoint(100,100));
+ mouseRelease.setScenePos(QPointF(100,100));
+
+ QApplication::sendEvent(m_subject,&mousePress);
+
+ //Initial press timer has been started.
+ QVERIFY(m_subject->d_func()->initialPressTimer->isActive());
+ m_subject->d_func()->initialPressTimer->stop();
+ m_subject->d_func()->_q_initialPressDeliveryTimeout();
+
+ QCOMPARE(eventTester->mousePressReceived, true);
+ QCOMPARE(eventTester->mouseMoveReceived, false);
+ QCOMPARE(eventTester->mouseReleaseReceived, false);
+ eventTester->mousePressReceived = false;
+
+ QPanGesture panGesture;
+ QList<QGesture*> gestureList;
+ gestureList.append(&panGesture);
+ QGestureEvent gestureEvent(gestureList);
+ currentPanState = Qt::GestureStarted;
+
+ QApplication::sendEvent(m_subject,&gestureEvent);
+
+ m_subject->d_func()->notifyChildRequestedMouseCancel();
+
+ currentPanState = Qt::GestureFinished;
+ QApplication::sendEvent(m_subject,&gestureEvent);
+
+ QCOMPARE(m_subject->mouseGrabberItem(), m_subject->d_func()->eventEater);
+
+ QApplication::sendEvent(m_subject,&mouseRelease);
+ QCOMPARE(eventTester->mousePressReceived, false);
+ QCOMPARE(eventTester->mouseMoveReceived, false);
+ QCOMPARE(eventTester->mouseReleaseReceived, false);
+ QCOMPARE(eventTester->cancelReceived, true);
+}
+
+void Ut_MScene::ignoredGestureShouldNotCancelMouseEvents()
+{
+ QGraphicsSceneMouseEvent mousePress(QEvent::GraphicsSceneMousePress);
+ mousePress.setButton(Qt::LeftButton);
+ mousePress.setPos(QPointF(100,100));
+ mousePress.setScreenPos(QPoint(100,100));
+ mousePress.setScenePos(QPointF(100,100));
+
+ QGraphicsSceneMouseEvent mouseRelease(QEvent::GraphicsSceneMouseRelease);
+ mouseRelease.setButton(Qt::LeftButton);
+ mouseRelease.setPos(QPointF(100,100));
+ mouseRelease.setScreenPos(QPoint(100,100));
+ mouseRelease.setScenePos(QPointF(100,100));
+
+ QApplication::sendEvent(m_subject,&mousePress);
+
+ //Initial press timer has been started.
+ QVERIFY(m_subject->d_func()->initialPressTimer->isActive());
+ m_subject->d_func()->initialPressTimer->stop();
+ m_subject->d_func()->_q_initialPressDeliveryTimeout();
+
+ QCOMPARE(eventTester->mousePressReceived, true);
+ QCOMPARE(eventTester->mouseMoveReceived, false);
+ QCOMPARE(eventTester->mouseReleaseReceived, false);
+ eventTester->mousePressReceived = false;
+
+ QPanGesture panGesture;
+ QList<QGesture*> gestureList;
+ gestureList.append(&panGesture);
+ QGestureEvent gestureEvent(gestureList);
+ currentPanState = Qt::GestureStarted;
+
+ QApplication::sendEvent(m_subject,&gestureEvent);
+
+ currentPanState = Qt::GestureFinished;
+ QApplication::sendEvent(m_subject,&gestureEvent);
+
+ QApplication::sendEvent(m_subject,&mouseRelease);
+ QCOMPARE(eventTester->mousePressReceived, false);
+ QCOMPARE(eventTester->mouseMoveReceived, false);
+ QCOMPARE(eventTester->mouseReleaseReceived, true);
+ QCOMPARE(eventTester->cancelReceived, false);
+}
+
QTEST_APPLESS_MAIN(Ut_MScene)
diff --git a/tests/ut_mscene/ut_mscene.h b/tests/ut_mscene/ut_mscene.h
index 2d974470..f000f31c 100644
--- a/tests/ut_mscene/ut_mscene.h
+++ b/tests/ut_mscene/ut_mscene.h
@@ -22,7 +22,7 @@
#include "mapplication.h"
#include <QObject>
#include <QtTest/QtTest>
-#include <mscene.h>
+#include "mscene.h"
class Ut_MScene : public QObject
{
@@ -35,7 +35,19 @@ private slots:
void cleanupTestCase();
void drawForeground();
+ void mousePressIsDelayed();
+ void touchBeginIsDelayed();
+
+ void mousePressAndReleaseAreDeliveredToGrabber();
+ void touchBeginAndEndAreDeliveredToGrabber();
+ void mouseMoveIsDelieveredToGrabberIfNoGestureIsRecognized();
+ void mouseReleaseResetsStateOfEventEater();
+
+ void panGestureCancelsMouseEvents();
+ void ignoredGestureShouldNotCancelMouseEvents();
+
private:
+
MApplication *app;
MScene *m_subject;
};
diff --git a/tests/ut_mscene/ut_mscene.pro b/tests/ut_mscene/ut_mscene.pro
index 9a515819..f9e8c8ad 100644
--- a/tests/ut_mscene/ut_mscene.pro
+++ b/tests/ut_mscene/ut_mscene.pro
@@ -2,30 +2,19 @@ include(../common_top.pri)
TARGET = ut_mscene
-TEST_SOURCES = \
+INCLUDEPATH += \
+ $$MSRCDIR/corelib/scene \
support_files.files += \
ut_mscene_image.svg \
ut_mscene_template.css \
-# unit test and unit
SOURCES += \
+ $$MSRCDIR/corelib/scene/mscene.cpp \
ut_mscene.cpp \
-# base classes
-SOURCES += \
-
-# service classes
-SOURCES += \
-
-# unit test and unit
HEADERS += \
ut_mscene.h \
-
-# base classes
-HEADERS += \
-
-# service classes
-HEADERS += \
+ $$MSRCDIR/corelib/scene/mscene.h \
include(../common_bot.pri)
diff --git a/tests/ut_mswiperecognizer/ut_mswiperecognizer.cpp b/tests/ut_mswiperecognizer/ut_mswiperecognizer.cpp
index 824c1534..65ec460f 100644
--- a/tests/ut_mswiperecognizer/ut_mswiperecognizer.cpp
+++ b/tests/ut_mswiperecognizer/ut_mswiperecognizer.cpp
@@ -25,7 +25,7 @@
#include <MApplication>
-#include <QGraphicsSceneMouseEvent>
+#include <QMouseEvent>
#include <QtTest/QtTest>
@@ -103,15 +103,8 @@ void Ut_MSwipeRecognizer::testCreateGesture()
void Ut_MSwipeRecognizer::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(55,0));
- moveEvent.setScenePos(QPointF(55,0));
- moveEvent.setScreenPos(QPoint(55,0));
+ QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(0,0), QPoint(0,0), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent(QEvent::MouseMove, QPoint(100,0), QPoint(100,0), Qt::LeftButton, Qt::LeftButton, 0);
QGestureRecognizer::Result currentState;
currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
@@ -119,21 +112,12 @@ void Ut_MSwipeRecognizer::testRecognize()
currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
QCOMPARE( currentState, QGestureRecognizer::TriggerGesture);
-
}
void Ut_MSwipeRecognizer::testFastTap()
{
-
- QGraphicsSceneMouseEvent pressEvent(QEvent::GraphicsSceneMousePress);
- pressEvent.setPos(QPointF(0,0));
- pressEvent.setScenePos(QPointF(0,0));
- pressEvent.setScreenPos(QPoint(0,0));
-
- QGraphicsSceneMouseEvent releaseEvent(QEvent::GraphicsSceneMouseRelease);
- releaseEvent.setPos(QPointF(0,0));
- releaseEvent.setScenePos(QPointF(0,0));
- releaseEvent.setScreenPos(QPoint(0,0));
+ QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(0,0), QPoint(0,0), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(0,0), QPoint(0,0), Qt::LeftButton, Qt::LeftButton, 0);
QGestureRecognizer::Result currentState;
currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
@@ -145,15 +129,8 @@ void Ut_MSwipeRecognizer::testFastTap()
void Ut_MSwipeRecognizer::testTimedout()
{
- 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(30,0));
- moveEvent.setScenePos(QPointF(30,0));
- moveEvent.setScreenPos(QPoint(30,0));
+ QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(0,0), QPoint(0,0), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent(QEvent::MouseMove, QPoint(30,0), QPoint(30,0), Qt::LeftButton, Qt::LeftButton, 0);
QGestureRecognizer::Result currentState;
currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
@@ -168,46 +145,31 @@ void Ut_MSwipeRecognizer::testTimedout()
void Ut_MSwipeRecognizer::testZigzagged()
{
- 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(55,0));
- moveEvent.setScenePos(QPointF(55,0));
- moveEvent.setScreenPos(QPoint(55,0));
+ QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(0,0), QPoint(0,0), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent1(QEvent::MouseMove, QPoint(55,0), QPoint(55,0), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent2(QEvent::MouseMove, QPoint(-100,0), QPoint(-100,0), Qt::LeftButton, Qt::LeftButton, 0);
QGestureRecognizer::Result currentState;
currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
- currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
+ currentState = recognizer->recognize(swipeGesture, 0, &moveEvent2);
QCOMPARE( currentState, QGestureRecognizer::TriggerGesture);
- moveEvent.setPos(QPointF(-100,0));
- moveEvent.setScenePos(QPointF(-100,0));
- moveEvent.setScreenPos(QPoint(-100,0));
-
currentGestureState = Qt::GestureStarted;
- currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
+ currentState = recognizer->recognize(swipeGesture, 0, &moveEvent2);
QCOMPARE( currentState, QGestureRecognizer::CancelGesture);
}
void Ut_MSwipeRecognizer::testSnappingToRightAngles()
{
-
- 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(100,10));
- moveEvent.setScenePos(QPointF(100,10));
- moveEvent.setScreenPos(QPoint(100,10));
+ QMouseEvent pressEvent(QEvent::MouseButtonPress,QPoint(0,0), QPoint(0,0), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent1(QEvent::MouseMove, QPoint(100,10), QPoint(100,10), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent2(QEvent::MouseMove, QPoint(10,-100), QPoint(10,-100), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent3(QEvent::MouseMove, QPoint(-100,-10), QPoint(-100,-10), Qt::LeftButton, Qt::LeftButton, 0);
+ QMouseEvent moveEvent4(QEvent::MouseMove, QPoint(10,100), QPoint(10,100), Qt::LeftButton, Qt::LeftButton, 0);
currentGestureState = Qt::NoGesture;
@@ -215,7 +177,7 @@ void Ut_MSwipeRecognizer::testSnappingToRightAngles()
currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
- currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
+ currentState = recognizer->recognize(swipeGesture, 0, &moveEvent1);
QCOMPARE( currentState, QGestureRecognizer::TriggerGesture);
QCOMPARE( swipeGesture->swipeAngle(), 0.0);
@@ -223,14 +185,10 @@ void Ut_MSwipeRecognizer::testSnappingToRightAngles()
currentGestureState = Qt::NoGesture;
- moveEvent.setPos(QPointF(10,-100));
- moveEvent.setScenePos(QPointF(10,-100));
- moveEvent.setScreenPos(QPoint(10,-100));
-
currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
- currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
+ currentState = recognizer->recognize(swipeGesture, 0, &moveEvent2);
QCOMPARE( currentState, QGestureRecognizer::TriggerGesture);
QCOMPARE( swipeGesture->swipeAngle(), 90.0);
@@ -238,14 +196,10 @@ void Ut_MSwipeRecognizer::testSnappingToRightAngles()
currentGestureState = Qt::NoGesture;
- moveEvent.setPos(QPointF(-100,-10));
- moveEvent.setScenePos(QPointF(-100,-10));
- moveEvent.setScreenPos(QPoint(-100,-10));
-
currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
- currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
+ currentState = recognizer->recognize(swipeGesture, 0, &moveEvent3);
QCOMPARE( currentState, QGestureRecognizer::TriggerGesture);
QCOMPARE( swipeGesture->swipeAngle(), 180.0);
@@ -253,14 +207,10 @@ void Ut_MSwipeRecognizer::testSnappingToRightAngles()
currentGestureState = Qt::NoGesture;
- moveEvent.setPos(QPointF(10,100));
- moveEvent.setScenePos(QPointF(10,100));
- moveEvent.setScreenPos(QPoint(10,100));
-
currentState = recognizer->recognize(swipeGesture, 0, &pressEvent);
QCOMPARE( currentState, QGestureRecognizer::MayBeGesture);
- currentState = recognizer->recognize(swipeGesture, 0, &moveEvent);
+ currentState = recognizer->recognize(swipeGesture, 0, &moveEvent4);
QCOMPARE( currentState, QGestureRecognizer::TriggerGesture);
QCOMPARE( swipeGesture->swipeAngle(), 270.0);
}
diff --git a/tests/ut_mtoolbar/ut_mtoolbar.pro b/tests/ut_mtoolbar/ut_mtoolbar.pro
index d7eb10a1..214a3edf 100644
--- a/tests/ut_mtoolbar/ut_mtoolbar.pro
+++ b/tests/ut_mtoolbar/ut_mtoolbar.pro
@@ -1,18 +1,21 @@
include(../common_top.pri)
TARGET = ut_mtoolbar
-
-INCLUDEPATH += $$MSRCDIR/corelib/widgets $$MSRCDIR/corelib/style
+INCLUDEPATH += $$MSRCDIR/corelib/widgets \
+ $$MSRCDIR/corelib/style \
+ $$MSRCDIR/corelib/scene
SOURCES += \
ut_mtoolbar.cpp \
$$MSRCDIR/corelib/widgets/mtoolbar.cpp \
$$MSRCDIR/corelib/widgets/core/mwidgetcontroller.cpp \
$$MSRCDIR/corelib/widgets/core/mwidget.cpp \
-
+ $$MSRCDIR/corelib/scene/mscene.cpp \
+
HEADERS += \
ut_mtoolbar.h \
$$MSRCDIR/corelib/widgets/mtoolbar_p.h \
$$MSRCDIR/corelib/widgets/core/mwidgetcontroller_p.h \
+ $$MSRCDIR/corelib/scene/mscene.h \
include(../common_bot.pri)