From 00664e8b59af37ab741ba2ae5674354a9a25e6b2 Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 18 Apr 2018 13:52:09 +0200 Subject: RangeSlider: add first|second.implicitHandleWidth|Height [ChangeLog][Controls][RangeSlider] Added first.implicitHandleWidth, first.implicitHandleHeight, second.implicitHandleWidth, and second.implicitHandleHeight properties. Change-Id: Iab68a7a905c4b6515517e3b9eb11c6fd70782764 Reviewed-by: Mitch Curtis --- src/quicktemplates2/qquickrangeslider.cpp | 75 +++++++++++++++++++++++++++++++ src/quicktemplates2/qquickrangeslider_p.h | 10 +++++ 2 files changed, 85 insertions(+) (limited to 'src/quicktemplates2') diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp index 49384fe4..e5c0766b 100644 --- a/src/quicktemplates2/qquickrangeslider.cpp +++ b/src/quicktemplates2/qquickrangeslider.cpp @@ -270,8 +270,13 @@ void QQuickRangeSliderNode::setHandle(QQuickItem *handle) if (!d->handle.isExecuting()) d->cancelHandle(); + const qreal oldImplicitHandleWidth = implicitHandleWidth(); + const qreal oldImplicitHandleHeight = implicitHandleHeight(); + + QQuickControlPrivate::get(d->slider)->removeImplicitSizeListener(d->handle); delete d->handle; d->handle = handle; + if (handle) { if (!handle->parentItem()) handle->setParentItem(d->slider); @@ -295,7 +300,13 @@ void QQuickRangeSliderNode::setHandle(QQuickItem *handle) } handle->setActiveFocusOnTab(true); + QQuickControlPrivate::get(d->slider)->addImplicitSizeListener(handle); } + + if (!qFuzzyCompare(oldImplicitHandleWidth, implicitHandleWidth())) + emit implicitHandleWidthChanged(); + if (!qFuzzyCompare(oldImplicitHandleHeight, implicitHandleHeight())) + emit implicitHandleHeightChanged(); if (!d->handle.isExecuting()) emit handleChanged(); } @@ -333,6 +344,22 @@ void QQuickRangeSliderNode::setHovered(bool hovered) emit hoveredChanged(); } +qreal QQuickRangeSliderNode::implicitHandleWidth() const +{ + Q_D(const QQuickRangeSliderNode); + if (!d->handle) + return 0; + return d->handle->implicitWidth(); +} + +qreal QQuickRangeSliderNode::implicitHandleHeight() const +{ + Q_D(const QQuickRangeSliderNode); + if (!d->handle) + return 0; + return d->handle->implicitHeight(); +} + void QQuickRangeSliderNode::increase() { Q_D(QQuickRangeSliderNode); @@ -380,6 +407,9 @@ public: void updateHover(const QPointF &pos); + void itemImplicitWidthChanged(QQuickItem *item) override; + void itemImplicitHeightChanged(QQuickItem *item) override; + bool live; qreal from; qreal to; @@ -588,6 +618,24 @@ void QQuickRangeSliderPrivate::updateHover(const QPointF &pos) second->setHovered(secondHandle && secondHandle->isEnabled() && secondHandle->contains(q->mapToItem(secondHandle, pos))); } +void QQuickRangeSliderPrivate::itemImplicitWidthChanged(QQuickItem *item) +{ + QQuickControlPrivate::itemImplicitWidthChanged(item); + if (item == first->handle()) + emit first->implicitHandleWidthChanged(); + else if (item == second->handle()) + emit second->implicitHandleWidthChanged(); +} + +void QQuickRangeSliderPrivate::itemImplicitHeightChanged(QQuickItem *item) +{ + QQuickControlPrivate::itemImplicitHeightChanged(item); + if (item == first->handle()) + emit first->implicitHandleHeightChanged(); + else if (item == second->handle()) + emit second->implicitHandleHeightChanged(); +} + QQuickRangeSlider::QQuickRangeSlider(QQuickItem *parent) : QQuickControl(*(new QQuickRangeSliderPrivate), parent) { @@ -602,6 +650,13 @@ QQuickRangeSlider::QQuickRangeSlider(QQuickItem *parent) #endif } +QQuickRangeSlider::~QQuickRangeSlider() +{ + Q_D(QQuickRangeSlider); + d->removeImplicitSizeListener(d->first->handle()); + d->removeImplicitSizeListener(d->second->handle()); +} + /*! \qmlproperty real QtQuick.Controls::RangeSlider::from @@ -715,6 +770,8 @@ qreal QQuickRangeSlider::valueAt(qreal position) const \qmlproperty Item QtQuick.Controls::RangeSlider::first.handle \qmlproperty bool QtQuick.Controls::RangeSlider::first.pressed \qmlproperty bool QtQuick.Controls::RangeSlider::first.hovered + \qmlproperty real QtQuick.Controls::RangeSlider::first.implicitHandleWidth + \qmlproperty real QtQuick.Controls::RangeSlider::first.implicitHandleHeight \qmlsignal void QtQuick.Controls::RangeSlider::moved() \table @@ -755,6 +812,14 @@ qreal QQuickRangeSlider::valueAt(qreal position) const \li hovered \li This property holds whether the first handle is hovered. This property was introduced in QtQuick.Controls 2.1. + \row + \li implicitHandleWidth + \li This property holds the implicit width of the first handle. + This property was introduced in QtQuick.Controls 2.5. + \row + \li implicitHandleHeight + \li This property holds the implicit height of the first handle. + This property was introduced in QtQuick.Controls 2.5. \row \li moved() \li This signal is emitted when the first handle has been interactively moved @@ -779,6 +844,8 @@ QQuickRangeSliderNode *QQuickRangeSlider::first() const \qmlproperty Item QtQuick.Controls::RangeSlider::second.handle \qmlproperty bool QtQuick.Controls::RangeSlider::second.pressed \qmlproperty bool QtQuick.Controls::RangeSlider::second.hovered + \qmlproperty real QtQuick.Controls::RangeSlider::second.implicitHandleWidth + \qmlproperty real QtQuick.Controls::RangeSlider::second.implicitHandleHeight \qmlsignal void QtQuick.Controls::RangeSlider::moved() \table @@ -819,6 +886,14 @@ QQuickRangeSliderNode *QQuickRangeSlider::first() const \li hovered \li This property holds whether the second handle is hovered. This property was introduced in QtQuick.Controls 2.1. + \row + \li implicitHandleWidth + \li This property holds the implicit width of the second handle. + This property was introduced in QtQuick.Controls 2.5. + \row + \li implicitHandleHeight + \li This property holds the implicit height of the second handle. + This property was introduced in QtQuick.Controls 2.5. \row \li moved() \li This signal is emitted when the second handle has been interactively moved diff --git a/src/quicktemplates2/qquickrangeslider_p.h b/src/quicktemplates2/qquickrangeslider_p.h index 135ba9e5..a42245a1 100644 --- a/src/quicktemplates2/qquickrangeslider_p.h +++ b/src/quicktemplates2/qquickrangeslider_p.h @@ -75,6 +75,7 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickRangeSlider : public QQuickControl public: explicit QQuickRangeSlider(QQuickItem *parent = nullptr); + ~QQuickRangeSlider(); qreal from() const; void setFrom(qreal from); @@ -166,6 +167,9 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickRangeSliderNode : public QObject Q_PROPERTY(bool pressed READ isPressed WRITE setPressed NOTIFY pressedChanged FINAL) // 2.1 (Qt 5.8) Q_PROPERTY(bool hovered READ isHovered WRITE setHovered NOTIFY hoveredChanged FINAL REVISION 1) + // 2.5 (Qt 5.12) + 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", "handle") public: @@ -188,6 +192,10 @@ public: bool isHovered() const; void setHovered(bool hovered); + // 2.5 (Qt 5.12) + qreal implicitHandleWidth() const; + qreal implicitHandleHeight() const; + public Q_SLOTS: void increase(); void decrease(); @@ -202,6 +210,8 @@ Q_SIGNALS: Q_REVISION(1) void hoveredChanged(); // 2.5 (Qt 5.12) /*Q_REVISION(5)*/ void moved(); + /*Q_REVISION(5)*/ void implicitHandleWidthChanged(); + /*Q_REVISION(5)*/ void implicitHandleHeightChanged(); private: Q_DISABLE_COPY(QQuickRangeSliderNode) -- cgit v1.2.3