diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-05 16:07:21 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@nokia.com> | 2010-02-05 16:07:21 (GMT) |
commit | f85b35d5b8a005e2d7128c203f7402750b94e1da (patch) | |
tree | 5ffdfa368ca52a6ffa2d02350e6a6af81a9e3207 /tests/auto/qstatictext/tst_qstatictext.cpp | |
parent | 3d89703be18d13cc4a571ce875cff3ec6cca498f (diff) | |
download | Qt-f85b35d5b8a005e2d7128c203f7402750b94e1da.zip Qt-f85b35d5b8a005e2d7128c203f7402750b94e1da.tar.gz Qt-f85b35d5b8a005e2d7128c203f7402750b94e1da.tar.bz2 |
Add tests for using QStaticText with a QGLWidget
Some tests with and without VBO caching.
Diffstat (limited to 'tests/auto/qstatictext/tst_qstatictext.cpp')
-rw-r--r-- | tests/auto/qstatictext/tst_qstatictext.cpp | 211 |
1 files changed, 211 insertions, 0 deletions
diff --git a/tests/auto/qstatictext/tst_qstatictext.cpp b/tests/auto/qstatictext/tst_qstatictext.cpp index 9e6f3d6..9e4b540 100644 --- a/tests/auto/qstatictext/tst_qstatictext.cpp +++ b/tests/auto/qstatictext/tst_qstatictext.cpp @@ -44,6 +44,8 @@ #include <QtGui/QPainter> #include <QtGui/QImage> +#include <QtOpenGl/QGLWidget> + #include <private/qstatictext_p.h> #include <private/qstatictext_p_p.h> #include <private/qpainter_p.h> @@ -73,6 +75,11 @@ private slots: void projectedPainter(); void rotatedScaledAndTranslatedPainter(); void transformationChanged(); + + void drawToGLWidget(); + void drawToGLWidgetRepeated(); + void drawToGLWidgetWithCaching(); + void drawToGLWidgetWithCachingRepeated(); }; void tst_QStaticText::init() @@ -430,5 +437,209 @@ void tst_QStaticText::transformationChanged() QCOMPARE(imageDrawStaticText, imageDrawText); } +class MyGLWidget: public QGLWidget +{ +public: + enum PaintEventType { + NormalDrawText, + NormalDrawStaticText, + DrawStaticTextWithCaching + }; + + MyGLWidget(PaintEventType paintEventType, QWidget *parent = 0) + : QGLWidget(parent), m_paintEventType(paintEventType) + { + m_staticText.setText("Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + if (m_paintEventType == DrawStaticTextWithCaching) + m_staticText.setUseBackendOptimizations(true); + shown = false; + } + + void paintEvent(QPaintEvent *) + { + QPainter painter(this); + painter.fillRect(rect(), Qt::white); + switch (m_paintEventType) { + case NormalDrawStaticText: + case DrawStaticTextWithCaching: + qt_draw_static_text(&painter, QPointF(11, 12), m_staticText); + break; + case NormalDrawText: + painter.drawText(11, 12, "Lorem ipsum dolor sit amet, consectetur adipiscing elit."); + break; + }; + shown = true; + } + + bool shown; + +private: + QStaticText m_staticText; + PaintEventType m_paintEventType; +}; + +void tst_QStaticText::drawToGLWidget() +{ + QImage imageDrawText; + { + MyGLWidget glWidget(MyGLWidget::NormalDrawText); + glWidget.show(); + while (!glWidget.shown) + QApplication::processEvents(); + imageDrawText = glWidget.grabFrameBuffer(); + } + + QImage imageDrawStaticText; + { + MyGLWidget glWidget(MyGLWidget::NormalDrawStaticText); + glWidget.show(); + while (!glWidget.shown) + QApplication::processEvents(); + imageDrawStaticText = glWidget.grabFrameBuffer(); + } + +#if defined(DEBUG_SAVE_IMAGE) + imageDrawText.save("drawToGLWidget_imageDrawText.png"); + imageDrawStaticText.save("drawToGLWidget_imageDrawStaticText.png"); +#endif + + QCOMPARE(imageDrawStaticText, imageDrawText); +} + +void tst_QStaticText::drawToGLWidgetWithCaching() +{ + QImage imageDrawText; + { + MyGLWidget glWidget(MyGLWidget::NormalDrawText); + glWidget.show(); + while (!glWidget.shown) + QApplication::processEvents(); + imageDrawText = glWidget.grabFrameBuffer(); + } + + QImage imageDrawStaticText; + { + MyGLWidget glWidget(MyGLWidget::DrawStaticTextWithCaching); + glWidget.show(); + while (!glWidget.shown) + QApplication::processEvents(); + imageDrawStaticText = glWidget.grabFrameBuffer(); + } + +#if defined(DEBUG_SAVE_IMAGE) + imageDrawText.save("drawToGLWidgetWithCaching_imageDrawText.png"); + imageDrawStaticText.save("drawToGLWidgetWithCaching_imageDrawStaticText.png"); +#endif + + QCOMPARE(imageDrawStaticText, imageDrawText); +} + +void tst_QStaticText::drawToGLWidgetWithCachingRepeated() +{ + QImage imageDrawText; + MyGLWidget glWidgetNormal(MyGLWidget::NormalDrawText); + + { + glWidgetNormal.show(); + while (!glWidgetNormal.shown) + QApplication::processEvents(); + imageDrawText = glWidgetNormal.grabFrameBuffer(); + } + + QImage imageDrawStaticText; + MyGLWidget glWidgetAbnormal(MyGLWidget::DrawStaticTextWithCaching); + { + + glWidgetAbnormal.show(); + while (!glWidgetAbnormal.shown) + QApplication::processEvents(); + imageDrawStaticText = glWidgetAbnormal.grabFrameBuffer(); + } + +#if defined(DEBUG_SAVE_IMAGE) + imageDrawText.save("drawToGLWidgetWithCachingRepeated_imageDrawText1.png"); + imageDrawStaticText.save("drawToGLWidgetWithCachingRepeated_imageDrawStaticText1.png"); +#endif + + QCOMPARE(imageDrawStaticText, imageDrawText); + + { + glWidgetNormal.shown = false; + glWidgetNormal.update(); + while (!glWidgetNormal.shown) + QApplication::processEvents(); + imageDrawText = glWidgetNormal.grabFrameBuffer(); + } + + { + glWidgetAbnormal.shown = false; + glWidgetAbnormal.update(); + while (!glWidgetAbnormal.shown) + QApplication::processEvents(); + imageDrawStaticText = glWidgetAbnormal.grabFrameBuffer(); + } + +#if defined(DEBUG_SAVE_IMAGE) + imageDrawText.save("drawToGLWidgetWithCachingRepeated_imageDrawText2.png"); + imageDrawStaticText.save("drawToGLWidgetWithCachingRepeated_imageDrawStaticText2.png"); +#endif + + QCOMPARE(imageDrawStaticText, imageDrawText); +} + +void tst_QStaticText::drawToGLWidgetRepeated() +{ + QImage imageDrawText; + MyGLWidget glWidgetNormal(MyGLWidget::NormalDrawText); + + { + glWidgetNormal.show(); + while (!glWidgetNormal.shown) + QApplication::processEvents(); + imageDrawText = glWidgetNormal.grabFrameBuffer(); + } + + QImage imageDrawStaticText; + MyGLWidget glWidgetAbnormal(MyGLWidget::NormalDrawStaticText); + { + + glWidgetAbnormal.show(); + while (!glWidgetAbnormal.shown) + QApplication::processEvents(); + imageDrawStaticText = glWidgetAbnormal.grabFrameBuffer(); + } + +#if defined(DEBUG_SAVE_IMAGE) + imageDrawText.save("drawToGLWidgetWithCachingRepeated_imageDrawText1.png"); + imageDrawStaticText.save("drawToGLWidgetWithCachingRepeated_imageDrawStaticText1.png"); +#endif + + QCOMPARE(imageDrawStaticText, imageDrawText); + + { + glWidgetNormal.shown = false; + glWidgetNormal.update(); + while (!glWidgetNormal.shown) + QApplication::processEvents(); + imageDrawText = glWidgetNormal.grabFrameBuffer(); + } + + { + glWidgetAbnormal.shown = false; + glWidgetAbnormal.update(); + while (!glWidgetAbnormal.shown) + QApplication::processEvents(); + imageDrawStaticText = glWidgetAbnormal.grabFrameBuffer(); + } + +#if defined(DEBUG_SAVE_IMAGE) + imageDrawText.save("drawToGLWidgetWithCachingRepeated_imageDrawText2.png"); + imageDrawStaticText.save("drawToGLWidgetWithCachingRepeated_imageDrawStaticText2.png"); +#endif + + QCOMPARE(imageDrawStaticText, imageDrawText); +} + + QTEST_MAIN(tst_QStaticText) #include "tst_qstatictext.moc" |