42 #include <QtTest/QSignalSpy> |
42 #include <QtTest/QSignalSpy> |
43 #include <QtDeclarative/qdeclarativeengine.h> |
43 #include <QtDeclarative/qdeclarativeengine.h> |
44 #include <QtDeclarative/qdeclarativecomponent.h> |
44 #include <QtDeclarative/qdeclarativecomponent.h> |
45 #include <private/qdeclarativeflickable_p.h> |
45 #include <private/qdeclarativeflickable_p.h> |
46 #include <private/qdeclarativevaluetype_p.h> |
46 #include <private/qdeclarativevaluetype_p.h> |
|
47 #include <QtGui/qgraphicswidget.h> |
47 #include <math.h> |
48 #include <math.h> |
48 |
49 |
49 #ifdef Q_OS_SYMBIAN |
50 #ifdef Q_OS_SYMBIAN |
50 // In Symbian OS test data is located in applications private dir |
51 // In Symbian OS test data is located in applications private dir |
51 #define SRCDIR "." |
52 #define SRCDIR "." |
65 void boundsBehavior(); |
66 void boundsBehavior(); |
66 void maximumFlickVelocity(); |
67 void maximumFlickVelocity(); |
67 void flickDeceleration(); |
68 void flickDeceleration(); |
68 void pressDelay(); |
69 void pressDelay(); |
69 void flickableDirection(); |
70 void flickableDirection(); |
|
71 void qgraphicswidget(); |
70 |
72 |
71 private: |
73 private: |
72 QDeclarativeEngine engine; |
74 QDeclarativeEngine engine; |
|
75 |
|
76 template<typename T> |
|
77 T *findItem(QGraphicsObject *parent, const QString &objectName); |
73 }; |
78 }; |
74 |
79 |
75 tst_qdeclarativeflickable::tst_qdeclarativeflickable() |
80 tst_qdeclarativeflickable::tst_qdeclarativeflickable() |
76 { |
81 { |
77 } |
82 } |
259 flickable->setFlickableDirection(QDeclarativeFlickable::HorizontalFlick); |
264 flickable->setFlickableDirection(QDeclarativeFlickable::HorizontalFlick); |
260 QCOMPARE(flickable->flickableDirection(), QDeclarativeFlickable::HorizontalFlick); |
265 QCOMPARE(flickable->flickableDirection(), QDeclarativeFlickable::HorizontalFlick); |
261 QCOMPARE(spy.count(),3); |
266 QCOMPARE(spy.count(),3); |
262 } |
267 } |
263 |
268 |
|
269 void tst_qdeclarativeflickable::qgraphicswidget() |
|
270 { |
|
271 QDeclarativeEngine engine; |
|
272 QDeclarativeComponent c(&engine, QUrl::fromLocalFile(SRCDIR "/data/flickableqgraphicswidget.qml")); |
|
273 QDeclarativeFlickable *flickable = qobject_cast<QDeclarativeFlickable*>(c.create()); |
|
274 |
|
275 QVERIFY(flickable != 0); |
|
276 QGraphicsWidget *widget = findItem<QGraphicsWidget>(flickable->contentItem(), "widget1"); |
|
277 QVERIFY(widget); |
|
278 } |
|
279 |
|
280 template<typename T> |
|
281 T *tst_qdeclarativeflickable::findItem(QGraphicsObject *parent, const QString &objectName) |
|
282 { |
|
283 const QMetaObject &mo = T::staticMetaObject; |
|
284 //qDebug() << parent->childItems().count() << "children"; |
|
285 for (int i = 0; i < parent->childItems().count(); ++i) { |
|
286 QGraphicsObject *item = qobject_cast<QGraphicsObject*>(parent->childItems().at(i)); |
|
287 if(!item) |
|
288 continue; |
|
289 //qDebug() << "try" << item; |
|
290 if (mo.cast(item) && (objectName.isEmpty() || item->objectName() == objectName)) { |
|
291 return static_cast<T*>(item); |
|
292 } |
|
293 item = findItem<T>(item, objectName); |
|
294 if (item) |
|
295 return static_cast<T*>(item); |
|
296 } |
|
297 |
|
298 return 0; |
|
299 } |
|
300 |
264 QTEST_MAIN(tst_qdeclarativeflickable) |
301 QTEST_MAIN(tst_qdeclarativeflickable) |
265 |
302 |
266 #include "tst_qdeclarativeflickable.moc" |
303 #include "tst_qdeclarativeflickable.moc" |