109 void fontChangedEvent(); |
109 void fontChangedEvent(); |
110 void fontPropagationWidgetItemWidget(); |
110 void fontPropagationWidgetItemWidget(); |
111 void fontPropagationSceneChange(); |
111 void fontPropagationSceneChange(); |
112 void geometry_data(); |
112 void geometry_data(); |
113 void geometry(); |
113 void geometry(); |
|
114 void width(); |
|
115 void height(); |
114 void getContentsMargins_data(); |
116 void getContentsMargins_data(); |
115 void getContentsMargins(); |
117 void getContentsMargins(); |
116 void initStyleOption_data(); |
118 void initStyleOption_data(); |
117 void initStyleOption(); |
119 void initStyleOption(); |
118 void layout_data(); |
120 void layout_data(); |
161 void widgetSendsGeometryChanges(); |
163 void widgetSendsGeometryChanges(); |
162 void respectHFW(); |
164 void respectHFW(); |
163 void addChildInpolishEvent(); |
165 void addChildInpolishEvent(); |
164 void polishEvent(); |
166 void polishEvent(); |
165 void polishEvent2(); |
167 void polishEvent2(); |
|
168 void autoFillBackground(); |
166 void initialShow(); |
169 void initialShow(); |
167 void initialShow2(); |
170 void initialShow2(); |
168 void itemChangeEvents(); |
171 void itemChangeEvents(); |
|
172 void itemSendGeometryPosChangesDeactivated(); |
169 |
173 |
170 // Task fixes |
174 // Task fixes |
171 void task236127_bspTreeIndexFails(); |
175 void task236127_bspTreeIndexFails(); |
172 void task243004_setStyleCrash(); |
176 void task243004_setStyleCrash(); |
173 void task250119_shortcutContext(); |
177 void task250119_shortcutContext(); |
764 // QRectF geometry() const public |
768 // QRectF geometry() const public |
765 void tst_QGraphicsWidget::geometry() |
769 void tst_QGraphicsWidget::geometry() |
766 { |
770 { |
767 SubQGraphicsWidget widget; |
771 SubQGraphicsWidget widget; |
768 QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size())); |
772 QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size())); |
769 |
773 QSignalSpy spy(&widget, SIGNAL(geometryChanged())); |
770 QFETCH(QPointF, pos); |
774 QFETCH(QPointF, pos); |
771 QFETCH(QSizeF, size); |
775 QFETCH(QSizeF, size); |
772 widget.setPos(pos); |
776 widget.setPos(pos); |
773 widget.resize(size); |
777 widget.resize(size); |
|
778 if (!size.isNull()) |
|
779 QCOMPARE(spy.count(), 1); |
774 QCOMPARE(widget.geometry(), QRectF(pos, size)); |
780 QCOMPARE(widget.geometry(), QRectF(pos, size)); |
|
781 } |
|
782 |
|
783 void tst_QGraphicsWidget::width() |
|
784 { |
|
785 QGraphicsWidget w; |
|
786 QCOMPARE(w.property("width").toReal(), qreal(0)); |
|
787 QSignalSpy spy(&w, SIGNAL(widthChanged())); |
|
788 w.setProperty("width", qreal(50)); |
|
789 QCOMPARE(w.property("width").toReal(), qreal(50)); |
|
790 QCOMPARE(spy.count(), 1); |
|
791 //calling old school setGeometry should work too |
|
792 w.setGeometry(0, 0, 200, 200); |
|
793 QCOMPARE(spy.count(), 2); |
|
794 } |
|
795 |
|
796 void tst_QGraphicsWidget::height() |
|
797 { |
|
798 QGraphicsWidget w; |
|
799 QCOMPARE(w.property("height").toReal(), qreal(0)); |
|
800 QSignalSpy spy(&w, SIGNAL(heightChanged())); |
|
801 w.setProperty("height", qreal(50)); |
|
802 QCOMPARE(w.property("height").toReal(), qreal(50)); |
|
803 QCOMPARE(spy.count(), 1); |
|
804 //calling old school setGeometry should work too |
|
805 w.setGeometry(0, 0, 200, 200); |
|
806 QCOMPARE(spy.count(), 2); |
775 } |
807 } |
776 |
808 |
777 void tst_QGraphicsWidget::getContentsMargins_data() |
809 void tst_QGraphicsWidget::getContentsMargins_data() |
778 { |
810 { |
779 QTest::addColumn<qreal>("left"); |
811 QTest::addColumn<qreal>("left"); |
911 for (int i = 0; i < childCount; ++i) { |
943 for (int i = 0; i < childCount; ++i) { |
912 SubQGraphicsWidget *item = new SubQGraphicsWidget; |
944 SubQGraphicsWidget *item = new SubQGraphicsWidget; |
913 layout->addItem(item); |
945 layout->addItem(item); |
914 children.append(item); |
946 children.append(item); |
915 } |
947 } |
|
948 QSignalSpy spy(&widget, SIGNAL(layoutChanged())); |
916 widget.setLayout(layout); |
949 widget.setLayout(layout); |
917 |
950 |
918 QTRY_COMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout)); |
951 QTRY_COMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout)); |
919 for (int i = 0; i < children.count(); ++i) { |
952 for (int i = 0; i < children.count(); ++i) { |
920 SubQGraphicsWidget *item = children[i]; |
953 SubQGraphicsWidget *item = children[i]; |
921 QCOMPARE(item->parentWidget(), (QGraphicsWidget *)&widget); |
954 QCOMPARE(item->parentWidget(), (QGraphicsWidget *)&widget); |
922 QVERIFY(item->geometry() != QRectF(0, 0, -1, -1)); |
955 QVERIFY(item->geometry() != QRectF(0, 0, -1, -1)); |
923 } |
956 } |
924 |
957 QCOMPARE(spy.count(), 1); |
925 // don't crash |
958 // don't crash |
926 widget.setLayout(0); |
959 widget.setLayout(0); |
927 } |
960 } |
928 |
961 |
929 void tst_QGraphicsWidget::layoutDirection_data() |
962 void tst_QGraphicsWidget::layoutDirection_data() |
2822 |
2855 |
2823 // Make sure the item got polish event. |
2856 // Make sure the item got polish event. |
2824 QTRY_VERIFY(widget->events.contains(QEvent::Polish)); |
2857 QTRY_VERIFY(widget->events.contains(QEvent::Polish)); |
2825 } |
2858 } |
2826 |
2859 |
|
2860 void tst_QGraphicsWidget::autoFillBackground() |
|
2861 { |
|
2862 QGraphicsWidget *widget = new QGraphicsWidget; |
|
2863 QCOMPARE(widget->autoFillBackground(), false); |
|
2864 widget->setAutoFillBackground(true); |
|
2865 QCOMPARE(widget->autoFillBackground(), true); |
|
2866 |
|
2867 const QColor color(Qt::red); |
|
2868 const QRect rect(0, 0, 1, 1); |
|
2869 |
|
2870 QGraphicsScene scene; |
|
2871 scene.addItem(widget); |
|
2872 widget->setGeometry(rect); |
|
2873 |
|
2874 QPalette palette = widget->palette(); |
|
2875 palette.setColor(QPalette::Window, color); |
|
2876 widget->setPalette(palette); |
|
2877 |
|
2878 QImage image(rect.size(), QImage::Format_RGB32); |
|
2879 QPainter painter; |
|
2880 painter.begin(&image); |
|
2881 scene.render(&painter, rect, rect); |
|
2882 painter.end(); |
|
2883 QCOMPARE(image.pixel(0, 0), color.rgb()); |
|
2884 } |
|
2885 |
2827 void tst_QGraphicsWidget::initialShow() |
2886 void tst_QGraphicsWidget::initialShow() |
2828 { |
2887 { |
2829 class MyGraphicsWidget : public QGraphicsWidget |
2888 class MyGraphicsWidget : public QGraphicsWidget |
2830 { public: |
2889 { public: |
2831 MyGraphicsWidget() : repaints(0) {} |
2890 MyGraphicsWidget() : repaints(0) {} |
2970 item->setEnabled(false); |
3029 item->setEnabled(false); |
2971 QVERIFY(!item->isEnabled()); |
3030 QVERIFY(!item->isEnabled()); |
2972 QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::EnabledChange).toBool()); |
3031 QTRY_VERIFY(!item->valueDuringEvents.value(QEvent::EnabledChange).toBool()); |
2973 } |
3032 } |
2974 |
3033 |
|
3034 void tst_QGraphicsWidget::itemSendGeometryPosChangesDeactivated() |
|
3035 { |
|
3036 QGraphicsScene scene; |
|
3037 QGraphicsView view(&scene); |
|
3038 QGraphicsWidget *item = new QGraphicsWidget; |
|
3039 scene.addItem(item); |
|
3040 view.show(); |
|
3041 QTest::qWaitForWindowShown(&view); |
|
3042 item->setGeometry(QRectF(0, 0, 50, 50)); |
|
3043 QTRY_COMPARE(item->geometry(), QRectF(0, 0, 50, 50)); |
|
3044 |
|
3045 item->setFlag(QGraphicsItem::ItemSendsGeometryChanges, false); |
|
3046 item->setGeometry(QRectF(0, 0, 60, 60)); |
|
3047 QCOMPARE(item->geometry(), QRectF(0, 0, 60, 60)); |
|
3048 QCOMPARE(item->pos(), QPointF(0, 0)); |
|
3049 item->setPos(QPointF(10, 10)); |
|
3050 QCOMPARE(item->pos(), QPointF(10, 10)); |
|
3051 QCOMPARE(item->geometry(), QRectF(10, 10, 60, 60)); |
|
3052 |
|
3053 item->setFlag(QGraphicsItem::ItemSendsScenePositionChanges, false); |
|
3054 item->setGeometry(QRectF(0, 0, 60, 60)); |
|
3055 QCOMPARE(item->geometry(), QRectF(0, 0, 60, 60)); |
|
3056 QCOMPARE(item->pos(), QPointF(0, 0)); |
|
3057 item->setPos(QPointF(10, 10)); |
|
3058 QCOMPARE(item->pos(), QPointF(10, 10)); |
|
3059 QCOMPARE(item->geometry(), QRectF(10, 10, 60, 60)); |
|
3060 } |
|
3061 |
2975 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() |
3062 void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() |
2976 { |
3063 { |
2977 QGraphicsScene scene; |
3064 QGraphicsScene scene; |
2978 QGraphicsWidget* parent1 = new QGraphicsWidget; |
3065 QGraphicsWidget* parent1 = new QGraphicsWidget; |
2979 QGraphicsWidget* child1_0 = new QGraphicsWidget; |
3066 QGraphicsWidget* child1_0 = new QGraphicsWidget; |