mobile/profile: don't pan unless we are zoomed in

This way someone trying to swipe from dive to dive won't inadvertantly
pan the profile instead. And panning it really only makes sense when
zoomed in in the first place.

This could leave us in a situation where we zoom in, pan, zoom out and
now the profile is out of whack and we cannot correct it. A simple click
on the profile fixes that.

The real solution would be some constraining / adjusting as we zoom and
pan to ensure we keep things correctly positioned. Maybe I'll figure out
the correct way to do this later...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-03-22 12:16:58 -07:00
parent bba73fdc87
commit c7dd1e1bab

View file

@ -256,19 +256,35 @@ Item {
}
MouseArea {
anchors.fill: parent
drag.target: qmlProfile
drag.axis: Drag.XAndYAxis
drag.smoothed: true
pressAndHoldInterval: 50 // very short - feels about right
// we want to pan the profile if we are zoomed in, but we want to immediately
// pass the mouse events through to the ListView if we are not. That way you
// can swipe through the dive list, even if you happen to swipe the profile
property bool isZoomed: qmlProfile.scale - 1.0 > 0.02
// this indicates that we are actually dragging
property bool dragging: false
// cursor/finger position as we start dragging
property real initialX
property real initialY
// the offset previously used to show the profile
property real oldXOffset
property real oldYOffset
// this indicates that we are actually dragging
property bool dragging: false
// if the profile is not scaled in, don't start panning
// but if the profile is scaled in, then start almost immediately
pressAndHoldInterval: isZoomed ? 50 : 50000
// pass events through to the parent and eventually into the ListView
propagateComposedEvents: true
anchors.fill: parent
drag.target: qmlProfile
drag.axis: Drag.XAndYAxis
drag.smoothed: true
onPressed: {
if (!isZoomed)
mouse.accepted = false
}
onPressAndHold: {
dragging = true;
oldXOffset = qmlProfile.xOffset
@ -289,12 +305,24 @@ Item {
qmlProfile.xOffset = oldXOffset + x
qmlProfile.yOffset = oldYOffset + y
qmlProfile.update()
} else {
mouse.accepted = false
}
}
onReleased: {
// reset things
dragging = false
qmlProfile.opacity = 1.0
if (dragging) {
// reset things
dragging = false
qmlProfile.opacity = 1.0
}
mouse.accepted = false
}
onClicked: {
// reset the position if not zoomed in
if (!isZoomed) {
qmlProfile.xOffset = qmlProfile.yOffset = oldXOffset = oldYOffset = 0
mouse.accepted = false
}
}
}
}