diff options
author | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-08-14 15:38:31 (GMT) |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eblomfel@trolltech.com> | 2009-08-14 15:55:10 (GMT) |
commit | a7b24170890aad476345a5d7a56ded8d62c53df0 (patch) | |
tree | f4d8dd08f8801e984b9a35b5dee1fab2996d8781 /src/gui/text | |
parent | 78fbb9cf6ef5e8440f0453ef60bd7845ce418745 (diff) | |
download | Qt-a7b24170890aad476345a5d7a56ded8d62c53df0.zip Qt-a7b24170890aad476345a5d7a56ded8d62c53df0.tar.gz Qt-a7b24170890aad476345a5d7a56ded8d62c53df0.tar.bz2 |
Avoid wrapping outside word boundaries in QTextDocument unless necessary
If you have a floating object which affects the width available to the
text, we need to recalculate the width of the text line. In the code,
the setLineWidth() call to do this would by default have WrapAnywhere
as its wrap mode, even when this was not necessary. The code has now
been moved so that WrapAnywhere is only used if we try to set the
line width to match the available width and detect that the text is
too wide (the natural text width exceeds the available space.)
Task-number: 240325
Reviewed-by: Simon Hausmann
Diffstat (limited to 'src/gui/text')
-rw-r--r-- | src/gui/text/qtextdocumentlayout.cpp | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/gui/text/qtextdocumentlayout.cpp b/src/gui/text/qtextdocumentlayout.cpp index e26961f..a795c1f 100644 --- a/src/gui/text/qtextdocumentlayout.cpp +++ b/src/gui/text/qtextdocumentlayout.cpp @@ -2601,13 +2601,13 @@ void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosi // float has been added in the meantime, redo layoutStruct->pendingFloats.clear(); - if (haveWordOrAnyWrapMode) { - option.setWrapMode(QTextOption::WrapAnywhere); - tl->setTextOption(option); - } - line.setLineWidth((right-left).toReal()); if (QFixed::fromReal(line.naturalTextWidth()) > right-left) { + if (haveWordOrAnyWrapMode) { + option.setWrapMode(QTextOption::WrapAnywhere); + tl->setTextOption(option); + } + layoutStruct->pendingFloats.clear(); // lines min width more than what we have layoutStruct->y = findY(layoutStruct->y, layoutStruct, QFixed::fromReal(line.naturalTextWidth())); @@ -2619,12 +2619,13 @@ void QTextDocumentLayoutPrivate::layoutBlock(const QTextBlock &bl, int blockPosi else right -= text_indent; line.setLineWidth(qMax<qreal>(line.naturalTextWidth(), (right-left).toReal())); - } - if (haveWordOrAnyWrapMode) { - option.setWrapMode(QTextOption::WordWrap); - tl->setTextOption(option); + if (haveWordOrAnyWrapMode) { + option.setWrapMode(QTextOption::WordWrap); + tl->setTextOption(option); + } } + } QFixed lineHeight = QFixed::fromReal(line.height()); |