summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/declarative/listview/recipes.qml6
-rw-r--r--examples/declarative/tabwidget/tabs.qml6
-rw-r--r--examples/declarative/webview/alerts.qml2
-rw-r--r--examples/declarative/xmldata/daringfireball.qml2
-rw-r--r--examples/declarative/xmldata/yahoonews.qml2
-rw-r--r--src/declarative/QmlChanges.txt1
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp54
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p.h15
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p_p.h6
-rw-r--r--src/declarative/util/qdeclarativepropertychanges.cpp2
-rw-r--r--tests/auto/declarative/qdeclarativestates/data/reset.qml2
-rw-r--r--tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp8
-rw-r--r--tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml8
-rw-r--r--tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml8
14 files changed, 76 insertions, 46 deletions
diff --git a/examples/declarative/listview/recipes.qml b/examples/declarative/listview/recipes.qml
index b76a9ab..59f4e59 100644
--- a/examples/declarative/listview/recipes.qml
+++ b/examples/declarative/listview/recipes.qml
@@ -60,7 +60,9 @@ Rectangle {
opacity: wrapper.detailsOpacity
}
Text {
- text: ingredients; wrap: true; width: parent.width
+ text: ingredients
+ wrapMode: Text.WordWrap
+ width: parent.width
opacity: wrapper.detailsOpacity
}
}
@@ -82,7 +84,7 @@ Rectangle {
id: flick
anchors.top: methodTitle.bottom; anchors.bottom: parent.bottom
width: parent.width; contentHeight: methodText.height; clip: true
- Text { id: methodText; text: method; wrap: true; width: details.width }
+ Text { id: methodText; text: method; wrapMode: Text.WordWrap; width: details.width }
}
Image {
anchors.right: flick.right; anchors.top: flick.top
diff --git a/examples/declarative/tabwidget/tabs.qml b/examples/declarative/tabwidget/tabs.qml
index 1d11b03..3d7ee6d 100644
--- a/examples/declarative/tabwidget/tabs.qml
+++ b/examples/declarative/tabwidget/tabs.qml
@@ -13,7 +13,7 @@ TabWidget {
Text {
anchors.centerIn: parent; horizontalAlignment: Qt.AlignHCenter
text: "Roses are red"; font.pixelSize: 20
- wrap: true; width: parent.width - 20
+ wrapMode: Text.WordWrap; width: parent.width - 20
}
}
}
@@ -27,7 +27,7 @@ TabWidget {
Text {
anchors.centerIn: parent; horizontalAlignment: Qt.AlignHCenter
text: "Flower stems are green"; font.pixelSize: 20
- wrap: true; width: parent.width - 20
+ wrapMode: Text.WordWrap; width: parent.width - 20
}
}
}
@@ -41,7 +41,7 @@ TabWidget {
Text {
anchors.centerIn: parent; horizontalAlignment: Qt.AlignHCenter
text: "Violets are blue"; font.pixelSize: 20
- wrap: true; width: parent.width - 20
+ wrapMode: Text.WordWrap; width: parent.width - 20
}
}
}
diff --git a/examples/declarative/webview/alerts.qml b/examples/declarative/webview/alerts.qml
index ab2e860..2549226 100644
--- a/examples/declarative/webview/alerts.qml
+++ b/examples/declarative/webview/alerts.qml
@@ -51,7 +51,7 @@ WebView {
color: "white"
font.pixelSize: 20
width: webView.width*0.75
- wrap: true
+ wrapMode: Text.WordWrap
horizontalAlignment: "AlignHCenter"
}
}
diff --git a/examples/declarative/xmldata/daringfireball.qml b/examples/declarative/xmldata/daringfireball.qml
index 456f309..25eb1ac 100644
--- a/examples/declarative/xmldata/daringfireball.qml
+++ b/examples/declarative/xmldata/daringfireball.qml
@@ -32,7 +32,7 @@ Rectangle {
x: 10
text: content
anchors.top: titleText.bottom
- width: 580; wrap: true
+ width: 580; wrapMode: Text.WordWrap
onLinkActivated: { console.log('link clicked: ' + link) }
}
}
diff --git a/examples/declarative/xmldata/yahoonews.qml b/examples/declarative/xmldata/yahoonews.qml
index f7c269c..d69982e 100644
--- a/examples/declarative/xmldata/yahoonews.qml
+++ b/examples/declarative/xmldata/yahoonews.qml
@@ -45,7 +45,7 @@ Rectangle {
id: descriptionText
text: description
width: 560
- wrap: true
+ wrapMode: Text.WordWrap
font.family: "Helvetica"
anchors.top: titleText.bottom
anchors.topMargin: 5
diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt
index c86bdc6..d3737b0 100644
--- a/src/declarative/QmlChanges.txt
+++ b/src/declarative/QmlChanges.txt
@@ -1,6 +1,7 @@
=============================================================================
The changes below are pre Qt 4.7.0 beta
+Text: wrap property is replaced by wrapMode enumeration.
Removed Q-prefix from validators (IntValidator, DoubleValidator, and RegExpValidator)
PathView: offset property now uses range 0-1.0 rather than 0-100
ListView, GridView::positionViewAtIndex() gained a 'mode' parameter
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index a4f3068..c950e31 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -42,6 +42,7 @@
#include "private/qdeclarativetext_p.h"
#include "private/qdeclarativetext_p_p.h"
#include <qdeclarativestyledtext_p.h>
+#include <qdeclarativeinfo.h>
#include <QTextLayout>
#include <QTextLine>
@@ -70,7 +71,7 @@ QT_BEGIN_NAMESPACE
\image declarative-text.png
If height and width are not explicitly set, Text will attempt to determine how
- much room is needed and set it accordingly. Unless \c wrap is set, it will always
+ much room is needed and set it accordingly. Unless \c wrapMode is set, it will always
prefer width to height (all text will be placed on a single line).
The \c elide property can alternatively be used to fit a single line of
@@ -98,7 +99,7 @@ QT_BEGIN_NAMESPACE
\image text.png
If height and width are not explicitly set, Text will attempt to determine how
- much room is needed and set it accordingly. Unless \c wrap is set, it will always
+ much room is needed and set it accordingly. Unless \c wrapMode is set, it will always
prefer width to height (all text will be placed on a single line).
The \c elide property can alternatively be used to fit a line of plain text to a set width.
@@ -319,37 +320,52 @@ void QDeclarativeText::setVAlign(VAlignment align)
}
/*!
- \qmlproperty bool Text::wrap
+ \qmlproperty enumeration Text::wrapMode
Set this property to wrap the text to the Text item's width. The text will only
- wrap if an explicit width has been set.
+ wrap if an explicit width has been set. wrapMode can be one of:
- Wrapping is done on word boundaries (i.e. it is a "word-wrap"). If the text cannot be
+ \list
+ \o NoWrap - no wrapping will be performed.
+ \o WordWrap - wrapping is done on word boundaries. If the text cannot be
word-wrapped to the specified width it will be partially drawn outside of the item's bounds.
If this is undesirable then enable clipping on the item (Item::clip).
+ \endlist
- Wrapping is off by default.
+ The default is NoWrap.
*/
-//### Future may provide choice of wrap modes, such as QTextOption::WrapAtWordBoundaryOrAnywhere
-bool QDeclarativeText::wrap() const
+QDeclarativeText::WrapMode QDeclarativeText::wrapMode() const
{
Q_D(const QDeclarativeText);
- return d->wrap;
+ return d->wrapMode;
}
-void QDeclarativeText::setWrap(bool w)
+void QDeclarativeText::setWrapMode(WrapMode mode)
{
Q_D(QDeclarativeText);
- if (w == d->wrap)
+ if (mode == d->wrapMode)
return;
- d->wrap = w;
+ d->wrapMode = mode;
d->updateLayout();
d->markImgDirty();
- emit wrapChanged(d->wrap);
+ emit wrapModeChanged();
+}
+
+bool QDeclarativeText::wrap() const
+{
+ Q_D(const QDeclarativeText);
+ return d->wrapMode != NoWrap;
+}
+
+void QDeclarativeText::setWrap(bool w)
+{
+ qmlInfo(this) << "\"wrap\" property is deprecated and will soon be removed. Use wrapMode";
+ setWrapMode(WordWrap);
}
+
/*!
\qmlproperty enumeration Text::textFormat
@@ -437,7 +453,7 @@ void QDeclarativeText::setTextFormat(TextFormat format)
Set this property to elide parts of the text fit to the Text item's width.
The text will only elide if an explicit width has been set.
- This property cannot be used with wrap enabled or with rich text.
+ This property cannot be used with wrapping enabled or with rich text.
Eliding can be \c ElideNone (the default), \c ElideLeft, \c ElideMiddle, or \c ElideRight.
@@ -471,7 +487,7 @@ void QDeclarativeText::geometryChanged(const QRectF &newGeometry,
{
Q_D(QDeclarativeText);
if (newGeometry.width() != oldGeometry.width()) {
- if (d->wrap || d->elideMode != QDeclarativeText::ElideNone) {
+ if (d->wrapMode != QDeclarativeText::NoWrap || d->elideMode != QDeclarativeText::ElideNone) {
//re-elide if needed
if (d->singleline && d->elideMode != QDeclarativeText::ElideNone &&
isComponentComplete() && widthValid()) {
@@ -538,12 +554,12 @@ void QDeclarativeTextPrivate::updateSize()
singleline = false; // richtext can't elide or be optimized for single-line case
doc->setDefaultFont(font);
QTextOption option((Qt::Alignment)int(hAlign | vAlign));
- if (wrap)
+ if (wrapMode == QDeclarativeText::WordWrap)
option.setWrapMode(QTextOption::WordWrap);
else
option.setWrapMode(QTextOption::NoWrap);
doc->setDefaultTextOption(option);
- if (wrap && !q->heightValid() && q->widthValid())
+ if (wrapMode != QDeclarativeText::NoWrap && !q->heightValid() && q->widthValid())
doc->setTextWidth(q->width());
else
doc->setTextWidth(doc->idealWidth()); // ### Text does not align if width is not set (QTextDoc bug)
@@ -623,7 +639,7 @@ QSize QDeclarativeTextPrivate::setupTextLayout(QTextLayout *layout)
qreal lineWidth = 0;
//set manual width
- if ((wrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid())
+ if ((wrapMode != QDeclarativeText::NoWrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid())
lineWidth = q->width();
layout->beginLayout();
@@ -633,7 +649,7 @@ QSize QDeclarativeTextPrivate::setupTextLayout(QTextLayout *layout)
if (!line.isValid())
break;
- if ((wrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid())
+ if ((wrapMode != QDeclarativeText::NoWrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid())
line.setLineWidth(lineWidth);
}
layout->endLayout();
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h
index cbea8f3..7a09b2f 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p.h
@@ -42,6 +42,7 @@
#ifndef QDECLARATIVETEXT_H
#define QDECLARATIVETEXT_H
+#include <QtGui/qtextoption.h>
#include "qdeclarativeitem.h"
QT_BEGIN_HEADER
@@ -58,6 +59,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeText : public QDeclarativeItem
Q_ENUMS(TextStyle)
Q_ENUMS(TextFormat)
Q_ENUMS(TextElideMode)
+ Q_ENUMS(WrapMode)
Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
@@ -66,7 +68,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeText : public QDeclarativeItem
Q_PROPERTY(QColor styleColor READ styleColor WRITE setStyleColor NOTIFY styleColorChanged)
Q_PROPERTY(HAlignment horizontalAlignment READ hAlign WRITE setHAlign NOTIFY horizontalAlignmentChanged)
Q_PROPERTY(VAlignment verticalAlignment READ vAlign WRITE setVAlign NOTIFY verticalAlignmentChanged)
- Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapChanged) //### there are several wrap modes in Qt
+ Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged)
+ Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapModeChanged)
Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged)
Q_PROPERTY(TextElideMode elide READ elideMode WRITE setElideMode NOTIFY elideModeChanged) //### elideMode?
@@ -93,6 +96,12 @@ public:
ElideMiddle = Qt::ElideMiddle,
ElideNone = Qt::ElideNone };
+ enum WrapMode { NoWrap = QTextOption::NoWrap,
+ WordWrap = QTextOption::WordWrap
+// WrapAnywhere = QTextOption::WrapAnywhere,
+// WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere
+ };
+
QString text() const;
void setText(const QString &);
@@ -116,6 +125,8 @@ public:
bool wrap() const;
void setWrap(bool w);
+ WrapMode wrapMode() const;
+ void setWrapMode(WrapMode w);
TextFormat textFormat() const;
void setTextFormat(TextFormat format);
@@ -136,7 +147,7 @@ Q_SIGNALS:
void styleColorChanged(const QColor &color);
void horizontalAlignmentChanged(HAlignment alignment);
void verticalAlignmentChanged(VAlignment alignment);
- void wrapChanged(bool wrap);
+ void wrapModeChanged();
void textFormatChanged(TextFormat textFormat);
void elideModeChanged(TextElideMode mode);
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p_p.h b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
index 85a65ce..cc5a9f2 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
@@ -72,8 +72,8 @@ public:
QDeclarativeTextPrivate()
: color((QRgb)0), style(QDeclarativeText::Normal),
hAlign(QDeclarativeText::AlignLeft), vAlign(QDeclarativeText::AlignTop), elideMode(QDeclarativeText::ElideNone),
- imgDirty(true), dirty(true), wrap(false), richText(false), singleline(false), cache(true), doc(0),
- format(QDeclarativeText::AutoText)
+ imgDirty(true), dirty(true), richText(false), singleline(false), cache(true), doc(0),
+ format(QDeclarativeText::AutoText), wrapMode(QDeclarativeText::NoWrap)
{
#if defined(QML_NO_TEXT_CACHE)
cache = false;
@@ -115,7 +115,6 @@ public:
QDeclarativeText::TextElideMode elideMode;
bool imgDirty:1;
bool dirty:1;
- bool wrap:1;
bool richText:1;
bool singleline:1;
bool cache:1;
@@ -123,6 +122,7 @@ public:
QTextLayout layout;
QSize cachedLayoutSize;
QDeclarativeText::TextFormat format;
+ QDeclarativeText::WrapMode wrapMode;
};
QT_END_NAMESPACE
diff --git a/src/declarative/util/qdeclarativepropertychanges.cpp b/src/declarative/util/qdeclarativepropertychanges.cpp
index e7228cc..0ed97bf 100644
--- a/src/declarative/util/qdeclarativepropertychanges.cpp
+++ b/src/declarative/util/qdeclarativepropertychanges.cpp
@@ -111,7 +111,7 @@ QT_BEGIN_NAMESPACE
Text {
id: theText
width: 50
- wrap: true
+ wrapMode: Text.WordWrap
text: "a text string that is longer than 50 pixels"
}
diff --git a/tests/auto/declarative/qdeclarativestates/data/reset.qml b/tests/auto/declarative/qdeclarativestates/data/reset.qml
index 8e9b13a..7da80b3 100644
--- a/tests/auto/declarative/qdeclarativestates/data/reset.qml
+++ b/tests/auto/declarative/qdeclarativestates/data/reset.qml
@@ -6,7 +6,7 @@ Rectangle {
Text {
id: theText
width: 40
- wrap: true
+ wrapMode: Text.WordWrap
text: "a text string that is longer than 40 pixels"
}
diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
index bbbbd83..bf7d110 100644
--- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
+++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp
@@ -251,18 +251,18 @@ void tst_qdeclarativetext::wrap()
// for specified width and wrap set true
{
QDeclarativeComponent textComponent(&engine);
- textComponent.setData("import Qt 4.6\nText { text: \"Hello\"; wrap: true; width: 300 }", QUrl::fromLocalFile(""));
+ textComponent.setData("import Qt 4.6\nText { text: \"Hello\"; wrapMode: Text.WordWrap; width: 300 }", QUrl::fromLocalFile(""));
QDeclarativeText *textObject = qobject_cast<QDeclarativeText*>(textComponent.create());
textHeight = textObject->height();
QVERIFY(textObject != 0);
- QVERIFY(textObject->wrap() == true);
+ QVERIFY(textObject->wrapMode() == QDeclarativeText::WordWrap);
QCOMPARE(textObject->width(), 300.);
}
for (int i = 0; i < standard.size(); i++)
{
- QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + standard.at(i) + "\" }";
+ QString componentStr = "import Qt 4.6\nText { wrapMode: Text.WordWrap; width: 30; text: \"" + standard.at(i) + "\" }";
QDeclarativeComponent textComponent(&engine);
textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
QDeclarativeText *textObject = qobject_cast<QDeclarativeText*>(textComponent.create());
@@ -278,7 +278,7 @@ void tst_qdeclarativetext::wrap()
for (int i = 0; i < richText.size(); i++)
{
- QString componentStr = "import Qt 4.6\nText { wrap: true; width: 30; text: \"" + richText.at(i) + "\" }";
+ QString componentStr = "import Qt 4.6\nText { wrapMode: Text.WordWrap; width: 30; text: \"" + richText.at(i) + "\" }";
QDeclarativeComponent textComponent(&engine);
textComponent.setData(componentStr.toLatin1(), QUrl::fromLocalFile(""));
QDeclarativeText *textObject = qobject_cast<QDeclarativeText*>(textComponent.create());
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml
index a3aa929..c44088b 100644
--- a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml
+++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml
@@ -61,7 +61,7 @@ Rectangle {
text: s.text; horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignBottom; width: 800; height: 20
}
Text {
- text: s.text; font.pixelSize: 18; style: Text.Outline; styleColor: "white"; wrap: true; width: 200
+ text: s.text; font.pixelSize: 18; style: Text.Outline; styleColor: "white"; wrapMode: Text.WordWrap; width: 200
}
Text {
text: s.text; elide: Text.ElideLeft; width: 200
@@ -73,13 +73,13 @@ Rectangle {
text: s.text; elide: Text.ElideRight; width: 200
}
Text {
- text: s.text; elide: Text.ElideLeft; width: 200; wrap: true
+ text: s.text; elide: Text.ElideLeft; width: 200; wrapMode: Text.WordWrap
}
Text {
- text: s.text; elide: Text.ElideMiddle; width: 200; wrap: true
+ text: s.text; elide: Text.ElideMiddle; width: 200; wrapMode: Text.WordWrap
}
Text {
- text: s.text; elide: Text.ElideRight; width: 200; wrap: true
+ text: s.text; elide: Text.ElideRight; width: 200; wrapMode: Text.WordWrap
}
}
}
diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml
index 35aa232..b5d05da 100644
--- a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml
+++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml
@@ -61,7 +61,7 @@ Rectangle {
text: s.text; horizontalAlignment: Text.AlignRight; verticalAlignment: Text.AlignBottom; width: 800; height: 20
}
Text {
- text: s.text; font.pixelSize: 18; style: Text.Outline; styleColor: "white"; wrap: true; width: 200
+ text: s.text; font.pixelSize: 18; style: Text.Outline; styleColor: "white"; wrapMode: Text.WordWrap; width: 200
}
Text {
text: s.text; elide: Text.ElideLeft; width: 200
@@ -73,13 +73,13 @@ Rectangle {
text: s.text; elide: Text.ElideRight; width: 200
}
Text {
- text: s.text; elide: Text.ElideLeft; width: 200; wrap: true
+ text: s.text; elide: Text.ElideLeft; width: 200; wrapMode: Text.WordWrap
}
Text {
- text: s.text; elide: Text.ElideMiddle; width: 200; wrap: true
+ text: s.text; elide: Text.ElideMiddle; width: 200; wrapMode: Text.WordWrap
}
Text {
- text: s.text; elide: Text.ElideRight; width: 200; wrap: true
+ text: s.text; elide: Text.ElideRight; width: 200; wrapMode: Text.WordWrap
}
}
}