tests/auto/qgraphicswidget/tst_qgraphicswidget.cpp
changeset 30 5dc02b23752f
parent 25 e24348a560a6
child 33 3e2da88830cd
equal deleted inserted replaced
29:b72c6db6890b 30:5dc02b23752f
   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();
   169     void itemSendGeometryPosChangesDeactivated();
   172     void itemSendGeometryPosChangesDeactivated();
   170 
   173 
   765 // QRectF geometry() const public
   768 // QRectF geometry() const public
   766 void tst_QGraphicsWidget::geometry()
   769 void tst_QGraphicsWidget::geometry()
   767 {
   770 {
   768     SubQGraphicsWidget widget;
   771     SubQGraphicsWidget widget;
   769     QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size()));
   772     QCOMPARE(widget.geometry(), QRectF(widget.pos(), widget.size()));
   770 
   773     QSignalSpy spy(&widget, SIGNAL(geometryChanged()));
   771     QFETCH(QPointF, pos);
   774     QFETCH(QPointF, pos);
   772     QFETCH(QSizeF, size);
   775     QFETCH(QSizeF, size);
   773     widget.setPos(pos);
   776     widget.setPos(pos);
   774     widget.resize(size);
   777     widget.resize(size);
       
   778     if (!size.isNull())
       
   779         QCOMPARE(spy.count(), 1);
   775     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);
   776 }
   807 }
   777 
   808 
   778 void tst_QGraphicsWidget::getContentsMargins_data()
   809 void tst_QGraphicsWidget::getContentsMargins_data()
   779 {
   810 {
   780     QTest::addColumn<qreal>("left");
   811     QTest::addColumn<qreal>("left");
   912     for (int i = 0; i < childCount; ++i) {
   943     for (int i = 0; i < childCount; ++i) {
   913         SubQGraphicsWidget *item = new SubQGraphicsWidget;
   944         SubQGraphicsWidget *item = new SubQGraphicsWidget;
   914         layout->addItem(item);
   945         layout->addItem(item);
   915         children.append(item);
   946         children.append(item);
   916     }
   947     }
       
   948     QSignalSpy spy(&widget, SIGNAL(layoutChanged()));
   917     widget.setLayout(layout);
   949     widget.setLayout(layout);
   918 
   950 
   919     QTRY_COMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout));
   951     QTRY_COMPARE(widget.layout(), static_cast<QGraphicsLayout*>(layout));
   920     for (int i = 0; i < children.count(); ++i) {
   952     for (int i = 0; i < children.count(); ++i) {
   921         SubQGraphicsWidget *item = children[i];
   953         SubQGraphicsWidget *item = children[i];
   922         QCOMPARE(item->parentWidget(), (QGraphicsWidget *)&widget);
   954         QCOMPARE(item->parentWidget(), (QGraphicsWidget *)&widget);
   923         QVERIFY(item->geometry() != QRectF(0, 0, -1, -1));
   955         QVERIFY(item->geometry() != QRectF(0, 0, -1, -1));
   924     }
   956     }
   925 
   957     QCOMPARE(spy.count(), 1);
   926     // don't crash
   958     // don't crash
   927     widget.setLayout(0);
   959     widget.setLayout(0);
   928 }
   960 }
   929 
   961 
   930 void tst_QGraphicsWidget::layoutDirection_data()
   962 void tst_QGraphicsWidget::layoutDirection_data()
  2823 
  2855 
  2824     // Make sure the item got polish event.
  2856     // Make sure the item got polish event.
  2825     QTRY_VERIFY(widget->events.contains(QEvent::Polish));
  2857     QTRY_VERIFY(widget->events.contains(QEvent::Polish));
  2826 }
  2858 }
  2827 
  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 
  2828 void tst_QGraphicsWidget::initialShow()
  2886 void tst_QGraphicsWidget::initialShow()
  2829 {
  2887 {
  2830     class MyGraphicsWidget : public QGraphicsWidget
  2888     class MyGraphicsWidget : public QGraphicsWidget
  2831     { public:
  2889     { public:
  2832         MyGraphicsWidget() : repaints(0) {}
  2890         MyGraphicsWidget() : repaints(0) {}