aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYulong Bai <yulong.bai@qt.io>2018-03-14 15:06:17 +0100
committerYulong Bai <yulong.bai@qt.io>2018-03-14 15:36:56 +0000
commit365059017722b32a3fe9ae7dec38d29944d6704c (patch)
tree1318668d854425b0bdc4f408974e108df0719161
parent12030ce62ef8fa0451679d19fc419ee0fa02bb6a (diff)
QQuickRangeSlider: add touchDragThreshold property
Add touchDragThreshold property for configuring the threshold to initiate a 'drag', i.e. touch move, of the handle of the slider. The mouse 'drag' won't be affected by the property. This property may be also used to configure the drag events stealing priorities of nested draggable items in the future. [ChangeLog][RangeSlider] Added touchDragThreshold property for configuring the threshold to initiate the touch 'drag' of the handle of the slider. The mouse 'drag' won't be affected by the property. Task-number: QTBUG-62784 Change-Id: I5555deb827de9d1dc7be00970fba15001105e419 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/imports/templates/qtquicktemplates2plugin.cpp1
-rw-r--r--src/quicktemplates2/qquickrangeslider.cpp38
-rw-r--r--src/quicktemplates2/qquickrangeslider_p.h9
-rw-r--r--tests/auto/controls/data/tst_rangeslider.qml90
4 files changed, 136 insertions, 2 deletions
diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp
index 545e2596..d8496558 100644
--- a/src/imports/templates/qtquicktemplates2plugin.cpp
+++ b/src/imports/templates/qtquicktemplates2plugin.cpp
@@ -333,6 +333,7 @@ void QtQuickTemplates2Plugin::registerTypes(const char *uri)
qmlRegisterType<QQuickDialogButtonBox, 5>(uri, 2, 5, "DialogButtonBox");
qmlRegisterType<QQuickControl, 5>(uri, 2, 5, "Control");
qmlRegisterType<QQuickPopup, 5>(uri, 2, 5, "Popup");
+ qmlRegisterType<QQuickRangeSlider, 5>(uri, 2, 5, "RangeSlider");
qmlRegisterType<QQuickSlider, 5>(uri, 2, 5, "Slider");
qmlRegisterType<QQuickTextArea, 5>(uri, 2, 5, "TextArea");
qmlRegisterType<QQuickTextField, 5>(uri, 2, 5, "TextField");
diff --git a/src/quicktemplates2/qquickrangeslider.cpp b/src/quicktemplates2/qquickrangeslider.cpp
index 36d8ca02..a33bddc5 100644
--- a/src/quicktemplates2/qquickrangeslider.cpp
+++ b/src/quicktemplates2/qquickrangeslider.cpp
@@ -358,6 +358,7 @@ public:
from(defaultFrom),
to(defaultTo),
stepSize(0),
+ touchDragThreshold(-1),
first(nullptr),
second(nullptr),
orientation(Qt::Horizontal),
@@ -381,6 +382,7 @@ public:
qreal from;
qreal to;
qreal stepSize;
+ qreal touchDragThreshold;
QQuickRangeSliderNode *first;
QQuickRangeSliderNode *second;
QPointF pressPoint;
@@ -647,6 +649,38 @@ 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);
+}
+
+/*!
\qmlpropertygroup QtQuick.Controls::RangeSlider::first
\qmlproperty real QtQuick.Controls::RangeSlider::first.value
\qmlproperty real QtQuick.Controls::RangeSlider::first.position
@@ -1067,9 +1101,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());
diff --git a/src/quicktemplates2/qquickrangeslider_p.h b/src/quicktemplates2/qquickrangeslider_p.h
index 45de6bbb..ae761ed0 100644
--- a/src/quicktemplates2/qquickrangeslider_p.h
+++ b/src/quicktemplates2/qquickrangeslider_p.h
@@ -70,6 +70,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickRangeSlider : public QQuickControl
Q_PROPERTY(bool horizontal READ isHorizontal NOTIFY orientationChanged FINAL REVISION 3)
// 2.3 (Qt 5.10)
Q_PROPERTY(bool vertical READ isVertical NOTIFY orientationChanged FINAL REVISION 3)
+ // 2.5 (Qt 5.12)
+ Q_PROPERTY(qreal touchDragThreshold READ touchDragThreshold WRITE setTouchDragThreshold RESET resetTouchDragThreshold NOTIFY touchDragThresholdChanged FINAL REVISION 5)
public:
explicit QQuickRangeSlider(QQuickItem *parent = nullptr);
@@ -109,6 +111,11 @@ public:
bool isHorizontal() const;
bool isVertical() const;
+ // 2.5 (Qt 5.12)
+ qreal touchDragThreshold() const;
+ void setTouchDragThreshold(qreal touchDragThreshold);
+ void resetTouchDragThreshold();
+
Q_SIGNALS:
void fromChanged();
void toChanged();
@@ -117,6 +124,8 @@ Q_SIGNALS:
void orientationChanged();
// 2.2 (Qt 5.9)
Q_REVISION(2) void liveChanged();
+ // 2.5 (Qt 5.12)
+ Q_REVISION(5) void touchDragThresholdChanged();
protected:
void focusInEvent(QFocusEvent *event) override;
diff --git a/tests/auto/controls/data/tst_rangeslider.qml b/tests/auto/controls/data/tst_rangeslider.qml
index 39b0c4b0..399348ca 100644
--- a/tests/auto/controls/data/tst_rangeslider.qml
+++ b/tests/auto/controls/data/tst_rangeslider.qml
@@ -929,4 +929,94 @@ TestCase {
compare(control.first.pressed, false)
compare(control.second.pressed, false)
}
+
+ function test_touchDragThreshold_data() {
+ var d1 = 3; var d2 = 7;
+ return [
+ { tag: "horizontal", orientation: Qt.Horizontal, dx1: d1, dy1: 0, dx2: d2, dy2: 0 },
+ { tag: "vertical", orientation: Qt.Vertical, dx1: 0, dy1: -d1, dx2: 0, dy2: -d2 },
+ { tag: "horizontal2", orientation: Qt.Horizontal, dx1: -d1, dy1: 0, dx2: -d2, dy2: 0 },
+ { tag: "vertical2", orientation: Qt.Vertical, dx1: 0, dy1: d1, dx2: 0, dy2: d2 },
+ ]
+ }
+
+ function test_touchDragThreshold(data) {
+ var control = createTemporaryObject(sliderComponent, testCase, {touchDragThreshold: 10, live: true, orientation: data.orientation, first: {value: 0}, second: {value: 1}})
+ verify(control)
+ compare(control.touchDragThreshold, 10)
+
+ var valueChangedCount = 0
+ var valueChangedSpy = signalSpy.createObject(control, {target: control, signalName: "touchDragThresholdChanged"})
+ verify(valueChangedSpy.valid)
+
+ control.touchDragThreshold = undefined
+ compare(control.touchDragThreshold, -1) // reset to -1
+ compare(valueChangedSpy.count, ++valueChangedCount)
+
+ var t = 5
+ control.touchDragThreshold = t
+ compare(control.touchDragThreshold, t)
+ compare(valueChangedSpy.count, ++valueChangedCount)
+
+ control.touchDragThreshold = t
+ compare(control.touchDragThreshold, t)
+ compare(valueChangedSpy.count, valueChangedCount)
+
+ var pressedCount = 0
+ var pressedCount2 = 0
+ var visualPositionCount = 0
+ var visualPositionCount2 = 0
+
+ var pressedSpy = signalSpy.createObject(control, {target: control.first, signalName: "pressedChanged"})
+ verify(pressedSpy.valid)
+ var pressedSpy2 = signalSpy.createObject(control, {target: control.second, signalName: "pressedChanged"})
+ verify(pressedSpy2.valid)
+
+ var visualPositionSpy = signalSpy.createObject(control, {target: control.first, signalName: "visualPositionChanged"})
+ verify(visualPositionSpy.valid)
+ var visualPositionSpy2 = signalSpy.createObject(control, {target: control.second, signalName: "visualPositionChanged"})
+ verify(visualPositionSpy2.valid)
+
+ var touch = touchEvent(control)
+ control.first.value = 0.4
+ control.second.value = 1
+ var x0 = control.first.handle.x + control.first.handle.width * 0.5
+ var y0 = control.first.handle.y + control.first.handle.height * 0.5
+ touch.press(0, control, x0, y0).commit()
+ compare(pressedSpy.count, ++pressedCount)
+ compare(control.first.pressed, true)
+ compare(visualPositionSpy.count, ++visualPositionCount)
+
+ touch.move(0, control, x0 + data.dx1, y0 + data.dy1).commit()
+ compare(pressedSpy.count, pressedCount)
+ compare(control.first.pressed, true)
+ compare(visualPositionSpy.count, visualPositionCount)
+
+ touch.move(0, control, x0 + data.dx2, y0 + data.dy2).commit()
+ compare(pressedSpy.count, pressedCount)
+ compare(control.first.pressed, true)
+ compare(visualPositionSpy.count, ++visualPositionCount)
+
+ touch.release(0, control, x0 + data.dx2, y0 + data.dy2).commit()
+
+ control.first.value = 0
+ control.second.value = 0.6
+ x0 = control.second.handle.x + control.second.handle.width * 0.5
+ y0 = control.second.handle.y + control.second.handle.height * 0.5
+ touch.press(0, control, x0, y0).commit()
+ compare(pressedSpy2.count, ++pressedCount2)
+ compare(control.second.pressed, true)
+ compare(visualPositionSpy2.count, ++visualPositionCount2)
+
+ touch.move(0, control, x0 + data.dx1, y0 + data.dy1).commit()
+ compare(pressedSpy2.count, pressedCount2)
+ compare(control.second.pressed, true)
+ compare(visualPositionSpy2.count, visualPositionCount2)
+
+ touch.move(0, control, x0 + data.dx2, y0 + data.dy2).commit()
+ compare(pressedSpy2.count, pressedCount2)
+ compare(control.second.pressed, true)
+ compare(visualPositionSpy2.count, ++visualPositionCount2)
+ touch.release(0, control, x0 + data.dx2, y0 + data.dy2).commit()
+ }
}