Browse Source

OnScreenGimbalController.qml: first commit, process onscreen mouse actions for gimbal control

QGC4.4
davidsastresas 11 months ago committed by Julian Oes
parent
commit
91b050d88d
No known key found for this signature in database
GPG Key ID: F0ED380FEA56DE41
  1. 1
      qgroundcontrol.qrc
  2. 101
      src/FlightDisplay/OnScreenGimbalController.qml
  3. 1
      src/QmlControls/QGroundControl/FlightDisplay/qmldir

1
qgroundcontrol.qrc

@ -215,6 +215,7 @@ @@ -215,6 +215,7 @@
<file alias="QGroundControl/FlightDisplay/FlyViewToolStrip.qml">src/FlightDisplay/FlyViewToolStrip.qml</file>
<file alias="QGroundControl/FlightDisplay/FlyViewToolStripActionList.qml">src/FlightDisplay/FlyViewToolStripActionList.qml</file>
<file alias="QGroundControl/FlightDisplay/FlyViewVideo.qml">src/FlightDisplay/FlyViewVideo.qml</file>
<file alias="QGroundControl/FlightDisplay/OnScreenGimbalController.qml">src/FlightDisplay/OnScreenGimbalController.qml</file>
<file alias="QGroundControl/FlightDisplay/FlyViewWidgetLayer.qml">src/FlightDisplay/FlyViewWidgetLayer.qml</file>
<file alias="QGroundControl/FlightDisplay/GuidedActionActionList.qml">src/FlightDisplay/GuidedActionActionList.qml</file>
<file alias="QGroundControl/FlightDisplay/GuidedActionConfirm.qml">src/FlightDisplay/GuidedActionConfirm.qml</file>

101
src/FlightDisplay/OnScreenGimbalController.qml

@ -0,0 +1,101 @@ @@ -0,0 +1,101 @@
/****************************************************************************
*
* (c) 2009-2024 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
*
* QGroundControl is licensed according to the terms in the file
* COPYING.md in the root of the source code directory.
*
****************************************************************************/
import QtQuick 2.12
import QGroundControl 1.0
import QGroundControl.Controls 1.0
import QGroundControl.Controllers 1.0
import QGroundControl.ScreenTools 1.0
import QGroundControl.Palette 1.0
Item {
id: rootItem
anchors.fill: parent
property var screenX
property var screenY
property var screenXrateInitCoocked
property var screenYrateInitCoocked
property var activeVehicle: QGroundControl.multiVehicleManager.activeVehicle
property var gimbalController: activeVehicle ? activeVehicle.gimbalController : undefined
property var activeGimbal: gimbalController ? gimbalController.activeGimbal : undefined
property bool gimbalAvailable: activeGimbal != undefined
property var gimbalControllerSettings: QGroundControl.settingsManager.gimbalControllerSettings
property bool shouldProcessClicks: gimbalControllerSettings.EnableOnScreenControl.value && activeGimbal ? true : false
function clickControl() {
if (!shouldProcessClicks) {
return
}
// If click and slide control, return, it uses press and release
if (!gimbalControllerSettings.ControlType.rawValue == 0) {
return
}
clickAndPoint(x, y)
}
// Sends a +-(0-1) xy value to vehicle.gimbalController.gimbalOnScreenControl
function clickAndPoint() {
if (rootItem.gimbalAvailable) {
var xCoocked = ( (screenX / parent.width) * 2) - 1
var yCoocked = -( (screenY / parent.height) * 2) + 1
// console.log("X global: " + x + " Y global: " + y)
// console.log("X coocked: " + xCoocked + " Y coocked: " + yCoocked)
gimbalController.gimbalOnScreenControl(xCoocked, yCoocked, true, false, false)
} else {
// We should never be here
console.log("gimbal not available")
}
}
function pressControl() {
if (!shouldProcessClicks) {
return
}
// If click and point control return, that is handled exclusively on clickAndPoint()
if (!gimbalControllerSettings.ControlType.rawValue == 1) {
return
}
sendRateTimer.start()
screenXrateInitCoocked = ( ( screenX / parent.width) * 2) - 1
screenYrateInitCoocked = -( ( screenY / parent.height) * 2) + 1
}
function releaseControl() {
if (!shouldProcessClicks) {
return
}
// If click and point control return, that is handled exclusively on clickAndPoint()
if (!gimbalControllerSettings.ControlType.rawValue == 1) {
return
}
sendRateTimer.stop()
screenXrateInitCoocked = null
screenYrateInitCoocked = null
}
Timer {
id: sendRateTimer
interval: 100
repeat: true
onTriggered: {
if (rootItem.gimbalAvailable) {
var xCoocked = ( ( screenX / parent.width) * 2) - 1
var yCoocked = -( ( screenY / parent.height) * 2) + 1
xCoocked -= screenXrateInitCoocked
yCoocked -= screenYrateInitCoocked
gimbalController.gimbalOnScreenControl(xCoocked, yCoocked, false, true, true)
} else {
console.log("gimbal not available")
}
}
}
}

1
src/QmlControls/QGroundControl/FlightDisplay/qmldir

@ -38,3 +38,4 @@ ObstacleDistanceOverlay 1.0 ObstacleDistanceOverlay.qml @@ -38,3 +38,4 @@ ObstacleDistanceOverlay 1.0 ObstacleDistanceOverlay.qml
ObstacleDistanceOverlayMap 1.0 ObstacleDistanceOverlayMap.qml
ObstacleDistanceOverlayVideo 1.0 ObstacleDistanceOverlayVideo.qml
GripperMenu 1.0 GripperMenu.qml
OnScreenGimbalController 1.0 OnScreenGimbalController.qml

Loading…
Cancel
Save