diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-07-21 04:16:34 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-07-21 04:16:34 (GMT) |
commit | 3aeafb4839f49f524f10eae65be27fd189d37060 (patch) | |
tree | 5d35f55d8e68d8a2f5c2ab79d8614eed6a0ff28a /src/declarative/graphicsitems/qdeclarativetext.cpp | |
parent | 21806ff0921641b4e4d9d39721ab4ebeae74dddc (diff) | |
download | Qt-3aeafb4839f49f524f10eae65be27fd189d37060.zip Qt-3aeafb4839f49f524f10eae65be27fd189d37060.tar.gz Qt-3aeafb4839f49f524f10eae65be27fd189d37060.tar.bz2 |
Bounding rect of text was not always calculated correctly.
The boundingRect depended upon the image cache which may not become
valid until after boundingRect is called.
Task-number: QTBUG-12291
Reviewed-by: Michael Brasser
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativetext.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativetext.cpp | 80 |
1 files changed, 27 insertions, 53 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index a1703c1..ab2be9c 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -712,63 +712,37 @@ QRectF QDeclarativeText::boundingRect() const int x = 0; int y = 0; - // Could include font max left/right bearings to either side of rectangle. - - if (d->cache || d->style != Normal) { - QDeclarativeTextPrivate *dd = const_cast<QDeclarativeTextPrivate *>(d); - dd->checkImgCache(); - switch (d->hAlign) { - case AlignLeft: - x = 0; - break; - case AlignRight: - x = w - d->imgCache.width(); - break; - case AlignHCenter: - x = (w - d->imgCache.width()) / 2; - break; - } - - switch (d->vAlign) { - case AlignTop: - y = 0; - break; - case AlignBottom: - y = h - d->imgCache.height(); - break; - case AlignVCenter: - y = (h - d->imgCache.height()) / 2; - break; - } + QSize size = d->cachedLayoutSize; + if (d->style != Normal) + size += QSize(2,2); - return QRectF(x,y,d->imgCache.width(),d->imgCache.height()); - } else { - switch (d->hAlign) { - case AlignLeft: - x = 0; - break; - case AlignRight: - x = w - d->cachedLayoutSize.width(); - break; - case AlignHCenter: - x = (w - d->cachedLayoutSize.width()) / 2; - break; - } + // Could include font max left/right bearings to either side of rectangle. - switch (d->vAlign) { - case AlignTop: - y = 0; - break; - case AlignBottom: - y = h - d->cachedLayoutSize.height(); - break; - case AlignVCenter: - y = (h - d->cachedLayoutSize.height()) / 2; - break; - } + switch (d->hAlign) { + case AlignLeft: + x = 0; + break; + case AlignRight: + x = w - size.width(); + break; + case AlignHCenter: + x = (w - size.width()) / 2; + break; + } - return QRectF(x,y,d->cachedLayoutSize.width(),d->cachedLayoutSize.height()); + switch (d->vAlign) { + case AlignTop: + y = 0; + break; + case AlignBottom: + y = h - size.height(); + break; + case AlignVCenter: + y = (h - size.height()) / 2; + break; } + + return QRectF(x,y,size.width(),size.height()); } void QDeclarativeText::geometryChanged(const QRectF &newGeometry, |