QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
CameraPinchZoom.qml
Go to the documentation of this file.
1import QtQuick
2
3// Steps the camera's zoom as two fingers spread or pinch: one step per zoomStepScale of pinch, the same in and out.
4PinchArea {
5 id: root
6
7 /// The camera to zoom; any object with hasZoom and stepZoom(direction), which takes -1 (wide) or 1 (tele), will do.
8 property var camera: null
9 /// Pinch scale per zoom step.
10 property real zoomStepScale: 1.25
11
12 // Zoom steps sent during the current pinch.
13 property int _sent: 0
14 readonly property bool _hasZoom: !!root.camera && root.camera.hasZoom
15
16 /// Sends the camera one zoom step toward the step count @p scale stands for, given the @p sent steps of this pinch
17 /// so far; returns the count sent after it. A step a pinch update skips goes with the next one.
18 function _stepToward(scale, sent) {
19 const target = Math.round(Math.log(scale) / Math.log(root.zoomStepScale))
20 if (!root._hasZoom || target === sent) {
21 return sent
22 }
23 const direction = target > sent ? 1 : -1
24 root.camera.stepZoom(direction)
25 return sent + direction
26 }
27
28 enabled: root._hasZoom
29
30 onPinchStarted: root._sent = 0
31 onPinchUpdated: (pinch) => { root._sent = root._stepToward(pinch.scale, root._sent) }
32}