diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-04-23 11:42:37 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-04-23 15:49:31 +0000 |
commit | 7e3c882d9a5cd6a25f547091a4ece786f516f2a4 (patch) | |
tree | af93fed4a300b68933ceb749187649668c7d3976 /src/quicktemplates2/qquickcontrol.cpp | |
parent | 12e22e333d99d1a2fe9d878bb86108c87626e7ec (diff) |
Control: fix background size
Don't reset QQuickItemPrivate::widthValid and heightValid flags,
because that will cause the item to update its geometry when its
implicit size changes. Instead, keep track whether background has
an explicit size at the time of assignment, or if the background
changes its geometry outside of resizeBackground().
Task-number: QTBUG-66455
Change-Id: If14eeae6863f7e5e47ebf2d6dbdaf718fc8368d4
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickcontrol.cpp')
-rw-r--r-- | src/quicktemplates2/qquickcontrol.cpp | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index 8b571612..afb7c08a 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -130,7 +130,7 @@ QT_BEGIN_NAMESPACE \sa ApplicationWindow, Container */ -static const QQuickItemPrivate::ChangeTypes ImplicitSizeChanges = QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed; +const QQuickItemPrivate::ChangeTypes QQuickControlPrivate::ImplicitSizeChanges = QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight | QQuickItemPrivate::Destroyed; static bool isKeyFocusReason(Qt::FocusReason reason) { @@ -147,6 +147,8 @@ QQuickControlPrivate::ExtraData::ExtraData() hasLeftInset(false), hasRightInset(false), hasBottomInset(false), + hasBackgroundWidth(false), + hasBackgroundHeight(false), topPadding(0), leftPadding(0), rightPadding(0), @@ -167,6 +169,7 @@ QQuickControlPrivate::QQuickControlPrivate() hovered(false), explicitHoverEnabled(false), #endif + resizingBackground(false), touchId(-1), padding(0), horizontalPadding(0), @@ -400,19 +403,21 @@ void QQuickControlPrivate::resizeBackground() if (!background) return; + resizingBackground = true; + QQuickItemPrivate *p = QQuickItemPrivate::get(background); - if ((!p->widthValid && qFuzzyIsNull(background->x())) + if (((!p->widthValid || !extra.isAllocated() || !extra->hasBackgroundWidth) && qFuzzyIsNull(background->x())) || (extra.isAllocated() && (extra->hasLeftInset || extra->hasRightInset))) { background->setX(getLeftInset()); background->setWidth(width - getLeftInset() - getRightInset()); - p->widthValid = false; } - if ((!p->heightValid && qFuzzyIsNull(background->y())) + if (((!p->heightValid || !extra.isAllocated() || !extra->hasBackgroundHeight) && qFuzzyIsNull(background->y())) || (extra.isAllocated() && (extra->hasTopInset || extra->hasBottomInset))) { background->setY(getTopInset()); background->setHeight(height - getTopInset() - getBottomInset()); - p->heightValid = false; } + + resizingBackground = false; } void QQuickControlPrivate::resizeContent() @@ -872,18 +877,18 @@ void QQuickControlPrivate::updateBaselineOffset() q->QQuickItem::setBaselineOffset(getTopPadding() + contentItem->baselineOffset()); } -void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item) +void QQuickControlPrivate::addImplicitSizeListener(QQuickItem *item, ChangeTypes changes) { if (!item) return; - QQuickItemPrivate::get(item)->addItemChangeListener(this, ImplicitSizeChanges); + QQuickItemPrivate::get(item)->addItemChangeListener(this, changes); } -void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item) +void QQuickControlPrivate::removeImplicitSizeListener(QQuickItem *item, ChangeTypes changes) { if (!item) return; - QQuickItemPrivate::get(item)->removeItemChangeListener(this, ImplicitSizeChanges); + QQuickItemPrivate::get(item)->removeItemChangeListener(this, changes); } void QQuickControlPrivate::itemImplicitWidthChanged(QQuickItem *item) @@ -904,6 +909,18 @@ void QQuickControlPrivate::itemImplicitHeightChanged(QQuickItem *item) updateImplicitContentHeight(); } +void QQuickControlPrivate::itemGeometryChanged(QQuickItem *item, QQuickGeometryChange change, const QRectF &diff) +{ + Q_UNUSED(diff); + if (resizingBackground || item != background || !change.sizeChange()) + return; + + QQuickItemPrivate *p = QQuickItemPrivate::get(item); + extra.value().hasBackgroundWidth = p->widthValid; + extra.value().hasBackgroundHeight = p->heightValid; + resizeBackground(); +} + void QQuickControlPrivate::itemDestroyed(QQuickItem *item) { Q_Q(QQuickControl); @@ -934,7 +951,7 @@ QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent) QQuickControl::~QQuickControl() { Q_D(QQuickControl); - d->removeImplicitSizeListener(d->background); + d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry); d->removeImplicitSizeListener(d->contentItem); } @@ -1559,7 +1576,12 @@ void QQuickControl::setBackground(QQuickItem *background) const qreal oldImplicitBackgroundWidth = implicitBackgroundWidth(); const qreal oldImplicitBackgroundHeight = implicitBackgroundHeight(); - d->removeImplicitSizeListener(d->background); + if (d->extra.isAllocated()) { + d->extra.value().hasBackgroundWidth = false; + d->extra.value().hasBackgroundHeight = false; + } + + d->removeImplicitSizeListener(d->background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry); delete d->background; d->background = background; @@ -1567,9 +1589,14 @@ void QQuickControl::setBackground(QQuickItem *background) background->setParentItem(this); if (qFuzzyIsNull(background->z())) background->setZ(-1); + QQuickItemPrivate *p = QQuickItemPrivate::get(background); + if (p->widthValid || p->heightValid) { + d->extra.value().hasBackgroundWidth = p->widthValid; + d->extra.value().hasBackgroundHeight = p->heightValid; + } if (isComponentComplete()) d->resizeBackground(); - d->addImplicitSizeListener(background); + d->addImplicitSizeListener(background, QQuickControlPrivate::ImplicitSizeChanges | QQuickItemPrivate::Geometry); } if (!qFuzzyCompare(oldImplicitBackgroundWidth, implicitBackgroundWidth())) |