diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2020-08-07 15:05:23 +0200 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2021-01-14 10:29:23 +0100 |
commit | 83f49d3f4c0041bf2c74ff1ff2eb03c5d37aa1f4 (patch) | |
tree | 3130df827a1c5de85c794267e5fd980d6d13229d /src | |
parent | 10bfc067d005d6156ba549f581fb2394c4ff8ef1 (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
Pick-to: 5.15 6.0
Change-Id: I36684bf2797719db87fe93063cc7685efe594eea
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquickcontrol_p_p.h | 2 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswipedelegate.cpp | 27 | ||||
-rw-r--r-- | src/quicktemplates2/qquickswipedelegate_p_p.h | 1 |
3 files changed, 28 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickcontrol_p_p.h b/src/quicktemplates2/qquickcontrol_p_p.h index 15d0ef74..cb2eb419 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 77acb498..bc34a4ba 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 7ed043d6..e45416af 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; QPalette defaultPalette() const override; |