summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2011-04-21 04:15:38 (GMT)
committerMartin Jones <martin.jones@nokia.com>2011-04-21 05:20:55 (GMT)
commit6e5a642c9484536fc173714f560f739944368cf5 (patch)
tree140001aeada569e4c6cb71d65ecebb35c3f9498e /src
parent92062a9af1dea35b9bdd781ee087755168ac1e77 (diff)
downloadQt-6e5a642c9484536fc173714f560f739944368cf5.zip
Qt-6e5a642c9484536fc173714f560f739944368cf5.tar.gz
Qt-6e5a642c9484536fc173714f560f739944368cf5.tar.bz2
Elide has unexpected effect on Text's implicitWidth
The elided string was used to calculate the implicitWidth rather than the full string. Change-Id: I51b8800b47d4e32f4d5eef07c71df10e2df905b7 Task-number: QTBUG-18627 Reviewed-by: Michael Brasser
Diffstat (limited to 'src')
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext.cpp23
-rw-r--r--src/declarative/graphicsitems/qdeclarativetext_p_p.h1
2 files changed, 19 insertions, 5 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp
index 720692c..1d51840 100644
--- a/src/declarative/graphicsitems/qdeclarativetext.cpp
+++ b/src/declarative/graphicsitems/qdeclarativetext.cpp
@@ -101,7 +101,8 @@ QDeclarativeTextPrivate::QDeclarativeTextPrivate()
format(QDeclarativeText::AutoText), wrapMode(QDeclarativeText::NoWrap), lineHeight(1),
lineHeightMode(QDeclarativeText::ProportionalHeight), lineCount(1), truncated(false), maximumLineCount(INT_MAX),
maximumLineCountValid(false), imageCacheDirty(true), updateOnComponentComplete(true), richText(false), singleline(false),
- cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), hAlignImplicit(true), rightToLeftText(false), naturalWidth(0), doc(0)
+ cacheAllTextAsImage(true), internalWidthUpdate(false), requireImplicitWidth(false), hAlignImplicit(true),
+ rightToLeftText(false), layoutTextElided(false), naturalWidth(0), doc(0)
{
cacheAllTextAsImage = enableImageCache();
QGraphicsItemPrivate::acceptedMouseButtons = Qt::LeftButton;
@@ -217,6 +218,7 @@ void QDeclarativeTextPrivate::updateLayout()
return;
}
+ layoutTextElided = false;
// Setup instance of QTextLayout for all cases other than richtext
if (!richText) {
layout.clearLayout();
@@ -227,10 +229,13 @@ void QDeclarativeTextPrivate::updateLayout()
singleline = !tmp.contains(QChar::LineSeparator);
if (singleline && !maximumLineCountValid && elideMode != QDeclarativeText::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);
@@ -377,6 +382,12 @@ QRect QDeclarativeTextPrivate::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();
@@ -390,6 +401,8 @@ QRect QDeclarativeTextPrivate::setupTextLayout()
br = br.united(line.naturalTextRect());
}
naturalWidth = br.width();
+ if (layoutTextElided)
+ layout.setText(elidedText);
}
if (maximumLineCountValid) {
diff --git a/src/declarative/graphicsitems/qdeclarativetext_p_p.h b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
index e3ab62a..6a3d581 100644
--- a/src/declarative/graphicsitems/qdeclarativetext_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativetext_p_p.h
@@ -116,6 +116,7 @@ public:
bool requireImplicitWidth:1;
bool hAlignImplicit:1;
bool rightToLeftText:1;
+ bool layoutTextElided:1;
QRect layedOutTextRect;
QSize paintedSize;