diff options
author | Ralf Habacker <ralf.habacker@freenet.de> | 2021-11-17 13:54:32 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2021-12-15 11:36:37 +0000 |
commit | 2e2f1e2af76d94a41f382e81ab8a6fdccf8ca579 (patch) | |
tree | ead0f36bf1d959a1cf71f7af538de513bad9f30e /src/gui/text/qtextdocument.cpp | |
parent | ff97c8164253a882037836ae4381f6e669d3fce5 (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 'src/gui/text/qtextdocument.cpp')
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 68cdbc092e..0fed8c98d3 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -351,6 +351,7 @@ QTextDocument *QTextDocument::clone(QObject *parent) const QTextDocumentPrivate *priv = doc->d_func(); priv->title = d->title; priv->url = d->url; + priv->cssMedia = d->cssMedia; priv->pageSize = d->pageSize; priv->indentWidth = d->indentWidth; priv->defaultTextOption = d->defaultTextOption; @@ -1135,6 +1136,8 @@ QString QTextDocument::metaInformation(MetaInformation info) const return d->title; case DocumentUrl: return d->url; + case CssMedia: + return d->cssMedia; } return QString(); } @@ -1155,6 +1158,9 @@ void QTextDocument::setMetaInformation(MetaInformation info, const QString &stri case DocumentUrl: d->url = string; break; + case CssMedia: + d->cssMedia = string; + break; } } @@ -1242,11 +1248,14 @@ void QTextDocument::setPlainText(const QString &text) "<b>bold</b> text" will produce text where the first word has a font weight that gives it a bold appearance: "\b{bold} text". + To select a css media rule other than the default "screen" rule, + use setMetaInformation() with 'CssMedia' as "info" parameter. + \note It is the responsibility of the caller to make sure that the text is correctly decoded when a QString containing HTML is created and passed to setHtml(). - \sa setPlainText(), {Supported HTML Subset} + \sa setPlainText(), {Supported HTML Subset}, setMetaInformation() */ #ifndef QT_NO_TEXTHTMLPARSER @@ -1286,8 +1295,11 @@ void QTextDocument::setHtml(const QString &html) \value DocumentTitle The title of the document. \value DocumentUrl The url of the document. The loadResource() function uses this url as the base when loading relative resources. + \value CssMedia This value is used to select the corresponding '@media' + rule, if any, from a specified CSS stylesheet when setHtml() + is called. This enum value has been introduced in Qt 6.3. - \sa metaInformation(), setMetaInformation() + \sa metaInformation(), setMetaInformation(), setHtml() */ static bool findInBlock(const QTextBlock &block, const QString &expression, int offset, |