diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-04-04 23:15:06 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-04-05 13:59:37 +0000 |
commit | 3c4942f12fd33e91973cfa55aef8d675f4e32126 (patch) | |
tree | a68c4d5b960433899e06e196284e405f167a408c /src/quicktemplates2/qquickpane.cpp | |
parent | 98a65a9c74e148758be1619b1fd3844f3f31c789 (diff) |
QQuickPane: cleanup content size calculation - part II
A follow up commit to 6fcfb8d. This is a preparation step to make
QQuickPane a suitable base class for QQuickScrollView.
Change-Id: I98cda1a03a93ee31676b79c2542cce61075392f5
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src/quicktemplates2/qquickpane.cpp')
-rw-r--r-- | src/quicktemplates2/qquickpane.cpp | 83 |
1 files changed, 53 insertions, 30 deletions
diff --git a/src/quicktemplates2/qquickpane.cpp b/src/quicktemplates2/qquickpane.cpp index 96481c54..47a96126 100644 --- a/src/quicktemplates2/qquickpane.cpp +++ b/src/quicktemplates2/qquickpane.cpp @@ -145,16 +145,14 @@ void QQuickPanePrivate::removeImplicitSizeListener(QQuickItem *item) void QQuickPanePrivate::itemImplicitWidthChanged(QQuickItem *item) { - Q_Q(QQuickPane); - if ((item == contentItem || item == firstChild) && updateContentWidth()) - emit q->contentWidthChanged(); + if (item == contentItem || item == firstChild) + updateContentWidth(); } void QQuickPanePrivate::itemImplicitHeightChanged(QQuickItem *item) { - Q_Q(QQuickPane); - if ((item == contentItem || item == firstChild) && updateContentHeight()) - emit q->contentHeightChanged(); + if (item == contentItem || item == firstChild) + updateContentHeight(); } void QQuickPanePrivate::itemDestroyed(QQuickItem *item) @@ -179,63 +177,83 @@ void QQuickPanePrivate::contentChildrenChange() emit q->contentChildrenChanged(); } -static qreal getContentWidth(QQuickItem *item) +qreal QQuickPanePrivate::getContentWidth() const { - if (!item) + if (!contentItem) return 0; - const qreal cw = item->implicitWidth(); + const qreal cw = contentItem->implicitWidth(); if (!qFuzzyIsNull(cw)) return cw; - const auto contentChildren = item->childItems(); + const auto contentChildren = contentItem->childItems(); if (contentChildren.count() == 1) return contentChildren.first()->implicitWidth(); return 0; } -static qreal getContentHeight(QQuickItem *item) +qreal QQuickPanePrivate::getContentHeight() const { - if (!item) + if (!contentItem) return 0; - const qreal ch = item->implicitHeight(); + const qreal ch = contentItem->implicitHeight(); if (!qFuzzyIsNull(ch)) return ch; - const auto contentChildren = item->childItems(); + const auto contentChildren = contentItem->childItems(); if (contentChildren.count() == 1) return contentChildren.first()->implicitHeight(); return 0; } -bool QQuickPanePrivate::updateContentWidth() +void QQuickPanePrivate::updateContentWidth() { - if (hasContentWidth) - return false; + Q_Q(QQuickPane); + if (hasContentWidth || !componentComplete) + return; qreal oldContentWidth = contentWidth; - contentWidth = getContentWidth(contentItem); - return !qFuzzyCompare(contentWidth, oldContentWidth); + contentWidth = getContentWidth(); + if (qFuzzyCompare(contentWidth, oldContentWidth)) + return; + + emit q->contentWidthChanged(); } -bool QQuickPanePrivate::updateContentHeight() +void QQuickPanePrivate::updateContentHeight() { - if (hasContentHeight) - return false; + Q_Q(QQuickPane); + if (hasContentHeight || !componentComplete) + return; qreal oldContentHeight = contentHeight; - contentHeight = getContentHeight(contentItem); - return !qFuzzyCompare(contentHeight, oldContentHeight); + contentHeight = getContentHeight(); + if (qFuzzyCompare(contentHeight, oldContentHeight)) + return; + + emit q->contentHeightChanged(); } void QQuickPanePrivate::updateContentSize() { Q_Q(QQuickPane); - bool widthChanged = updateContentWidth(); - bool heightChanged = updateContentHeight(); + if ((hasContentWidth && hasContentHeight) || !componentComplete) + return; + + const qreal oldContentWidth = contentWidth; + if (!hasContentWidth) + contentWidth = getContentWidth(); + + const qreal oldContentHeight = contentHeight; + if (!hasContentHeight) + contentHeight = getContentHeight(); + + const bool widthChanged = !qFuzzyCompare(contentWidth, oldContentWidth); + const bool heightChanged = !qFuzzyCompare(contentHeight, oldContentHeight); + if (widthChanged) emit q->contentWidthChanged(); if (heightChanged) @@ -303,8 +321,7 @@ void QQuickPane::resetContentWidth() return; d->hasContentHeight = false; - if (d->updateContentWidth()) - emit contentWidthChanged(); + d->updateContentWidth(); } /*! @@ -341,8 +358,7 @@ void QQuickPane::resetContentHeight() return; d->hasContentHeight = false; - if (d->updateContentHeight()) - emit contentHeightChanged(); + d->updateContentHeight(); } /*! @@ -392,6 +408,13 @@ QQmlListProperty<QQuickItem> QQuickPanePrivate::contentChildren() QQuickItemPrivate::children_clear); } +void QQuickPane::componentComplete() +{ + Q_D(QQuickPane); + QQuickControl::componentComplete(); + d->updateContentSize(); +} + void QQuickPane::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) { Q_D(QQuickPane); |