333 { |
334 { |
334 QDeclarativeView *view = new QDeclarativeView; |
335 QDeclarativeView *view = new QDeclarativeView; |
335 view->setSource(QUrl::fromLocalFile(SRCDIR "/data/chain.qml")); |
336 view->setSource(QUrl::fromLocalFile(SRCDIR "/data/chain.qml")); |
336 QVERIFY(view->rootObject()); |
337 QVERIFY(view->rootObject()); |
337 |
338 |
338 QVERIFY(view->rootObject()->property("focus1") == true); |
339 QVERIFY(view->rootObject()->property("focus1") == false); |
339 QVERIFY(view->rootObject()->property("focus2") == false); |
340 QVERIFY(view->rootObject()->property("focus2") == false); |
340 QVERIFY(view->rootObject()->property("focus3") == true); |
341 QVERIFY(view->rootObject()->property("focus3") == true); |
341 QVERIFY(view->rootObject()->property("focus4") == true); |
342 QVERIFY(view->rootObject()->property("focus4") == true); |
342 QVERIFY(view->rootObject()->property("focus5") == true); |
343 QVERIFY(view->rootObject()->property("focus5") == true); |
343 |
344 |
344 delete view; |
345 delete view; |
345 } |
346 } |
346 |
347 |
|
348 void tst_qdeclarativefocusscope::signalEmission() |
|
349 { |
|
350 QDeclarativeView *view = new QDeclarativeView; |
|
351 view->setSource(QUrl::fromLocalFile(SRCDIR "/data/signalEmission.qml")); |
|
352 |
|
353 QDeclarativeRectangle *item1 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item1")); |
|
354 QDeclarativeRectangle *item2 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item2")); |
|
355 QDeclarativeRectangle *item3 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item3")); |
|
356 QDeclarativeRectangle *item4 = findItem<QDeclarativeRectangle>(view->rootObject(), QLatin1String("item4")); |
|
357 QVERIFY(item1 != 0); |
|
358 QVERIFY(item2 != 0); |
|
359 QVERIFY(item3 != 0); |
|
360 QVERIFY(item4 != 0); |
|
361 |
|
362 view->show(); |
|
363 qApp->setActiveWindow(view); |
|
364 qApp->processEvents(); |
|
365 |
|
366 #ifdef Q_WS_X11 |
|
367 // to be safe and avoid failing setFocus with window managers |
|
368 qt_x11_wait_for_window_manager(view); |
|
369 #endif |
|
370 |
|
371 QVariant blue(QColor("blue")); |
|
372 QVariant red(QColor("red")); |
|
373 |
|
374 QVERIFY(view->hasFocus()); |
|
375 QVERIFY(view->scene()->hasFocus()); |
|
376 item1->setFocus(true); |
|
377 QCOMPARE(item1->property("color"), red); |
|
378 QCOMPARE(item2->property("color"), blue); |
|
379 QCOMPARE(item3->property("color"), blue); |
|
380 QCOMPARE(item4->property("color"), blue); |
|
381 |
|
382 item2->setFocus(true); |
|
383 QCOMPARE(item1->property("color"), blue); |
|
384 QCOMPARE(item2->property("color"), red); |
|
385 QCOMPARE(item3->property("color"), blue); |
|
386 QCOMPARE(item4->property("color"), blue); |
|
387 |
|
388 item3->setFocus(true); |
|
389 QCOMPARE(item1->property("color"), blue); |
|
390 QCOMPARE(item2->property("color"), red); |
|
391 QCOMPARE(item3->property("color"), red); |
|
392 QCOMPARE(item4->property("color"), blue); |
|
393 |
|
394 item4->setFocus(true); |
|
395 QCOMPARE(item1->property("color"), blue); |
|
396 QCOMPARE(item2->property("color"), red); |
|
397 QCOMPARE(item3->property("color"), blue); |
|
398 QCOMPARE(item4->property("color"), red); |
|
399 |
|
400 delete view; |
|
401 } |
|
402 |
347 QTEST_MAIN(tst_qdeclarativefocusscope) |
403 QTEST_MAIN(tst_qdeclarativefocusscope) |
348 |
404 |
349 #include "tst_qdeclarativefocusscope.moc" |
405 #include "tst_qdeclarativefocusscope.moc" |