Fix missing strike out
Added <s></s> and <del></del> tag aka strike out to QQuickStyledText. QQuickStyledText covers the essential text decorations, apart from strike out. In order to use it, one had to switch to RichText, which comes with its own overhead and limitations. <s> for no longer accurate or no longer relevant content <del> for removed content Fixes: QTBUG-72376 Change-Id: I3c191d91d57afcc48090facc49d643f8ad708fb4 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
parent
0b586e5b50
commit
c352ca4a3d
|
@ -2082,6 +2082,8 @@ void QQuickText::resetMaximumLineCount()
|
|||
|
||||
\code
|
||||
<b></b> - bold
|
||||
<del></del> - strike out (removed content)
|
||||
<s></s> - strike out (no longer accurate or no longer relevant content)
|
||||
<strong></strong> - bold
|
||||
<i></i> - italic
|
||||
<br> - new line
|
||||
|
|
|
@ -50,6 +50,8 @@
|
|||
QQuickStyledText supports few tags:
|
||||
|
||||
<b></b> - bold
|
||||
<del></del> - strike out (removed content)
|
||||
<s></s> - strike out (no longer accurate or no longer relevant content)
|
||||
<strong></strong> - bold
|
||||
<i></i> - italic
|
||||
<br> - new line
|
||||
|
@ -379,8 +381,16 @@ bool QQuickStyledTextPrivate::parseTag(const QChar *&ch, const QString &textIn,
|
|||
format.setFontWeight(QFont::Bold);
|
||||
return true;
|
||||
}
|
||||
} else if (tag == QLatin1String("strong")) {
|
||||
format.setFontWeight(QFont::Bold);
|
||||
} else if (char0 == QLatin1Char('s')) {
|
||||
if (tagLength == 1) {
|
||||
format.setFontStrikeOut(true);
|
||||
return true;
|
||||
} else if (tag == QLatin1String("strong")) {
|
||||
format.setFontWeight(QFont::Bold);
|
||||
return true;
|
||||
}
|
||||
} else if (tag == QLatin1String("del")) {
|
||||
format.setFontStrikeOut(true);
|
||||
return true;
|
||||
} else if (tag == QLatin1String("ol")) {
|
||||
List listItem;
|
||||
|
@ -511,7 +521,13 @@ bool QQuickStyledTextPrivate::parseCloseTag(const QChar *&ch, const QString &tex
|
|||
return true;
|
||||
} else if (tag == QLatin1String("font")) {
|
||||
return true;
|
||||
} else if (tag == QLatin1String("strong")) {
|
||||
} else if (char0 == QLatin1Char('s')) {
|
||||
if (tagLength == 1) {
|
||||
return true;
|
||||
} else if (tag == QLatin1String("strong")) {
|
||||
return true;
|
||||
}
|
||||
} else if (tag == QLatin1String("del")) {
|
||||
return true;
|
||||
} else if (tag == QLatin1String("ol")) {
|
||||
if (!listStack.isEmpty()) {
|
||||
|
|
|
@ -44,7 +44,8 @@ public:
|
|||
Bold = 0x01,
|
||||
Underline = 0x02,
|
||||
Italic = 0x04,
|
||||
Anchor = 0x08
|
||||
Anchor = 0x08,
|
||||
StrikeOut = 0x10
|
||||
};
|
||||
Format(int t, int s, int l)
|
||||
: type(t), start(s), length(l) {}
|
||||
|
@ -92,6 +93,10 @@ void tst_qquickstyledtext::textOutput_data()
|
|||
QTest::newRow("underline") << "<u>underline</u>" << "underline" << (FormatList() << Format(Format::Underline, 0, 9)) << false;
|
||||
QTest::newRow("strong") << "<strong>strong</strong>" << "strong" << (FormatList() << Format(Format::Bold, 0, 6)) << false;
|
||||
QTest::newRow("underline") << "<u>underline</u>" << "underline" << (FormatList() << Format(Format::Underline, 0, 9)) << false;
|
||||
QTest::newRow("strike out s") << "<s>strike out</s>" << "strike out" << (FormatList() << Format(Format::StrikeOut, 0, 10)) << false;
|
||||
QTest::newRow("strike out del") << "<del>strike out</del>" << "strike out" << (FormatList() << Format(Format::StrikeOut, 0, 10)) << false;
|
||||
QTest::newRow("strike out not s") << "this is <s>not</s> a test" << "this is not a test" << (FormatList() << Format(Format::StrikeOut, 8, 3)) << false;
|
||||
QTest::newRow("strike out not del") << "this is <del>not</del> a test" << "this is not a test" << (FormatList() << Format(Format::StrikeOut, 8, 3)) << false;
|
||||
QTest::newRow("missing >") << "<b>text</b" << "text" << (FormatList() << Format(Format::Bold, 0, 4)) << false;
|
||||
QTest::newRow("missing b>") << "<b>text</" << "text" << (FormatList() << Format(Format::Bold, 0, 4)) << false;
|
||||
QTest::newRow("missing /b>") << "<b>text<" << "text" << (FormatList() << Format(Format::Bold, 0, 4)) << false;
|
||||
|
@ -178,6 +183,7 @@ void tst_qquickstyledtext::textOutput()
|
|||
QCOMPARE(layoutFormats.at(i).format.fontWeight(), int(QFont::Normal));
|
||||
QVERIFY(layoutFormats.at(i).format.fontItalic() == bool(formats.at(i).type & Format::Italic));
|
||||
QVERIFY(layoutFormats.at(i).format.fontUnderline() == bool(formats.at(i).type & Format::Underline));
|
||||
QVERIFY(layoutFormats.at(i).format.fontStrikeOut() == bool(formats.at(i).type & Format::StrikeOut));
|
||||
}
|
||||
QCOMPARE(fontSizeModified, modifiesFontSize);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue