aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYulong Bai <yulong.bai@qt.io>2018-03-02 14:31:36 +0100
committerYulong Bai <yulong.bai@qt.io>2018-03-12 12:08:24 +0000
commitb6dbfe623ab6df58ccb7bf8a922eb853fc10155a (patch)
tree0b50cbc8f30246fa96b0ee7b49273172cfd0d826
parent41dd1405d5c5bfac05f9c42a4c4017de5075f5cc (diff)
QQuickSlider: 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][Slider] 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: Ifaeea4653b48c44efbe7e1cb09d399a91359c16a Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r--src/imports/templates/qtquicktemplates2plugin.cpp1
-rw-r--r--src/quicktemplates2/qquickslider.cpp37
-rw-r--r--src/quicktemplates2/qquickslider_p.h10
-rw-r--r--tests/auto/controls/data/tst_slider.qml60
4 files changed, 105 insertions, 3 deletions
diff --git a/src/imports/templates/qtquicktemplates2plugin.cpp b/src/imports/templates/qtquicktemplates2plugin.cpp
index 09bd2d87..545e2596 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<QQuickSlider, 5>(uri, 2, 5, "Slider");
qmlRegisterType<QQuickTextArea, 5>(uri, 2, 5, "TextArea");
qmlRegisterType<QQuickTextField, 5>(uri, 2, 5, "TextField");
qmlRegisterType<QQuickToolTip, 5>(uri, 2, 5, "ToolTip");
diff --git a/src/quicktemplates2/qquickslider.cpp b/src/quicktemplates2/qquickslider.cpp
index ef2077af..9b922215 100644
--- a/src/quicktemplates2/qquickslider.cpp
+++ b/src/quicktemplates2/qquickslider.cpp
@@ -95,6 +95,7 @@ public:
value(0),
position(0),
stepSize(0),
+ touchDragThreshold(-1), // in QQuickWindowPrivate::dragOverThreshold, '-1' implies using styleHints::startDragDistance()
live(true),
pressed(false),
orientation(Qt::Horizontal),
@@ -121,6 +122,7 @@ public:
qreal value;
qreal position;
qreal stepSize;
+ qreal touchDragThreshold;
bool live;
bool pressed;
QPointF pressPoint;
@@ -636,6 +638,37 @@ void QQuickSlider::decrease()
setValue(d->value - step);
}
+/*!
+ \since QtQuick.Controls 2.5 (Qt 5.12)
+ \qmlproperty qreal QtQuick.Controls::Slider::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 QQuickSlider::touchDragThreshold() const
+{
+ Q_D(const QQuickSlider);
+ return d->touchDragThreshold;
+}
+
+void QQuickSlider::setTouchDragThreshold(qreal touchDragThreshold)
+{
+ Q_D(QQuickSlider);
+ if (d->touchDragThreshold == touchDragThreshold)
+ return;
+
+ d->touchDragThreshold = touchDragThreshold;
+ emit touchDragThresholdChanged();
+}
+
+void QQuickSlider::resetTouchDragThreshold()
+{
+ setTouchDragThreshold(-1);
+}
+
void QQuickSlider::keyPressEvent(QKeyEvent *event)
{
Q_D(QQuickSlider);
@@ -715,9 +748,9 @@ void QQuickSlider::touchEvent(QTouchEvent *event)
case Qt::TouchPointMoved:
if (!keepTouchGrab()) {
if (d->orientation == Qt::Horizontal)
- setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().x() - d->pressPoint.x(), Qt::XAxis, &point));
+ setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().x() - d->pressPoint.x(), Qt::XAxis, &point, qRound(d->touchDragThreshold)));
else
- setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().y() - d->pressPoint.y(), Qt::YAxis, &point));
+ setKeepTouchGrab(QQuickWindowPrivate::dragOverThreshold(point.pos().y() - d->pressPoint.y(), Qt::YAxis, &point, qRound(d->touchDragThreshold)));
}
if (keepTouchGrab())
d->handleMove(point.pos());
diff --git a/src/quicktemplates2/qquickslider_p.h b/src/quicktemplates2/qquickslider_p.h
index 95545462..4aac6e2c 100644
--- a/src/quicktemplates2/qquickslider_p.h
+++ b/src/quicktemplates2/qquickslider_p.h
@@ -72,7 +72,8 @@ class Q_QUICKTEMPLATES2_PRIVATE_EXPORT QQuickSlider : public QQuickControl
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)
public:
explicit QQuickSlider(QQuickItem *parent = nullptr);
@@ -121,6 +122,11 @@ public:
bool isHorizontal() const;
bool isVertical() const;
+ // 2.5 (Qt 5.12)
+ qreal touchDragThreshold() const;
+ void setTouchDragThreshold(qreal touchDragThreshold);
+ void resetTouchDragThreshold();
+
public Q_SLOTS:
void increase();
void decrease();
@@ -139,6 +145,8 @@ Q_SIGNALS:
// 2.2 (Qt 5.9)
Q_REVISION(2) void moved();
Q_REVISION(2) void liveChanged();
+ // 2.5 (Qt 5.12)
+ Q_REVISION(5) void touchDragThresholdChanged();
protected:
void keyPressEvent(QKeyEvent *event) override;
diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml
index a831e402..39e0ea17 100644
--- a/tests/auto/controls/data/tst_slider.qml
+++ b/tests/auto/controls/data/tst_slider.qml
@@ -804,4 +804,64 @@ TestCase {
mouseRelease(control)
compare(control.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(slider, testCase, {touchDragThreshold: 10, live: true, orientation: data.orientation, value: 0.5})
+ 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 movedCount = 0
+
+ var pressedSpy = signalSpy.createObject(control, {target: control, signalName: "pressedChanged"})
+ verify(pressedSpy.valid)
+
+ var movedSpy = signalSpy.createObject(control, {target: control, signalName: "moved"})
+ verify(movedSpy.valid)
+
+ var touch = touchEvent(control)
+ var x0 = control.handle.x + control.handle.width * 0.5
+ var y0 = control.handle.y + control.handle.height * 0.5
+ touch.press(0, control, x0, y0).commit()
+ compare(pressedSpy.count, ++pressedCount)
+ compare(movedSpy.count, movedCount)
+ compare(control.pressed, true)
+
+ touch.move(0, control, x0 + data.dx1, y0 + data.dy1).commit()
+ compare(pressedSpy.count, pressedCount)
+ compare(movedSpy.count, movedCount) // shouldn't move
+ compare(control.pressed, true)
+
+ touch.move(0, control, x0 + data.dx2, y0 + data.dy2).commit()
+ compare(pressedSpy.count, pressedCount)
+ compare(movedSpy.count, ++movedCount)
+ compare(control.pressed, true)
+ }
}