diff options
Diffstat (limited to 'src/declarative/items/qsgtext.cpp')
-rw-r--r-- | src/declarative/items/qsgtext.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/declarative/items/qsgtext.cpp b/src/declarative/items/qsgtext.cpp index f796006c18..f2ec7b21fa 100644 --- a/src/declarative/items/qsgtext.cpp +++ b/src/declarative/items/qsgtext.cpp @@ -1,4 +1,4 @@ -// Commit: a5c3c11e3e2204da6c8be9af98b38929366fafb8 +// Commit: cce89db1e2555cbca8fc28072e1c6dd737cec6c4 /**************************************************************************** ** ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). @@ -106,7 +106,7 @@ QSGTextPrivate::QSGTextPrivate() imageCacheDirty(true), updateOnComponentComplete(true), richText(false), singleline(false), cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), truncated(false), hAlignImplicit(true), rightToLeftText(false), - naturalWidth(0), doc(0), nodeType(NodeIsNull) + layoutTextElided(false), naturalWidth(0), doc(0), nodeType(NodeIsNull) { cacheAllTextAsImage = enableImageCache(); } @@ -219,6 +219,7 @@ void QSGTextPrivate::updateLayout() return; } + layoutTextElided = false; // Setup instance of QTextLayout for all cases other than richtext if (!richText) { layout.clearLayout(); @@ -229,10 +230,13 @@ void QSGTextPrivate::updateLayout() singleline = !tmp.contains(QChar::LineSeparator); if (singleline && !maximumLineCountValid && elideMode != QSGText::ElideNone && q->widthValid()) { QFontMetrics fm(font); - tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); // XXX still worth layout...? - if (tmp != text && !truncated) { - truncated = true; - emit q->truncatedChanged(); + tmp = fm.elidedText(tmp,(Qt::TextElideMode)elideMode,q->width()); + if (tmp != text) { + layoutTextElided = true; + if (!truncated) { + truncated = true; + emit q->truncatedChanged(); + } } } layout.setText(tmp); @@ -379,6 +383,12 @@ QRect QSGTextPrivate::setupTextLayout() if (requireImplicitWidth && q->widthValid()) { // requires an extra layout + QString elidedText; + if (layoutTextElided) { + // We have provided elided text to the layout, but we must calculate unelided width. + elidedText = layout.text(); + layout.setText(text); + } layout.beginLayout(); forever { QTextLine line = layout.createLine(); @@ -392,6 +402,8 @@ QRect QSGTextPrivate::setupTextLayout() br = br.united(line.naturalTextRect()); } naturalWidth = br.width(); + if (layoutTextElided) + layout.setText(elidedText); } if (maximumLineCountValid) { |