diff options
author | Qt Forward Merge Bot <qt_forward_merge_bot@qt-project.org> | 2019-11-15 01:00:11 +0100 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2019-11-15 16:29:40 +0100 |
commit | adc7bbe910a4b89a579ffa93da5a937cfc1379f4 (patch) | |
tree | e28a2fadc82652798302cc7f79a6f4310a2eb8d7 /src/widgets/widgets | |
parent | 14bb413309092adc53e8451daff5690c4698c07d (diff) | |
parent | c15a069830baf87f57c84e86326cf86ba9a39713 (diff) |
Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts:
src/gui/rhi/qshader.cpp
tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
Change-Id: I1c4ae718eb3592a0a0a90af9d11553f3ab68cad5
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r-- | src/widgets/widgets/qlabel.cpp | 33 | ||||
-rw-r--r-- | src/widgets/widgets/qlabel_p.h | 6 |
2 files changed, 25 insertions, 14 deletions
diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index a840bf4ee6..77d117775a 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -85,6 +85,7 @@ QLabelPrivate::QLabelPrivate() shortcutId(0), #endif textformat(Qt::AutoText), + effectiveTextFormat(Qt::PlainText), textInteractionFlags(Qt::LinksAccessibleByMouse), sizePolicy(), margin(0), @@ -94,7 +95,6 @@ QLabelPrivate::QLabelPrivate() scaledcontents(false), textLayoutDirty(false), textDirty(false), - isRichText(false), isTextLabel(false), hasShortcut(/*???*/), #ifndef QT_NO_CURSOR @@ -294,8 +294,14 @@ void QLabel::setText(const QString &text) d->text = text; d->isTextLabel = true; d->textDirty = true; - d->isRichText = d->textformat == Qt::RichText - || (d->textformat == Qt::AutoText && Qt::mightBeRichText(d->text)); + if (d->textformat == Qt::AutoText) { + if (Qt::mightBeRichText(d->text)) + d->effectiveTextFormat = Qt::RichText; + else + d->effectiveTextFormat = Qt::PlainText; + } else { + d->effectiveTextFormat = d->textformat; + } d->control = oldControl; @@ -306,7 +312,7 @@ void QLabel::setText(const QString &text) d->control = nullptr; } - if (d->isRichText) { + if (d->effectiveTextFormat != Qt::PlainText) { setMouseTracking(true); } else { // Note: mouse tracking not disabled intentionally @@ -1478,14 +1484,19 @@ void QLabelPrivate::ensureTextPopulated() const if (control) { QTextDocument *doc = control->document(); if (textDirty) { -#ifndef QT_NO_TEXTHTMLPARSER - if (isRichText) - doc->setHtml(text); - else + if (effectiveTextFormat == Qt::PlainText) { doc->setPlainText(text); -#else - doc->setPlainText(text); +#if QT_CONFIG(texthtmlparser) + } else if (effectiveTextFormat == Qt::RichText) { + doc->setHtml(text); +#endif +#if QT_CONFIG(textmarkdownreader) + } else if (effectiveTextFormat == Qt::MarkdownText) { + doc->setMarkdown(text); #endif + } else { + doc->setPlainText(text); + } doc->setUndoRedoEnabled(false); #ifndef QT_NO_SHORTCUT @@ -1623,7 +1634,7 @@ QMenu *QLabelPrivate::createStandardContextMenu(const QPoint &pos) { QString linkToCopy; QPoint p; - if (control && isRichText) { + if (control && effectiveTextFormat != Qt::PlainText) { p = layoutPoint(pos); linkToCopy = control->document()->documentLayout()->anchorAt(p); } diff --git a/src/widgets/widgets/qlabel_p.h b/src/widgets/widgets/qlabel_p.h index 59188563a9..6b3fbc5f0c 100644 --- a/src/widgets/widgets/qlabel_p.h +++ b/src/widgets/widgets/qlabel_p.h @@ -93,8 +93,8 @@ public: #endif inline bool needTextControl() const { return isTextLabel - && (isRichText - || (!isRichText && (textInteractionFlags & (Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard)))); + && (effectiveTextFormat != Qt::PlainText + || (textInteractionFlags & (Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard))); } void ensureTextPopulated() const; @@ -134,6 +134,7 @@ public: int shortcutId; #endif Qt::TextFormat textformat; + Qt::TextFormat effectiveTextFormat; Qt::TextInteractionFlags textInteractionFlags; mutable QSizePolicy sizePolicy; int margin; @@ -143,7 +144,6 @@ public: uint scaledcontents : 1; mutable uint textLayoutDirty : 1; mutable uint textDirty : 1; - mutable uint isRichText : 1; mutable uint isTextLabel : 1; mutable uint hasShortcut : 1; #ifndef QT_NO_CURSOR |