1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include <QtTest/QtTest>
43 #include <QtTest/QSignalSpy>
44 #include <private/qsgmousearea_p.h>
45 #include <private/qsgrectangle_p.h>
46 #include <private/qsgflickable_p.h>
47 #include <QtDeclarative/qsgview.h>
48 #include <QtDeclarative/qdeclarativecontext.h>
49 #include <QtDeclarative/qdeclarativeengine.h>
50 #include <QtOpenGL/QGLShaderProgram>
51 #include "../shared/util.h"
52 #include "../../../shared/util.h"
56 class tst_QSGMouseArea: public QObject
61 void cleanupTestCase();
62 void dragProperties();
65 void updateMouseAreaPosOnClick();
66 void updateMouseAreaPosOnResize();
67 void noOnClickedWithPressAndHold();
68 void onMousePressRejected();
69 void pressedCanceledOnWindowDeactivate();
72 void pressedOrdering();
73 void preventStealing();
75 void testQtQuick11Attributes();
76 void testQtQuick11Attributes_data();
78 void hoverPropagation();
81 QSGView *createView();
84 void tst_QSGMouseArea::initTestCase()
89 void tst_QSGMouseArea::cleanupTestCase()
94 void tst_QSGMouseArea::dragProperties()
96 QSGView *canvas = createView();
98 canvas->setSource(QUrl::fromLocalFile(TESTDATA("dragproperties.qml")));
100 canvas->requestActivateWindow();
101 QVERIFY(canvas->rootObject() != 0);
103 QSGMouseArea *mouseRegion = canvas->rootObject()->findChild<QSGMouseArea*>("mouseregion");
104 QSGDrag *drag = mouseRegion->drag();
105 QVERIFY(mouseRegion != 0);
109 QSGItem *blackRect = canvas->rootObject()->findChild<QSGItem*>("blackrect");
110 QVERIFY(blackRect != 0);
111 QVERIFY(blackRect == drag->target());
112 QSGItem *rootItem = qobject_cast<QSGItem*>(canvas->rootObject());
113 QVERIFY(rootItem != 0);
114 QSignalSpy targetSpy(drag, SIGNAL(targetChanged()));
115 drag->setTarget(rootItem);
116 QCOMPARE(targetSpy.count(),1);
117 drag->setTarget(rootItem);
118 QCOMPARE(targetSpy.count(),1);
121 QCOMPARE(drag->axis(), QSGDrag::XandYAxis);
122 QSignalSpy axisSpy(drag, SIGNAL(axisChanged()));
123 drag->setAxis(QSGDrag::XAxis);
124 QCOMPARE(drag->axis(), QSGDrag::XAxis);
125 QCOMPARE(axisSpy.count(),1);
126 drag->setAxis(QSGDrag::XAxis);
127 QCOMPARE(axisSpy.count(),1);
129 // minimum and maximum properties
130 QSignalSpy xminSpy(drag, SIGNAL(minimumXChanged()));
131 QSignalSpy xmaxSpy(drag, SIGNAL(maximumXChanged()));
132 QSignalSpy yminSpy(drag, SIGNAL(minimumYChanged()));
133 QSignalSpy ymaxSpy(drag, SIGNAL(maximumYChanged()));
135 QCOMPARE(drag->xmin(), 0.0);
136 QCOMPARE(drag->xmax(), rootItem->width()-blackRect->width());
137 QCOMPARE(drag->ymin(), 0.0);
138 QCOMPARE(drag->ymax(), rootItem->height()-blackRect->height());
145 QCOMPARE(drag->xmin(), 10.0);
146 QCOMPARE(drag->xmax(), 10.0);
147 QCOMPARE(drag->ymin(), 10.0);
148 QCOMPARE(drag->ymax(), 10.0);
150 QCOMPARE(xminSpy.count(),1);
151 QCOMPARE(xmaxSpy.count(),1);
152 QCOMPARE(yminSpy.count(),1);
153 QCOMPARE(ymaxSpy.count(),1);
160 QCOMPARE(xminSpy.count(),1);
161 QCOMPARE(xmaxSpy.count(),1);
162 QCOMPARE(yminSpy.count(),1);
163 QCOMPARE(ymaxSpy.count(),1);
166 QSignalSpy filterChildrenSpy(drag, SIGNAL(filterChildrenChanged()));
168 drag->setFilterChildren(true);
170 QVERIFY(drag->filterChildren());
171 QCOMPARE(filterChildrenSpy.count(), 1);
173 drag->setFilterChildren(true);
174 QCOMPARE(filterChildrenSpy.count(), 1);
179 void tst_QSGMouseArea::resetDrag()
181 QSGView *canvas = createView();
183 canvas->rootContext()->setContextProperty("haveTarget", QVariant(true));
184 canvas->setSource(QUrl::fromLocalFile(TESTDATA("dragreset.qml")));
186 canvas->requestActivateWindow();
187 QVERIFY(canvas->rootObject() != 0);
189 QSGMouseArea *mouseRegion = canvas->rootObject()->findChild<QSGMouseArea*>("mouseregion");
190 QSGDrag *drag = mouseRegion->drag();
191 QVERIFY(mouseRegion != 0);
195 QSGItem *blackRect = canvas->rootObject()->findChild<QSGItem*>("blackrect");
196 QVERIFY(blackRect != 0);
197 QVERIFY(blackRect == drag->target());
198 QSGItem *rootItem = qobject_cast<QSGItem*>(canvas->rootObject());
199 QVERIFY(rootItem != 0);
200 QSignalSpy targetSpy(drag, SIGNAL(targetChanged()));
201 QVERIFY(drag->target() != 0);
202 canvas->rootContext()->setContextProperty("haveTarget", QVariant(false));
203 QCOMPARE(targetSpy.count(),1);
204 QVERIFY(drag->target() == 0);
210 void tst_QSGMouseArea::dragging()
212 QSGView *canvas = createView();
214 canvas->setSource(QUrl::fromLocalFile(TESTDATA("dragging.qml")));
216 canvas->requestActivateWindow();
218 QVERIFY(canvas->rootObject() != 0);
220 QSGMouseArea *mouseRegion = canvas->rootObject()->findChild<QSGMouseArea*>("mouseregion");
221 QSGDrag *drag = mouseRegion->drag();
222 QVERIFY(mouseRegion != 0);
226 QSGItem *blackRect = canvas->rootObject()->findChild<QSGItem*>("blackrect");
227 QVERIFY(blackRect != 0);
228 QVERIFY(blackRect == drag->target());
230 QVERIFY(!drag->active());
233 QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
234 QApplication::sendEvent(canvas, &pressEvent);
236 QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
239 QVERIFY(!drag->active());
240 QCOMPARE(blackRect->x(), 50.0);
241 QCOMPARE(blackRect->y(), 50.0);
243 // First move event triggers drag, second is acted upon.
244 // This is due to possibility of higher stacked area taking precedence.
246 QTest::mouseMove(canvas, QPoint(111,111));
248 QTest::mouseMove(canvas, QPoint(122,122));
251 QVERIFY(drag->active());
252 QCOMPARE(blackRect->x(), 72.0);
253 QCOMPARE(blackRect->y(), 72.0);
256 QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
257 QApplication::sendEvent(canvas, &releaseEvent);
259 QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(122,122));
263 QVERIFY(!drag->active());
264 QCOMPARE(blackRect->x(), 72.0);
265 QCOMPARE(blackRect->y(), 72.0);
270 QSGView *tst_QSGMouseArea::createView()
272 QSGView *canvas = new QSGView(0);
273 canvas->setBaseSize(QSize(240,320));
278 void tst_QSGMouseArea::updateMouseAreaPosOnClick()
280 QSGView *canvas = createView();
281 canvas->setSource(QUrl::fromLocalFile(TESTDATA("updateMousePosOnClick.qml")));
283 canvas->requestActivateWindow();
284 QVERIFY(canvas->rootObject() != 0);
286 QSGMouseArea *mouseRegion = canvas->rootObject()->findChild<QSGMouseArea*>("mouseregion");
287 QVERIFY(mouseRegion != 0);
289 QSGRectangle *rect = canvas->rootObject()->findChild<QSGRectangle*>("ball");
292 QCOMPARE(mouseRegion->mouseX(), rect->x());
293 QCOMPARE(mouseRegion->mouseY(), rect->y());
295 QMouseEvent event(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
296 QApplication::sendEvent(canvas, &event);
298 QCOMPARE(mouseRegion->mouseX(), 100.0);
299 QCOMPARE(mouseRegion->mouseY(), 100.0);
301 QCOMPARE(mouseRegion->mouseX(), rect->x());
302 QCOMPARE(mouseRegion->mouseY(), rect->y());
307 void tst_QSGMouseArea::updateMouseAreaPosOnResize()
309 QSGView *canvas = createView();
310 canvas->setSource(QUrl::fromLocalFile(TESTDATA("updateMousePosOnResize.qml")));
312 canvas->requestActivateWindow();
313 QVERIFY(canvas->rootObject() != 0);
315 QSGMouseArea *mouseRegion = canvas->rootObject()->findChild<QSGMouseArea*>("mouseregion");
316 QVERIFY(mouseRegion != 0);
318 QSGRectangle *rect = canvas->rootObject()->findChild<QSGRectangle*>("brother");
321 QCOMPARE(mouseRegion->mouseX(), 0.0);
322 QCOMPARE(mouseRegion->mouseY(), 0.0);
324 QMouseEvent event(QEvent::MouseButtonPress, rect->pos().toPoint(), Qt::LeftButton, Qt::LeftButton, 0);
325 QApplication::sendEvent(canvas, &event);
327 QVERIFY(!mouseRegion->property("emitPositionChanged").toBool());
328 QVERIFY(mouseRegion->property("mouseMatchesPos").toBool());
330 QCOMPARE(mouseRegion->property("x1").toInt(), 0);
331 QCOMPARE(mouseRegion->property("y1").toInt(), 0);
333 // XXX: is it on purpose that mouseX is real and mouse.x is int?
334 QCOMPARE(mouseRegion->property("x2").toInt(), (int) rect->x());
335 QCOMPARE(mouseRegion->property("y2").toInt(), (int) rect->y());
337 QCOMPARE(mouseRegion->mouseX(), rect->x());
338 QCOMPARE(mouseRegion->mouseY(), rect->y());
343 void tst_QSGMouseArea::noOnClickedWithPressAndHold()
346 // We handle onPressAndHold, therefore no onClicked
347 QSGView *canvas = createView();
348 canvas->setSource(QUrl::fromLocalFile(TESTDATA("clickandhold.qml")));
350 canvas->requestActivateWindow();
351 QVERIFY(canvas->rootObject() != 0);
353 QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
354 QApplication::sendEvent(canvas, &pressEvent);
356 QVERIFY(!canvas->rootObject()->property("clicked").toBool());
357 QVERIFY(!canvas->rootObject()->property("held").toBool());
361 QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
362 QApplication::sendEvent(canvas, &releaseEvent);
364 QVERIFY(!canvas->rootObject()->property("clicked").toBool());
365 QVERIFY(canvas->rootObject()->property("held").toBool());
371 // We do not handle onPressAndHold, therefore we get onClicked
372 QSGView *canvas = createView();
373 canvas->setSource(QUrl::fromLocalFile(TESTDATA("noclickandhold.qml")));
375 canvas->requestActivateWindow();
376 QVERIFY(canvas->rootObject() != 0);
378 QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
379 QApplication::sendEvent(canvas, &pressEvent);
381 QVERIFY(!canvas->rootObject()->property("clicked").toBool());
385 QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
386 QApplication::sendEvent(canvas, &releaseEvent);
388 QVERIFY(canvas->rootObject()->property("clicked").toBool());
394 void tst_QSGMouseArea::onMousePressRejected()
396 QSGView *canvas = createView();
397 canvas->setSource(QUrl::fromLocalFile(TESTDATA("rejectEvent.qml")));
399 canvas->requestActivateWindow();
400 QVERIFY(canvas->rootObject() != 0);
401 QVERIFY(canvas->rootObject()->property("enabled").toBool());
403 QVERIFY(!canvas->rootObject()->property("mr1_pressed").toBool());
404 QVERIFY(!canvas->rootObject()->property("mr1_released").toBool());
405 QVERIFY(!canvas->rootObject()->property("mr1_canceled").toBool());
406 QVERIFY(!canvas->rootObject()->property("mr2_pressed").toBool());
407 QVERIFY(!canvas->rootObject()->property("mr2_released").toBool());
408 QVERIFY(!canvas->rootObject()->property("mr2_canceled").toBool());
410 QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
411 QApplication::sendEvent(canvas, &pressEvent);
413 QVERIFY(canvas->rootObject()->property("mr1_pressed").toBool());
414 QVERIFY(!canvas->rootObject()->property("mr1_released").toBool());
415 QVERIFY(!canvas->rootObject()->property("mr1_canceled").toBool());
416 QVERIFY(canvas->rootObject()->property("mr2_pressed").toBool());
417 QVERIFY(!canvas->rootObject()->property("mr2_released").toBool());
418 QVERIFY(canvas->rootObject()->property("mr2_canceled").toBool());
422 QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
423 QApplication::sendEvent(canvas, &releaseEvent);
425 QVERIFY(canvas->rootObject()->property("mr1_released").toBool());
426 QVERIFY(!canvas->rootObject()->property("mr1_canceled").toBool());
427 QVERIFY(!canvas->rootObject()->property("mr2_released").toBool());
431 void tst_QSGMouseArea::pressedCanceledOnWindowDeactivate()
433 QSGView *canvas = createView();
434 canvas->setSource(QUrl::fromLocalFile(TESTDATA("pressedCanceled.qml")));
436 canvas->requestActivateWindow();
437 QVERIFY(canvas->rootObject() != 0);
438 QVERIFY(!canvas->rootObject()->property("pressed").toBool());
439 QVERIFY(!canvas->rootObject()->property("canceled").toBool());
440 QVERIFY(!canvas->rootObject()->property("released").toBool());
442 QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
443 QApplication::sendEvent(canvas, &pressEvent);
445 QVERIFY(canvas->rootObject()->property("pressed").toBool());
446 QVERIFY(!canvas->rootObject()->property("canceled").toBool());
447 QVERIFY(!canvas->rootObject()->property("released").toBool());
451 QEvent windowDeactivateEvent(QEvent::WindowDeactivate);
452 QApplication::sendEvent(canvas, &windowDeactivateEvent);
453 QVERIFY(!canvas->rootObject()->property("pressed").toBool());
454 QVERIFY(canvas->rootObject()->property("canceled").toBool());
455 QVERIFY(!canvas->rootObject()->property("released").toBool());
460 QApplication::sendEvent(canvas, &pressEvent);
461 QVERIFY(canvas->rootObject()->property("pressed").toBool());
462 QVERIFY(!canvas->rootObject()->property("canceled").toBool());
463 QVERIFY(!canvas->rootObject()->property("released").toBool());
468 QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
469 QApplication::sendEvent(canvas, &releaseEvent);
470 QVERIFY(!canvas->rootObject()->property("pressed").toBool());
471 QVERIFY(!canvas->rootObject()->property("canceled").toBool());
472 QVERIFY(canvas->rootObject()->property("released").toBool());
476 void tst_QSGMouseArea::doubleClick()
478 QSGView *canvas = createView();
479 canvas->setSource(QUrl::fromLocalFile(TESTDATA("doubleclick.qml")));
481 canvas->requestActivateWindow();
482 QVERIFY(canvas->rootObject() != 0);
484 QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
485 QApplication::sendEvent(canvas, &pressEvent);
487 QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
488 QApplication::sendEvent(canvas, &releaseEvent);
490 QCOMPARE(canvas->rootObject()->property("released").toInt(), 1);
492 pressEvent = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
493 QApplication::sendEvent(canvas, &pressEvent);
495 QApplication::sendEvent(canvas, &releaseEvent);
497 QCOMPARE(canvas->rootObject()->property("clicked").toInt(), 1);
498 QCOMPARE(canvas->rootObject()->property("doubleClicked").toInt(), 1);
499 QCOMPARE(canvas->rootObject()->property("released").toInt(), 2);
505 void tst_QSGMouseArea::clickTwice()
507 QSGView *canvas = createView();
508 canvas->setSource(QUrl::fromLocalFile(TESTDATA("clicktwice.qml")));
510 canvas->requestActivateWindow();
511 QVERIFY(canvas->rootObject() != 0);
513 QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
514 QApplication::sendEvent(canvas, &pressEvent);
516 QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
517 QApplication::sendEvent(canvas, &releaseEvent);
519 QCOMPARE(canvas->rootObject()->property("pressed").toInt(), 1);
520 QCOMPARE(canvas->rootObject()->property("released").toInt(), 1);
521 QCOMPARE(canvas->rootObject()->property("clicked").toInt(), 1);
523 pressEvent = QMouseEvent(QEvent::MouseButtonDblClick, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
524 QApplication::sendEvent(canvas, &pressEvent);
526 QApplication::sendEvent(canvas, &pressEvent);
527 QApplication::sendEvent(canvas, &releaseEvent);
529 QCOMPARE(canvas->rootObject()->property("pressed").toInt(), 2);
530 QCOMPARE(canvas->rootObject()->property("released").toInt(), 2);
531 QCOMPARE(canvas->rootObject()->property("clicked").toInt(), 2);
536 void tst_QSGMouseArea::pressedOrdering()
538 QSGView *canvas = createView();
539 canvas->setSource(QUrl::fromLocalFile(TESTDATA("pressedOrdering.qml")));
541 canvas->requestActivateWindow();
542 QVERIFY(canvas->rootObject() != 0);
544 QCOMPARE(canvas->rootObject()->property("value").toString(), QLatin1String("base"));
546 QMouseEvent pressEvent(QEvent::MouseButtonPress, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
547 QApplication::sendEvent(canvas, &pressEvent);
549 QCOMPARE(canvas->rootObject()->property("value").toString(), QLatin1String("pressed"));
551 QMouseEvent releaseEvent(QEvent::MouseButtonRelease, QPoint(100, 100), Qt::LeftButton, Qt::LeftButton, 0);
552 QApplication::sendEvent(canvas, &releaseEvent);
554 QCOMPARE(canvas->rootObject()->property("value").toString(), QLatin1String("toggled"));
556 QApplication::sendEvent(canvas, &pressEvent);
558 QCOMPARE(canvas->rootObject()->property("value").toString(), QLatin1String("pressed"));
563 void tst_QSGMouseArea::preventStealing()
565 QSGView *canvas = createView();
567 canvas->setSource(QUrl::fromLocalFile(TESTDATA("preventstealing.qml")));
569 canvas->requestActivateWindow();
570 QVERIFY(canvas->rootObject() != 0);
572 QSGFlickable *flickable = qobject_cast<QSGFlickable*>(canvas->rootObject());
573 QVERIFY(flickable != 0);
575 QSGMouseArea *mouseArea = canvas->rootObject()->findChild<QSGMouseArea*>("mousearea");
576 QVERIFY(mouseArea != 0);
578 QSignalSpy mousePositionSpy(mouseArea, SIGNAL(positionChanged(QSGMouseEvent*)));
580 QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(80, 80));
582 // Without preventStealing, mouse movement over MouseArea would
583 // cause the Flickable to steal mouse and trigger content movement.
585 QTest::mouseMove(canvas,QPoint(69,69));
586 QTest::mouseMove(canvas,QPoint(58,58));
587 QTest::mouseMove(canvas,QPoint(47,47));
589 // We should have received all three move events
590 QCOMPARE(mousePositionSpy.count(), 3);
591 QVERIFY(mouseArea->pressed());
593 // Flickable content should not have moved.
594 QCOMPARE(flickable->contentX(), 0.);
595 QCOMPARE(flickable->contentY(), 0.);
597 QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(47, 47));
599 // Now allow stealing and confirm Flickable does its thing.
600 canvas->rootObject()->setProperty("stealing", false);
602 QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(80, 80));
604 // Without preventStealing, mouse movement over MouseArea would
605 // cause the Flickable to steal mouse and trigger content movement.
607 QTest::mouseMove(canvas,QPoint(69,69));
608 QTest::mouseMove(canvas,QPoint(58,58));
609 QTest::mouseMove(canvas,QPoint(47,47));
611 // We should only have received the first move event
612 QCOMPARE(mousePositionSpy.count(), 4);
613 // Our press should be taken away
614 QVERIFY(!mouseArea->pressed());
616 // Flickable content should have moved.
618 QCOMPARE(flickable->contentX(), 11.);
619 QCOMPARE(flickable->contentY(), 11.);
621 QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(50, 50));
626 void tst_QSGMouseArea::clickThrough()
628 //With no handlers defined click, doubleClick and PressAndHold should propagate to those with handlers
629 QSGView *canvas = createView();
630 canvas->setSource(QUrl::fromLocalFile(TESTDATA("clickThrough.qml")));
632 canvas->requestActivateWindow();
633 QVERIFY(canvas->rootObject() != 0);
635 QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
636 QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
638 QTRY_COMPARE(canvas->rootObject()->property("presses").toInt(), 0);
639 QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 1);
641 QTest::qWait(800); // to avoid generating a double click.
643 QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
645 QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
647 QTRY_COMPARE(canvas->rootObject()->property("presses").toInt(), 0);
648 QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 1);
649 QTRY_COMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 1);
651 QTest::mouseDClick(canvas, Qt::LeftButton, 0, QPoint(100,100));
654 QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
655 QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 2);
656 QTRY_COMPARE(canvas->rootObject()->property("doubleClicks").toInt(), 1);
657 QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 1);
661 //With handlers defined click, doubleClick and PressAndHold should propagate only when explicitly ignored
662 canvas = createView();
663 canvas->setSource(QUrl::fromLocalFile(TESTDATA("clickThrough2.qml")));
665 canvas->requestActivateWindow();
666 QVERIFY(canvas->rootObject() != 0);
668 QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
669 QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
671 QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
672 QCOMPARE(canvas->rootObject()->property("clicks").toInt(), 0);
674 QTest::qWait(800); // to avoid generating a double click.
676 QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
678 QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
681 QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
682 QCOMPARE(canvas->rootObject()->property("clicks").toInt(), 0);
683 QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 0);
685 QTest::mouseDClick(canvas, Qt::LeftButton, 0, QPoint(100,100));
688 QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
689 QCOMPARE(canvas->rootObject()->property("clicks").toInt(), 0);
690 QCOMPARE(canvas->rootObject()->property("doubleClicks").toInt(), 0);
691 QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 0);
693 canvas->rootObject()->setProperty("letThrough", QVariant(true));
695 QTest::qWait(800); // to avoid generating a double click.
696 QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
697 QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
699 QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
700 QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 1);
702 QTest::qWait(800); // to avoid generating a double click.
703 QTest::mousePress(canvas, Qt::LeftButton, 0, QPoint(100,100));
705 QTest::mouseRelease(canvas, Qt::LeftButton, 0, QPoint(100,100));
708 QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
709 QCOMPARE(canvas->rootObject()->property("clicks").toInt(), 1);
710 QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 1);
712 QTest::mouseDClick(canvas, Qt::LeftButton, 0, QPoint(100,100));
715 QCOMPARE(canvas->rootObject()->property("presses").toInt(), 0);
716 QTRY_COMPARE(canvas->rootObject()->property("clicks").toInt(), 2);
717 QCOMPARE(canvas->rootObject()->property("doubleClicks").toInt(), 1);
718 QCOMPARE(canvas->rootObject()->property("pressAndHolds").toInt(), 1);
723 void tst_QSGMouseArea::testQtQuick11Attributes()
725 QFETCH(QString, code);
726 QFETCH(QString, warning);
727 QFETCH(QString, error);
729 QDeclarativeEngine engine;
732 QDeclarativeComponent valid(&engine);
733 valid.setData("import QtQuick 1.1; MouseArea { " + code.toUtf8() + " }", QUrl(""));
734 obj = valid.create();
736 QVERIFY(valid.errorString().isEmpty());
739 QDeclarativeComponent invalid(&engine);
740 invalid.setData("import QtQuick 1.0; MouseArea { " + code.toUtf8() + " }", QUrl(""));
741 QTest::ignoreMessage(QtWarningMsg, warning.toUtf8());
742 obj = invalid.create();
743 QCOMPARE(invalid.errorString(), error);
747 void tst_QSGMouseArea::testQtQuick11Attributes_data()
749 QTest::addColumn<QString>("code");
750 QTest::addColumn<QString>("warning");
751 QTest::addColumn<QString>("error");
753 QTest::newRow("preventStealing") << "preventStealing: true"
754 << "QDeclarativeComponent: Component is not ready"
755 << ":1 \"MouseArea.preventStealing\" is not available in QtQuick 1.0.\n";
758 void tst_QSGMouseArea::hoverPosition()
760 QSGView *canvas = createView();
761 canvas->setSource(QUrl::fromLocalFile(TESTDATA("hoverPosition.qml")));
763 QSGItem *root = canvas->rootObject();
766 QCOMPARE(root->property("mouseX").toReal(), qreal(0));
767 QCOMPARE(root->property("mouseY").toReal(), qreal(0));
769 QTest::mouseMove(canvas,QPoint(10,32));
772 QCOMPARE(root->property("mouseX").toReal(), qreal(10));
773 QCOMPARE(root->property("mouseY").toReal(), qreal(32));
778 void tst_QSGMouseArea::hoverPropagation()
780 //QTBUG-18175, to behave like GV did.
781 QSGView *canvas = createView();
782 canvas->setSource(QUrl::fromLocalFile(TESTDATA("hoverPropagation.qml")));
784 QSGItem *root = canvas->rootObject();
787 QCOMPARE(root->property("point1").toBool(), false);
788 QCOMPARE(root->property("point2").toBool(), false);
790 QMouseEvent moveEvent(QEvent::MouseMove, QPoint(32, 32), Qt::NoButton, Qt::NoButton, 0);
791 QApplication::sendEvent(canvas, &moveEvent);
793 QCOMPARE(root->property("point1").toBool(), true);
794 QCOMPARE(root->property("point2").toBool(), false);
796 QMouseEvent moveEvent2(QEvent::MouseMove, QPoint(232, 32), Qt::NoButton, Qt::NoButton, 0);
797 QApplication::sendEvent(canvas, &moveEvent2);
798 QCOMPARE(root->property("point1").toBool(), false);
799 QCOMPARE(root->property("point2").toBool(), true);
804 QTEST_MAIN(tst_QSGMouseArea)
806 #include "tst_qsgmousearea.moc"