346 void childrenBoundingRect(); |
346 void childrenBoundingRect(); |
347 void childrenBoundingRectTransformed(); |
347 void childrenBoundingRectTransformed(); |
348 void childrenBoundingRect2(); |
348 void childrenBoundingRect2(); |
349 void childrenBoundingRect3(); |
349 void childrenBoundingRect3(); |
350 void childrenBoundingRect4(); |
350 void childrenBoundingRect4(); |
|
351 void childrenBoundingRect5(); |
351 void group(); |
352 void group(); |
352 void setGroup(); |
353 void setGroup(); |
353 void setGroup2(); |
354 void setGroup2(); |
354 void nestedGroups(); |
355 void nestedGroups(); |
355 void warpChildrenIntoGroup(); |
356 void warpChildrenIntoGroup(); |
419 void focusProxyDeletion(); |
420 void focusProxyDeletion(); |
420 void negativeZStacksBehindParent(); |
421 void negativeZStacksBehindParent(); |
421 void setGraphicsEffect(); |
422 void setGraphicsEffect(); |
422 void panel(); |
423 void panel(); |
423 void addPanelToActiveScene(); |
424 void addPanelToActiveScene(); |
|
425 void panelWithFocusItem(); |
424 void activate(); |
426 void activate(); |
425 void setActivePanelOnInactiveScene(); |
427 void setActivePanelOnInactiveScene(); |
426 void activationOnShowHide(); |
428 void activationOnShowHide(); |
427 void moveWhileDeleting(); |
429 void moveWhileDeleting(); |
428 void ensureDirtySceneTransform(); |
430 void ensureDirtySceneTransform(); |
439 void itemIsInFront(); |
441 void itemIsInFront(); |
440 void scenePosChange(); |
442 void scenePosChange(); |
441 void updateMicroFocus(); |
443 void updateMicroFocus(); |
442 void textItem_shortcuts(); |
444 void textItem_shortcuts(); |
443 void scroll(); |
445 void scroll(); |
|
446 void stopClickFocusPropagation(); |
444 |
447 |
445 // task specific tests below me |
448 // task specific tests below me |
446 void task141694_textItemEnsureVisible(); |
449 void task141694_textItemEnsureVisible(); |
447 void task128696_textItemEnsureMovable(); |
450 void task128696_textItemEnsureMovable(); |
448 void ensureUpdateOnTextItem(); |
451 void ensureUpdateOnTextItem(); |
458 void QT_2653_fullUpdateDiscardingOpacityUpdate(); |
461 void QT_2653_fullUpdateDiscardingOpacityUpdate(); |
459 void QT_2649_focusScope(); |
462 void QT_2649_focusScope(); |
460 void sortItemsWhileAdding(); |
463 void sortItemsWhileAdding(); |
461 void doNotMarkFullUpdateIfNotInScene(); |
464 void doNotMarkFullUpdateIfNotInScene(); |
462 void itemDiesDuringDraggingOperation(); |
465 void itemDiesDuringDraggingOperation(); |
|
466 void QTBUG_12112_focusItem(); |
463 |
467 |
464 private: |
468 private: |
465 QList<QGraphicsItem *> paintedItems; |
469 QList<QGraphicsItem *> paintedItems; |
466 }; |
470 }; |
467 |
471 |
3365 rect3->setOpacity(0.0); |
3369 rect3->setOpacity(0.0); |
3366 rect3->setParentItem(rect2); |
3370 rect3->setParentItem(rect2); |
3367 |
3371 |
3368 QCOMPARE(rect->childrenBoundingRect(), rect3->boundingRect()); |
3372 QCOMPARE(rect->childrenBoundingRect(), rect3->boundingRect()); |
3369 QCOMPARE(rect2->childrenBoundingRect(), rect3->boundingRect()); |
3373 QCOMPARE(rect2->childrenBoundingRect(), rect3->boundingRect()); |
|
3374 } |
|
3375 |
|
3376 void tst_QGraphicsItem::childrenBoundingRect5() |
|
3377 { |
|
3378 QGraphicsScene scene; |
|
3379 |
|
3380 QGraphicsRectItem *parent = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3381 QGraphicsRectItem *child = scene.addRect(QRectF(0, 0, 100, 100)); |
|
3382 child->setParentItem(parent); |
|
3383 |
|
3384 QGraphicsView view(&scene); |
|
3385 view.show(); |
|
3386 |
|
3387 QTest::qWaitForWindowShown(&view); |
|
3388 |
|
3389 // Try to mess up the cached bounding rect. |
|
3390 QRectF expectedChildrenBoundingRect = parent->boundingRect(); |
|
3391 QCOMPARE(parent->childrenBoundingRect(), expectedChildrenBoundingRect); |
|
3392 |
|
3393 // Apply some effects. |
|
3394 QGraphicsDropShadowEffect *dropShadow = new QGraphicsDropShadowEffect; |
|
3395 dropShadow->setOffset(25, 25); |
|
3396 child->setGraphicsEffect(dropShadow); |
|
3397 parent->setGraphicsEffect(new QGraphicsOpacityEffect); |
|
3398 |
|
3399 QVERIFY(parent->childrenBoundingRect() != expectedChildrenBoundingRect); |
|
3400 expectedChildrenBoundingRect |= dropShadow->boundingRect(); |
|
3401 QCOMPARE(parent->childrenBoundingRect(), expectedChildrenBoundingRect); |
3370 } |
3402 } |
3371 |
3403 |
3372 void tst_QGraphicsItem::group() |
3404 void tst_QGraphicsItem::group() |
3373 { |
3405 { |
3374 QGraphicsScene scene; |
3406 QGraphicsScene scene; |
7553 //We now test the content of the style option |
7585 //We now test the content of the style option |
7554 MyStyleOptionTester *rect = new MyStyleOptionTester(QRect(0, 0, 100, 100)); |
7586 MyStyleOptionTester *rect = new MyStyleOptionTester(QRect(0, 0, 100, 100)); |
7555 scene.addItem(rect); |
7587 scene.addItem(rect); |
7556 rect->setPos(200, 200); |
7588 rect->setPos(200, 200); |
7557 QGraphicsView view(&scene); |
7589 QGraphicsView view(&scene); |
|
7590 view.setWindowFlags(Qt::X11BypassWindowManagerHint); |
7558 rect->startTrack = false; |
7591 rect->startTrack = false; |
7559 view.show(); |
7592 view.show(); |
7560 QTest::qWaitForWindowShown(&view); |
7593 QTest::qWaitForWindowShown(&view); |
7561 QTest::qWait(60); |
7594 QTest::qWait(60); |
7562 rect->startTrack = true; |
7595 rect->startTrack = true; |
8381 scene.setActivePanel(0); |
8414 scene.setActivePanel(0); |
8382 |
8415 |
8383 // Reactivate the scene |
8416 // Reactivate the scene |
8384 QApplication::sendEvent(&scene, &activate); |
8417 QApplication::sendEvent(&scene, &activate); |
8385 QVERIFY(!panel1->isActive()); |
8418 QVERIFY(!panel1->isActive()); |
|
8419 } |
|
8420 |
|
8421 void tst_QGraphicsItem::panelWithFocusItem() |
|
8422 { |
|
8423 QGraphicsScene scene; |
|
8424 QEvent activate(QEvent::WindowActivate); |
|
8425 QApplication::sendEvent(&scene, &activate); |
|
8426 |
|
8427 QGraphicsRectItem *parentPanel = new QGraphicsRectItem; |
|
8428 QGraphicsRectItem *parentPanelFocusItem = new QGraphicsRectItem(parentPanel); |
|
8429 parentPanel->setFlag(QGraphicsItem::ItemIsPanel); |
|
8430 parentPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable); |
|
8431 parentPanelFocusItem->setFocus(); |
|
8432 scene.addItem(parentPanel); |
|
8433 |
|
8434 QVERIFY(parentPanel->isActive()); |
|
8435 QVERIFY(parentPanelFocusItem->hasFocus()); |
|
8436 QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem); |
|
8437 QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem); |
|
8438 |
|
8439 QGraphicsRectItem *childPanel = new QGraphicsRectItem; |
|
8440 QGraphicsRectItem *childPanelFocusItem = new QGraphicsRectItem(childPanel); |
|
8441 childPanel->setFlag(QGraphicsItem::ItemIsPanel); |
|
8442 childPanelFocusItem->setFlag(QGraphicsItem::ItemIsFocusable); |
|
8443 childPanelFocusItem->setFocus(); |
|
8444 |
|
8445 QVERIFY(!childPanelFocusItem->hasFocus()); |
|
8446 QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)childPanelFocusItem); |
|
8447 QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)childPanelFocusItem); |
|
8448 |
|
8449 childPanel->setParentItem(parentPanel); |
|
8450 |
|
8451 QVERIFY(!parentPanel->isActive()); |
|
8452 QVERIFY(!parentPanelFocusItem->hasFocus()); |
|
8453 QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem); |
|
8454 QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem); |
|
8455 |
|
8456 QVERIFY(childPanel->isActive()); |
|
8457 QVERIFY(childPanelFocusItem->hasFocus()); |
|
8458 QCOMPARE(childPanel->focusItem(), (QGraphicsItem *)childPanelFocusItem); |
|
8459 QCOMPARE(childPanelFocusItem->focusItem(), (QGraphicsItem *)childPanelFocusItem); |
|
8460 |
|
8461 childPanel->hide(); |
|
8462 |
|
8463 QVERIFY(parentPanel->isActive()); |
|
8464 QVERIFY(parentPanelFocusItem->hasFocus()); |
|
8465 QCOMPARE(parentPanel->focusItem(), (QGraphicsItem *)parentPanelFocusItem); |
|
8466 QCOMPARE(parentPanelFocusItem->focusItem(), (QGraphicsItem *)parentPanelFocusItem); |
8386 } |
8467 } |
8387 |
8468 |
8388 void tst_QGraphicsItem::addPanelToActiveScene() |
8469 void tst_QGraphicsItem::addPanelToActiveScene() |
8389 { |
8470 { |
8390 QGraphicsScene scene; |
8471 QGraphicsScene scene; |
10234 |
10315 |
10235 expectedItem2Expose = item2BoundingRect; |
10316 expectedItem2Expose = item2BoundingRect; |
10236 // NB! Adjusted by 2 pixels for antialiasing |
10317 // NB! Adjusted by 2 pixels for antialiasing |
10237 expectedItem2Expose &= item1->mapRectToItem(item2, QRectF(50, 50, 100, 100).adjusted(-2, -2, 2, 2)); |
10318 expectedItem2Expose &= item1->mapRectToItem(item2, QRectF(50, 50, 100, 100).adjusted(-2, -2, 2, 2)); |
10238 QCOMPARE(item2->lastExposedRect, expectedItem2Expose); |
10319 QCOMPARE(item2->lastExposedRect, expectedItem2Expose); |
|
10320 } |
|
10321 |
|
10322 void tst_QGraphicsItem::stopClickFocusPropagation() |
|
10323 { |
|
10324 class MyItem : public QGraphicsRectItem |
|
10325 { |
|
10326 public: |
|
10327 MyItem() : QGraphicsRectItem(0, 0, 100, 100) {} |
|
10328 void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) |
|
10329 { |
|
10330 painter->fillRect(boundingRect(), hasFocus() ? QBrush(Qt::red) : brush()); |
|
10331 } |
|
10332 }; |
|
10333 |
|
10334 QGraphicsScene scene(-50, -50, 400, 400); |
|
10335 scene.setStickyFocus(true); |
|
10336 |
|
10337 QGraphicsRectItem *noFocusOnTop = new MyItem; |
|
10338 noFocusOnTop->setBrush(Qt::yellow); |
|
10339 noFocusOnTop->setFlag(QGraphicsItem::ItemStopsClickFocusPropagation); |
|
10340 |
|
10341 QGraphicsRectItem *focusableUnder = new MyItem; |
|
10342 focusableUnder->setBrush(Qt::blue); |
|
10343 focusableUnder->setFlag(QGraphicsItem::ItemIsFocusable); |
|
10344 focusableUnder->setPos(50, 50); |
|
10345 |
|
10346 QGraphicsRectItem *itemWithFocus = new MyItem; |
|
10347 itemWithFocus->setBrush(Qt::black); |
|
10348 itemWithFocus->setFlag(QGraphicsItem::ItemIsFocusable); |
|
10349 itemWithFocus->setPos(250, 10); |
|
10350 |
|
10351 scene.addItem(noFocusOnTop); |
|
10352 scene.addItem(focusableUnder); |
|
10353 scene.addItem(itemWithFocus); |
|
10354 focusableUnder->stackBefore(noFocusOnTop); |
|
10355 itemWithFocus->setFocus(); |
|
10356 |
|
10357 QGraphicsView view(&scene); |
|
10358 view.show(); |
|
10359 QTest::qWaitForWindowShown(&view); |
|
10360 |
|
10361 QApplication::setActiveWindow(&view); |
|
10362 QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(&view)); |
|
10363 QVERIFY(itemWithFocus->hasFocus()); |
|
10364 |
|
10365 QPointF mousePressPoint = noFocusOnTop->mapToScene(QPointF()); |
|
10366 mousePressPoint.rx() += 60; |
|
10367 mousePressPoint.ry() += 60; |
|
10368 const QList<QGraphicsItem *> itemsAtMousePressPosition = scene.items(mousePressPoint); |
|
10369 QVERIFY(itemsAtMousePressPosition.contains(focusableUnder)); |
|
10370 |
|
10371 sendMousePress(&scene, mousePressPoint); |
|
10372 QVERIFY(itemWithFocus->hasFocus()); |
10239 } |
10373 } |
10240 |
10374 |
10241 void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() |
10375 void tst_QGraphicsItem::QTBUG_5418_textItemSetDefaultColor() |
10242 { |
10376 { |
10243 struct Item : public QGraphicsTextItem |
10377 struct Item : public QGraphicsTextItem |
10589 QApplication::sendEvent(&scene, &event); |
10723 QApplication::sendEvent(&scene, &event); |
10590 QVERIFY(QGraphicsScenePrivate::get(&scene)->dragDropItem == item); |
10724 QVERIFY(QGraphicsScenePrivate::get(&scene)->dragDropItem == item); |
10591 delete item; |
10725 delete item; |
10592 QVERIFY(QGraphicsScenePrivate::get(&scene)->dragDropItem == 0); |
10726 QVERIFY(QGraphicsScenePrivate::get(&scene)->dragDropItem == 0); |
10593 } |
10727 } |
|
10728 |
|
10729 void tst_QGraphicsItem::QTBUG_12112_focusItem() |
|
10730 { |
|
10731 QGraphicsScene scene; |
|
10732 QGraphicsView view(&scene); |
|
10733 QGraphicsRectItem *item1 = new QGraphicsRectItem(0, 0, 20, 20); |
|
10734 item1->setFlag(QGraphicsItem::ItemIsFocusable); |
|
10735 QGraphicsRectItem *item2 = new QGraphicsRectItem(20, 20, 20, 20); |
|
10736 item2->setFlag(QGraphicsItem::ItemIsFocusable); |
|
10737 item1->setFocus(); |
|
10738 scene.addItem(item2); |
|
10739 scene.addItem(item1); |
|
10740 |
|
10741 view.show(); |
|
10742 QApplication::setActiveWindow(&view); |
|
10743 QTest::qWaitForWindowShown(&view); |
|
10744 QTRY_COMPARE(QApplication::activeWindow(), (QWidget *)&view); |
|
10745 |
|
10746 QVERIFY(item1->focusItem()); |
|
10747 QVERIFY(!item2->focusItem()); |
|
10748 |
|
10749 item2->setFocus(); |
|
10750 QVERIFY(!item1->focusItem()); |
|
10751 QVERIFY(item2->focusItem()); |
|
10752 } |
|
10753 |
10594 QTEST_MAIN(tst_QGraphicsItem) |
10754 QTEST_MAIN(tst_QGraphicsItem) |
10595 #include "tst_qgraphicsitem.moc" |
10755 #include "tst_qgraphicsitem.moc" |