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 /src/quicktemplates2/qquickslider.cpp | |
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>
Diffstat (limited to 'src/quicktemplates2/qquickslider.cpp')
-rw-r--r-- | src/quicktemplates2/qquickslider.cpp | 86 |
1 files changed, 84 insertions, 2 deletions
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); |