diff options
-rw-r--r-- | src/quick/items/qquicktext.cpp | 2 | ||||
-rw-r--r-- | src/quick/util/qdeclarativestyledtext.cpp | 22 | ||||
-rw-r--r-- | tests/auto/qtquick2/qdeclarativestyledtext/tst_qdeclarativestyledtext.cpp | 1 |
3 files changed, 25 insertions, 0 deletions
diff --git a/src/quick/items/qquicktext.cpp b/src/quick/items/qquicktext.cpp index 5072bf1a58..b96ee71e46 100644 --- a/src/quick/items/qquicktext.cpp +++ b/src/quick/items/qquicktext.cpp @@ -1528,6 +1528,7 @@ void QQuickText::resetMaximumLineCount() \code <b></b> - bold + <strong></strong> - bold <i></i> - italic <br> - new line <p> - paragraph @@ -1536,6 +1537,7 @@ void QQuickText::resetMaximumLineCount() <h1> to <h6> - headers <a href=""> - anchor <ol type="">, <ul type=""> and <li> - ordered and unordered lists + <pre></pre> - preformatted > < & \endcode diff --git a/src/quick/util/qdeclarativestyledtext.cpp b/src/quick/util/qdeclarativestyledtext.cpp index d2c2ef8f1b..78add300f6 100644 --- a/src/quick/util/qdeclarativestyledtext.cpp +++ b/src/quick/util/qdeclarativestyledtext.cpp @@ -51,6 +51,7 @@ QDeclarativeStyledText supports few tags: <b></b> - bold + <strong></strong> - bold <i></i> - italic <br> - new line <p> - paragraph @@ -59,6 +60,7 @@ <h1> to <h6> - headers <a href=""> - anchor <ol type="">, <ul type=""> and <li> - ordered and unordered lists + <pre></pre> - preformated The opening and closing tags must be correctly nested. */ @@ -79,6 +81,7 @@ public: QDeclarativeStyledTextPrivate(const QString &t, QTextLayout &l) : text(t), layout(l), baseFont(layout.font()), hasNewLine(false) + , preFormat(false) { } @@ -106,6 +109,7 @@ public: QFont baseFont; QStack<List> listStack; bool hasNewLine; + bool preFormat; static const QChar lessThan; static const QChar greaterThan; @@ -216,6 +220,11 @@ void QDeclarativeStyledTextPrivate::parse() parseEntity(ch, text, drawText); textStart = ch - text.constData() + 1; textLength = 0; + } else if (preFormat && ch->isSpace()) { + drawText.append(QStringRef(&text, textStart, textLength)); + drawText.append(QChar(QChar::Nbsp)); + textStart = ch - text.constData() + 1; + textLength = 0; } else { ++textLength; } @@ -269,6 +278,13 @@ bool QDeclarativeStyledTextPrivate::parseTag(const QChar *&ch, const QString &te if (tagLength == 1) { if (!hasNewLine) textOut.append(QChar::LineSeparator); + } else if (tag == QLatin1String("pre")) { + preFormat = true; + if (!hasNewLine) + textOut.append(QChar::LineSeparator); + format.setFontFamily(QString::fromLatin1("Courier New,courier")); + format.setFontFixedPitch(true); + return true; } } else if (char0 == QLatin1Char('u')) { if (tagLength == 1) { @@ -392,6 +408,12 @@ bool QDeclarativeStyledTextPrivate::parseCloseTag(const QChar *&ch, const QStrin textOut.append(QChar::LineSeparator); hasNewLine = true; return false; + } else if (tag == QLatin1String("pre")) { + preFormat = false; + if (!hasNewLine) + textOut.append(QChar::LineSeparator); + hasNewLine = true; + return true; } } else if (char0 == QLatin1Char('u')) { if (tagLength == 1) diff --git a/tests/auto/qtquick2/qdeclarativestyledtext/tst_qdeclarativestyledtext.cpp b/tests/auto/qtquick2/qdeclarativestyledtext/tst_qdeclarativestyledtext.cpp index a17c4294b3..5adc6fc70e 100644 --- a/tests/auto/qtquick2/qdeclarativestyledtext/tst_qdeclarativestyledtext.cpp +++ b/tests/auto/qtquick2/qdeclarativestyledtext/tst_qdeclarativestyledtext.cpp @@ -114,6 +114,7 @@ void tst_qdeclarativestyledtext::textOutput_data() QTest::newRow("h5") << "<h5>head" << QChar(QChar::LineSeparator) + QLatin1String("head") << (FormatList() << Format(Format::Bold, 0, 5)); QTest::newRow("h6") << "<h6>head" << QChar(QChar::LineSeparator) + QLatin1String("head") << (FormatList() << Format(Format::Bold, 0, 5)); QTest::newRow("h7") << "<h7>head" << "head" << FormatList(); + QTest::newRow("pre") << "normal<pre>pre text</pre>normal" << QLatin1String("normal") + QChar(QChar::LineSeparator) + QLatin1String("pre") + QChar(QChar::Nbsp) + QLatin1String("text") + QChar(QChar::LineSeparator) + QLatin1String("normal") << (FormatList() << Format(0, 6, 9)); } void tst_qdeclarativestyledtext::textOutput() |