diff --git a/src/controls/Slider.qml b/src/controls/Slider.qml index 94653bf82c11c00653a3765bb898170561eb3aff..5c54e7a2e1cbf450667560a8381d8fcb96f9656f 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 3836fdde4f5053ea530a3d46cfc4ce37130cd1b8..2b3a00a53ffff783b89eceafdd776d94a0bc9afa 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()