diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2018-04-18 13:35:36 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2018-04-18 13:56:33 +0000 |
commit | c8e4c78ec752d64f8e34dbebd1c9baa98831bb53 (patch) | |
tree | ed1e1972f352fb6768836c9be20920dd267fba34 | |
parent | 616e86dcb211f47c4d62593de6a051eac70105f7 (diff) |
Slider: add implicitHandleWidth|Height
[ChangeLog][Controls][Slider] Added implicitHandleWidth and
implicitHandleHeight properties.
Change-Id: Id3a67f052a7b234b7eef0e946433e69c3e8add1d
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/imports/controls/Slider.qml | 4 | ||||
-rw-r--r-- | src/imports/controls/fusion/Slider.qml | 4 | ||||
-rw-r--r-- | src/imports/controls/imagine/Slider.qml | 4 | ||||
-rw-r--r-- | src/imports/controls/material/Slider.qml | 4 | ||||
-rw-r--r-- | src/imports/controls/universal/Slider.qml | 4 | ||||
-rw-r--r-- | src/quicktemplates2/qquickslider.cpp | 86 | ||||
-rw-r--r-- | src/quicktemplates2/qquickslider_p.h | 11 |
7 files changed, 104 insertions, 13 deletions
diff --git a/src/imports/controls/Slider.qml b/src/imports/controls/Slider.qml index b08f9723..38d5ca22 100644 --- a/src/imports/controls/Slider.qml +++ b/src/imports/controls/Slider.qml @@ -43,9 +43,9 @@ T.Slider { id: control implicitWidth: Math.max(implicitBackgroundWidth, - (handle ? handle.implicitWidth : 0) + leftPadding + rightPadding) + implicitHandleWidth + leftPadding + rightPadding) implicitHeight: Math.max(implicitBackgroundHeight, - (handle ? handle.implicitHeight : 0) + topPadding + bottomPadding) + implicitHandleHeight + topPadding + bottomPadding) padding: 6 diff --git a/src/imports/controls/fusion/Slider.qml b/src/imports/controls/fusion/Slider.qml index db496888..d322ff08 100644 --- a/src/imports/controls/fusion/Slider.qml +++ b/src/imports/controls/fusion/Slider.qml @@ -45,9 +45,9 @@ T.Slider { id: control implicitWidth: Math.max(implicitBackgroundWidth, - (handle ? handle.implicitWidth : 0) + leftPadding + rightPadding) + implicitHandleWidth + leftPadding + rightPadding) implicitHeight: Math.max(implicitBackgroundHeight, - (handle ? handle.implicitHeight : 0) + topPadding + bottomPadding) + implicitHandleHeight + topPadding + bottomPadding) handle: SliderHandle { x: control.leftPadding + Math.round(control.horizontal ? control.visualPosition * (control.availableWidth - width) : (control.availableWidth - width) / 2) diff --git a/src/imports/controls/imagine/Slider.qml b/src/imports/controls/imagine/Slider.qml index 3c2710c7..ff560d00 100644 --- a/src/imports/controls/imagine/Slider.qml +++ b/src/imports/controls/imagine/Slider.qml @@ -43,9 +43,9 @@ T.Slider { id: control implicitWidth: Math.max(implicitBackgroundWidth, - (handle ? handle.implicitWidth : 0) + leftPadding + rightPadding) + implicitHandleWidth + leftPadding + rightPadding) implicitHeight: Math.max(implicitBackgroundHeight, - (handle ? handle.implicitHeight : 0) + topPadding + bottomPadding) + implicitHandleHeight + topPadding + bottomPadding) topPadding: background ? background.topPadding : 0 leftPadding: background ? background.leftPadding : 0 diff --git a/src/imports/controls/material/Slider.qml b/src/imports/controls/material/Slider.qml index d722bf45..81a2bf8f 100644 --- a/src/imports/controls/material/Slider.qml +++ b/src/imports/controls/material/Slider.qml @@ -43,9 +43,9 @@ T.Slider { id: control implicitWidth: Math.max(implicitBackgroundWidth, - (handle ? handle.implicitWidth : 0) + leftPadding + rightPadding) + implicitHandleWidth + leftPadding + rightPadding) implicitHeight: Math.max(implicitBackgroundHeight, - (handle ? handle.implicitHeight : 0) + topPadding + bottomPadding) + implicitHandleHeight + topPadding + bottomPadding) padding: 6 diff --git a/src/imports/controls/universal/Slider.qml b/src/imports/controls/universal/Slider.qml index b2171563..94e7c8f0 100644 --- a/src/imports/controls/universal/Slider.qml +++ b/src/imports/controls/universal/Slider.qml @@ -42,9 +42,9 @@ T.Slider { id: control implicitWidth: Math.max(implicitBackgroundWidth, - (handle ? handle.implicitWidth : 0) + leftPadding + rightPadding) + implicitHandleWidth + leftPadding + rightPadding) implicitHeight: Math.max(implicitBackgroundHeight, - (handle ? handle.implicitHeight : 0) + topPadding + bottomPadding) + implicitHandleHeight + topPadding + bottomPadding) padding: 6 diff --git a/src/quicktemplates2/qquickslider.cpp b/src/quicktemplates2/qquickslider.cpp index 60667267..406199c9 100644 --- a/src/quicktemplates2/qquickslider.cpp +++ b/src/quicktemplates2/qquickslider.cpp @@ -120,6 +120,9 @@ public: void cancelHandle(); void executeHandle(bool complete = false); + void itemImplicitWidthChanged(QQuickItem *item) override; + void itemImplicitHeightChanged(QQuickItem *item) override; + qreal from; qreal to; qreal value; @@ -264,6 +267,22 @@ void QQuickSliderPrivate::executeHandle(bool complete) quickCompleteDeferred(q, handleName(), handle); } +void QQuickSliderPrivate::itemImplicitWidthChanged(QQuickItem *item) +{ + Q_Q(QQuickSlider); + QQuickControlPrivate::itemImplicitWidthChanged(item); + if (item == handle) + emit q->implicitHandleWidthChanged(); +} + +void QQuickSliderPrivate::itemImplicitHeightChanged(QQuickItem *item) +{ + Q_Q(QQuickSlider); + QQuickControlPrivate::itemImplicitHeightChanged(item); + if (item == handle) + emit q->implicitHandleHeightChanged(); +} + QQuickSlider::QQuickSlider(QQuickItem *parent) : QQuickControl(*(new QQuickSliderPrivate), parent) { @@ -275,6 +294,12 @@ QQuickSlider::QQuickSlider(QQuickItem *parent) #endif } +QQuickSlider::~QQuickSlider() +{ + Q_D(QQuickSlider); + d->removeImplicitSizeListener(d->handle); +} + /*! \qmlproperty real QtQuick.Controls::Slider::from @@ -561,10 +586,23 @@ void QQuickSlider::setHandle(QQuickItem *handle) if (!d->handle.isExecuting()) d->cancelHandle(); + const qreal oldImplicitHandleWidth = implicitHandleWidth(); + const qreal oldImplicitHandleHeight = implicitHandleHeight(); + + d->removeImplicitSizeListener(d->handle); delete d->handle; d->handle = handle; - if (handle && !handle->parentItem()) - handle->setParentItem(this); + + if (handle) { + if (!handle->parentItem()) + handle->setParentItem(this); + d->addImplicitSizeListener(handle); + } + + if (!qFuzzyCompare(oldImplicitHandleWidth, implicitHandleWidth())) + emit implicitHandleWidthChanged(); + if (!qFuzzyCompare(oldImplicitHandleHeight, implicitHandleHeight())) + emit implicitHandleHeightChanged(); if (!d->handle.isExecuting()) emit handleChanged(); } @@ -672,6 +710,50 @@ void QQuickSlider::resetTouchDragThreshold() setTouchDragThreshold(-1); } +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Slider::implicitHandleWidth + \readonly + + This property holds the implicit handle width. + + The value is equal to \c {handle ? handle.implicitWidth : 0}. + + This is typically used, together with \l {Control::}{implicitContentWidth} and + \l {Control::}{implicitBackgroundWidth}, to calculate the \l {Item::}{implicitWidth}. + + \sa implicitHandleHeight +*/ +qreal QQuickSlider::implicitHandleWidth() const +{ + Q_D(const QQuickSlider); + if (!d->handle) + return 0; + return d->handle->implicitWidth(); +} + +/*! + \since QtQuick.Controls 2.5 (Qt 5.12) + \qmlproperty real QtQuick.Controls::Slider::implicitHandleHeight + \readonly + + This property holds the implicit handle height. + + The value is equal to \c {handle ? handle.implicitHeight : 0}. + + This is typically used, together with \l {Control::}{implicitContentHeight} and + \l {Control::}{implicitBackgroundHeight}, to calculate the \l {Item::}{implicitHeight}. + + \sa implicitHandleWidth +*/ +qreal QQuickSlider::implicitHandleHeight() const +{ + Q_D(const QQuickSlider); + if (!d->handle) + return 0; + return d->handle->implicitHeight(); +} + void QQuickSlider::keyPressEvent(QKeyEvent *event) { Q_D(QQuickSlider); diff --git a/src/quicktemplates2/qquickslider_p.h b/src/quicktemplates2/qquickslider_p.h index 847e15ec..c65733dc 100644 --- a/src/quicktemplates2/qquickslider_p.h +++ b/src/quicktemplates2/qquickslider_p.h @@ -71,11 +71,15 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSlider : public QQuickControl // 2.3 (Qt 5.10) Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3) Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3) - Q_CLASSINFO("DeferredPropertyNames", "background,handle") // 2.5 (Qt 5.12) Q_PROPERTY(qreal touchDragThreshold READ touchDragThreshold WRITE setTouchDragThreshold RESET resetTouchDragThreshold NOTIFY touchDragThresholdChanged FINAL REVISION 5) + Q_PROPERTY(qreal implicitHandleWidth READ implicitHandleWidth NOTIFY implicitHandleWidthChanged FINAL REVISION 5) + Q_PROPERTY(qreal implicitHandleHeight READ implicitHandleHeight NOTIFY implicitHandleHeightChanged FINAL REVISION 5) + Q_CLASSINFO("DeferredPropertyNames", "background,handle") + public: explicit QQuickSlider(QQuickItem *parent = nullptr); + ~QQuickSlider(); qreal from() const; void setFrom(qreal from); @@ -127,6 +131,9 @@ public: void setTouchDragThreshold(qreal touchDragThreshold); void resetTouchDragThreshold(); + qreal implicitHandleWidth() const; + qreal implicitHandleHeight() const; + public Q_SLOTS: void increase(); void decrease(); @@ -147,6 +154,8 @@ Q_SIGNALS: Q_REVISION(2) void liveChanged(); // 2.5 (Qt 5.12) Q_REVISION(5) void touchDragThresholdChanged(); + Q_REVISION(5) void implicitHandleWidthChanged(); + Q_REVISION(5) void implicitHandleHeightChanged(); protected: void keyPressEvent(QKeyEvent *event) override; |