diff options
8 files changed, 47 insertions, 19 deletions
diff --git a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml index 992c7e2..c1ae3e5 100644 --- a/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml +++ b/demos/declarative/twitter/TwitterCore/HomeTitleBar.qml @@ -88,7 +88,7 @@ Item { width: parent.width - 12 height: parent.height - 8 font.pointSize: 10 - wrapMode: TextEdit.WordWrap + wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere color: "#151515"; selectionColor: "green" } Keys.forwardTo: [(returnKey), (editor)] diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 1f53b75..1730ee4 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -330,6 +330,9 @@ void QDeclarativeText::setVAlign(VAlignment align) \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). + \o WrapAnywhere - Text can be wrapped at any point on a line, even if it occurs in the middle of a word. + \o WrapAtWordBoundaryOrAnywhere - If possible, wrapping occurs at a word boundary; otherwise it + will occur at the appropriate point on the line, even in the middle of a word. \endlist The default is NoWrap. @@ -554,10 +557,7 @@ 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 (wrapMode == QDeclarativeText::WordWrap) - option.setWrapMode(QTextOption::WordWrap); - else - option.setWrapMode(QTextOption::NoWrap); + option.setWrapMode(QTextOption::WrapMode(wrapMode)); doc->setDefaultTextOption(option); if (wrapMode != QDeclarativeText::NoWrap && !q->heightValid() && q->widthValid()) doc->setTextWidth(q->width()); @@ -642,6 +642,10 @@ QSize QDeclarativeTextPrivate::setupTextLayout(QTextLayout *layout) if ((wrapMode != QDeclarativeText::NoWrap || elideMode != QDeclarativeText::ElideNone) && q->widthValid()) lineWidth = q->width(); + QTextOption textOption = layout->textOption(); + textOption.setWrapMode(QTextOption::WrapMode(wrapMode)); + layout->setTextOption(textOption); + layout->beginLayout(); while (1) { diff --git a/src/declarative/graphicsitems/qdeclarativetext_p.h b/src/declarative/graphicsitems/qdeclarativetext_p.h index 7a09b2f..871c833 100644 --- a/src/declarative/graphicsitems/qdeclarativetext_p.h +++ b/src/declarative/graphicsitems/qdeclarativetext_p.h @@ -97,9 +97,9 @@ public: ElideNone = Qt::ElideNone }; enum WrapMode { NoWrap = QTextOption::NoWrap, - WordWrap = QTextOption::WordWrap -// WrapAnywhere = QTextOption::WrapAnywhere, -// WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere + WordWrap = QTextOption::WordWrap, + WrapAnywhere = QTextOption::WrapAnywhere, + WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere }; QString text() const; diff --git a/src/declarative/graphicsitems/qdeclarativetextedit.cpp b/src/declarative/graphicsitems/qdeclarativetextedit.cpp index 1db5ffe..6f1f6ac 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit.cpp +++ b/src/declarative/graphicsitems/qdeclarativetextedit.cpp @@ -370,6 +370,9 @@ void QDeclarativeTextEdit::setVAlign(QDeclarativeTextEdit::VAlignment alignment) \list \o NoWrap - no wrapping will be performed. \o WordWrap - wrapping is done on word boundaries. + \o WrapAnywhere - Text can be wrapped at any point on a line, even if it occurs in the middle of a word. + \o WrapAtWordBoundaryOrAnywhere - If possible, wrapping occurs at a word boundary; otherwise it + will occur at the appropriate point on the line, even in the middle of a word. \endlist The default is NoWrap. @@ -1039,11 +1042,7 @@ void QDeclarativeTextEditPrivate::updateDefaultTextOption() opt.setAlignment((Qt::Alignment)(int)(hAlign | vAlign)); QTextOption::WrapMode oldWrapMode = opt.wrapMode(); - - if (wrapMode == QDeclarativeTextEdit::WordWrap) - opt.setWrapMode(QTextOption::WordWrap); - else - opt.setWrapMode(QTextOption::NoWrap); + opt.setWrapMode(QTextOption::WrapMode(wrapMode)); if (oldWrapMode == opt.wrapMode() && oldAlignment == opt.alignment()) return; diff --git a/src/declarative/graphicsitems/qdeclarativetextedit_p.h b/src/declarative/graphicsitems/qdeclarativetextedit_p.h index 3ac2b42..605b620 100644 --- a/src/declarative/graphicsitems/qdeclarativetextedit_p.h +++ b/src/declarative/graphicsitems/qdeclarativetextedit_p.h @@ -110,9 +110,9 @@ public: }; enum WrapMode { NoWrap = QTextOption::NoWrap, - WordWrap = QTextOption::WordWrap -// WrapAnywhere = QTextOption::WrapAnywhere, -// WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere + WordWrap = QTextOption::WordWrap, + WrapAnywhere = QTextOption::WrapAnywhere, + WrapAtWordBoundaryOrAnywhere = QTextOption::WrapAtWordBoundaryOrAnywhere }; QString text() const; diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml index c44088b..90b5411 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/plaintext.qml @@ -81,5 +81,11 @@ Rectangle { Text { text: s.text; elide: Text.ElideRight; width: 200; wrapMode: Text.WordWrap } + Text { + text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAnywhere + } + Text { + text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAtWordBoundaryOrAnywhere + } } } diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml index b5d05da..0dba47c 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetext/font/richtext.qml @@ -81,5 +81,11 @@ Rectangle { Text { text: s.text; elide: Text.ElideRight; width: 200; wrapMode: Text.WordWrap } + Text { + text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAnywhere + } + Text { + text: s.text + " thisisaverylongstringwithnospaces"; width: 150; wrapMode: Text.WrapAtWordBoundaryOrAnywhere + } } } diff --git a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml index af69994..b2a0754 100644 --- a/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml +++ b/tests/auto/declarative/qmlvisual/qdeclarativetextedit/wrap.qml @@ -5,17 +5,30 @@ Item { width: 200 TextEdit { width: 200 - height: 200 + height: 100 wrapMode: TextEdit.WordWrap focus: true } //With QTBUG-6273 only the bottom one would be wrapped TextEdit { width: 200 - height: 200 + height: 100 wrapMode: TextEdit.WordWrap text: "This is a test that text edit wraps correctly." + y:100 + } + TextEdit { + width: 150 + height: 100 + wrapMode: TextEdit.WrapAnywhere + text: "This is a test that text edit wraps correctly. thisisaverylongstringwithnospaces" y:200 } - + TextEdit { + width: 150 + height: 100 + wrapMode: TextEdit.WrapAtWordBoundaryOrAnywhere + text: "This is a test that text edit wraps correctly. thisisaverylongstringwithnospaces" + y:300 + } } |