Add basic static text drawing capability to lance
authorJiang Jiang <jiang.jiang@nokia.com>
Fri, 3 Jun 2011 11:31:05 +0000 (13:31 +0200)
committerQt Continuous Integration System <qt-info@nokia.com>
Fri, 3 Jun 2011 13:13:11 +0000 (15:13 +0200)
Task-number: QTBUG-17514
Change-Id: Ife7cd8f940424d805f634ca190bcbf6fd83d8682
Reviewed-on: http://codereview.qt.nokia.com/321
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: aavit <qt_aavit@ovi.com>
tests/arthur/common/paintcommands.cpp
tests/arthur/common/paintcommands.h
tests/auto/lancelot/scripts/statictext.qps [new file with mode: 0644]

index 8060bc7..d005ffd 100644 (file)
@@ -48,6 +48,7 @@
 #include <qtextstream.h>
 #include <qtextlayout.h>
 #include <qdebug.h>
+#include <QStaticText>
 
 #ifndef QT_NO_OPENGL
 #include <qglpixelbuffer.h>
@@ -433,6 +434,10 @@ void PaintCommands::staticInit()
                       "^drawText\\s+(-?\\w*)\\s+(-?\\w*)\\s+\"(.*)\"$",
                       "drawText <x> <y> <text>",
                       "drawText 10 10 \"my text\"");
+    DECL_PAINTCOMMAND("drawStaticText", command_drawStaticText,
+                      "^drawStaticText\\s+(-?\\w*)\\s+(-?\\w*)\\s+\"(.*)\"$",
+                      "drawStaticText <x> <y> <text>",
+                      "drawStaticText 10 10 \"my text\"");
     DECL_PAINTCOMMAND("drawTiledPixmap", command_drawTiledPixmap,
                       "^drawTiledPixmap\\s+([\\w.:\\/]*)"
                       "\\s+(-?\\w*)\\s+(-?\\w*)\\s*(-?\\w*)\\s*(-?\\w*)"
@@ -1256,6 +1261,21 @@ void PaintCommands::command_drawText(QRegExp re)
     m_painter->drawText(x, y, txt);
 }
 
+void PaintCommands::command_drawStaticText(QRegExp re)
+{
+    if (!m_shouldDrawText)
+        return;
+    QStringList caps = re.capturedTexts();
+    int x = convertToInt(caps.at(1));
+    int y = convertToInt(caps.at(2));
+    QString txt = caps.at(3);
+
+    if (m_verboseMode)
+        printf(" -(lance) drawStaticText(%d, %d, %s)\n", x, y, qPrintable(txt));
+
+    m_painter->drawStaticText(x, y, QStaticText(txt));
+}
+
 /***************************************************************************************************/
 void PaintCommands::command_noop(QRegExp)
 {
index cc64aef..925a867 100644 (file)
@@ -201,6 +201,7 @@ private:
     void command_drawRoundedRect(QRegExp re);
     void command_drawRoundRect(QRegExp re);
     void command_drawText(QRegExp re);
+    void command_drawStaticText(QRegExp re);
     void command_drawTiledPixmap(QRegExp re);
     void command_path_addEllipse(QRegExp re);
     void command_path_addPolygon(QRegExp re);
diff --git a/tests/auto/lancelot/scripts/statictext.qps b/tests/auto/lancelot/scripts/statictext.qps
new file mode 100644 (file)
index 0000000..b62b623
--- /dev/null
@@ -0,0 +1,122 @@
+drawStaticText -5 5 "Text that is drawn outside the bounds..."
+
+translate 20 20
+begin_block text_drawing
+save
+  setFont "sansserif" 10 normal
+  drawStaticText 0 20 "sansserif 10pt, normal"
+
+  setFont "sansserif" 12 normal
+  drawStaticText 0 40 "sansserif 12pt, normal"
+
+  setFont "sansserif" 10 bold
+  drawStaticText 0 60 "sansserif 12pt, bold"
+
+  setFont "sansserif" 10 bold italic
+  drawStaticText 0 80 "sansserif 10pt, bold italic"
+
+
+  translate 0 100
+  setPen #7fff0000
+
+  setFont "sansserif" 10 normal
+  drawStaticText 0 20 "alpha sansserif 10pt, normal"
+
+  setFont "sansserif" 12 normal
+  drawStaticText 0 40 "alpha sansserif 12pt, normal"
+
+  setFont "sansserif" 10 bold
+  drawStaticText 0 60 "alpha sansserif 12pt, bold"
+
+  setFont "sansserif" 10 bold italic
+  drawStaticText 0 80 "alpha sansserif 10pt, bold italic"
+
+
+  translate 0 100
+  setPen black
+  save
+    scale 0.9 0.9
+
+    setFont "sansserif" 10 normal
+    drawStaticText 0 20 "scaled sansserif 10pt, normal"
+
+    setFont "sansserif" 12 normal
+    drawStaticText 0 40 "scaled sansserif 12pt, normal"
+
+    setFont "sansserif" 10 bold
+    drawStaticText 0 60 "scaled sansserif 12pt, bold"
+
+    setFont "sansserif" 10 bold italic
+    drawStaticText 0 80 "scaled sansserif 10pt, bold italic"
+  restore
+
+  translate 0 100
+  setPen black
+  save
+    translate 200 90
+    rotate 185
+
+    setFont "sansserif" 10 normal
+    drawStaticText 0 20 "scaled sansserif 10pt, normal"
+
+    setFont "sansserif" 12 normal
+    drawStaticText 0 40 "scaled sansserif 12pt, normal"
+
+    setFont "sansserif" 10 bold
+    drawStaticText 0 60 "scaled sansserif 12pt, bold"
+
+    setFont "sansserif" 10 bold italic
+    drawStaticText 0 80 "scaled sansserif 10pt, bold italic"
+  restore
+
+  translate 0 100
+  gradient_appendStop 0 red
+  gradient_appendStop 0.5 #00ff00
+  gradient_appendStop 1 blue
+  gradient_setLinear 0 0 200 0
+  setPen brush
+
+  setFont "sansserif" 10 normal
+  drawStaticText 0 0 "gradient sansserif 10pt, normal"
+
+  setFont "sansserif" 12 normal
+  drawStaticText 0 20 "gradient sansserif 12pt, normal"
+
+  setFont "sansserif" 10 bold
+  drawStaticText 0 40 "gradient sansserif 12pt, bold"
+
+  setFont "sansserif" 10 bold italic
+  drawStaticText 0 60 "gradient sansserif 10pt, bold italic"
+restore
+end_block
+
+translate 250 0
+drawStaticText 25 520 "clipped to rectangle"
+save
+  setPen #3f000000
+  setBrush nobrush
+  drawRect 20 0 100 500
+  setClipRect 20 0 100 500
+  setPen black
+  repeat_block text_drawing
+restore
+
+translate 150 0
+drawStaticText 25 520 "clipped to path"
+save
+  path_moveTo clip 20 0
+  path_cubicTo clip 0 200  40 400  20 400
+  path_lineTo clip 30 500
+  path_lineTo clip 30 0
+  path_lineTo clip 40 0
+  path_lineTo clip 40 500
+  path_lineTo clip 120 500
+  path_lineTo clip 120 0
+  path_lineTo clip 20 0
+  setPen #3f000000
+  setBrush nobrush
+  drawPath clip
+  setClipPath clip
+  setPen black
+  repeat_block text_drawing
+restore