summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgraphicsitem
diff options
context:
space:
mode:
authorMichael Hasselmann <michaelh@openismus.com>2011-04-01 09:27:07 (GMT)
committerDenis Dzyubenko <denis.dzyubenko@nokia.com>2011-04-01 09:27:07 (GMT)
commit777e1c5a18ba1d738d2394d157c2cc27d88ba3f5 (patch)
tree906e0f5a4d85e155db07b3909e708d54a80be96c /tests/auto/qgraphicsitem
parent97f030d8e314010b141604b71821f4c83a66f6a8 (diff)
downloadQt-777e1c5a18ba1d738d2394d157c2cc27d88ba3f5.zip
Qt-777e1c5a18ba1d738d2394d157c2cc27d88ba3f5.tar.gz
Qt-777e1c5a18ba1d738d2394d157c2cc27d88ba3f5.tar.bz2
QGraphicsItem::ItemStops[ClickFocusProgration|FocusHandling] must not interfer with touch event propagation
Both flags are only supposed to affect focus handling but not the regular touch event propagation. In this case, touch begin events were not propagated to any item beneath the one carrying those flags. Merge-request: 2588 Reviewed-by: Denis Dzyubenko <denis.dzyubenko@nokia.com>
Diffstat (limited to 'tests/auto/qgraphicsitem')
-rw-r--r--tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp79
1 files changed, 78 insertions, 1 deletions
diff --git a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
index 168f75e..73e5656 100644
--- a/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
+++ b/tests/auto/qgraphicsitem/tst_qgraphicsitem.cpp
@@ -66,6 +66,7 @@
#include <QPushButton>
#include <QLineEdit>
#include <QGraphicsLinearLayout>
+#include <float.h>
#include "../../shared/util.h"
@@ -449,6 +450,8 @@ private slots:
void scroll();
void focusHandling_data();
void focusHandling();
+ void touchEventPropagation_data();
+ void touchEventPropagation();
void deviceCoordinateCache_simpleRotations();
// task specific tests below me
@@ -10637,6 +10640,80 @@ void tst_QGraphicsItem::focusHandling()
QCOMPARE(scene.focusItem(), focusableUnder);
}
+void tst_QGraphicsItem::touchEventPropagation_data()
+{
+ QTest::addColumn<QGraphicsItem::GraphicsItemFlag>("flag");
+ QTest::addColumn<int>("expectedCount");
+
+ QTest::newRow("ItemIsPanel")
+ << QGraphicsItem::ItemIsPanel << 0;
+ QTest::newRow("ItemStopsClickFocusPropagation")
+ << QGraphicsItem::ItemStopsClickFocusPropagation << 1;
+ QTest::newRow("ItemStopsFocusHandling")
+ << QGraphicsItem::ItemStopsFocusHandling << 1;
+}
+
+void tst_QGraphicsItem::touchEventPropagation()
+{
+ QFETCH(QGraphicsItem::GraphicsItemFlag, flag);
+ QFETCH(int, expectedCount);
+
+ class Testee : public QGraphicsRectItem
+ {
+ public:
+ int touchBeginEventCount;
+
+ Testee()
+ : QGraphicsRectItem(0, 0, 100, 100)
+ , touchBeginEventCount(0)
+ {
+ setAcceptTouchEvents(true);
+ setFlag(QGraphicsItem::ItemIsFocusable, false);
+ }
+
+ bool sceneEvent(QEvent *ev)
+ {
+ if (ev->type() == QEvent::TouchBegin)
+ ++touchBeginEventCount;
+
+ return QGraphicsRectItem::sceneEvent(ev);
+ }
+ };
+
+ Testee *touchEventReceiver = new Testee;
+ QGraphicsItem *topMost = new QGraphicsRectItem(touchEventReceiver->boundingRect());
+
+ QGraphicsScene scene;
+ scene.addItem(topMost);
+ scene.addItem(touchEventReceiver);
+
+ topMost->setAcceptTouchEvents(true);
+ topMost->setZValue(FLT_MAX);
+ topMost->setFlag(QGraphicsItem::ItemIsFocusable, false);
+ topMost->setFlag(flag, true);
+
+ QGraphicsView view(&scene);
+ view.setSceneRect(touchEventReceiver->boundingRect());
+ view.show();
+ QTest::qWaitForWindowShown(&view);
+
+ QCOMPARE(touchEventReceiver->touchBeginEventCount, 0);
+
+ QTouchEvent::TouchPoint tp(0);
+ tp.setState(Qt::TouchPointPressed);
+ tp.setScenePos(view.sceneRect().center());
+ tp.setLastScenePos(view.sceneRect().center());
+
+ QList<QTouchEvent::TouchPoint> touchPoints;
+ touchPoints << tp;
+
+ sendMousePress(&scene, tp.scenePos());
+ QTouchEvent touchBegin(QEvent::TouchBegin, QTouchEvent::TouchScreen, Qt::NoModifier, Qt::TouchPointPressed, touchPoints);
+
+ qApp->sendEvent(&scene, &touchBegin);
+ QCOMPARE(touchEventReceiver->touchBeginEventCount, expectedCount);
+}
+
void tst_QGraphicsItem::deviceCoordinateCache_simpleRotations()
{
// Make sure we don't invalidate the cache when applying simple
@@ -11176,6 +11253,6 @@ void tst_QGraphicsItem::QTBUG_16374_crashInDestructor()
view.show();
QTest::qWaitForWindowShown(&view);
}
-
+
QTEST_MAIN(tst_QGraphicsItem)
#include "tst_qgraphicsitem.moc"