summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2021-10-12 13:46:24 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2021-10-14 17:09:20 +0200
commit5c436365f579f820344566101e746e244672995a (patch)
tree38fd5c22de7d6474ae000d3983616aa1fb3d9246 /tests/auto/gui
parentf83a3c4b6e703d3d6b48f2f8d2f71ab69c084b8f (diff)
Support background-color CSS styling on <hr/>
[ChangeLog][QtGui][CSS] The background-color style can now be applied to <hr/> to set the rule color. Task-number: QTBUG-74342 Change-Id: Ib960ce4d38caa225f258b6d228fb794cef43e1b7 Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
Diffstat (limited to 'tests/auto/gui')
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp156
-rw-r--r--tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp6
2 files changed, 60 insertions, 102 deletions
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"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
+ "hr { height: 1px; border-width: 0; }\n"
"</style></head>"
"<body style=\" font-family:'%1'; font-size:%2; font-weight:%3; font-style:%4;\">\n");
htmlHead = htmlHead.arg(defaultFont.family())
@@ -1501,7 +1502,19 @@ void tst_QTextDocument::toHtml_data()
QTest::newRow("horizontal-ruler-with-width") << QTextDocumentFragment::fromHtml("<hr width=\"50%\"/>")
<<
QString("EMPTYBLOCK") +
- QString("<hr width=\"50%\"/>");
+ QString("<hr width=\"50%\" />");
+ }
+ {
+ QTest::newRow("horizontal-ruler-with-color") << QTextDocumentFragment::fromHtml("<hr style=\"background-color:green;\"/>")
+ <<
+ QString("EMPTYBLOCK") +
+ QString("<hr style=\"background-color:#008000;\"/>");
+ }
+ {
+ QTest::newRow("horizontal-ruler-with-width-and-color") << QTextDocumentFragment::fromHtml("<hr width=\"50%\" style=\"background-color:green;\"/>")
+ <<
+ QString("EMPTYBLOCK") +
+ QString("<hr width=\"50%\" style=\"background-color:#008000;\"/>");
}
{
CREATE_DOC_AND_CURSOR();
@@ -1904,20 +1917,12 @@ void tst_QTextDocument::toHtmlBodyBgColor()
fmt.setBackground(QColor("#0000ff"));
doc.rootFrame()->setFrameFormat(fmt);
- QString expectedHtml("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
- "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
- "<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
- "p, li { white-space: pre-wrap; }\n"
- "</style></head>"
- "<body style=\" font-family:'%1'; font-size:%2; font-weight:%3; font-style:%4;\""
- " bgcolor=\"#0000ff\">\n"
- "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
- "</body></html>");
+ QString expectedHtml = htmlHead;
+ expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"#0000ff\"");
+ expectedHtml += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
+ + 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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
- "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
- "<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
- "p, li { white-space: pre-wrap; }\n"
- "</style></head>"
- "<body style=\" font-family:'%1'; font-size:%2; font-weight:%3; font-style:%4;\""
- " bgcolor=\"rgba(255,0,0,0.2)\">\n"
- "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
- "</body></html>");
+ QString expectedHtml = htmlHead;
+ expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"rgba(255,0,0,0.2)\"");
+ expectedHtml += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
+ + 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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
- "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
- "<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
- "p, li { white-space: pre-wrap; }\n"
- "</style></head>"
- "<body style=\" font-family:'%1'; font-size:%2; font-weight:%3; font-style:%4;\""
- " bgcolor=\"transparent\">\n"
- "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
- "</body></html>");
+ QString expectedHtml = htmlHead;
+ expectedHtml.insert(htmlHead.length() - 2, " bgcolor=\"transparent\"");
+ expectedHtml += "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
+ + 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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
- "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
- "<html><head><meta name=\"qrichtext\" content=\"1\" />"
- "<meta charset=\"utf-8\" /><style type=\"text/css\">\n"
- "p, li { white-space: pre-wrap; }\n"
- "</style></head>"
- "<body style=\" font-family:'%1'; font-size:%2; "
- "font-weight:%3; font-style:%4; letter-spacing:13px; "
- "word-spacing:15px;\">\n"
- "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
- "</body></html>");
- 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 +=
+ "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
+ + 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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
- "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
- "<html><head><meta name=\"qrichtext\" content=\"1\" />"
- "<meta charset=\"utf-8\" /><style type=\"text/css\">\n"
- "p, li { white-space: pre-wrap; }\n"
- "</style></head>"
- "<body style=\" font-family:'%1'; font-size:%2; "
- "font-weight:%3; font-style:%4; text-decoration: underline;\">\n"
- "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
- "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Some text</p>"
- "</body></html>");
-
- 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 +=
+ "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Some text</p>"
+ + 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("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
- "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
- "<html><head><meta name=\"qrichtext\" content=\"1\" />"
- "<meta charset=\"utf-8\" /><style type=\"text/css\">\n"
- "p, li { white-space: pre-wrap; }\n"
- "</style></head>"
- "<body style=\" font-family:'%1'; font-size:%2; "
- "font-weight:%3; font-style:%4; text-decoration: underline;\">\n"
- "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
- "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
- "<span style=\" text-decoration:none;\">Some text</span></p>"
- "</body></html>");
+ expectedOutput = htmlHead;
+ expectedOutput.insert(htmlHead.length() - 3, " text-decoration: underline;");
+ expectedOutput +=
+ "<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; "
+ "margin-right:0px; -qt-block-indent:0; text-indent:0px;\">"
+ "<span style=\" text-decoration:none;\">Some text</span></p>"
+ + 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("<body><table><tr><td background=\"foo.png\">
void tst_QTextDocument::backgroundImage_checkExpectedHtml(const QTextDocument &doc)
{
- QString expectedHtml("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" "
- "\"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
- "<html><head><meta name=\"qrichtext\" content=\"1\" /><meta charset=\"utf-8\" /><style type=\"text/css\">\n"
- "p, li { white-space: pre-wrap; }\n"
- "</style></head>"
- "<body style=\" font-family:'%1'; font-size:%2; font-weight:%3; font-style:%4;\">\n"
+ QString expectedHtml = htmlHead +
"<table border=\"0\" style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px;\" cellspacing=\"2\" cellpadding=\"0\">"
"\n<tr>\n<td background=\"foo.png\">"
"\n<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">Blah</p>"
- "</td></tr></table></body></html>");
-
- expectedHtml = expectedHtml.arg(defaultFont.family())
- .arg(cssFontSizeString(defaultFont))
- .arg(defaultFont.weight())
- .arg((defaultFont.italic() ? "italic" : "normal"));
+ "</td></tr></table>" + htmlTail;
writeActualAndExpected(QTest::currentTestFunction(), doc.toHtml(), expectedHtml);
diff --git a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
index c0c52b5c04..24704bec37 100644
--- a/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
+++ b/tests/auto/gui/text/qtextdocumentfragment/tst_qtextdocumentfragment.cpp
@@ -3499,6 +3499,12 @@ void tst_QTextDocumentFragment::html_hr()
doc->setHtml("<hr />");
QCOMPARE(doc->blockCount(), 1);
QVERIFY(doc->begin().blockFormat().hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth));
+ doc->setHtml("<hr style=\"background-color:green;\"/>");
+ QCOMPARE(doc->blockCount(), 1);
+ QVERIFY(doc->begin().blockFormat().hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth));
+ QVERIFY(doc->begin().blockFormat().hasProperty(QTextFormat::BackgroundBrush));
+ const auto brush = qvariant_cast<QBrush>(doc->begin().blockFormat().property(QTextFormat::BackgroundBrush));
+ QCOMPARE(brush.color(), QColor("green"));
}
void tst_QTextDocumentFragment::html_hrMargins()