Skip to content

Commit

Permalink
QQuickCanvas::event should return true if the touch event was accepted
Browse files Browse the repository at this point in the history
If QQuickCanvas::event delivers a touch event and it is accepted
the control ends up in QWindow::event which invalidates the event.
These touch events end up as if they were unhadled which causes Qt to
automatically synthesize mouse events even for accepted touch events.

Add a unit test for testing this behavior.

Change-Id: I83d4aeafee1ea7ec5d219e4b45aae699188717c3
Reviewed-by: Zeno Albisser <zeno.albisser@nokia.com>
Reviewed-by: Samuel Rødal <samuel.rodal@nokia.com>
  • Loading branch information
bbandix authored and Qt by Nokia committed Jan 24, 2012
1 parent 39f4b17 commit 1ea7442
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/quick/items/qquickcanvas.cpp
Expand Up @@ -718,9 +718,8 @@ bool QQuickCanvas::event(QEvent *e)
QTouchEvent *touch = static_cast<QTouchEvent *>(e);
d->translateTouchEvent(touch);
d->deliverTouchEvent(touch);
if (!touch->isAccepted())
return false;
break;

return touch->isAccepted();
}
case QEvent::Leave:
d->clearHover();
Expand Down
40 changes: 40 additions & 0 deletions tests/auto/qtquick2/qquickitem/tst_qquickitem.cpp
Expand Up @@ -66,9 +66,23 @@ Q_OBJECT
virtual void focusOutEvent(QFocusEvent *) { Q_ASSERT(focused); focused = false; }
virtual void mousePressEvent(QMouseEvent *event) { event->accept(); ++pressCount; }
virtual void mouseReleaseEvent(QMouseEvent *event) { event->accept(); ++releaseCount; }
virtual void touchEvent(QTouchEvent *event) { event->accept(); }
virtual void wheelEvent(QWheelEvent *event) { event->accept(); ++wheelCount; }
};

class TestCanvas: public QQuickCanvas
{
public:
TestCanvas()
: QQuickCanvas()
{}

virtual bool event(QEvent *event)
{
return QQuickCanvas::event(event);
}
};

class TestPolishItem : public QQuickItem
{
Q_OBJECT
Expand Down Expand Up @@ -124,6 +138,7 @@ private slots:
void enabled();

void mouseGrab();
void touchEventAccept();
void polishOutsideAnimation();
void polishOnCompleted();

Expand Down Expand Up @@ -862,6 +877,31 @@ void tst_qquickitem::mouseGrab()
delete canvas;
}

void tst_qquickitem::touchEventAccept()
{
TestCanvas *canvas = new TestCanvas;
canvas->resize(100, 100);
canvas->show();

TestItem *item = new TestItem;
item->setSize(QSizeF(100, 100));
item->setParentItem(canvas->rootItem());

static QTouchDevice* device = new QTouchDevice;
device->setType(QTouchDevice::TouchScreen);
QWindowSystemInterface::registerTouchDevice(device);

QTouchEvent *event = new QTouchEvent(QEvent::TouchBegin, device);

bool accepted = canvas->event(event);

QVERIFY(accepted && event->isAccepted());

delete event;
delete item;
delete canvas;
}

void tst_qquickitem::polishOutsideAnimation()
{
QQuickCanvas *canvas = new QQuickCanvas;
Expand Down

0 comments on commit 1ea7442

Please sign in to comment.