Improve usability of qmlvideofx example on small touchscreens

* Add tolerance to mouse press detection on divider and slider grips,
  so that clicks just outside of the grip radius are treated as if the
  click was inside the grip.
* When slider bar outside of grip radius is clicked, increment slider
  position by a fixed amount, towards the click position.

Change-Id: Iefb0b274ee5a97ed5cb789596bf6b3c07a7fc8b8
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
This commit is contained in:
Gareth Stockwell
2012-02-10 15:25:14 +00:00
committed by Qt by Nokia
parent 2d188bdb3f
commit a93be80d33
5 changed files with 60 additions and 50 deletions

View File

@@ -45,50 +45,29 @@ Rectangle {
id: root id: root
anchors.fill: parent anchors.fill: parent
color: "transparent" color: "transparent"
property alias value: grip.value property alias value: slider.value
property alias lineWidth: line.width property alias lineWidth: line.width
property alias gripSize: grip.width property alias gripSize: slider.gripSize
Rectangle {
id: grip
property real value: 0.5
x: (value * parent.width) - width/2
anchors.top: parent.top
width: 20
height: width
radius: width/2
color: "red"
MouseArea {
anchors.fill: parent
drag {
target: grip
axis: Drag.XAxis
minimumX: -parent.width/2
maximumX: root.width - parent.width/2
}
onPositionChanged: {
if (drag.active)
updatePosition()
}
onReleased: {
updatePosition()
}
function updatePosition() {
value = (grip.x + grip.width/2) / grip.parent.width
}
}
}
Rectangle { Rectangle {
id: line id: line
anchors { top: parent.top; bottom: parent.bottom } anchors { top: parent.top; bottom: parent.bottom }
x: value * parent.width - (width / 2) x: parent.value * parent.width - (width / 2)
width: 2 width: 2
color: "red" color: "red"
} }
Slider {
id: slider
increment: 0.0
lineColor: "transparent"
fillColor: "transparent"
gripColor: "red"
anchors {
top: parent.top
topMargin: gripSize / 2
left: parent.left
right: parent.right
}
}
} }

View File

@@ -92,6 +92,7 @@ Rectangle {
right: parent.right right: parent.right
rightMargin: 20 rightMargin: 20
} }
gripSize: root.gripSize
value: model.value value: model.value
onValueChanged: view.model.setProperty(index, "value", value) onValueChanged: view.model.setProperty(index, "value", value)
} }

View File

@@ -48,13 +48,16 @@ Rectangle {
property alias value: grip.value property alias value: grip.value
property color fillColor: "white" property color fillColor: "white"
property color lineColor: "black" property color lineColor: "black"
property alias gripSize: grip.width property color gripColor: "white"
property alias enabled: mouseArea.enabled property real gripSize: 20
property real gripTolerance: 3.0
property real increment: 0.1
property bool enabled: true
Rectangle { Rectangle {
anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter } anchors { left: parent.left; right: parent.right; verticalCenter: parent.verticalCenter }
height: 3 height: 3
color: displayedColor() color: displayedColor(root.lineColor)
Rectangle { Rectangle {
anchors { fill: parent; margins: 1 } anchors { fill: parent; margins: 1 }
@@ -62,18 +65,35 @@ Rectangle {
} }
} }
MouseArea {
anchors.fill: parent
enabled: root.enabled
onClicked: {
if (parent.width) {
var newValue = mouse.x / parent.width
if (Math.abs(newValue - parent.value) > parent.increment) {
if (newValue > parent.value)
parent.value = Math.min(1.0, parent.value + parent.increment)
else
parent.value = Math.max(0.0, parent.value - parent.increment)
}
}
}
}
Rectangle { Rectangle {
id: grip id: grip
property real value: 0.5 property real value: 0.5
x: (value * parent.width) - width/2 x: (value * parent.width) - width/2
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
width: 20 width: root.gripTolerance * root.gripSize
height: width height: width
radius: width/2 radius: width/2
color: displayedColor() color: "transparent"
MouseArea { MouseArea {
id: mouseArea id: mouseArea
enabled: root.enabled
anchors.fill: parent anchors.fill: parent
drag { drag {
target: grip target: grip
@@ -94,14 +114,16 @@ Rectangle {
} }
Rectangle { Rectangle {
anchors { fill: parent; margins: 1 } anchors.centerIn: parent
width: root.gripSize
height: width
radius: width/2 radius: width/2
color: root.fillColor color: root.gripColor
} }
} }
function displayedColor() { function displayedColor(c) {
var tint = Qt.rgba(fillColor.r, fillColor.g, fillColor.b, 0.25) var tint = Qt.rgba(c.r, c.g, c.b, 0.25)
return enabled ? lineColor : Qt.tint(fillColor, tint) return enabled ? c : Qt.tint(c, tint)
} }
} }

View File

@@ -51,6 +51,11 @@ Rectangle {
property bool perfMonitorsLogging: false property bool perfMonitorsLogging: false
property bool perfMonitorsVisible: false property bool perfMonitorsVisible: false
QtObject {
id: d
property real gripSize: 20
}
Rectangle { Rectangle {
id: inner id: inner
anchors.fill: parent anchors.fill: parent
@@ -65,6 +70,7 @@ Rectangle {
right: effectSelectionPanel.left right: effectSelectionPanel.left
margins: 5 margins: 5
} }
gripSize: d.gripSize
width: 600 width: 600
height: 600 height: 600
} }
@@ -95,6 +101,7 @@ Rectangle {
right: effectSelectionPanel.left right: effectSelectionPanel.left
margins: 20 margins: 20
} }
gripSize: d.gripSize
} }
EffectSelectionPanel { EffectSelectionPanel {

View File

@@ -57,6 +57,7 @@ Rectangle {
effectSelectionPanel.state == "shown" || effectSelectionPanel.state == "shown" ||
videoFileBrowser.shown || videoFileBrowser.shown ||
imageFileBrowser.shown) imageFileBrowser.shown)
property real gripSize: 40
} }
// Create ScreenSaver element via Loader, so this app will still run if the // Create ScreenSaver element via Loader, so this app will still run if the
@@ -100,7 +101,7 @@ Rectangle {
Content { Content {
id: content id: content
anchors.fill: parent anchors.fill: parent
gripSize: 40 gripSize: d.gripSize
onVideoFramePainted: performanceLoader.item.videoFramePainted() onVideoFramePainted: performanceLoader.item.videoFramePainted()
} }
@@ -112,7 +113,7 @@ Rectangle {
margins: 10 margins: 10
} }
y: parent.height y: parent.height
gripSize: 40 gripSize: d.gripSize
states: [ states: [
State { State {