diff options
author | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2014-10-29 18:37:20 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@digia.com> | 2014-10-31 07:26:01 +0100 |
commit | a2b20d230604f90b343611c0df93032ecbeecc3a (patch) | |
tree | effbf0e9952f2603f1ca8fae0ecfd0e96634a0aa /src/controls | |
parent | dc1bd3859ea91668a47319449beca13f0e8e9755 (diff) | |
download | qtquickcontrols-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>
Diffstat (limited to 'src/controls')
-rw-r--r-- | src/controls/Slider.qml | 41 |
1 files changed, 25 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 } |