aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2020-08-07 15:05:23 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-01-14 11:27:31 +0000
commit3ff601134de497bd624bc27f454b92b326c7cf27 (patch)
tree12945a910cc5c852e68ec37b248961e3766af9b6
parent5f6133aac0f11feefabc9006c9633b7f6d61f2c0 (diff)
SwipeDelegate: ensure background and contentItem are resized
When the geometry of a control changes, this code is called: void QQuickControl::geometryChange(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QQuickControl); QQuickItem::geometryChange(newGeometry, oldGeometry); d->resizeBackground(); d->resizeContent(); if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width())) emit availableWidthChanged(); if (!qFuzzyCompare(newGeometry.height(), oldGeometry.height())) emit availableHeightChanged(); } SwipeDelegate works by moving the background and contentItem together when it is swiped to expose the various delegates. Because this involves setting the position of the background, the check for background's x position being 0 in QQuickControlPrivate::resizeBackground() would fail and the background would not be resized at all. Fix this by making resizeBackground() virtual and don't check the x when checking if we should set the width. Similarly, in QQuickSwipeDelegatePrivate::resizeContent(), we should set the contentItem's width instead of just repositioning and resizing it vertically. Fixes: QTBUG-85770 Change-Id: I36684bf2797719db87fe93063cc7685efe594eea Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 83f49d3f4c0041bf2c74ff1ff2eb03c5d37aa1f4) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--src/quicktemplates2/qquickcontrol_p_p.h2
-rw-r--r--src/quicktemplates2/qquickswipedelegate.cpp27
-rw-r--r--src/quicktemplates2/qquickswipedelegate_p_p.h1
-rw-r--r--tests/auto/controls/data/tst_swipedelegate.qml35
4 files changed, 63 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickcontrol_p_p.h b/src/quicktemplates2/qquickcontrol_p_p.h
index fa06c97f..8e979079 100644
--- a/src/quicktemplates2/qquickcontrol_p_p.h
+++ b/src/quicktemplates2/qquickcontrol_p_p.h
@@ -122,7 +122,7 @@ public:
void setRightInset(qreal value, bool reset = false);
void setBottomInset(qreal value, bool reset = false);
- void resizeBackground();
+ virtual void resizeBackground();
virtual void resizeContent();
virtual QQuickItem *getContentItem();
diff --git a/src/quicktemplates2/qquickswipedelegate.cpp b/src/quicktemplates2/qquickswipedelegate.cpp
index 018768a2..b2627f32 100644
--- a/src/quicktemplates2/qquickswipedelegate.cpp
+++ b/src/quicktemplates2/qquickswipedelegate.cpp
@@ -713,6 +713,29 @@ QQuickSwipeDelegatePrivate::QQuickSwipeDelegatePrivate(QQuickSwipeDelegate *cont
{
}
+void QQuickSwipeDelegatePrivate::resizeBackground()
+{
+ if (!background)
+ return;
+
+ resizingBackground = true;
+
+ QQuickItemPrivate *p = QQuickItemPrivate::get(background);
+ const bool extraAllocated = extra.isAllocated();
+ // Don't check for or set the x here since it will just be overwritten by reposition().
+ if (((!p->widthValid || !extraAllocated || !extra->hasBackgroundWidth))
+ || (extraAllocated && (extra->hasLeftInset || extra->hasRightInset))) {
+ background->setWidth(width - getLeftInset() - getRightInset());
+ }
+ if (((!p->heightValid || !extraAllocated || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y()))
+ || (extraAllocated && (extra->hasTopInset || extra->hasBottomInset))) {
+ background->setY(getTopInset());
+ background->setHeight(height - getTopInset() - getBottomInset());
+ }
+
+ resizingBackground = false;
+}
+
bool QQuickSwipeDelegatePrivate::handleMousePressEvent(QQuickItem *item, QMouseEvent *event)
{
Q_Q(QQuickSwipeDelegate);
@@ -935,13 +958,15 @@ void QQuickSwipeDelegatePrivate::resizeContent()
// If the background and contentItem are repositioned due to a swipe,
// we don't want to call QQuickControlPrivate's implementation of this function,
// as it repositions the contentItem to be visible.
- // However, we still want to resize the control vertically.
+ // However, we still want to position the contentItem vertically
+ // and resize it (in case the control was resized while open).
QQuickSwipePrivate *swipePrivate = QQuickSwipePrivate::get(&swipe);
if (!swipePrivate->complete) {
QQuickItemDelegatePrivate::resizeContent();
} else if (contentItem) {
Q_Q(QQuickSwipeDelegate);
contentItem->setY(q->topPadding());
+ contentItem->setWidth(q->availableWidth());
contentItem->setHeight(q->availableHeight());
}
}
diff --git a/src/quicktemplates2/qquickswipedelegate_p_p.h b/src/quicktemplates2/qquickswipedelegate_p_p.h
index 78c72ec8..95a999a0 100644
--- a/src/quicktemplates2/qquickswipedelegate_p_p.h
+++ b/src/quicktemplates2/qquickswipedelegate_p_p.h
@@ -67,6 +67,7 @@ public:
bool handleMouseReleaseEvent(QQuickItem *item, QMouseEvent *event);
void resizeContent() override;
+ void resizeBackground() override;
QQuickSwipe swipe;
};
diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml
index d37ea42b..85cb8092 100644
--- a/tests/auto/controls/data/tst_swipedelegate.qml
+++ b/tests/auto/controls/data/tst_swipedelegate.qml
@@ -1713,4 +1713,39 @@ TestCase {
break;
}
}
+
+ function test_resizeParent() {
+ let container = createTemporaryObject(itemComponent, testCase, { objectName: "container", width: 100, height: 200 })
+ verify(container)
+
+ let control = swipeDelegateComponent.createObject(container, { width: Qt.binding(function() { return container.width }) })
+ verify(control)
+
+ // Resize while closed.
+ container.width = 200
+ compare(container.width, 200)
+ compare(control.width, 200)
+ compare(control.background.width, 200)
+ compare(control.contentItem.width, 200 - control.leftPadding - control.rightPadding)
+
+ // Return to original size.
+ container.width = 100
+ compare(control.width, 100)
+ compare(control.background.width, 100)
+ compare(control.contentItem.width, 100 - control.leftPadding - control.rightPadding)
+
+ // Swipe to the left to open.
+ swipe(control, 0, -1.0)
+ // Nothing should have changed except positions.
+ compare(control.width, 100)
+ compare(control.background.width, 100)
+ compare(control.contentItem.width, 100 - control.leftPadding - control.rightPadding)
+
+ // Resize while open.
+ container.width = 200
+ // The items should fill the width as usual.
+ compare(control.width, 200)
+ compare(control.background.width, 200)
+ compare(control.contentItem.width, 200 - control.leftPadding - control.rightPadding)
+ }
}