diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2009-05-19 23:43:58 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2009-05-19 23:43:58 (GMT) |
commit | ccc5039c22d2e507b61cf3fc3b9be9684638db12 (patch) | |
tree | df8106bf533b7a780c2f24526538b7a5580226b9 /src/declarative/fx/qfxtext.cpp | |
parent | cc51d0f166354ad5acdc5ce054a83a02eeb21229 (diff) | |
download | Qt-ccc5039c22d2e507b61cf3fc3b9be9684638db12.zip Qt-ccc5039c22d2e507b61cf3fc3b9be9684638db12.tar.gz Qt-ccc5039c22d2e507b61cf3fc3b9be9684638db12.tar.bz2 |
Don't recreate text layout everytime it is used.
Diffstat (limited to 'src/declarative/fx/qfxtext.cpp')
-rw-r--r-- | src/declarative/fx/qfxtext.cpp | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/src/declarative/fx/qfxtext.cpp b/src/declarative/fx/qfxtext.cpp index bc3856d..e84255d 100644 --- a/src/declarative/fx/qfxtext.cpp +++ b/src/declarative/fx/qfxtext.cpp @@ -458,10 +458,11 @@ void QFxTextPrivate::updateSize() singleline = !tmp.contains(QChar::LineSeparator); if (singleline && elideMode != Qt::ElideNone && q->widthValid()) tmp = fm.elidedText(tmp,elideMode,q->width()); // XXX still worth layout...? - QTextLayout layout; + layout.clearLayout(); layout.setFont(f); layout.setText(tmp); size = setupTextLayout(&layout); + cachedLayoutSize = size; } if (richText) { singleline = false; // richtext can't elide or be optimized for single-line case @@ -608,18 +609,11 @@ QImage QFxTextPrivate::wrappedTextImage(bool drawStyle) //do layout Q_Q(const QFxText); QFont f; if (_font) f = _font->font(); - QString tmp = text; - if (singleline && elideMode != Qt::ElideNone && q->widthValid()) { - QFontMetrics fm(f); - tmp = fm.elidedText(tmp,elideMode,q->width()); // XXX still worth layout...? - } - tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); - QTextLayout textLayout(tmp, f); - QSize size = setupTextLayout(&textLayout); + QSize size = cachedLayoutSize; int x = 0; - for (int i = 0; i < textLayout.lineCount(); ++i) { - QTextLine line = textLayout.lineAt(i); + for (int i = 0; i < layout.lineCount(); ++i) { + QTextLine line = layout.lineAt(i); if (hAlign == QFxText::AlignLeft) { x = 0; } else if (hAlign == QFxText::AlignRight) { @@ -640,7 +634,7 @@ QImage QFxTextPrivate::wrappedTextImage(bool drawStyle) else p.setPen(color); p.setFont(f); - textLayout.draw(&p, QPointF(0, 0)); + layout.draw(&p, QPointF(0, 0)); return img; } |