tests/auto/qstatictext/tst_qstatictext.cpp
changeset 37 758a864f9613
parent 33 3e2da88830cd
equal deleted inserted replaced
36:ef0373b55136 37:758a864f9613
    71     void setFont();
    71     void setFont();
    72     void setTextWidth();
    72     void setTextWidth();
    73     void prepareToCorrectData();
    73     void prepareToCorrectData();
    74     void prepareToWrongData();
    74     void prepareToWrongData();
    75 
    75 
       
    76     void copyConstructor();
       
    77 
    76     void translatedPainter();
    78     void translatedPainter();
    77     void rotatedPainter();
    79     void rotatedPainter();
    78     void scaledPainter();
    80     void scaledPainter();
    79     void projectedPainter();
    81     void projectedPainter();
    80     void rotatedScaledAndTranslatedPainter();
    82     void rotatedScaledAndTranslatedPainter();
    83     void plainTextVsRichText();
    85     void plainTextVsRichText();
    84 
    86 
    85     void setPenPlainText();
    87     void setPenPlainText();
    86     void setPenRichText();
    88     void setPenRichText();
    87     void richTextOverridesPen();
    89     void richTextOverridesPen();
       
    90 
       
    91     void drawStruckOutText();
       
    92     void drawOverlinedText();
       
    93     void drawUnderlinedText();
    88 };
    94 };
    89 
    95 
    90 void tst_QStaticText::init()
    96 void tst_QStaticText::init()
    91 {
    97 {
    92 }
    98 }
    96 }
   102 }
    97 
   103 
    98 void tst_QStaticText::constructionAndDestruction()
   104 void tst_QStaticText::constructionAndDestruction()
    99 {
   105 {
   100     QStaticText text("My text");
   106     QStaticText text("My text");
       
   107 }
       
   108 
       
   109 void tst_QStaticText::copyConstructor()
       
   110 {
       
   111     QStaticText text(QLatin1String("My text"));
       
   112 
       
   113     QTextOption textOption(Qt::AlignRight);
       
   114     text.setTextOption(textOption);
       
   115 
       
   116     text.setPerformanceHint(QStaticText::AggressiveCaching);
       
   117     text.setTextWidth(123.456);
       
   118     text.setTextFormat(Qt::PlainText);
       
   119 
       
   120     QStaticText copiedText(text);
       
   121     copiedText.setText(QLatin1String("Other text"));
       
   122 
       
   123     QCOMPARE(copiedText.textOption().alignment(), Qt::AlignRight);
       
   124     QCOMPARE(copiedText.performanceHint(), QStaticText::AggressiveCaching);
       
   125     QCOMPARE(copiedText.textWidth(), 123.456);
       
   126     QCOMPARE(copiedText.textFormat(), Qt::PlainText);
       
   127 
       
   128     QStaticText otherCopiedText(copiedText);
       
   129     otherCopiedText.setTextWidth(789);
       
   130 
       
   131     QCOMPARE(otherCopiedText.text(), QString::fromLatin1("Other text"));
   101 }
   132 }
   102 
   133 
   103 Q_DECLARE_METATYPE(QStaticText::PerformanceHint)
   134 Q_DECLARE_METATYPE(QStaticText::PerformanceHint)
   104 void tst_QStaticText::drawToPoint_data()
   135 void tst_QStaticText::drawToPoint_data()
   105 {
   136 {
   618                     || pixel == QColor(Qt::red).rgba());
   649                     || pixel == QColor(Qt::red).rgba());
   619         }
   650         }
   620     }
   651     }
   621 }
   652 }
   622 
   653 
       
   654 void tst_QStaticText::drawStruckOutText()
       
   655 {
       
   656     QPixmap imageDrawText(1000, 1000);
       
   657     QPixmap imageDrawStaticText(1000, 1000);
       
   658 
       
   659     imageDrawText.fill(Qt::white);
       
   660     imageDrawStaticText.fill(Qt::white);
       
   661 
       
   662     QString s = QString::fromLatin1("Foobar");
       
   663 
       
   664     QFont font;
       
   665     font.setStrikeOut(true);
       
   666 
       
   667     {
       
   668         QPainter p(&imageDrawText);
       
   669         p.setFont(font);
       
   670         p.drawText(QPointF(50, 50), s);
       
   671     }
       
   672 
       
   673     {
       
   674         QPainter p(&imageDrawStaticText);
       
   675         QStaticText text = QStaticText(s);
       
   676         p.setFont(font);
       
   677         p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text);
       
   678     }
       
   679 
       
   680 #if defined(DEBUG_SAVE_IMAGE)
       
   681     imageDrawText.save("drawStruckOutText_imageDrawText.png");
       
   682     imageDrawStaticText.save("drawStruckOutText_imageDrawStaticText.png");
       
   683 #endif
       
   684 
       
   685     QCOMPARE(imageDrawText, imageDrawStaticText);
       
   686 }
       
   687 
       
   688 void tst_QStaticText::drawOverlinedText()
       
   689 {
       
   690     QPixmap imageDrawText(1000, 1000);
       
   691     QPixmap imageDrawStaticText(1000, 1000);
       
   692 
       
   693     imageDrawText.fill(Qt::white);
       
   694     imageDrawStaticText.fill(Qt::white);
       
   695 
       
   696     QString s = QString::fromLatin1("Foobar");
       
   697 
       
   698     QFont font;
       
   699     font.setOverline(true);
       
   700 
       
   701     {
       
   702         QPainter p(&imageDrawText);
       
   703         p.setFont(font);
       
   704         p.drawText(QPointF(50, 50), s);
       
   705     }
       
   706 
       
   707     {
       
   708         QPainter p(&imageDrawStaticText);
       
   709         QStaticText text = QStaticText(s);
       
   710         p.setFont(font);
       
   711         p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text);
       
   712     }
       
   713 
       
   714 #if defined(DEBUG_SAVE_IMAGE)
       
   715     imageDrawText.save("drawOverlinedText_imageDrawText.png");
       
   716     imageDrawStaticText.save("drawOverlinedText_imageDrawStaticText.png");
       
   717 #endif
       
   718 
       
   719     QCOMPARE(imageDrawText, imageDrawStaticText);
       
   720 }
       
   721 
       
   722 void tst_QStaticText::drawUnderlinedText()
       
   723 {
       
   724     QPixmap imageDrawText(1000, 1000);
       
   725     QPixmap imageDrawStaticText(1000, 1000);
       
   726 
       
   727     imageDrawText.fill(Qt::white);
       
   728     imageDrawStaticText.fill(Qt::white);
       
   729 
       
   730     QString s = QString::fromLatin1("Foobar");
       
   731 
       
   732     QFont font;
       
   733     font.setUnderline(true);
       
   734 
       
   735     {
       
   736         QPainter p(&imageDrawText);
       
   737         p.setFont(font);
       
   738         p.drawText(QPointF(50, 50), s);
       
   739     }
       
   740 
       
   741     {
       
   742         QPainter p(&imageDrawStaticText);
       
   743         QStaticText text = QStaticText(s);
       
   744         p.setFont(font);
       
   745         p.drawStaticText(QPointF(50, 50 - QFontMetricsF(p.font()).ascent()), text);
       
   746     }
       
   747 
       
   748 #if defined(DEBUG_SAVE_IMAGE)
       
   749     imageDrawText.save("drawUnderlinedText_imageDrawText.png");
       
   750     imageDrawStaticText.save("drawUnderlinedText_imageDrawStaticText.png");
       
   751 #endif
       
   752 
       
   753     QCOMPARE(imageDrawText, imageDrawStaticText);
       
   754 }
       
   755 
   623 QTEST_MAIN(tst_QStaticText)
   756 QTEST_MAIN(tst_QStaticText)
   624 #include "tst_qstatictext.moc"
   757 #include "tst_qstatictext.moc"