summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2014-03-10 15:42:35 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-03-18 09:38:44 +0100
commit354ff5e7733703ba6304ccf3241ab35b3e235cf1 (patch)
tree0fe683ffa1af4d946cfd83bd83dd65c4f9f2389b
parent6aba49f84a17bad51f83968a03e5e9a58de726c6 (diff)
downloadqtquickcontrols-354ff5e7733703ba6304ccf3241ab35b3e235cf1.tar.gz
Slider: don't prevent stealing until drag threshold is exceeded
If a Slider is placed in a Flickable (or ListView, etc.), preventStealing means that you cannot flick the flickable by dragging over the Slider. It's better to postpone setting that until we detect whether the user is really attempting to drag the slider, because we don't want to rule out use cases such as vertical sliders in a horizontal ListView or vice-versa, so that you drag in one direction to move the slider and in another direction to flick. Platform drag threshold is exposed in Settings (from QStyleHints). (reverts/refines c9665f3e2d1eb12f1cc5a569c20f5d569fafde7f) Change-Id: I82feda6028f6effa5b26ad575a1933e48e971453 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@digia.com>
-rw-r--r--src/controls/Private/qquickcontrolsettings.cpp7
-rw-r--r--src/controls/Private/qquickcontrolsettings_p.h2
-rw-r--r--src/controls/Slider.qml10
3 files changed, 18 insertions, 1 deletions
diff --git a/src/controls/Private/qquickcontrolsettings.cpp b/src/controls/Private/qquickcontrolsettings.cpp
index d89ffc1e..e1d0cabb 100644
--- a/src/controls/Private/qquickcontrolsettings.cpp
+++ b/src/controls/Private/qquickcontrolsettings.cpp
@@ -45,6 +45,8 @@
#include <qqmlengine.h>
#include <qdir.h>
#include <QTouchDevice>
+#include <QGuiApplication>
+#include <QStyleHints>
QT_BEGIN_NAMESPACE
@@ -175,5 +177,10 @@ qreal QQuickControlSettings::dpiScaleFactor() const
return 1.0;
}
+qreal QQuickControlSettings::dragThreshold() const
+{
+ return qApp->styleHints()->startDragDistance();
+}
+
QT_END_NAMESPACE
diff --git a/src/controls/Private/qquickcontrolsettings_p.h b/src/controls/Private/qquickcontrolsettings_p.h
index 2b36e662..0687e209 100644
--- a/src/controls/Private/qquickcontrolsettings_p.h
+++ b/src/controls/Private/qquickcontrolsettings_p.h
@@ -56,6 +56,7 @@ class QQuickControlSettings : public QObject
Q_PROPERTY(QString styleName READ styleName WRITE setStyleName NOTIFY styleNameChanged)
Q_PROPERTY(QString stylePath READ stylePath WRITE setStylePath NOTIFY stylePathChanged)
Q_PROPERTY(qreal dpiScaleFactor READ dpiScaleFactor CONSTANT)
+ Q_PROPERTY(qreal dragThreshold READ dragThreshold CONSTANT)
Q_PROPERTY(bool hasTouchScreen READ hasTouchScreen CONSTANT)
public:
@@ -70,6 +71,7 @@ public:
void setStylePath(const QString &path);
qreal dpiScaleFactor() const;
+ qreal dragThreshold() const;
bool hasTouchScreen() const;
diff --git a/src/controls/Slider.qml b/src/controls/Slider.qml
index e2be07d8..c2869563 100644
--- a/src/controls/Slider.qml
+++ b/src/controls/Slider.qml
@@ -218,8 +218,9 @@ Control {
anchors.fill: parent
hoverEnabled: true
- preventStealing: true
property int clickOffset: 0
+ property real pressX: 0
+ property real pressY: 0
function clamp ( val ) {
return Math.max(range.positionAtMinimum, Math.min(range.positionAtMaximum, val))
@@ -229,6 +230,8 @@ Control {
if (pressed && __horizontal) {
var pos = clamp (mouse.x + clickOffset - fakeHandle.width/2)
fakeHandle.x = pos
+ if (Math.abs(mouse.x - pressX) >= Settings.dragThreshold)
+ preventStealing = true
}
}
@@ -236,6 +239,8 @@ Control {
if (pressed && !__horizontal) {
var pos = clamp (mouse.y + clickOffset- fakeHandle.height/2)
fakeHandle.y = pos
+ if (Math.abs(mouse.y - pressY) >= Settings.dragThreshold)
+ preventStealing = true
}
}
@@ -247,6 +252,8 @@ Control {
if (fakeHandle.contains(Qt.point(point.x, point.y))) {
clickOffset = __horizontal ? fakeHandle.width/2 - point.x : fakeHandle.height/2 - point.y
}
+ pressX = mouse.x
+ pressY = mouse.y
}
onReleased: {
@@ -255,6 +262,7 @@ Control {
if (!slider.updateValueWhileDragging)
range.position = __horizontal ? fakeHandle.x : fakeHandle.y;
clickOffset = 0
+ preventStealing = false
}
}