QGCCompassWidget.qml 7.12 KB
Newer Older
1 2
/****************************************************************************
 *
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10 11 12


/**
 * @file
13
 *   @brief QGC Compass Widget
14
 *   @author Gus Grubba <gus@auterion.com>
15 16
 */

17
import QtQuick              2.3
18
import QtGraphicalEffects   1.0
dogmaphobic's avatar
dogmaphobic committed
19

20 21 22 23 24
import QGroundControl              1.0
import QGroundControl.Controls     1.0
import QGroundControl.ScreenTools  1.0
import QGroundControl.Vehicle      1.0
import QGroundControl.Palette      1.0
25

dogmaphobic's avatar
dogmaphobic committed
26
Item {
27 28 29
    id:     root
    width:  size
    height: size
30

dogmaphobic's avatar
dogmaphobic committed
31
    property real size:     _defaultSize
32
    property var  vehicle:  null
33

34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
    property var  _activeVehicle:       QGroundControl.multiVehicleManager.activeVehicle
    property real _defaultSize:         ScreenTools.defaultFontPixelHeight * (10)
    property real _sizeRatio:           ScreenTools.isTinyScreen ? (size / _defaultSize) * 0.5 : size / _defaultSize
    property int  _fontSize:            ScreenTools.defaultFontPointSize * _sizeRatio
    property real _heading:             vehicle ? vehicle.heading.rawValue : 0
    property real _headingToHome:       vehicle ? vehicle.headingToHome.rawValue : 0
    property real _groundSpeed:         vehicle ? vehicle.groundSpeed.rawValue : 0
    property real _headingToNextWP:     vehicle ? vehicle.headingToNextWP.rawValue : 0
    property real _courseOverGround:    _activeVehicle ? _activeVehicle.gps.courseOverGround.rawValue : 0

    property bool usedByMultipleVehicleList:  false

    function isCOGAngleOK(){
        if(_groundSpeed < 0.5){
            return false
        }
        else{
            return vehicle && _showAdditionalIndicatorsCompass
        }
    }

    function isHeadingHomeOK(){
        return vehicle && _showAdditionalIndicatorsCompass && !isNaN(_headingToHome)
    }

    function isHeadingToNextWPOK(){
        return vehicle && _showAdditionalIndicatorsCompass && !isNaN(_headingToNextWP)
    }

    function isNoseUpLocked(){
        return _lockNoseUpCompass
    }

    readonly property bool _showAdditionalIndicatorsCompass:     QGroundControl.settingsManager.flyViewSettings.showAdditionalIndicatorsCompass.value && !usedByMultipleVehicleList
    readonly property bool _lockNoseUpCompass:        QGroundControl.settingsManager.flyViewSettings.lockNoseUpCompass.value
69

70
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
dogmaphobic's avatar
dogmaphobic committed
71

72
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
73 74 75
        id:             borderRect
        anchors.fill:   parent
        radius:         width / 2
76 77 78
        color:          qgcPal.window
        border.color:   qgcPal.text
        border.width:   1
79
    }
dogmaphobic's avatar
dogmaphobic committed
80 81 82 83 84 85

    Item {
        id:             instrument
        anchors.fill:   parent
        visible:        false

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134

        Image {
            id:                 cOGPointer
            source:             isCOGAngleOK() ? "/qmlimages/cOGPointer.svg" : ""
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
            sourceSize.height:  parent.height

            transform: Rotation {
                property var _angle:isNoseUpLocked()?_courseOverGround-_heading:_courseOverGround
                origin.x:       cOGPointer.width  / 2
                origin.y:       cOGPointer.height / 2
                angle:         _angle
            }
        }

        Image {
            id:                 nextWPPointer
            source:             isHeadingToNextWPOK() ? "/qmlimages/compassDottedLine.svg":"" 
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
            sourceSize.height:  parent.height

            transform: Rotation {
                property var _angle: isNoseUpLocked()?_headingToNextWP-_heading:_headingToNextWP
                origin.x:       cOGPointer.width  / 2
                origin.y:       cOGPointer.height / 2
                angle:         _angle
            }
        }

        Image {
            id:                     homePointer
            width:                  size * 0.1
            source:                 isHeadingHomeOK()  ? "/qmlimages/Home.svg" : ""
            mipmap:                 true
            fillMode:               Image.PreserveAspectFit
            anchors.centerIn:   	parent
            sourceSize.width:       width

            transform: Translate {
                property double _angle: isNoseUpLocked()?-_heading+_headingToHome:_headingToHome
                x: size/2.3 * Math.sin((_angle)*(3.14/180))
                y: - size/2.3 * Math.cos((_angle)*(3.14/180))
            }
        }

dogmaphobic's avatar
dogmaphobic committed
135 136
        Image {
            id:                 pointer
137
            width:              size * 0.65
138
            source:             vehicle ? vehicle.vehicleImageCompass : ""
dogmaphobic's avatar
dogmaphobic committed
139
            mipmap:             true
dogmaphobic's avatar
dogmaphobic committed
140
            sourceSize.width:   width
dogmaphobic's avatar
dogmaphobic committed
141 142 143 144 145
            fillMode:           Image.PreserveAspectFit
            anchors.centerIn:   parent
            transform: Rotation {
                origin.x:       pointer.width  / 2
                origin.y:       pointer.height / 2
146
                angle:          isNoseUpLocked()?0:_heading
dogmaphobic's avatar
dogmaphobic committed
147 148 149
            }
        }

150

151
        QGCColoredImage {
dogmaphobic's avatar
dogmaphobic committed
152 153 154 155 156
            id:                 compassDial
            source:             "/qmlimages/compassInstrumentDial.svg"
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
dogmaphobic's avatar
dogmaphobic committed
157
            sourceSize.height:  parent.height
158
            color:              qgcPal.text
159 160 161 162 163
            transform: Rotation {
                origin.x:       compassDial.width  / 2
                origin.y:       compassDial.height / 2
                angle:          isNoseUpLocked()?-_heading:0
            }
dogmaphobic's avatar
dogmaphobic committed
164 165
        }

166

dogmaphobic's avatar
dogmaphobic committed
167 168 169 170
        Rectangle {
            anchors.centerIn:   parent
            width:              size * 0.35
            height:             size * 0.2
171 172 173
            border.color:       qgcPal.text
            color:              qgcPal.window
            opacity:            0.65
dogmaphobic's avatar
dogmaphobic committed
174 175

            QGCLabel {
176 177 178 179 180
                text:               _headingString3
                font.family:        vehicle ? ScreenTools.demiboldFontFamily : ScreenTools.normalFontFamily
                font.pointSize:     _fontSize < 8 ? 8 : _fontSize;
                color:              qgcPal.text
                anchors.centerIn:   parent
181 182 183 184

                property string _headingString: vehicle ? _heading.toFixed(0) : "OFF"
                property string _headingString2: _headingString.length === 1 ? "0" + _headingString : _headingString
                property string _headingString3: _headingString2.length === 2 ? "0" + _headingString2 : _headingString2
dogmaphobic's avatar
dogmaphobic committed
185
            }
186 187
        }
    }
dogmaphobic's avatar
dogmaphobic committed
188

189
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
190 191 192 193 194
        id:             mask
        anchors.fill:   instrument
        radius:         width / 2
        color:          "black"
        visible:        false
195
    }
dogmaphobic's avatar
dogmaphobic committed
196 197 198 199 200 201 202

    OpacityMask {
        anchors.fill:   instrument
        source:         instrument
        maskSource:     mask
    }

203
}