aboutsummaryrefslogtreecommitdiffstats
path: root/src/quicktemplates2/qquickrangeslider.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quicktemplates2/qquickrangeslider.cpp')
-rw-r--r--src/quicktemplates2/qquickrangeslider.cpp156
1 files changed, 153 insertions, 3 deletions
diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp
index 569d7645..ff488dac 100644
--- a/src/quicktemplates2/qquickrangeslider.cpp
+++ b/src/quicktemplates2/qquickrangeslider.cpp
@@ -74,7 +74,7 @@ QT_BEGIN_NAMESPACE
use the following syntax:
\code
- first.onValueChanged: console.log("first.value changed to " + first.value)
+ first.onMoved: console.log("first.value changed to " + first.value)
\endcode
The \l {first.position} and \l {second.position} properties are expressed as
@@ -263,8 +263,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);
@@ -288,7 +293,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();
}
@@ -326,6 +337,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);
@@ -360,10 +387,14 @@ public:
void updateHover(const QPointF &pos);
+ void itemImplicitWidthChanged(QQuickItem *item) override;
+ void itemImplicitHeightChanged(QQuickItem *item) override;
+
bool live = true;
qreal from = defaultFrom;
qreal to = defaultTo;
qreal stepSize = 0;
+ qreal touchDragThreshold = -1;
QQuickRangeSliderNode *first = nullptr;
QQuickRangeSliderNode *second = nullptr;
QPointF pressPoint;
@@ -503,6 +534,7 @@ void QQuickRangeSliderPrivate::handleMove(const QPointF &point)
QQuickControlPrivate::handleMove(point);
QQuickRangeSliderNode *pressedNode = QQuickRangeSliderPrivate::pressedNode(touchId);
if (pressedNode) {
+ const qreal oldPos = pressedNode->position();
qreal pos = positionAt(q, pressedNode->handle(), point);
if (snapMode == QQuickRangeSlider::SnapAlways)
pos = snapPosition(q, pos);
@@ -510,6 +542,9 @@ void QQuickRangeSliderPrivate::handleMove(const QPointF &point)
pressedNode->setValue(valueAt(q, pos));
else
QQuickRangeSliderNodePrivate::get(pressedNode)->setPosition(pos);
+
+ if (!qFuzzyCompare(pressedNode->position(), oldPos))
+ emit pressedNode->moved();
}
}
@@ -525,6 +560,7 @@ void QQuickRangeSliderPrivate::handleRelease(const QPointF &point)
QQuickRangeSliderNodePrivate *pressedNodePrivate = QQuickRangeSliderNodePrivate::get(pressedNode);
if (q->keepMouseGrab() || q->keepTouchGrab()) {
+ const qreal oldPos = pressedNode->position();
qreal pos = positionAt(q, pressedNode->handle(), point);
if (snapMode != QQuickRangeSlider::NoSnap)
pos = snapPosition(q, pos);
@@ -535,6 +571,9 @@ void QQuickRangeSliderPrivate::handleRelease(const QPointF &point)
pressedNodePrivate->setPosition(pos);
q->setKeepMouseGrab(false);
q->setKeepTouchGrab(false);
+
+ if (!qFuzzyCompare(pressedNode->position(), oldPos))
+ emit pressedNode->moved();
}
pressedNode->setPressed(false);
pressedNodePrivate->touchId = -1;
@@ -559,6 +598,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)
{
@@ -573,6 +630,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
@@ -630,6 +694,55 @@ void QQuickRangeSlider::setTo(qreal to)
}
/*!
+ \since QtQuick.Controls 2.5 (Qt 5.12)
+ \qmlproperty qreal QtQuick.Controls::RangeSlider::touchDragThreshold
+
+ This property holds the threshold (in logical pixels) at which a touch drag event will be initiated.
+ The mouse drag threshold won't be affected.
+ The default value is \c Qt.styleHints.startDragDistance.
+
+ \sa QStyleHints
+
+*/
+qreal QQuickRangeSlider::touchDragThreshold() const
+{
+ Q_D(const QQuickRangeSlider);
+ return d->touchDragThreshold;
+}
+
+void QQuickRangeSlider::setTouchDragThreshold(qreal touchDragThreshold)
+{
+ Q_D(QQuickRangeSlider);
+ if (d->touchDragThreshold == touchDragThreshold)
+ return;
+
+ d->touchDragThreshold = touchDragThreshold;
+ emit touchDragThresholdChanged();
+}
+
+void QQuickRangeSlider::resetTouchDragThreshold()
+{
+ setTouchDragThreshold(-1);
+}
+
+/*!
+ \since QtQuick.Controls 2.5 (Qt 5.12)
+ \qmlmethod real QtQuick.Controls::RangeSlider::valueAt(real position)
+
+ Returns the value for the given \a position.
+
+ \sa first.value, second.value, first.position, second.position, live
+*/
+qreal QQuickRangeSlider::valueAt(qreal position) const
+{
+ Q_D(const QQuickRangeSlider);
+ const qreal value = (d->to - d->from) * position;
+ if (qFuzzyIsNull(d->stepSize))
+ return d->from + value;
+ return d->from + qRound(value / d->stepSize) * d->stepSize;
+}
+
+/*!
\qmlpropertygroup QtQuick.Controls::RangeSlider::first
\qmlproperty real QtQuick.Controls::RangeSlider::first.value
\qmlproperty real QtQuick.Controls::RangeSlider::first.position
@@ -637,6 +750,9 @@ void QQuickRangeSlider::setTo(qreal to)
\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
\header
@@ -677,6 +793,20 @@ void QQuickRangeSlider::setTo(qreal to)
\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
+ by the user by either touch, mouse, or keys.
+
+ This signal was introduced in QtQuick.Controls 2.5.
\endtable
\sa first.increase(), first.decrease()
@@ -695,6 +825,9 @@ 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
\header
@@ -735,6 +868,20 @@ 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
+ by the user by either touch, mouse, or keys.
+
+ This signal was introduced in QtQuick.Controls 2.5.
\endtable
\sa second.increase(), second.decrease()
@@ -971,6 +1118,7 @@ void QQuickRangeSlider::keyPressEvent(QKeyEvent *event)
if (!focusNode)
return;
+ const qreal oldValue = focusNode->value();
if (d->orientation == Qt::Horizontal) {
if (event->key() == Qt::Key_Left) {
focusNode->setPressed(true);
@@ -998,6 +1146,8 @@ void QQuickRangeSlider::keyPressEvent(QKeyEvent *event)
event->accept();
}
}
+ if (!qFuzzyCompare(focusNode->value(), oldValue))
+ emit focusNode->moved();
}
void QQuickRangeSlider::hoverEnterEvent(QHoverEvent *event)
@@ -1055,9 +1205,9 @@ void QQuickRangeSlider::touchEvent(QTouchEvent *event)
case Qt::TouchPointMoved:
if (!keepTouchGrab()) {
if (d->orientation == Qt::Horizontal)
- setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().x() - point.startPos().x(), Qt::XAxis, &point));
+ setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().x() - point.startPos().x(), Qt::XAxis, &point, qRound(d->touchDragThreshold)));
else
- setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().y() - point.startPos().y(), Qt::YAxis, &point));
+ setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().y() - point.startPos().y(), Qt::YAxis, &point, qRound(d->touchDragThreshold)));
}
if (keepTouchGrab())
d->handleMove(point.pos());