From 7fcc1daf1762d345ca39f9599a8de2567bb8e788 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 16 Aug 2010 15:17:27 +1000 Subject: More positioners with QGraphicsWidgets fixes. Task-number: QTBUG-12416 Reviewed-by: Michael Brasser --- .../graphicsitems/qdeclarativepositioners.cpp | 8 +++- .../tst_qdeclarativepositioners.cpp | 44 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp index f32c532..1a5c42d 100644 --- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp +++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp @@ -70,6 +70,8 @@ void QDeclarativeBasePositionerPrivate::watchChanges(QGraphicsObject *other) Q_Q(QDeclarativeBasePositioner); QObject::connect(other, SIGNAL(widthChanged()), q, SLOT(graphicsWidgetGeometryChanged())); QObject::connect(other, SIGNAL(heightChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + QObject::connect(other, SIGNAL(opacityChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + QObject::connect(other, SIGNAL(visibleChanged()), q, SLOT(graphicsWidgetGeometryChanged())); } } @@ -82,6 +84,8 @@ void QDeclarativeBasePositionerPrivate::unwatchChanges(QGraphicsObject* other) Q_Q(QDeclarativeBasePositioner); QObject::disconnect(other, SIGNAL(widthChanged()), q, SLOT(graphicsWidgetGeometryChanged())); QObject::disconnect(other, SIGNAL(heightChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + QObject::disconnect(other, SIGNAL(opacityChanged()), q, SLOT(graphicsWidgetGeometryChanged())); + QObject::disconnect(other, SIGNAL(visibleChanged()), q, SLOT(graphicsWidgetGeometryChanged())); } } @@ -235,7 +239,7 @@ void QDeclarativeBasePositioner::prePositioning() QGraphicsObject *child = children.at(ii)->toGraphicsObject(); if (!child) continue; - QDeclarativeItemPrivate *childPrivate = static_cast(QGraphicsItemPrivate::get(child)); + QGraphicsItemPrivate *childPrivate = static_cast(QGraphicsItemPrivate::get(child)); PositionedItem *item = 0; PositionedItem posItem(child); int wIdx = oldItems.find(posItem); @@ -320,7 +324,7 @@ void QDeclarativeBasePositioner::finishApplyTransitions() static inline bool isInvisible(QGraphicsObject *child) { - QDeclarativeItemPrivate *childPrivate = static_cast(QGraphicsItemPrivate::get(child)); + QGraphicsItemPrivate *childPrivate = static_cast(QGraphicsItemPrivate::get(child)); return child->opacity() == 0.0 || childPrivate->explicitlyHidden || !childPrivate->width() || !childPrivate->height(); } diff --git a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp index 0663991..887be50 100644 --- a/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp +++ b/tests/auto/declarative/qdeclarativepositioners/tst_qdeclarativepositioners.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include "../../../shared/util.h" #ifdef Q_OS_SYMBIAN @@ -77,6 +78,7 @@ private slots: void test_flow_resize(); void test_flow_implicit_resize(); void test_conflictinganchors(); + void test_vertical_qgraphicswidget(); private: QDeclarativeView *createView(const QString &filename); }; @@ -771,6 +773,48 @@ void tst_QDeclarativePositioners::test_conflictinganchors() QCOMPARE(warningMessage, QString("file::2:1: QML Flow: Cannot specify anchors for items inside Flow")); } +void tst_QDeclarativePositioners::test_vertical_qgraphicswidget() +{ + QDeclarativeView *canvas = createView(SRCDIR "/data/verticalqgraphicswidget.qml"); + + QGraphicsWidget *one = canvas->rootObject()->findChild("one"); + QVERIFY(one != 0); + + QGraphicsWidget *two = canvas->rootObject()->findChild("two"); + QVERIFY(two != 0); + + QGraphicsWidget *three = canvas->rootObject()->findChild("three"); + QVERIFY(three != 0); + + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(two->x(), 0.0); + QCOMPARE(two->y(), 50.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 60.0); + + QDeclarativeItem *column = canvas->rootObject()->findChild("column"); + QVERIFY(column); + QCOMPARE(column->height(), 80.0); + QCOMPARE(column->width(), 50.0); + + two->resize(QSizeF(two->size().width(), 20.0)); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 70.0); + + two->setOpacity(0.0); + QCOMPARE(one->x(), 0.0); + QCOMPARE(one->y(), 0.0); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 50.0); + + one->setVisible(false); + QCOMPARE(three->x(), 0.0); + QCOMPARE(three->y(), 0.0); + + delete canvas; +} + QDeclarativeView *tst_QDeclarativePositioners::createView(const QString &filename) { QDeclarativeView *canvas = new QDeclarativeView(0); -- cgit v0.12