summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>2014-10-29 18:37:20 +0100
committerShawn Rutledge <shawn.rutledge@digia.com>2014-10-31 07:26:01 +0100
commita2b20d230604f90b343611c0df93032ecbeecc3a (patch)
treeeffbf0e9952f2603f1ca8fae0ecfd0e96634a0aa
parentdc1bd3859ea91668a47319449beca13f0e8e9755 (diff)
downloadqtquickcontrols-a2b20d230604f90b343611c0df93032ecbeecc3a.tar.gz
Slider: Hover only on the handle
Most styles rely on the handle being hovered, not the whole slider. [ChangeLog][Slider] The hovered property is set only when the handle is hovered, not anymore on the groove Change-Id: I749b076c98fba8e344218e46637ec00d24c0250c Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com>
-rw-r--r--src/controls/Slider.qml41
-rw-r--r--tests/auto/controls/data/tst_slider.qml4
2 files changed, 29 insertions, 16 deletions
diff --git a/src/controls/Slider.qml b/src/controls/Slider.qml
index 94653bf8..5c54e7a2 100644
--- a/src/controls/Slider.qml
+++ b/src/controls/Slider.qml
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Quick Controls module of the Qt Toolkit.
@@ -117,9 +117,9 @@ Control {
/*!
\qmlproperty bool Slider::hovered
- This property indicates whether the control is being hovered.
+ This property indicates whether the slider handle is being hovered.
*/
- readonly property alias hovered: mouseArea.containsMouse
+ readonly property alias hovered: mouseArea.handleHovered
/*!
\qmlproperty real Slider::stepSize
@@ -231,26 +231,24 @@ Control {
property int clickOffset: 0
property real pressX: 0
property real pressY: 0
+ property bool handleHovered: false
function clamp ( val ) {
return Math.max(range.positionAtMinimum, Math.min(range.positionAtMaximum, val))
}
- onMouseXChanged: {
- if (pressed && __horizontal) {
- var pos = clamp (mouse.x + clickOffset - fakeHandle.width/2)
- var overThreshold = Math.abs(mouse.x - pressX) >= Settings.dragThreshold
+ function updateHandlePosition(mouse) {
+ var pos, overThreshold
+ if (__horizontal) {
+ pos = clamp (mouse.x + clickOffset - fakeHandle.width/2)
+ overThreshold = Math.abs(mouse.x - pressX) >= Settings.dragThreshold
if (overThreshold)
preventStealing = true
if (overThreshold || !Settings.hasTouchScreen)
fakeHandle.x = pos
- }
- }
-
- onMouseYChanged: {
- if (pressed && !__horizontal) {
- var pos = clamp (mouse.y + clickOffset- fakeHandle.height/2)
- var overThreshold = Math.abs(mouse.y - pressY) >= Settings.dragThreshold
+ } else if (!__horizontal) {
+ pos = clamp (mouse.y + clickOffset- fakeHandle.height/2)
+ overThreshold = Math.abs(mouse.y - pressY) >= Settings.dragThreshold
if (overThreshold)
preventStealing = true
if (overThreshold || !Settings.hasTouchScreen)
@@ -258,16 +256,25 @@ Control {
}
}
+ onPositionChanged: {
+ if (pressed)
+ updateHandlePosition(mouse)
+
+ var point = mouseArea.mapToItem(fakeHandle, mouse.x, mouse.y)
+ handleHovered = fakeHandle.contains(Qt.point(point.x, point.y))
+ }
+
onPressed: {
if (slider.activeFocusOnPress)
slider.forceActiveFocus();
- var point = mouseArea.mapToItem(fakeHandle, mouse.x, mouse.y)
- if (fakeHandle.contains(Qt.point(point.x, point.y))) {
+ if (handleHovered) {
+ var point = mouseArea.mapToItem(fakeHandle, mouse.x, mouse.y)
clickOffset = __horizontal ? fakeHandle.width/2 - point.x : fakeHandle.height/2 - point.y
}
pressX = mouse.x
pressY = mouse.y
+ updateHandlePosition(mouse)
}
onReleased: {
@@ -278,6 +285,8 @@ Control {
clickOffset = 0
preventStealing = false
}
+
+ onExited: handleHovered = false
}
diff --git a/tests/auto/controls/data/tst_slider.qml b/tests/auto/controls/data/tst_slider.qml
index 3836fdde..2b3a00a5 100644
--- a/tests/auto/controls/data/tst_slider.qml
+++ b/tests/auto/controls/data/tst_slider.qml
@@ -280,12 +280,16 @@ Item {
function test_sliderOffset() {
var control = Qt.createQmlObject('import QtQuick.Controls 1.2; Slider {x: 20; y: 20; width: 100; height: 50}', container, '')
// Don't move slider value if mouse is inside handle regtion
+ mouseMove(control, control.width/2, control.height/2)
mouseClick(control, control.width/2, control.height/2)
compare(control.value, 0.5)
+ mouseMove(control, control.width/2 + 5, control.height/2)
mouseClick(control, control.width/2 + 5, control.height/2)
compare(control.value, 0.5)
+ mouseMove(control, control.width/2 - 5, control.height/2)
mouseClick(control, control.width/2 - 5, control.height/2)
compare(control.value, 0.5)
+ mouseMove(control, control.width/2 + 25, control.height/2)
mouseClick(control, control.width/2 + 25, control.height/2)
verify(control.value > 0.5)
control.destroy()