summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Bodson <yann.bodson@nokia.com>2010-11-02 06:41:01 (GMT)
committerYann Bodson <yann.bodson@nokia.com>2010-11-02 06:43:34 (GMT)
commit11bb4f85ef38270758ec0930709c23c7fcb5840c (patch)
tree5cbefe18875c73f2a7441de0ef51894fea38be34
parent13eebf835df3d8fec88a68b571d33e73da929413 (diff)
downloadQt-11bb4f85ef38270758ec0930709c23c7fcb5840c.zip
Qt-11bb4f85ef38270758ec0930709c23c7fcb5840c.tar.gz
Qt-11bb4f85ef38270758ec0930709c23c7fcb5840c.tar.bz2
Regression: Text element breaks when using \n for separating lines
Task-number: QTBUG-14915 Reviewed-by: Michael Brasser
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp24
-rw-r--r--tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-MAC/plaintext2.qml131
-rw-r--r--tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext2.qml22
3 files changed, 165 insertions, 12 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index 03c9765..8cb47aa 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -291,30 +291,30 @@ QSize QDeclarativeTextPrivate::setupTextLayout()
qreal height = 0;
qreal lineWidth = 0;
- //set manual width
- if (q->widthValid())
- lineWidth = q->width();
-
QTextOption textOption = layout.textOption();
- textOption.setWrapMode(QTextOption::WrapMode(wrapMode));
+ textOption.setWrapMode(QTextOption::NoWrap);
textOption.setAlignment(Qt::Alignment(hAlign));
- layout.setTextOption(textOption);
+ // if the item has an explicit width, we set the line width and enable wrapping
+ if (q->widthValid()) {
+ lineWidth = q->width();
+ textOption.setWrapMode(QTextOption::WrapMode(wrapMode));
+ }
+
+ layout.setTextOption(textOption);
layout.beginLayout();
while (1) {
QTextLine line = layout.createLine();
if (!line.isValid())
break;
- if (q->widthValid()) {
- line.setLineWidth(lineWidth);
- line.setPosition(QPointF(0, height));
- height += line.height();
- }
+ line.setLineWidth(lineWidth);
+ line.setPosition(QPointF(0, height));
+ height += line.height();
}
layout.endLayout();
- return QSize(qCeil(layout.boundingRect().width()), layout.boundingRect().height());
+ return layout.boundingRect().toAlignedRect().size();
}
/*!
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-MAC/plaintext2.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-MAC/plaintext2.qml
new file mode 100644
index 0000000..1a8af0e
--- /dev/null
+++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/data-MAC/plaintext2.qml
@@ -0,0 +1,131 @@
+import Qt.VisualTest 4.7
+
+VisualTest {
+ Frame {
+ msec: 0
+ }
+ Frame {
+ msec: 16
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 32
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 48
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 64
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 80
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 96
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 112
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 128
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 144
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 160
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 176
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 192
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 208
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 224
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 240
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 256
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 272
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 288
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 304
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 320
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 336
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 352
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 368
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 384
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 400
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 416
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 432
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Key {
+ type: 6
+ key: 16777249
+ modifiers: 67108864
+ text: ""
+ autorep: false
+ count: 1
+ }
+ Frame {
+ msec: 448
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+ Frame {
+ msec: 464
+ hash: "c68e50ef84647962481121e2eb1ba4d4"
+ }
+}
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext2.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext2.qml
new file mode 100644
index 0000000..901025a
--- /dev/null
+++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext2.qml
@@ -0,0 +1,22 @@
+import QtQuick 1.0
+
+Rectangle {
+ width: 400; height: 200
+
+ Row {
+ spacing: 20
+ anchors.centerIn: parent
+ Text {
+ text: "First line\nSecond line"; wrapMode: Text.Wrap
+ }
+ Text {
+ text: "First line\nSecond line"; width: 70
+ }
+ Text {
+ text: "First Second\nThird Fourth"; wrapMode: Text.Wrap; width: 50
+ }
+ Text {
+ text: "First line<br>Second line"; textFormat: Text.StyledText
+ }
+ }
+}