QDeclarativeStyledText supports few tags:
<b></b> - bold
+ <strong></strong> - bold
<i></i> - italic
<br> - new line
<p> - paragraph
<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.
*/
QDeclarativeStyledTextPrivate(const QString &t, QTextLayout &l)
: text(t), layout(l), baseFont(layout.font()), hasNewLine(false)
+ , preFormat(false)
{
}
QFont baseFont;
QStack<List> listStack;
bool hasNewLine;
+ bool preFormat;
static const QChar lessThan;
static const QChar greaterThan;
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;
}
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) {
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)
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()