Commit a2b20d23 authored by Gabriel de Dietrich's avatar Gabriel de Dietrich Committed by Shawn Rutledge
Browse files

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: default avatarShawn Rutledge <shawn.rutledge@digia.com>
Showing with 29 additions and 16 deletions
/****************************************************************************
**
** 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
}
......
......@@ -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()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment