From fff6239d2f98b41f4ef003f06f356fb0730f9d57 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 3 Jun 2015 17:02:20 +0200 Subject: Control::availableWidth & availableHeight The recently introduced contentWidth/Height was ambiguous. It had even different semantics than in Containers, TextXxx & Flickable etc. Thus, replace with availableWidth/Height. Change-Id: Iaeef25ec82b395c602724d222ca73666460ffd29 Reviewed-by: J-P Nurmi --- src/controls/qquickcontainer.cpp | 33 +++++++++++------------------- src/controls/qquickcontainer_p.h | 6 +++--- src/controls/qquickcontainer_p_p.h | 3 --- src/controls/qquickcontrol.cpp | 42 ++++++++++++++++---------------------- src/controls/qquickcontrol_p.h | 12 +++++------ src/controls/qquickcontrol_p_p.h | 3 --- 6 files changed, 39 insertions(+), 60 deletions(-) (limited to 'src/controls') diff --git a/src/controls/qquickcontainer.cpp b/src/controls/qquickcontainer.cpp index 95464e7e..456dd6c8 100644 --- a/src/controls/qquickcontainer.cpp +++ b/src/controls/qquickcontainer.cpp @@ -53,16 +53,6 @@ QQuickContainerPrivate::QQuickContainerPrivate() : { } -qreal QQuickContainerPrivate::getContentWidth() const -{ - return contentWidth; -} - -qreal QQuickContainerPrivate::getContentHeight() const -{ - return contentHeight; -} - QQuickContainer::QQuickContainer(QQuickItem *parent) : QQuickControl(*(new QQuickContainerPrivate), parent) { @@ -79,6 +69,12 @@ QQuickContainer::QQuickContainer(QQuickContainerPrivate &dd, QQuickItem *parent) TODO */ +qreal QQuickContainer::contentWidth() const +{ + Q_D(const QQuickContainer); + return d->contentWidth; +} + void QQuickContainer::setContentWidth(qreal width) { Q_D(QQuickContainer); @@ -88,6 +84,12 @@ void QQuickContainer::setContentWidth(qreal width) } } +qreal QQuickContainer::contentHeight() const +{ + Q_D(const QQuickContainer); + return d->contentHeight; +} + void QQuickContainer::setContentHeight(qreal height) { Q_D(QQuickContainer); @@ -129,15 +131,4 @@ void QQuickContainer::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem Q_UNUSED(oldItem); } -void QQuickContainer::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) -{ - Q_D(QQuickContainer); - QQuickItem::geometryChanged(newGeometry, oldGeometry); - d->resizeBackground(); -} - -void QQuickContainer::paddingChange() -{ -} - QT_END_NAMESPACE diff --git a/src/controls/qquickcontainer_p.h b/src/controls/qquickcontainer_p.h index 1deda597..6e3e224a 100644 --- a/src/controls/qquickcontainer_p.h +++ b/src/controls/qquickcontainer_p.h @@ -64,7 +64,10 @@ class Q_QUICKCONTROLS_EXPORT QQuickContainer : public QQuickControl public: explicit QQuickContainer(QQuickItem *parent = Q_NULLPTR); + qreal contentWidth() const; void setContentWidth(qreal width); + + qreal contentHeight() const; void setContentHeight(qreal height); QQuickItem *contentItem() const; @@ -80,9 +83,6 @@ protected: virtual void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem); - void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE; - void paddingChange() Q_DECL_OVERRIDE; - private: Q_DISABLE_COPY(QQuickContainer) Q_DECLARE_PRIVATE(QQuickContainer) diff --git a/src/controls/qquickcontainer_p_p.h b/src/controls/qquickcontainer_p_p.h index f7b605f0..c0b52cec 100644 --- a/src/controls/qquickcontainer_p_p.h +++ b/src/controls/qquickcontainer_p_p.h @@ -57,9 +57,6 @@ class Q_QUICKCONTROLS_EXPORT QQuickContainerPrivate : public QQuickControlPrivat public: QQuickContainerPrivate(); - qreal getContentWidth() const Q_DECL_OVERRIDE; - qreal getContentHeight() const Q_DECL_OVERRIDE; - qreal contentWidth; qreal contentHeight; QQuickItem *contentItem; diff --git a/src/controls/qquickcontrol.cpp b/src/controls/qquickcontrol.cpp index ac4c257d..db135fe1 100644 --- a/src/controls/qquickcontrol.cpp +++ b/src/controls/qquickcontrol.cpp @@ -62,18 +62,6 @@ void QQuickControlPrivate::mirrorChange() q->mirrorChange(); } -qreal QQuickControlPrivate::getContentWidth() const -{ - Q_Q(const QQuickControl); - return q->width() - q->leftPadding() - q->rightPadding(); -} - -qreal QQuickControlPrivate::getContentHeight() const -{ - Q_Q(const QQuickControl); - return q->height() - q->topPadding() - q->bottomPadding(); -} - void QQuickControlPrivate::setTopPadding(qreal value, bool reset) { Q_Q(QQuickControl); @@ -82,6 +70,7 @@ void QQuickControlPrivate::setTopPadding(qreal value, bool reset) hasTopPadding = !reset; if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { emit q->topPaddingChanged(); + emit q->availableHeightChanged(); q->paddingChange(); } } @@ -94,6 +83,7 @@ void QQuickControlPrivate::setLeftPadding(qreal value, bool reset) hasLeftPadding = !reset; if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { emit q->leftPaddingChanged(); + emit q->availableWidthChanged(); q->paddingChange(); } } @@ -106,6 +96,7 @@ void QQuickControlPrivate::setRightPadding(qreal value, bool reset) hasRightPadding = !reset; if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { emit q->rightPaddingChanged(); + emit q->availableWidthChanged(); q->paddingChange(); } } @@ -118,6 +109,7 @@ void QQuickControlPrivate::setBottomPadding(qreal value, bool reset) hasBottomPadding = !reset; if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { emit q->bottomPaddingChanged(); + emit q->availableHeightChanged(); q->paddingChange(); } } @@ -149,21 +141,19 @@ QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent) : } /*! - \qmlproperty real QtQuickControls2::Control::contentWidth - \qmlproperty real QtQuickControls2::Control::contentHeight + \qmlproperty real QtQuickControls2::Control::availableWidth + \qmlproperty real QtQuickControls2::Control::availableHeight TODO */ -qreal QQuickControl::contentWidth() const +qreal QQuickControl::availableWidth() const { - Q_D(const QQuickControl); - return d->getContentWidth(); + return width() - leftPadding() - rightPadding(); } -qreal QQuickControl::contentHeight() const +qreal QQuickControl::availableHeight() const { - Q_D(const QQuickControl); - return d->getContentHeight(); + return height() - topPadding() - bottomPadding(); } /*! @@ -196,6 +186,10 @@ void QQuickControl::setPadding(qreal padding) emit rightPaddingChanged(); if (!d->hasBottomPadding) emit bottomPaddingChanged(); + if (!d->hasTopPadding || !d->hasBottomPadding) + emit availableHeightChanged(); + if (!d->hasLeftPadding || !d->hasRightPadding) + emit availableWidthChanged(); paddingChange(); } @@ -362,8 +356,10 @@ void QQuickControl::geometryChanged(const QRectF &newGeometry, const QRectF &old Q_D(QQuickControl); QQuickItem::geometryChanged(newGeometry, oldGeometry); d->resizeBackground(); - emit contentWidthChanged(); - emit contentHeightChanged(); + if (newGeometry.width() != oldGeometry.width()) + emit availableWidthChanged(); + if (newGeometry.width() != oldGeometry.height()) + emit availableHeightChanged(); } void QQuickControl::mirrorChange() @@ -374,8 +370,6 @@ void QQuickControl::mirrorChange() void QQuickControl::paddingChange() { - emit contentWidthChanged(); - emit contentHeightChanged(); } QT_END_NAMESPACE diff --git a/src/controls/qquickcontrol_p.h b/src/controls/qquickcontrol_p.h index 737a917f..8d679e6a 100644 --- a/src/controls/qquickcontrol_p.h +++ b/src/controls/qquickcontrol_p.h @@ -58,8 +58,8 @@ class QQuickControlPrivate; class Q_QUICKCONTROLS_EXPORT QQuickControl : public QQuickItem { Q_OBJECT - Q_PROPERTY(qreal contentWidth READ contentWidth NOTIFY contentWidthChanged) - Q_PROPERTY(qreal contentHeight READ contentHeight NOTIFY contentHeightChanged) + Q_PROPERTY(qreal availableWidth READ availableWidth NOTIFY availableWidthChanged) + Q_PROPERTY(qreal availableHeight READ availableHeight NOTIFY availableHeightChanged) Q_PROPERTY(qreal padding READ padding WRITE setPadding RESET resetPadding NOTIFY paddingChanged FINAL) Q_PROPERTY(qreal topPadding READ topPadding WRITE setTopPadding RESET resetTopPadding NOTIFY topPaddingChanged FINAL) Q_PROPERTY(qreal leftPadding READ leftPadding WRITE setLeftPadding RESET resetLeftPadding NOTIFY leftPaddingChanged FINAL) @@ -73,8 +73,8 @@ class Q_QUICKCONTROLS_EXPORT QQuickControl : public QQuickItem public: explicit QQuickControl(QQuickItem *parent = Q_NULLPTR); - qreal contentWidth() const; - qreal contentHeight() const; + qreal availableWidth() const; + qreal availableHeight() const; qreal padding() const; void setPadding(qreal padding); @@ -106,8 +106,8 @@ public: void setBackground(QQuickItem *background); Q_SIGNALS: - void contentWidthChanged(); - void contentHeightChanged(); + void availableWidthChanged(); + void availableHeightChanged(); void paddingChanged(); void topPaddingChanged(); void leftPaddingChanged(); diff --git a/src/controls/qquickcontrol_p_p.h b/src/controls/qquickcontrol_p_p.h index 3a2154f1..d157f3e3 100644 --- a/src/controls/qquickcontrol_p_p.h +++ b/src/controls/qquickcontrol_p_p.h @@ -61,9 +61,6 @@ public: void mirrorChange() Q_DECL_OVERRIDE; - virtual qreal getContentWidth() const; - virtual qreal getContentHeight() const; - void setTopPadding(qreal value, bool reset = false); void setLeftPadding(qreal value, bool reset = false); void setRightPadding(qreal value, bool reset = false); -- cgit v1.2.3