619 QFont font(fontName); |
626 QFont font(fontName); |
620 widget.setFont(font); |
627 widget.setFont(font); |
621 QCOMPARE(widget.font().family(), font.family()); |
628 QCOMPARE(widget.font().family(), font.family()); |
622 } |
629 } |
623 |
630 |
|
631 void tst_QGraphicsWidget::fontPropagatesResolveToChildren() |
|
632 { |
|
633 QGraphicsWidget *root = new QGraphicsWidget(); |
|
634 QGraphicsWidget *child1 = new QGraphicsWidget(root); |
|
635 |
|
636 QGraphicsScene scene; |
|
637 scene.addItem(root); |
|
638 |
|
639 QFont font; |
|
640 font.setItalic(true); |
|
641 root->setFont(font); |
|
642 |
|
643 QGraphicsWidget *child2 = new QGraphicsWidget(root); |
|
644 QGraphicsWidget *child3 = new QGraphicsWidget(); |
|
645 child3->setParentItem(root); |
|
646 |
|
647 QGraphicsView view; |
|
648 view.setScene(&scene); |
|
649 view.show(); |
|
650 QTest::qWaitForWindowShown(&view); |
|
651 |
|
652 QCOMPARE(font.resolve(), uint(QFont::StyleResolved)); |
|
653 QCOMPARE(root->font().resolve(), uint(QFont::StyleResolved)); |
|
654 QCOMPARE(child1->font().resolve(), uint(QFont::StyleResolved)); |
|
655 QCOMPARE(child2->font().resolve(), uint(QFont::StyleResolved)); |
|
656 QCOMPARE(child3->font().resolve(), uint(QFont::StyleResolved)); |
|
657 } |
|
658 |
|
659 void tst_QGraphicsWidget::fontPropagatesResolveToGrandChildren() |
|
660 { |
|
661 QGraphicsWidget *root = new QGraphicsWidget(); |
|
662 QGraphicsWidget *child1 = new QGraphicsWidget(root); |
|
663 QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1); |
|
664 |
|
665 QGraphicsScene scene; |
|
666 scene.addItem(root); |
|
667 |
|
668 QFont font; |
|
669 font.setItalic(true); |
|
670 root->setFont(font); |
|
671 |
|
672 QGraphicsWidget *child2 = new QGraphicsWidget(root); |
|
673 QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2); |
|
674 QGraphicsWidget *grandChild3 = new QGraphicsWidget(child2); |
|
675 |
|
676 QGraphicsWidget *child3 = new QGraphicsWidget(); |
|
677 QGraphicsWidget *grandChild4 = new QGraphicsWidget(child3); |
|
678 QGraphicsWidget *grandChild5 = new QGraphicsWidget(child3); |
|
679 child3->setParentItem(root); |
|
680 grandChild5->setParentItem(child3); |
|
681 |
|
682 QGraphicsView view; |
|
683 view.setScene(&scene); |
|
684 view.show(); |
|
685 QTest::qWaitForWindowShown(&view); |
|
686 |
|
687 QCOMPARE(font.resolve(), uint(QFont::StyleResolved)); |
|
688 QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved)); |
|
689 QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved)); |
|
690 QCOMPARE(grandChild3->font().resolve(), uint(QFont::StyleResolved)); |
|
691 QCOMPARE(grandChild4->font().resolve(), uint(QFont::StyleResolved)); |
|
692 QCOMPARE(grandChild5->font().resolve(), uint(QFont::StyleResolved)); |
|
693 } |
|
694 |
|
695 void tst_QGraphicsWidget::fontPropagatesResolveViaNonWidget() |
|
696 { |
|
697 QGraphicsWidget *root = new QGraphicsWidget(); |
|
698 QGraphicsPixmapItem *child1 = new QGraphicsPixmapItem(root); |
|
699 QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1); |
|
700 |
|
701 QGraphicsScene scene; |
|
702 scene.addItem(root); |
|
703 |
|
704 QFont font; |
|
705 font.setItalic(true); |
|
706 root->setFont(font); |
|
707 |
|
708 QGraphicsPixmapItem *child2 = new QGraphicsPixmapItem(root); |
|
709 QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2); |
|
710 QGraphicsWidget *grandChild3 = new QGraphicsWidget(child2); |
|
711 |
|
712 QGraphicsPixmapItem *child3 = new QGraphicsPixmapItem(); |
|
713 QGraphicsWidget *grandChild4 = new QGraphicsWidget(child3); |
|
714 QGraphicsWidget *grandChild5 = new QGraphicsWidget(child3); |
|
715 child3->setParentItem(root); |
|
716 grandChild5->setParentItem(child3); |
|
717 |
|
718 QGraphicsView view; |
|
719 view.setScene(&scene); |
|
720 view.show(); |
|
721 QTest::qWaitForWindowShown(&view); |
|
722 |
|
723 QCOMPARE(font.resolve(), uint(QFont::StyleResolved)); |
|
724 QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved)); |
|
725 QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved)); |
|
726 QCOMPARE(grandChild3->font().resolve(), uint(QFont::StyleResolved)); |
|
727 QCOMPARE(grandChild4->font().resolve(), uint(QFont::StyleResolved)); |
|
728 QCOMPARE(grandChild5->font().resolve(), uint(QFont::StyleResolved)); |
|
729 } |
|
730 |
|
731 void tst_QGraphicsWidget::fontPropagatesResolveFromScene() |
|
732 { |
|
733 QGraphicsWidget *root = new QGraphicsWidget(); |
|
734 QGraphicsWidget *child1 = new QGraphicsWidget(root); |
|
735 QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1); |
|
736 |
|
737 QGraphicsScene scene; |
|
738 scene.addItem(root); |
|
739 |
|
740 QFont font; |
|
741 font.setItalic(true); |
|
742 scene.setFont(font); |
|
743 |
|
744 QGraphicsWidget *child2 = new QGraphicsWidget(root); |
|
745 QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2); |
|
746 QGraphicsWidget *grandChild3 = new QGraphicsWidget(child2); |
|
747 |
|
748 QGraphicsWidget *child3 = new QGraphicsWidget(); |
|
749 QGraphicsWidget *grandChild4 = new QGraphicsWidget(child3); |
|
750 QGraphicsWidget *grandChild5 = new QGraphicsWidget(child3); |
|
751 child3->setParentItem(root); |
|
752 grandChild5->setParentItem(child3); |
|
753 |
|
754 QGraphicsView view; |
|
755 view.setScene(&scene); |
|
756 view.show(); |
|
757 QTest::qWaitForWindowShown(&view); |
|
758 |
|
759 QCOMPARE(font.resolve(), uint(QFont::StyleResolved)); |
|
760 QCOMPARE(root->font().resolve(), uint(QFont::StyleResolved)); |
|
761 QCOMPARE(child1->font().resolve(), uint(QFont::StyleResolved)); |
|
762 QCOMPARE(child2->font().resolve(), uint(QFont::StyleResolved)); |
|
763 QCOMPARE(child3->font().resolve(), uint(QFont::StyleResolved)); |
|
764 QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved)); |
|
765 QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved)); |
|
766 QCOMPARE(grandChild3->font().resolve(), uint(QFont::StyleResolved)); |
|
767 QCOMPARE(grandChild4->font().resolve(), uint(QFont::StyleResolved)); |
|
768 QCOMPARE(grandChild5->font().resolve(), uint(QFont::StyleResolved)); |
|
769 } |
|
770 |
|
771 void tst_QGraphicsWidget::fontPropagatesResolveInParentChange() |
|
772 { |
|
773 QGraphicsWidget *root = new QGraphicsWidget(); |
|
774 |
|
775 QGraphicsWidget *child1 = new QGraphicsWidget(root); |
|
776 QGraphicsWidget *grandChild1 = new QGraphicsWidget(child1); |
|
777 |
|
778 QGraphicsWidget *child2 = new QGraphicsWidget(root); |
|
779 QGraphicsWidget *grandChild2 = new QGraphicsWidget(child2); |
|
780 |
|
781 QGraphicsScene scene; |
|
782 scene.addItem(root); |
|
783 |
|
784 QFont italicFont; |
|
785 italicFont.setItalic(true); |
|
786 child1->setFont(italicFont); |
|
787 |
|
788 QFont boldFont; |
|
789 boldFont.setBold(true); |
|
790 child2->setFont(boldFont); |
|
791 |
|
792 QVERIFY(grandChild1->font().italic()); |
|
793 QVERIFY(!grandChild1->font().bold()); |
|
794 QVERIFY(!grandChild2->font().italic()); |
|
795 QVERIFY(grandChild2->font().bold()); |
|
796 |
|
797 QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved)); |
|
798 QCOMPARE(grandChild2->font().resolve(), uint(QFont::WeightResolved)); |
|
799 |
|
800 grandChild2->setParentItem(child1); |
|
801 |
|
802 QGraphicsView view; |
|
803 view.setScene(&scene); |
|
804 view.show(); |
|
805 QTest::qWaitForWindowShown(&view); |
|
806 |
|
807 QVERIFY(grandChild1->font().italic()); |
|
808 QVERIFY(!grandChild1->font().bold()); |
|
809 QVERIFY(grandChild2->font().italic()); |
|
810 QVERIFY(!grandChild2->font().bold()); |
|
811 |
|
812 QCOMPARE(grandChild1->font().resolve(), uint(QFont::StyleResolved)); |
|
813 QCOMPARE(grandChild2->font().resolve(), uint(QFont::StyleResolved)); |
|
814 |
|
815 } |
|
816 |
624 void tst_QGraphicsWidget::fontPropagation() |
817 void tst_QGraphicsWidget::fontPropagation() |
625 { |
818 { |
626 QGraphicsWidget *root = new QGraphicsWidget; |
819 QGraphicsWidget *root = new QGraphicsWidget; |
627 QGraphicsWidget *child0 = new QGraphicsWidget(root); |
820 QGraphicsWidget *child0 = new QGraphicsWidget(root); |
628 QGraphicsWidget *child1 = new QGraphicsWidget(child0); |
821 QGraphicsWidget *child1 = new QGraphicsWidget(child0); |
774 QSignalSpy spy(&widget, SIGNAL(geometryChanged())); |
968 QSignalSpy spy(&widget, SIGNAL(geometryChanged())); |
775 QFETCH(QPointF, pos); |
969 QFETCH(QPointF, pos); |
776 QFETCH(QSizeF, size); |
970 QFETCH(QSizeF, size); |
777 widget.setPos(pos); |
971 widget.setPos(pos); |
778 widget.resize(size); |
972 widget.resize(size); |
779 if (!size.isNull()) |
973 if (!size.isNull() && !pos.isNull()) |
|
974 QCOMPARE(spy.count(), 2); |
|
975 if (!size.isNull() && pos.isNull()) |
780 QCOMPARE(spy.count(), 1); |
976 QCOMPARE(spy.count(), 1); |
781 QCOMPARE(widget.geometry(), QRectF(pos, size)); |
977 QCOMPARE(widget.geometry(), QRectF(pos, size)); |
|
978 } |
|
979 |
|
980 void tst_QGraphicsWidget::geometryChanged() |
|
981 { |
|
982 QGraphicsWidget w; |
|
983 w.setGeometry(0, 0, 200, 200); |
|
984 QCOMPARE(w.geometry(), QRectF(0, 0, 200, 200)); |
|
985 QSignalSpy spy(&w, SIGNAL(geometryChanged())); |
|
986 w.setGeometry(0, 0, 100, 100); |
|
987 QCOMPARE(spy.count(), 1); |
|
988 QCOMPARE(w.geometry(), QRectF(0, 0, 100, 100)); |
|
989 w.setPos(10, 10); |
|
990 QCOMPARE(spy.count(), 2); |
|
991 QCOMPARE(w.geometry(), QRectF(10, 10, 100, 100)); |
|
992 |
782 } |
993 } |
783 |
994 |
784 void tst_QGraphicsWidget::width() |
995 void tst_QGraphicsWidget::width() |
785 { |
996 { |
786 QGraphicsWidget w; |
997 QGraphicsWidget w; |