diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-07-21 04:16:34 (GMT) |
---|---|---|
committer | Toby Tomkins <toby.tomkins@nokia.com> | 2010-07-26 06:24:18 (GMT) |
commit | 26a1acf139f7a444bc68d9a1540d418c41aa89ec (patch) | |
tree | 2943aee398fab53819db821c2cd3d4781820758d | |
parent | 19835bd63a99e1b71b80f68fac249f4d207975ec (diff) | |
download | Qt-26a1acf139f7a444bc68d9a1540d418c41aa89ec.zip Qt-26a1acf139f7a444bc68d9a1540d418c41aa89ec.tar.gz Qt-26a1acf139f7a444bc68d9a1540d418c41aa89ec.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
(cherry picked from commit 3aeafb4839f49f524f10eae65be27fd189d37060)
3 files changed, 64 insertions, 53 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativetext.cpp b/src/declarative/graphicsitems/qdeclarativetext.cpp index 9b0391d..83911cb 100644 --- a/src/declarative/graphicsitems/qdeclarativetext.cpp +++ b/src/declarative/graphicsitems/qdeclarativetext.cpp @@ -710,63 +710,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, diff --git a/tests/auto/declarative/qdeclarativetext/data/rotated.qml b/tests/auto/declarative/qdeclarativetext/data/rotated.qml new file mode 100644 index 0000000..01eec44 --- /dev/null +++ b/tests/auto/declarative/qdeclarativetext/data/rotated.qml @@ -0,0 +1,18 @@ +import Qt 4.7 + +Rectangle { + width : 200 + height : 100 + + Text { + objectName: "text" + x: 20 + y: 20 + height : 20 + width : 80 + text : "Something" + rotation : 30 + transformOrigin : Item.TopLeft + } +} + diff --git a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp index 821394d..658f381 100644 --- a/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp +++ b/tests/auto/declarative/qdeclarativetext/tst_qdeclarativetext.cpp @@ -97,6 +97,8 @@ private slots: void clickLink(); + void QTBUG_12291(); + private: QStringList standard; QStringList richText; @@ -898,6 +900,23 @@ void tst_qdeclarativetext::wordSpacing() } } +void tst_qdeclarativetext::QTBUG_12291() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/rotated.qml"); + + canvas->show(); + QApplication::setActiveWindow(canvas); + QTest::qWaitForWindowShown(canvas); + QTRY_COMPARE(QApplication::activeWindow(), static_cast<QWidget *>(canvas)); + + QObject *ob = canvas->rootObject(); + QVERIFY(ob != 0); + + QDeclarativeText *text = ob->findChild<QDeclarativeText*>("text"); + QVERIFY(text); + QVERIFY(text->boundingRect().isValid()); +} + class EventSender : public QGraphicsItem { public: |