GuidedAltitudeSlider.qml 3.97 KB
Newer Older
DonLakeFlyer's avatar
DonLakeFlyer committed
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
DonLakeFlyer's avatar
DonLakeFlyer committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/

import QtQuick                  2.3
import QtQuick.Controls         1.2

import QGroundControl               1.0
import QGroundControl.Controls      1.0
import QGroundControl.Vehicle       1.0

/// Altitude slider for guided change altitude command
Rectangle {
    id:                 _root

    readonly property real _maxAlt: 121.92  // 400 feet
    readonly property real _minAlt: 3

24
    property var  _flyViewSettings:     QGroundControl.settingsManager.flyViewSettings
Gus Grubba's avatar
Gus Grubba committed
25 26
    property real _vehicleAltitude:     activeVehicle ? activeVehicle.altitudeRelative.rawValue : 0
    property bool _fixedWing:           activeVehicle ? activeVehicle.fixedWing : false
27 28
    property real _sliderMaxAlt:        _flyViewSettings ? _flyViewSettings.guidedMaximumAltitude.rawValue : 0
    property real _sliderMinAlt:        _flyViewSettings ? _flyViewSettings.guidedMinimumAltitude.rawValue : 0
29
    property bool _flying:              activeVehicle ? activeVehicle.flying : false
DonLakeFlyer's avatar
DonLakeFlyer committed
30 31

    function reset() {
32
        altSlider.value = 0
DonLakeFlyer's avatar
DonLakeFlyer committed
33 34
    }

35 36 37 38
    function setToMinimumTakeoff() {
        altField.setToMinimumTakeoff()
    }

DonLakeFlyer's avatar
DonLakeFlyer committed
39 40
    /// Returns the user specified change in altitude from the current vehicle altitude
    function getAltitudeChangeValue() {
DonLakeFlyer's avatar
DonLakeFlyer committed
41
        return altField.newAltitudeMeters - _vehicleAltitude
42 43 44 45 46 47 48 49
    }

    function log10(value) {
        if (value === 0) {
            return 0
        } else {
            return Math.log(value) / Math.LN10
        }
DonLakeFlyer's avatar
DonLakeFlyer committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
    }

    Column {
        id:                 headerColumn
        anchors.margins:    _margins
        anchors.top:        parent.top
        anchors.left:       parent.left
        anchors.right:      parent.right

        QGCLabel {
            anchors.left:           parent.left
            anchors.right:          parent.right
            wrapMode:               Text.WordWrap
            horizontalAlignment:    Text.AlignHCenter
            text:                   qsTr("New Alt(rel)")
        }

        QGCLabel {
            id:                         altField
            anchors.horizontalCenter:   parent.horizontalCenter
Remek Zajac's avatar
Remek Zajac committed
70
            text:                       newAltitudeAppUnits + " " + QGroundControl.unitsConversion.appSettingsHorizontalDistanceUnitsString
DonLakeFlyer's avatar
DonLakeFlyer committed
71

DonLakeFlyer's avatar
DonLakeFlyer committed
72 73 74 75 76
            property real   altGainRange:           Math.max(_sliderMaxAlt - _vehicleAltitude, 0)
            property real   altLossRange:           Math.max(_vehicleAltitude - _sliderMinAlt, 0)
            property real   altExp:                 Math.pow(altSlider.value, 3)
            property real   altLossGain:            altExp * (altSlider.value > 0 ? altGainRange : altLossRange)
            property real   newAltitudeMeters:      _vehicleAltitude + altLossGain
Remek Zajac's avatar
Remek Zajac committed
77
            property string newAltitudeAppUnits:    QGroundControl.unitsConversion.metersToAppSettingsHorizontalDistanceUnits(newAltitudeMeters).toFixed(1)
78 79

            function setToMinimumTakeoff() {
Gus Grubba's avatar
Gus Grubba committed
80
                altSlider.value = Math.pow(activeVehicle.minimumTakeoffAltitude() / altGainRange, 1.0/3.0)
81
            }
DonLakeFlyer's avatar
DonLakeFlyer committed
82 83 84 85 86 87 88 89 90 91 92
        }
    }

    QGCSlider {
        id:                 altSlider
        anchors.margins:    _margins
        anchors.top:        headerColumn.bottom
        anchors.bottom:     parent.bottom
        anchors.left:       parent.left
        anchors.right:      parent.right
        orientation:        Qt.Vertical
93
        minimumValue:       _flying ? -1 : 0
94 95
        maximumValue:       1
        zeroCentered:       true
DonLakeFlyer's avatar
DonLakeFlyer committed
96 97 98 99
        rotation:           180

        // We want slide up to be positive values
        transform: Rotation {
100
            origin.x:   altSlider.width  / 2
DonLakeFlyer's avatar
DonLakeFlyer committed
101 102 103 104 105
            origin.y:   altSlider.height / 2
            angle:      180
        }
    }
}