tests/auto/gestures/tst_gestures.cpp
branchRCL_3
changeset 7 3f74d0d4af4c
parent 4 3b1da2848fc7
equal deleted inserted replaced
6:dee5afe5301f 7:3f74d0d4af4c
   331     void ungrabGesture();
   331     void ungrabGesture();
   332     void consumeEventHint();
   332     void consumeEventHint();
   333     void unregisterRecognizer();
   333     void unregisterRecognizer();
   334     void autoCancelGestures();
   334     void autoCancelGestures();
   335     void autoCancelGestures2();
   335     void autoCancelGestures2();
       
   336     void panelPropagation();
       
   337     void panelStacksBehindParent();
   336 };
   338 };
   337 
   339 
   338 tst_Gestures::tst_Gestures()
   340 tst_Gestures::tst_Gestures()
   339 {
   341 {
   340 }
   342 }
  1455 
  1457 
  1456     CustomEvent event;
  1458     CustomEvent event;
  1457     event.serial = CustomGesture::SerialStartedThreshold;
  1459     event.serial = CustomGesture::SerialStartedThreshold;
  1458     event.hasHotSpot = true;
  1460     event.hasHotSpot = true;
  1459     event.hotSpot = mapToGlobal(QPointF(5, 5), child, &view);
  1461     event.hotSpot = mapToGlobal(QPointF(5, 5), child, &view);
  1460     // qDebug() << event.hotSpot;
       
  1461     scene.sendEvent(child, &event);
  1462     scene.sendEvent(child, &event);
  1462     //QEventLoop().exec();
       
  1463     QCOMPARE(parent->events.all.count(), 1);
  1463     QCOMPARE(parent->events.all.count(), 1);
  1464     QCOMPARE(child->events.started.count(), 1);
  1464     QCOMPARE(child->events.started.count(), 1);
  1465     QCOMPARE(child->events.canceled.count(), 1);
  1465     QCOMPARE(child->events.canceled.count(), 1);
  1466     QCOMPARE(child->events.all.count(), 2);
  1466     QCOMPARE(child->events.all.count(), 2);
  1467 
  1467 
  1469     event.serial = CustomGesture::SerialFinishedThreshold;
  1469     event.serial = CustomGesture::SerialFinishedThreshold;
  1470     scene.sendEvent(child, &event);
  1470     scene.sendEvent(child, &event);
  1471     QCOMPARE(parent->events.all.count(), 2);
  1471     QCOMPARE(parent->events.all.count(), 2);
  1472 }
  1472 }
  1473 
  1473 
       
  1474 void tst_Gestures::panelPropagation()
       
  1475 {
       
  1476     QGraphicsScene scene;
       
  1477     QGraphicsView view(&scene);
       
  1478     view.setWindowFlags(Qt::X11BypassWindowManagerHint);
       
  1479 
       
  1480     GestureItem *item0 = new GestureItem("item0");
       
  1481     scene.addItem(item0);
       
  1482     item0->setPos(0, 0);
       
  1483     item0->size = QRectF(0, 0, 200, 200);
       
  1484     item0->grabGesture(CustomGesture::GestureType);
       
  1485     item0->setZValue(1);
       
  1486 
       
  1487     GestureItem *item1 = new GestureItem("item1");
       
  1488     item1->grabGesture(CustomGesture::GestureType);
       
  1489     scene.addItem(item1);
       
  1490     item1->setPos(10, 10);
       
  1491     item1->size = QRectF(0, 0, 180, 180);
       
  1492     item1->setZValue(2);
       
  1493 
       
  1494     GestureItem *item1_child1 = new GestureItem("item1_child1[panel]");
       
  1495     item1_child1->setFlags(QGraphicsItem::ItemIsPanel);
       
  1496     item1_child1->setParentItem(item1);
       
  1497     item1_child1->grabGesture(CustomGesture::GestureType);
       
  1498     item1_child1->setPos(10, 10);
       
  1499     item1_child1->size = QRectF(0, 0, 160, 160);
       
  1500     item1_child1->setZValue(5);
       
  1501 
       
  1502     GestureItem *item1_child1_child1 = new GestureItem("item1_child1_child1");
       
  1503     item1_child1_child1->setParentItem(item1_child1);
       
  1504     item1_child1_child1->grabGesture(CustomGesture::GestureType);
       
  1505     item1_child1_child1->setPos(10, 10);
       
  1506     item1_child1_child1->size = QRectF(0, 0, 140, 140);
       
  1507     item1_child1_child1->setZValue(10);
       
  1508 
       
  1509     view.show();
       
  1510     QTest::qWaitForWindowShown(&view);
       
  1511     view.ensureVisible(scene.sceneRect());
       
  1512 
       
  1513     view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
       
  1514 
       
  1515     static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1;
       
  1516     static const int TotalCustomEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialMaybeThreshold + 1;
       
  1517 
       
  1518     CustomEvent event;
       
  1519     event.hotSpot = mapToGlobal(QPointF(5, 5), item1_child1_child1, &view);
       
  1520     event.hasHotSpot = true;
       
  1521     sendCustomGesture(&event, item0, &scene);
       
  1522 
       
  1523     QCOMPARE(item0->customEventsReceived, TotalCustomEventsCount);
       
  1524     QCOMPARE(item1_child1_child1->gestureEventsReceived, TotalGestureEventsCount);
       
  1525     QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 1);
       
  1526     QCOMPARE(item1_child1->gestureOverrideEventsReceived, 1);
       
  1527     QCOMPARE(item1->gestureEventsReceived, 0);
       
  1528     QCOMPARE(item1->gestureOverrideEventsReceived, 0);
       
  1529     QCOMPARE(item0->gestureEventsReceived, 0);
       
  1530     QCOMPARE(item0->gestureOverrideEventsReceived, 0);
       
  1531 
       
  1532     item0->reset(); item1->reset(); item1_child1->reset(); item1_child1_child1->reset();
       
  1533 
       
  1534     event.hotSpot = mapToGlobal(QPointF(5, 5), item1, &view);
       
  1535     event.hasHotSpot = true;
       
  1536     sendCustomGesture(&event, item1, &scene);
       
  1537 
       
  1538     QCOMPARE(item1_child1_child1->gestureEventsReceived, 0);
       
  1539     QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 0);
       
  1540     QCOMPARE(item1_child1->gestureEventsReceived, 0);
       
  1541     QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0);
       
  1542     QCOMPARE(item1->gestureEventsReceived, TotalGestureEventsCount);
       
  1543     QCOMPARE(item1->gestureOverrideEventsReceived, 1);
       
  1544     QCOMPARE(item0->gestureEventsReceived, 0);
       
  1545     QCOMPARE(item0->gestureOverrideEventsReceived, 1);
       
  1546 
       
  1547     item0->reset(); item1->reset(); item1_child1->reset(); item1_child1_child1->reset();
       
  1548     // try with a modal panel
       
  1549     item1_child1->setPanelModality(QGraphicsItem::PanelModal);
       
  1550 
       
  1551     event.hotSpot = mapToGlobal(QPointF(5, 5), item1, &view);
       
  1552     event.hasHotSpot = true;
       
  1553     sendCustomGesture(&event, item1, &scene);
       
  1554 
       
  1555     QCOMPARE(item1_child1_child1->gestureEventsReceived, 0);
       
  1556     QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 0);
       
  1557     QCOMPARE(item1_child1->gestureEventsReceived, TotalGestureEventsCount);
       
  1558     QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0);
       
  1559     QCOMPARE(item1->gestureEventsReceived, 0);
       
  1560     QCOMPARE(item1->gestureOverrideEventsReceived, 0);
       
  1561     QCOMPARE(item0->gestureEventsReceived, 0);
       
  1562     QCOMPARE(item0->gestureOverrideEventsReceived, 0);
       
  1563 
       
  1564     item0->reset(); item1->reset(); item1_child1->reset(); item1_child1_child1->reset();
       
  1565     // try with a modal panel, however set the hotspot to be outside of the
       
  1566     // panel and its parent
       
  1567     item1_child1->setPanelModality(QGraphicsItem::PanelModal);
       
  1568 
       
  1569     event.hotSpot = mapToGlobal(QPointF(5, 5), item0, &view);
       
  1570     event.hasHotSpot = true;
       
  1571     sendCustomGesture(&event, item1, &scene);
       
  1572 
       
  1573     QCOMPARE(item1_child1_child1->gestureEventsReceived, 0);
       
  1574     QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 0);
       
  1575     QCOMPARE(item1_child1->gestureEventsReceived, 0);
       
  1576     QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0);
       
  1577     QCOMPARE(item1->gestureEventsReceived, 0);
       
  1578     QCOMPARE(item1->gestureOverrideEventsReceived, 0);
       
  1579     QCOMPARE(item0->gestureEventsReceived, TotalGestureEventsCount);
       
  1580     QCOMPARE(item0->gestureOverrideEventsReceived, 0);
       
  1581 
       
  1582     item0->reset(); item1->reset(); item1_child1->reset(); item1_child1_child1->reset();
       
  1583     // try with a scene modal panel
       
  1584     item1_child1->setPanelModality(QGraphicsItem::SceneModal);
       
  1585 
       
  1586     event.hotSpot = mapToGlobal(QPointF(5, 5), item0, &view);
       
  1587     event.hasHotSpot = true;
       
  1588     sendCustomGesture(&event, item0, &scene);
       
  1589 
       
  1590     QCOMPARE(item1_child1_child1->gestureEventsReceived, 0);
       
  1591     QCOMPARE(item1_child1_child1->gestureOverrideEventsReceived, 0);
       
  1592     QCOMPARE(item1_child1->gestureEventsReceived, TotalGestureEventsCount);
       
  1593     QCOMPARE(item1_child1->gestureOverrideEventsReceived, 0);
       
  1594     QCOMPARE(item1->gestureEventsReceived, 0);
       
  1595     QCOMPARE(item1->gestureOverrideEventsReceived, 0);
       
  1596     QCOMPARE(item0->gestureEventsReceived, 0);
       
  1597     QCOMPARE(item0->gestureOverrideEventsReceived, 0);
       
  1598 }
       
  1599 
       
  1600 void tst_Gestures::panelStacksBehindParent()
       
  1601 {
       
  1602     QGraphicsScene scene;
       
  1603     QGraphicsView view(&scene);
       
  1604     view.setWindowFlags(Qt::X11BypassWindowManagerHint);
       
  1605 
       
  1606     GestureItem *item1 = new GestureItem("item1");
       
  1607     item1->grabGesture(CustomGesture::GestureType);
       
  1608     scene.addItem(item1);
       
  1609     item1->setPos(10, 10);
       
  1610     item1->size = QRectF(0, 0, 180, 180);
       
  1611     item1->setZValue(2);
       
  1612 
       
  1613     GestureItem *panel = new GestureItem("panel");
       
  1614     panel->setFlags(QGraphicsItem::ItemIsPanel | QGraphicsItem::ItemStacksBehindParent);
       
  1615     panel->setPanelModality(QGraphicsItem::PanelModal);
       
  1616     panel->setParentItem(item1);
       
  1617     panel->grabGesture(CustomGesture::GestureType);
       
  1618     panel->setPos(-10, -10);
       
  1619     panel->size = QRectF(0, 0, 200, 200);
       
  1620     panel->setZValue(5);
       
  1621 
       
  1622     view.show();
       
  1623     QTest::qWaitForWindowShown(&view);
       
  1624     view.ensureVisible(scene.sceneRect());
       
  1625 
       
  1626     view.viewport()->grabGesture(CustomGesture::GestureType, Qt::DontStartGestureOnChildren);
       
  1627 
       
  1628     static const int TotalGestureEventsCount = CustomGesture::SerialFinishedThreshold - CustomGesture::SerialStartedThreshold + 1;
       
  1629 
       
  1630     CustomEvent event;
       
  1631     event.hotSpot = mapToGlobal(QPointF(5, 5), item1, &view);
       
  1632     event.hasHotSpot = true;
       
  1633     sendCustomGesture(&event, item1, &scene);
       
  1634 
       
  1635     QCOMPARE(item1->gestureEventsReceived, 0);
       
  1636     QCOMPARE(item1->gestureOverrideEventsReceived, 0);
       
  1637     QCOMPARE(panel->gestureEventsReceived, TotalGestureEventsCount);
       
  1638     QCOMPARE(panel->gestureOverrideEventsReceived, 0);
       
  1639 }
       
  1640 
  1474 QTEST_MAIN(tst_Gestures)
  1641 QTEST_MAIN(tst_Gestures)
  1475 #include "tst_gestures.moc"
  1642 #include "tst_gestures.moc"