104 void focusPolicy_data(); |
104 void focusPolicy_data(); |
105 void focusPolicy(); |
105 void focusPolicy(); |
106 void font_data(); |
106 void font_data(); |
107 void font(); |
107 void font(); |
108 void fontPropagation(); |
108 void fontPropagation(); |
|
109 void fontChangedEvent(); |
109 void fontPropagationWidgetItemWidget(); |
110 void fontPropagationWidgetItemWidget(); |
110 void fontPropagationSceneChange(); |
111 void fontPropagationSceneChange(); |
111 void geometry_data(); |
112 void geometry_data(); |
112 void geometry(); |
113 void geometry(); |
113 void getContentsMargins_data(); |
114 void getContentsMargins_data(); |
158 void painterStateProtectionOnWindowFrame(); |
159 void painterStateProtectionOnWindowFrame(); |
159 void ensureClipping(); |
160 void ensureClipping(); |
160 void widgetSendsGeometryChanges(); |
161 void widgetSendsGeometryChanges(); |
161 void respectHFW(); |
162 void respectHFW(); |
162 void addChildInpolishEvent(); |
163 void addChildInpolishEvent(); |
|
164 void polishEvent(); |
|
165 void polishEvent2(); |
163 |
166 |
164 // Task fixes |
167 // Task fixes |
165 void task236127_bspTreeIndexFails(); |
168 void task236127_bspTreeIndexFails(); |
166 void task243004_setStyleCrash(); |
169 void task243004_setStyleCrash(); |
167 void task250119_shortcutContext(); |
170 void task250119_shortcutContext(); |
|
171 void QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems(); |
168 }; |
172 }; |
169 |
173 |
170 |
174 |
171 static void sendMouseMove(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = 0) |
175 static void sendMouseMove(QWidget *widget, const QPoint &point, Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = 0) |
172 { |
176 { |
667 QVERIFY(!child1->font().italic()); |
671 QVERIFY(!child1->font().italic()); |
668 QCOMPARE(child1->font().pointSize(), 43); |
672 QCOMPARE(child1->font().pointSize(), 43); |
669 QVERIFY(child2->font().bold()); |
673 QVERIFY(child2->font().bold()); |
670 QVERIFY(!child2->font().italic()); |
674 QVERIFY(!child2->font().italic()); |
671 QCOMPARE(child2->font().pointSize(), 43); |
675 QCOMPARE(child2->font().pointSize(), 43); |
|
676 } |
|
677 |
|
678 void tst_QGraphicsWidget::fontChangedEvent() |
|
679 { |
|
680 QGraphicsWidget *root = new QGraphicsWidget; |
|
681 QGraphicsScene scene; |
|
682 scene.addItem(root); |
|
683 |
|
684 // Check that only the application fonts apply. |
|
685 QFont appFont = QApplication::font(); |
|
686 QCOMPARE(scene.font(), appFont); |
|
687 QCOMPARE(root->font(), appFont); |
|
688 |
|
689 EventSpy rootSpyFont(root, QEvent::FontChange); |
|
690 EventSpy rootSpyPolish(root, QEvent::Polish); |
|
691 QCOMPARE(rootSpyFont.count(), 0); |
|
692 QApplication::processEvents(); //The polish event is sent |
|
693 QCOMPARE(rootSpyPolish.count(), 1); |
|
694 QApplication::processEvents(); //Process events to see if we get the font change event |
|
695 //The font is still the same so no fontChangeEvent |
|
696 QCOMPARE(rootSpyFont.count(), 0); |
|
697 |
|
698 QFont font; |
|
699 font.setPointSize(43); |
|
700 root->setFont(font); |
|
701 QApplication::processEvents(); //Process events to get the font change event |
|
702 //The font changed |
|
703 QCOMPARE(rootSpyFont.count(), 1); |
|
704 |
|
705 //then roll back to the default one. |
|
706 root->setFont(appFont); |
|
707 QApplication::processEvents(); //Process events to get the font change event |
|
708 //The font changed |
|
709 QCOMPARE(rootSpyFont.count(), 2); |
672 } |
710 } |
673 |
711 |
674 void tst_QGraphicsWidget::fontPropagationWidgetItemWidget() |
712 void tst_QGraphicsWidget::fontPropagationWidgetItemWidget() |
675 { |
713 { |
676 QGraphicsWidget *widget = new QGraphicsWidget; |
714 QGraphicsWidget *widget = new QGraphicsWidget; |
2766 view.show(); |
2804 view.show(); |
2767 QTest::qWaitForWindowShown(&view); |
2805 QTest::qWaitForWindowShown(&view); |
2768 QCOMPARE(PolishWidget::numberOfPolish, 2); |
2806 QCOMPARE(PolishWidget::numberOfPolish, 2); |
2769 } |
2807 } |
2770 |
2808 |
|
2809 void tst_QGraphicsWidget::polishEvent() |
|
2810 { |
|
2811 class MyGraphicsWidget : public QGraphicsWidget |
|
2812 { public: |
|
2813 void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) |
|
2814 { events << QEvent::Paint; } |
|
2815 void polishEvent() |
|
2816 { events << QEvent::Polish; } |
|
2817 QList<QEvent::Type> events; |
|
2818 }; |
|
2819 |
|
2820 QGraphicsScene scene; |
|
2821 |
|
2822 MyGraphicsWidget *widget = new MyGraphicsWidget; |
|
2823 scene.addItem(widget); |
|
2824 |
|
2825 QGraphicsView view(&scene); |
|
2826 view.show(); |
|
2827 QTest::qWaitForWindowShown(&view); |
|
2828 |
|
2829 // Make sure the item is painted. |
|
2830 QTRY_VERIFY(widget->events.contains(QEvent::Paint)); |
|
2831 |
|
2832 // Make sure the item got polish before paint. |
|
2833 QCOMPARE(widget->events.at(0), QEvent::Polish); |
|
2834 } |
|
2835 |
|
2836 void tst_QGraphicsWidget::polishEvent2() |
|
2837 { |
|
2838 class MyGraphicsWidget : public QGraphicsWidget |
|
2839 { public: |
|
2840 void polishEvent() |
|
2841 { events << QEvent::Polish; } |
|
2842 QList<QEvent::Type> events; |
|
2843 }; |
|
2844 |
|
2845 QGraphicsScene scene; |
|
2846 |
|
2847 MyGraphicsWidget *widget = new MyGraphicsWidget; |
|
2848 widget->hide(); |
|
2849 scene.addItem(widget); |
|
2850 |
|
2851 widget->events.clear(); |
|
2852 |
|
2853 QApplication::processEvents(); |
|
2854 |
|
2855 // Make sure the item got polish event. |
|
2856 QVERIFY(widget->events.contains(QEvent::Polish)); |
|
2857 } |
|
2858 |
|
2859 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() |
|
2860 { |
|
2861 QGraphicsScene scene; |
|
2862 QGraphicsWidget* parent1 = new QGraphicsWidget; |
|
2863 QGraphicsWidget* child1_0 = new QGraphicsWidget; |
|
2864 QGraphicsWidget* child1_1 = new QGraphicsWidget; |
|
2865 |
|
2866 QGraphicsWidget* parent2 = new QGraphicsWidget; |
|
2867 |
|
2868 // Add the parent and child to the scene. |
|
2869 scene.addItem(parent1); |
|
2870 child1_0->setParentItem(parent1); |
|
2871 child1_1->setParentItem(parent1); |
|
2872 |
|
2873 // Hide and show the child. |
|
2874 child1_0->setParentItem(NULL); |
|
2875 scene.removeItem(child1_0); |
|
2876 |
|
2877 // Remove parent from the scene. |
|
2878 scene.removeItem(parent1); |
|
2879 |
|
2880 delete child1_0; |
|
2881 delete child1_1; |
|
2882 delete parent1; |
|
2883 |
|
2884 // Add an item into the scene. |
|
2885 scene.addItem(parent2); |
|
2886 |
|
2887 //This should not crash |
|
2888 } |
2771 |
2889 |
2772 QTEST_MAIN(tst_QGraphicsWidget) |
2890 QTEST_MAIN(tst_QGraphicsWidget) |
2773 #include "tst_qgraphicswidget.moc" |
2891 #include "tst_qgraphicswidget.moc" |
2774 |
2892 |
2775 #else // QT_NO_STYLE_CLEANLOOKS |
2893 #else // QT_NO_STYLE_CLEANLOOKS |