From 95ad31adca64f639712fa378d25aa3e552b3dc72 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 9 Apr 2010 15:18:08 +1000 Subject: TextEdit::wrap changed to TextEdit::wrapMode enumeration --- .../twitter/TwitterCore/HomeTitleBar.qml | 2 +- demos/declarative/twitter/twitter.qml | 2 +- src/declarative/QmlChanges.txt | 1 + src/declarative/graphicsitems/qdeclarativetext.cpp | 2 +- .../graphicsitems/qdeclarativetextedit.cpp | 45 +++++++++++++++------- .../graphicsitems/qdeclarativetextedit_p.h | 14 ++++++- .../graphicsitems/qdeclarativetextedit_p_p.h | 21 +++++----- .../qdeclarativefocusscope/data/test5.qml | 4 +- .../tst_qdeclarativetextedit.cpp | 6 +-- .../qmlvisual/qdeclarativetextedit/wrap.qml | 4 +- 10 files changed, 66 insertions(+), 35 deletions(-) diff --git a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml index 0835315..55b7e62 100644 --- a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml +++ b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml @@ -90,7 +90,7 @@ Item { width: parent.width - 12 height: parent.height - 8 font.pointSize: 10 - wrap: true + wrapMode: TextEdit.WordWrap color: "#151515"; selectionColor: "green" } Keys.forwardTo: [(returnKey), (editor)] diff --git a/demos/declarative/twitter/twitter.qml b/demos/declarative/twitter/twitter.qml index 84926cd..583bf7f 100644 --- a/demos/declarative/twitter/twitter.qml +++ b/demos/declarative/twitter/twitter.qml @@ -35,7 +35,7 @@ Item { Text { width: 180 text: "Could not access twitter using this screen name and password pair."; - color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrap: true + color: "#cccccc"; style: Text.Raised; styleColor: "black"; wrapMode: Text.WordWrap visible: rssModel.status==XmlListModel.Error; anchors.centerIn: parent } diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index 079aacb..d5910e3 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 +TextEdit: wrap property is replaced by wrapMode enumeration. 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 diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index c950e31..1f53b75 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -362,7 +362,7 @@ bool QDeclarativeText::wrap() const void QDeclarativeText::setWrap(bool w) { qmlInfo(this) << "\"wrap\" property is deprecated and will soon be removed. Use wrapMode"; - setWrapMode(WordWrap); + setWrapMode(w ? WordWrap : NoWrap); } diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 7374bc8..1db5ffe 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -44,6 +44,7 @@ #include "private/qdeclarativeevents_p_p.h" #include +#include #include #include @@ -360,29 +361,47 @@ void QDeclarativeTextEdit::setVAlign(QDeclarativeTextEdit::VAlignment alignment) emit verticalAlignmentChanged(d->vAlign); } -bool QDeclarativeTextEdit::wrap() const -{ - Q_D(const QDeclarativeTextEdit); - return d->wrap; -} - /*! - \qmlproperty bool TextEdit::wrap + \qmlproperty enumeration TextEdit::wrapMode Set this property to wrap the text to the TextEdit item's width. The text will only wrap if an explicit width has been set. - Wrapping is done on word boundaries (i.e. it is a "word-wrap"). Wrapping is off by default. + \list + \o NoWrap - no wrapping will be performed. + \o WordWrap - wrapping is done on word boundaries. + \endlist + + The default is NoWrap. */ -void QDeclarativeTextEdit::setWrap(bool w) +QDeclarativeTextEdit::WrapMode QDeclarativeTextEdit::wrapMode() const +{ + Q_D(const QDeclarativeTextEdit); + return d->wrapMode; +} + +void QDeclarativeTextEdit::setWrapMode(WrapMode mode) { Q_D(QDeclarativeTextEdit); - if (w == d->wrap) + if (mode == d->wrapMode) return; - d->wrap = w; + d->wrapMode = mode; d->updateDefaultTextOption(); updateSize(); - emit wrapChanged(d->wrap); + emit wrapModeChanged(); +} + +bool QDeclarativeTextEdit::wrap() const +{ + Q_D(const QDeclarativeTextEdit); + return d->wrapMode != QDeclarativeTextEdit::NoWrap; +} + +void QDeclarativeTextEdit::setWrap(bool w) +{ + + qmlInfo(this) << "\"wrap\" property is deprecated and will soon be removed. Use wrapMode"; + setWrapMode(w ? WordWrap : NoWrap); } /*! @@ -1021,7 +1040,7 @@ void QDeclarativeTextEditPrivate::updateDefaultTextOption() QTextOption::WrapMode oldWrapMode = opt.wrapMode(); - if (wrap) + if (wrapMode == QDeclarativeTextEdit::WordWrap) opt.setWrapMode(QTextOption::WordWrap); else opt.setWrapMode(QTextOption::NoWrap); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 0e91e73..3ac2b42 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -64,6 +64,7 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem Q_ENUMS(VAlignment) Q_ENUMS(HAlignment) Q_ENUMS(TextFormat) + Q_ENUMS(WrapMode) Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) Q_PROPERTY(QColor color READ color WRITE setColor NOTIFY colorChanged) @@ -72,7 +73,8 @@ class Q_DECLARATIVE_EXPORT QDeclarativeTextEdit : public QDeclarativePaintedItem Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged) 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) //### other wrap modes + Q_PROPERTY(bool wrap READ wrap WRITE setWrap NOTIFY wrapChanged) //### deprecated + Q_PROPERTY(WrapMode wrapMode READ wrapMode WRITE setWrapMode NOTIFY wrapModeChanged) Q_PROPERTY(TextFormat textFormat READ textFormat WRITE setTextFormat NOTIFY textFormatChanged) Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly NOTIFY readOnlyChanged) Q_PROPERTY(bool cursorVisible READ isCursorVisible WRITE setCursorVisible NOTIFY cursorVisibleChanged) @@ -107,6 +109,12 @@ public: AutoText = Qt::AutoText }; + enum WrapMode { NoWrap = QTextOption::NoWrap, + WordWrap = QTextOption::WordWrap +// WrapAnywhere = QTextOption::WrapAnywhere, +// WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere + }; + QString text() const; void setText(const QString &); @@ -133,6 +141,8 @@ public: bool wrap() const; void setWrap(bool w); + WrapMode wrapMode() const; + void setWrapMode(WrapMode w); bool isCursorVisible() const; void setCursorVisible(bool on); @@ -185,7 +195,7 @@ Q_SIGNALS: void fontChanged(const QFont &font); void horizontalAlignmentChanged(HAlignment alignment); void verticalAlignmentChanged(VAlignment alignment); - void wrapChanged(bool isWrapped); + void wrapModeChanged(); void textFormatChanged(TextFormat textFormat); void readOnlyChanged(bool isReadOnly); void cursorVisibleChanged(bool isCursorVisible); diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h index 310db48..8d4b611 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p_p.h @@ -68,10 +68,11 @@ class QDeclarativeTextEditPrivate : public QDeclarativePaintedItemPrivate public: QDeclarativeTextEditPrivate() - : color("black"), imgDirty(true), hAlign(QDeclarativeTextEdit::AlignLeft), vAlign(QDeclarativeTextEdit::AlignTop), - dirty(false), wrap(false), richText(false), cursorVisible(false), focusOnPress(true), + : color("black"), hAlign(QDeclarativeTextEdit::AlignLeft), vAlign(QDeclarativeTextEdit::AlignTop), + imgDirty(true), dirty(false), richText(false), cursorVisible(false), focusOnPress(true), persistentSelection(true), textMargin(0.0), lastSelectionStart(0), lastSelectionEnd(0), - cursorComponent(0), cursor(0), format(QDeclarativeTextEdit::AutoText), document(0) + cursorComponent(0), cursor(0), format(QDeclarativeTextEdit::AutoText), document(0), + wrapMode(QDeclarativeTextEdit::NoWrap) { } @@ -89,17 +90,16 @@ public: QColor selectedTextColor; QString style; QColor styleColor; - bool imgDirty; QPixmap imgCache; QPixmap imgStyleCache; QDeclarativeTextEdit::HAlignment hAlign; QDeclarativeTextEdit::VAlignment vAlign; - bool dirty; - bool wrap; - bool richText; - bool cursorVisible; - bool focusOnPress; - bool persistentSelection; + bool imgDirty : 1; + bool dirty : 1; + bool richText : 1; + bool cursorVisible : 1; + bool focusOnPress : 1; + bool persistentSelection : 1; qreal textMargin; int lastSelectionStart; int lastSelectionEnd; @@ -108,6 +108,7 @@ public: QDeclarativeTextEdit::TextFormat format; QTextDocument *document; QTextControl *control; + QDeclarativeTextEdit::WrapMode wrapMode; }; QT_END_NAMESPACE diff --git a/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml b/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml index 0b75ec4..da452cf 100644 --- a/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml +++ b/tests/auto/declarative/qdeclarativefocusscope/data/test5.qml @@ -38,7 +38,7 @@ Rectangle { Keys.onReturnPressed: console.log("Top Left"); KeyNavigation.right: item2 focus: true - wrap: true + wrapMode: TextEdit.WordWrap text: "Box 1" } @@ -79,6 +79,6 @@ Rectangle { Keys.onReturnPressed: console.log("Bottom Left"); KeyNavigation.up: myScope - wrap: true + wrapMode: TextEdit.WordWrap } } diff --git a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp index b1935df..d578f68 100644 --- a/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp +++ b/tests/auto/declarative/qdeclarativetextedit/tst_qdeclarativetextedit.cpp @@ -235,7 +235,7 @@ void tst_qdeclarativetextedit::wrap() // for specified width and wrap set true { QDeclarativeComponent texteditComponent(&engine); - texteditComponent.setData("import Qt 4.6\nTextEdit { text: \"\"; wrap: true; width: 300 }", QUrl()); + texteditComponent.setData("import Qt 4.6\nTextEdit { text: \"\"; wrapMode: TextEdit.WordWrap; width: 300 }", QUrl()); QDeclarativeTextEdit *textEditObject = qobject_cast(texteditComponent.create()); QVERIFY(textEditObject != 0); @@ -244,7 +244,7 @@ void tst_qdeclarativetextedit::wrap() for (int i = 0; i < standard.size(); i++) { - QString componentStr = "import Qt 4.6\nTextEdit { wrap: true; width: 300; text: \"" + standard.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { wrapMode: TextEdit.WordWrap; width: 300; text: \"" + standard.at(i) + "\" }"; QDeclarativeComponent texteditComponent(&engine); texteditComponent.setData(componentStr.toLatin1(), QUrl()); QDeclarativeTextEdit *textEditObject = qobject_cast(texteditComponent.create()); @@ -255,7 +255,7 @@ void tst_qdeclarativetextedit::wrap() for (int i = 0; i < richText.size(); i++) { - QString componentStr = "import Qt 4.6\nTextEdit { wrap: true; width: 300; text: \"" + richText.at(i) + "\" }"; + QString componentStr = "import Qt 4.6\nTextEdit { wrapMode: TextEdit.WordWrap; width: 300; text: \"" + richText.at(i) + "\" }"; QDeclarativeComponent texteditComponent(&engine); texteditComponent.setData(componentStr.toLatin1(), QUrl()); QDeclarativeTextEdit *textEditObject = qobject_cast(texteditComponent.create()); diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml index f9fe025..af69994 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml @@ -6,14 +6,14 @@ Item { TextEdit { width: 200 height: 200 - wrap: true + wrapMode: TextEdit.WordWrap focus: true } //With QTBUG-6273 only the bottom one would be wrapped TextEdit { width: 200 height: 200 - wrap: true + wrapMode: TextEdit.WordWrap text: "This is a test that text edit wraps correctly." y:200 } -- cgit v0.12