aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2011-09-30 13:55:07 +1000
committerQt by Nokia <qt-info@nokia.com>2011-09-30 10:37:05 +0200
commit3fff5e654e1b39844deae43cf5b211c2f196227f (patch)
tree45b70e244ac2da27f4456e2112f506a6e492be64
parent270f4a7d6421b134b26b1aa10e6604b38689d638 (diff)
Text format AutoText should use StyledText instead of RichText.
Task-number: QTBUG-21723 Change-Id: Ife213be95985ad1022e2f60241e69ecd9f467caf Reviewed-on: http://codereview.qt-project.org/5825 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Yann Bodson <yann.bodson@nokia.com>
-rw-r--r--doc/src/declarative/whatsnew.qdoc2
-rw-r--r--src/declarative/items/qsgtext.cpp22
-rw-r--r--src/declarative/items/qsgtext_p_p.h1
-rw-r--r--tests/auto/declarative/qsgtext/data/embeddedImagesLocal.qml1
-rw-r--r--tests/auto/declarative/qsgtext/data/embeddedImagesLocalError.qml1
-rw-r--r--tests/auto/declarative/qsgtext/data/embeddedImagesRemote.qml1
-rw-r--r--tests/auto/declarative/qsgtext/data/embeddedImagesRemoteError.qml1
-rw-r--r--tests/auto/declarative/qsgtext/tst_qsgtext.cpp22
8 files changed, 39 insertions, 12 deletions
diff --git a/doc/src/declarative/whatsnew.qdoc b/doc/src/declarative/whatsnew.qdoc
index 044ce02a6d..190060c5c1 100644
--- a/doc/src/declarative/whatsnew.qdoc
+++ b/doc/src/declarative/whatsnew.qdoc
@@ -99,6 +99,8 @@ Added topMargin, bottomMargin, leftMargin, rightMargin, xOrigin, yOrigin propert
Image has two new properties: horizontalAlignment and verticalAlignment. It also has a new value for
fillMode (Image.Pad) that does not transform the image.
+Text will now automatically switch to StyledText instead of RichText if textFormat is set to AutoText.
+
Grid now has rowSpacing and columnSpacing properties.
Positioners now have attached properties that can be used to determine a subitem's location within a
diff --git a/src/declarative/items/qsgtext.cpp b/src/declarative/items/qsgtext.cpp
index a1b1260b3c..5b72eab8ff 100644
--- a/src/declarative/items/qsgtext.cpp
+++ b/src/declarative/items/qsgtext.cpp
@@ -104,7 +104,7 @@ QSGTextPrivate::QSGTextPrivate()
maximumLineCountValid(false),
texture(0),
imageCacheDirty(false), updateOnComponentComplete(true),
- richText(false), singleline(false), cacheAllTextAsImage(true), internalWidthUpdate(false),
+ richText(false), styledText(false), singleline(false), cacheAllTextAsImage(true), internalWidthUpdate(false),
requireImplicitWidth(false), truncated(false), hAlignImplicit(true), rightToLeftText(false),
layoutTextElided(false), richTextAsImage(false), textureImageCacheDirty(false), naturalWidth(0),
doc(0), nodeType(NodeIsNull)
@@ -230,7 +230,7 @@ void QSGTextPrivate::updateLayout()
if (!richText) {
layout.clearLayout();
layout.setFont(font);
- if (format != QSGText::StyledText) {
+ if (!styledText) {
QString tmp = text;
tmp.replace(QLatin1Char('\n'), QChar::LineSeparator);
singleline = !tmp.contains(QChar::LineSeparator);
@@ -937,7 +937,7 @@ void QSGText::setFont(const QFont &font)
The text to display. Text supports both plain and rich text strings.
The item will try to automatically determine whether the text should
- be treated as rich text. This determination is made using Qt::mightBeRichText().
+ be treated as styled text. This determination is made using Qt::mightBeRichText().
*/
QString QSGText::text() const
{
@@ -951,7 +951,8 @@ void QSGText::setText(const QString &n)
if (d->text == n)
return;
- d->richText = d->format == RichText || (d->format == AutoText && Qt::mightBeRichText(n));
+ d->richText = d->format == RichText;
+ d->styledText = d->format == StyledText || (d->format == AutoText && Qt::mightBeRichText(n));
d->text = n;
if (isComponentComplete()) {
if (d->richText) {
@@ -1316,13 +1317,13 @@ void QSGText::resetMaximumLineCount()
\list
\o Text.AutoText (default)
\o Text.PlainText
- \o Text.RichText
\o Text.StyledText
+ \o Text.RichText
\endlist
If the text format is \c Text.AutoText the text element
will automatically determine whether the text should be treated as
- rich text. This determination is made using Qt::mightBeRichText().
+ styled text. This determination is made using Qt::mightBeRichText().
Text.StyledText is an optimized format supporting some basic text
styling markup, in the style of html 3.2:
@@ -1379,7 +1380,8 @@ void QSGText::setTextFormat(TextFormat format)
return;
d->format = format;
bool wasRich = d->richText;
- d->richText = format == RichText || (format == AutoText && Qt::mightBeRichText(d->text));
+ d->richText = format == RichText;
+ d->styledText = format == StyledText || (format == AutoText && Qt::mightBeRichText(d->text));
if (!wasRich && d->richText && isComponentComplete()) {
d->ensureDoc();
@@ -1686,7 +1688,7 @@ void QSGText::componentComplete()
QString QSGTextPrivate::anchorAt(const QPointF &mousePos)
{
- if (format == QSGText::StyledText) {
+ if (styledText) {
for (int i = 0; i < layout.lineCount(); ++i) {
QTextLine line = layout.lineAt(i);
if (line.naturalTextRect().contains(mousePos)) {
@@ -1717,7 +1719,7 @@ void QSGText::mousePressEvent(QMouseEvent *event)
Q_D(QSGText);
if (d->isLinkActivatedConnected()) {
- if (d->format == QSGText::StyledText)
+ if (d->styledText)
d->activeLink = d->anchorAt(event->localPos());
else if (d->richText && d->doc)
d->activeLink = d->doc->documentLayout()->anchorAt(event->localPos());
@@ -1742,7 +1744,7 @@ void QSGText::mouseReleaseEvent(QMouseEvent *event)
QString link;
if (d->isLinkActivatedConnected()) {
- if (d->format == QSGText::StyledText)
+ if (d->styledText)
link = d->anchorAt(event->localPos());
else if (d->richText && d->doc)
link = d->doc->documentLayout()->anchorAt(event->localPos());
diff --git a/src/declarative/items/qsgtext_p_p.h b/src/declarative/items/qsgtext_p_p.h
index 2e999972b4..ddd54b6f0c 100644
--- a/src/declarative/items/qsgtext_p_p.h
+++ b/src/declarative/items/qsgtext_p_p.h
@@ -110,6 +110,7 @@ public:
bool imageCacheDirty:1;
bool updateOnComponentComplete:1;
bool richText:1;
+ bool styledText:1;
bool singleline:1;
bool cacheAllTextAsImage:1;
bool internalWidthUpdate:1;
diff --git a/tests/auto/declarative/qsgtext/data/embeddedImagesLocal.qml b/tests/auto/declarative/qsgtext/data/embeddedImagesLocal.qml
index d71e9bb5bf..74b2ab817a 100644
--- a/tests/auto/declarative/qsgtext/data/embeddedImagesLocal.qml
+++ b/tests/auto/declarative/qsgtext/data/embeddedImagesLocal.qml
@@ -1,5 +1,6 @@
import QtQuick 2.0
Text {
+ textFormat: Text.RichText
text: "<img src='http/exists.png'>"
}
diff --git a/tests/auto/declarative/qsgtext/data/embeddedImagesLocalError.qml b/tests/auto/declarative/qsgtext/data/embeddedImagesLocalError.qml
index e6719481db..a2f7e0c89f 100644
--- a/tests/auto/declarative/qsgtext/data/embeddedImagesLocalError.qml
+++ b/tests/auto/declarative/qsgtext/data/embeddedImagesLocalError.qml
@@ -1,5 +1,6 @@
import QtQuick 2.0
Text {
+ textFormat: Text.RichText
text: "<img src='http/notexists.png'>"
}
diff --git a/tests/auto/declarative/qsgtext/data/embeddedImagesRemote.qml b/tests/auto/declarative/qsgtext/data/embeddedImagesRemote.qml
index e524d028b5..702633c538 100644
--- a/tests/auto/declarative/qsgtext/data/embeddedImagesRemote.qml
+++ b/tests/auto/declarative/qsgtext/data/embeddedImagesRemote.qml
@@ -1,5 +1,6 @@
import QtQuick 2.0
Text {
+ textFormat: Text.RichText
text: "<img src='http://127.0.0.1:14453/exists.png'>"
}
diff --git a/tests/auto/declarative/qsgtext/data/embeddedImagesRemoteError.qml b/tests/auto/declarative/qsgtext/data/embeddedImagesRemoteError.qml
index f541e0e497..5762f3e47d 100644
--- a/tests/auto/declarative/qsgtext/data/embeddedImagesRemoteError.qml
+++ b/tests/auto/declarative/qsgtext/data/embeddedImagesRemoteError.qml
@@ -1,5 +1,6 @@
import QtQuick 2.0
Text {
+ textFormat: Text.RichText
text: "<img src='http://127.0.0.1:14453/notexists.png'>"
}
diff --git a/tests/auto/declarative/qsgtext/tst_qsgtext.cpp b/tests/auto/declarative/qsgtext/tst_qsgtext.cpp
index 7b04e76f01..5a27a69dec 100644
--- a/tests/auto/declarative/qsgtext/tst_qsgtext.cpp
+++ b/tests/auto/declarative/qsgtext/tst_qsgtext.cpp
@@ -321,14 +321,14 @@ void tst_qsgtext::width()
int documentWidth = document.idealWidth();
- QString componentStr = "import QtQuick 2.0\nText { text: \"" + richText.at(i) + "\" }";
+ QString componentStr = "import QtQuick 2.0\nText { text: \"" + richText.at(i) + "\"; textFormat: Text.RichText }";
QDeclarativeComponent textComponent(&engine);
textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
QSGText *textObject = qobject_cast<QSGText*>(textComponent.create());
QVERIFY(textObject != 0);
QCOMPARE(textObject->width(), qreal(documentWidth));
- QVERIFY(textObject->textFormat() == QSGText::AutoText); // setting text doesn't change format
+ QVERIFY(textObject->textFormat() == QSGText::RichText);
delete textObject;
}
@@ -465,6 +465,24 @@ void tst_qsgtext::textFormat()
QVERIFY(textObject != 0);
QVERIFY(textObject->textFormat() == QSGText::RichText);
+ QSGTextPrivate *textPrivate = QSGTextPrivate::get(textObject);
+ QVERIFY(textPrivate != 0);
+ QVERIFY(textPrivate->richText == true);
+
+ delete textObject;
+ }
+ {
+ QDeclarativeComponent textComponent(&engine);
+ textComponent.setData("import QtQuick 2.0\nText { text: \"<b>Hello</b>\" }", QUrl::fromLocalFile(""));
+ QSGText *textObject = qobject_cast<QSGText*>(textComponent.create());
+
+ QVERIFY(textObject != 0);
+ QVERIFY(textObject->textFormat() == QSGText::AutoText);
+
+ QSGTextPrivate *textPrivate = QSGTextPrivate::get(textObject);
+ QVERIFY(textPrivate != 0);
+ QVERIFY(textPrivate->styledText == true);
+
delete textObject;
}
{