aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2011-12-21 10:19:03 +1000
committerQt by Nokia <qt-info@nokia.com>2012-01-05 06:47:26 +0100
commit117f4934dbf444ce871c498f02bb066e4bb5eaa0 (patch)
tree06d77b4a5e90a9fdf31a7c0d113220ed8c3cda1f /src
parent966e8856837686668d04f089cfb75c2a48ae933e (diff)
Support <pre> in StyleText textFormat
Task-number: QTBUG-23159 Change-Id: I842d066efb3a78defba61cc31060840f771f9b11 Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/quick/items/qquicktext.cpp2
-rw-r--r--src/quick/util/qdeclarativestyledtext.cpp22
2 files changed, 24 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
&gt; &lt; &amp;
\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)