diff options
-rw-r--r-- | src/quicktemplates2/qquickpopup.cpp | 28 | ||||
-rw-r--r-- | src/quicktemplates2/qquickpopup_p_p.h | 2 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_popup.qml | 18 |
3 files changed, 38 insertions, 10 deletions
diff --git a/src/quicktemplates2/qquickpopup.cpp b/src/quicktemplates2/qquickpopup.cpp index 94cf5d76..0f2e8378 100644 --- a/src/quicktemplates2/qquickpopup.cpp +++ b/src/quicktemplates2/qquickpopup.cpp @@ -133,6 +133,8 @@ QQuickPopupPrivate::QQuickPopupPrivate() , allowHorizontalFlip(false) , x(0) , y(0) + , effectiveX(0) + , effectiveY(0) , margins(-1) , topMargin(0) , leftMargin(0) @@ -625,6 +627,17 @@ void QQuickPopupPrivate::reposition() } popupItem->setPosition(rect.topLeft()); + + const QPointF effectivePos = parentItem ? parentItem->mapFromScene(rect.topLeft()) : rect.topLeft(); + if (!qFuzzyCompare(effectiveX, effectivePos.x())) { + effectiveX = effectivePos.x(); + emit q->xChanged(); + } + if (!qFuzzyCompare(effectiveY, effectivePos.y())) { + effectiveY = effectivePos.y(); + emit q->yChanged(); + } + if (widthAdjusted && rect.width() > 0) popupItem->setWidth(rect.width()); if (heightAdjusted && rect.height() > 0) @@ -766,7 +779,8 @@ void QQuickPopup::close() */ qreal QQuickPopup::x() const { - return position().x(); + Q_D(const QQuickPopup); + return d->effectiveX; } void QQuickPopup::setX(qreal x) @@ -782,7 +796,8 @@ void QQuickPopup::setX(qreal x) */ qreal QQuickPopup::y() const { - return position().y(); + Q_D(const QQuickPopup); + return d->effectiveY; } void QQuickPopup::setY(qreal y) @@ -794,10 +809,7 @@ void QQuickPopup::setY(qreal y) QPointF QQuickPopup::position() const { Q_D(const QQuickPopup); - QPointF pos = d->popupItem->position(); - if (d->parentItem) - pos = d->parentItem->mapFromScene(pos); - return pos; + return QPointF(d->effectiveX, d->effectiveY); } void QQuickPopup::setPosition(const QPointF &pos) @@ -1889,10 +1901,6 @@ void QQuickPopup::geometryChanged(const QRectF &newGeometry, const QRectF &oldGe { Q_D(QQuickPopup); d->reposition(); - if (!qFuzzyCompare(newGeometry.x(), oldGeometry.x())) - emit xChanged(); - if (!qFuzzyCompare(newGeometry.y(), oldGeometry.y())) - emit yChanged(); if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width())) { emit widthChanged(); emit availableWidthChanged(); diff --git a/src/quicktemplates2/qquickpopup_p_p.h b/src/quicktemplates2/qquickpopup_p_p.h index 3ff55129..5e4e6c51 100644 --- a/src/quicktemplates2/qquickpopup_p_p.h +++ b/src/quicktemplates2/qquickpopup_p_p.h @@ -192,6 +192,8 @@ public: bool allowHorizontalFlip; qreal x; qreal y; + qreal effectiveX; + qreal effectiveY; qreal margins; qreal topMargin; qreal leftMargin; diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml index 156bc652..a681b2f9 100644 --- a/tests/auto/controls/data/tst_popup.qml +++ b/tests/auto/controls/data/tst_popup.qml @@ -334,6 +334,24 @@ TestCase { compare(xSpy.count, 1) compare(ySpy.count, 1) + // re-parent and reset the position + control.parent = rect.createObject(testCase, {color: "red", width: 100, height: 100}) + control.x = 0 + control.y = 0 + compare(xSpy.count, 2) + compare(ySpy.count, 2) + + // moving parent outside margins triggers change notifiers + control.parent.x = -50 + compare(control.x, 50 + control.leftMargin) + compare(xSpy.count, 3) + compare(ySpy.count, 2) + + control.parent.y = -60 + compare(control.y, 60 + control.topMargin) + compare(xSpy.count, 3) + compare(ySpy.count, 3) + control.destroy() } |