summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/text/qtextdocument
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2021-11-17 13:54:32 +0100
committerShawn Rutledge <shawn.rutledge@qt.io>2021-12-15 11:36:37 +0000
commit2e2f1e2af76d94a41f382e81ab8a6fdccf8ca579 (patch)
treeead0f36bf1d959a1cf71f7af538de513bad9f30e /tests/auto/gui/text/qtextdocument
parentff97c8164253a882037836ae4381f6e669d3fce5 (diff)
Add css media rule support for QTextDocument::setHtml()
CSS styles can contain '@media <rule> {...}' blocks, which were previously ignored for all values except "screen". To use a media rule other than the default "screen" rule, specify it before calling setHtml() with setMetaInformation() and the new info value 'CssMedia'. [ChangeLog][Gui][QTextDocument] Add css media rule support for QTextDocument::setHtml() Pick-to: 6.3 Fixes: QTBUG-98408 Change-Id: Ie05f815a6dedbd970210f467e26b116f6ee3b9ca Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/gui/text/qtextdocument')
-rw-r--r--tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
index 922226a3a3..a38defa656 100644
--- a/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
+++ b/tests/auto/gui/text/qtextdocument/tst_qtextdocument.cpp
@@ -96,6 +96,7 @@ private slots:
void toHtml2();
void setFragmentMarkersInHtmlExport();
+ void setMediaRule();
void toHtmlBodyBgColor();
void toHtmlBodyBgColorRgba();
@@ -1910,6 +1911,39 @@ void tst_QTextDocument::setFragmentMarkersInHtmlExport()
}
}
+void tst_QTextDocument::setMediaRule()
+{
+ {
+ CREATE_DOC_AND_CURSOR();
+ doc.setDefaultStyleSheet("@media screen { p { background:#000000 } } @media print { p { background:#ffffff } }");
+ doc.setHtml("<p>Hello World</p>");
+
+ QString expected = htmlHead;
+ expected += QString("<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#000000;\"><span style=\" background-color:#000000;\">Hello World</span></p>") + htmlTail;
+ QCOMPARE(doc.toHtml(), expected);
+ }
+ {
+ CREATE_DOC_AND_CURSOR();
+ doc.setDefaultStyleSheet("@media screen { p { background:#000000 } } @media print { p { background:#ffffff } }");
+ doc.setMetaInformation(QTextDocument::CssMedia, "screen");
+ doc.setHtml("<p>Hello World</p>");
+
+ QString expected = htmlHead;
+ expected += QString("<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#000000;\"><span style=\" background-color:#000000;\">Hello World</span></p>") + htmlTail;
+ QCOMPARE(doc.toHtml(), expected);
+ }
+ {
+ CREATE_DOC_AND_CURSOR();
+ doc.setDefaultStyleSheet("@media screen { p { background:#000000 } } @media print { p { background:#ffffff } }");
+ doc.setMetaInformation(QTextDocument::CssMedia, "print");
+ doc.setHtml("<p>Hello World</p>");
+
+ QString expected = htmlHead;
+ expected += QString("<p style=\" margin-top:12px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; background-color:#ffffff;\"><span style=\" background-color:#ffffff;\">Hello World</span></p>") + htmlTail;
+ QCOMPARE(doc.toHtml(), expected);
+ }
+}
+
void tst_QTextDocument::toHtmlBodyBgColor()
{
CREATE_DOC_AND_CURSOR();
@@ -2294,14 +2328,18 @@ void tst_QTextDocument::clonePreservesMetaInformation()
{
const QString title("Foobar");
const QString url("about:blank");
+ const QString media("print");
doc->setHtml("<html><head><title>" + title + "</title></head><body>Hrm</body></html>");
doc->setMetaInformation(QTextDocument::DocumentUrl, url);
+ doc->setMetaInformation(QTextDocument::CssMedia, media);
QCOMPARE(doc->metaInformation(QTextDocument::DocumentTitle), title);
QCOMPARE(doc->metaInformation(QTextDocument::DocumentUrl), url);
+ QCOMPARE(doc->metaInformation(QTextDocument::CssMedia), media);
QTextDocument *clone = doc->clone();
QCOMPARE(clone->metaInformation(QTextDocument::DocumentTitle), title);
QCOMPARE(clone->metaInformation(QTextDocument::DocumentUrl), url);
+ QCOMPARE(clone->metaInformation(QTextDocument::CssMedia), media);
delete clone;
}