From 5c436365f579f820344566101e746e244672995a Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Tue, 12 Oct 2021 13:46:24 +0200 Subject: Support background-color CSS styling on
[ChangeLog][QtGui][CSS] The background-color style can now be applied to
to set the rule color. Task-number: QTBUG-74342 Change-Id: Ib960ce4d38caa225f258b6d228fb794cef43e1b7 Reviewed-by: Eskil Abrahamsen Blomfeldt --- .../gui/text/qtextdocument/tst_qtextdocument.cpp | 156 +++++++-------------- 1 file changed, 54 insertions(+), 102 deletions(-) (limited to 'tests/auto/gui/text/qtextdocument') diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp index 74c8bfd260..c028ae1b9c 100644 --- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp +++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp @@ -289,6 +289,7 @@ void tst_QTextDocument::init() "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n" "" "\n"); htmlHead = htmlHead.arg(defaultFont.family()) @@ -1501,7 +1502,19 @@ void tst_QTextDocument::toHtml_data() QTest::newRow("horizontal-ruler-with-width") << QTextDocumentFragment::fromHtml("
") << QString("EMPTYBLOCK") + - QString("
"); + QString("
"); + } + { + QTest::newRow("horizontal-ruler-with-color") << QTextDocumentFragment::fromHtml("
") + << + QString("EMPTYBLOCK") + + QString("
"); + } + { + QTest::newRow("horizontal-ruler-with-width-and-color") << QTextDocumentFragment::fromHtml("
") + << + QString("EMPTYBLOCK") + + QString("
"); } { CREATE_DOC_AND_CURSOR(); @@ -1904,20 +1917,12 @@ void tst_QTextDocument::toHtmlBodyBgColor() fmt.setBackground(QColor("#0000ff")); doc.rootFrame()->setFrameFormat(fmt); - QString expectedHtml("\n" - "" - "\n" - "

Blah

" - ""); + QString expectedHtml = htmlHead; + expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"#0000ff\""); + expectedHtml += "

Blah

" + + htmlTail; - expectedHtml = expectedHtml.arg(defaultFont.family()) - .arg(cssFontSizeString(defaultFont)) - .arg(defaultFont.weight()) - .arg((defaultFont.italic() ? "italic" : "normal")); + writeActualAndExpected(QTest::currentDataTag(), doc.toHtml(), expectedHtml); QCOMPARE(doc.toHtml(), expectedHtml); } @@ -1932,20 +1937,12 @@ void tst_QTextDocument::toHtmlBodyBgColorRgba() fmt.setBackground(QColor(255, 0, 0, 51)); doc.rootFrame()->setFrameFormat(fmt); - QString expectedHtml("\n" - "" - "\n" - "

Blah

" - ""); + QString expectedHtml = htmlHead; + expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"rgba(255,0,0,0.2)\""); + expectedHtml += "

Blah

" + + htmlTail; - expectedHtml = expectedHtml.arg(defaultFont.family()) - .arg(cssFontSizeString(defaultFont)) - .arg(defaultFont.weight()) - .arg((defaultFont.italic() ? "italic" : "normal")); + writeActualAndExpected(QTest::currentDataTag(), doc.toHtml(), expectedHtml); QCOMPARE(doc.toHtml(), expectedHtml); } @@ -1960,20 +1957,12 @@ void tst_QTextDocument::toHtmlBodyBgColorTransparent() fmt.setBackground(QColor(255, 0, 0, 0)); doc.rootFrame()->setFrameFormat(fmt); - QString expectedHtml("\n" - "" - "\n" - "

Blah

" - ""); + QString expectedHtml = htmlHead; + expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"transparent\""); + expectedHtml += "

Blah

" + + htmlTail; - expectedHtml = expectedHtml.arg(defaultFont.family()) - .arg(cssFontSizeString(defaultFont)) - .arg(defaultFont.weight()) - .arg((defaultFont.italic() ? "italic" : "normal")); + writeActualAndExpected(QTest::currentDataTag(), doc.toHtml(), expectedHtml); QCOMPARE(doc.toHtml(), expectedHtml); } @@ -2034,21 +2023,13 @@ void tst_QTextDocument::toHtmlDefaultFontSpacingProperties() fnt.setWordSpacing(15); doc.setDefaultFont(fnt); - QString expectedOutput = QString("\n" - "" - "" - "\n" - "

Blah

" - ""); - expectedOutput = expectedOutput.arg(defaultFont.family()) - .arg(cssFontSizeString(defaultFont)) - .arg(defaultFont.weight()) - .arg((defaultFont.italic() ? "italic" : "normal")); + QString expectedOutput = htmlHead; + expectedOutput.insert(htmlHead.length() - 3, " letter-spacing:13px; word-spacing:15px;"); + expectedOutput += + "

Blah

" + + htmlTail; + + writeActualAndExpected(QTest::currentTestFunction(), doc.toHtml(), expectedOutput); QCOMPARE(doc.toHtml(), expectedOutput); } @@ -2062,23 +2043,13 @@ void tst_QTextDocument::toHtmlTextDecorationUnderline() fnt.setUnderline(true); doc.setDefaultFont(fnt); - QString expectedOutput = - QString("\n" - "" - "" - "\n" - "

Some text

" - ""); - - expectedOutput = expectedOutput.arg(doc.defaultFont().family()) - .arg(cssFontSizeString(doc.defaultFont())) - .arg(doc.defaultFont().weight()) - .arg((doc.defaultFont().italic() ? "italic" : "normal")); + QString expectedOutput = htmlHead; + expectedOutput.insert(htmlHead.length() - 3, " text-decoration: underline;"); + expectedOutput += + "

Some text

" + + htmlTail; + + writeActualAndExpected("toHtmlTextDecorationUnderline1", doc.toHtml(), expectedOutput); QCOMPARE(doc.toHtml(), expectedOutput); @@ -2087,26 +2058,17 @@ void tst_QTextDocument::toHtmlTextDecorationUnderline() cursor.select(QTextCursor::Document); cursor.mergeCharFormat(format); - QString expectedOutput2 = - QString("\n" - "" - "" - "\n" - "

" - "Some text

" - ""); + expectedOutput = htmlHead; + expectedOutput.insert(htmlHead.length() - 3, " text-decoration: underline;"); + expectedOutput += + "

" + "Some text

" + + htmlTail; - expectedOutput2 = expectedOutput2.arg(doc.defaultFont().family()) - .arg(cssFontSizeString(doc.defaultFont())) - .arg(doc.defaultFont().weight()) - .arg((doc.defaultFont().italic() ? "italic" : "normal")); + writeActualAndExpected("toHtmlTextDecorationUnderline2", doc.toHtml(), expectedOutput); - QCOMPARE(doc.toHtml(), expectedOutput2); + QCOMPARE(doc.toHtml(), expectedOutput); } void tst_QTextDocument::capitalizationHtmlInExport() @@ -2985,21 +2947,11 @@ const QString backgroundImage_html("
void tst_QTextDocument::backgroundImage_checkExpectedHtml(const QTextDocument &doc) { - QString expectedHtml("\n" - "" - "\n" + QString expectedHtml = htmlHead + "" "\n\n
" "\n

Blah

" - "
"); - - expectedHtml = expectedHtml.arg(defaultFont.family()) - .arg(cssFontSizeString(defaultFont)) - .arg(defaultFont.weight()) - .arg((defaultFont.italic() ? "italic" : "normal")); + "
" + htmlTail; writeActualAndExpected(QTest::currentTestFunction(), doc.toHtml(), expectedHtml); -- cgit v1.2.3