QGCCompassWidget.qml 7 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
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
Gus Grubba's avatar
Gus Grubba committed
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
    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
39 40
    property real _groundSpeed:     vehicle ? vehicle.groundSpeed.rawValue : 0
    property real _headingToNextWP: vehicle ? vehicle.headingToNextWP.rawValue : 0
41
    property real _courseOverGround:activeVehicle ? activeVehicle.gps.courseOverGround.rawValue : 0
42

43 44
    property bool usedByMultipleVehicleList:  false

45
    function isCOGAngleOK(){
46
        if(_groundSpeed < 0.5){
47 48 49
            return false
        }
        else{
50
            return vehicle && _showAdditionalIndicatorsCompass
51 52 53
        }
    }

54 55
    function isHeadingHomeOK(){
        return vehicle && _showAdditionalIndicatorsCompass && !isNaN(_headingToHome)
56 57
    }

58
    function isHeadingToNextWPOK(){
59
        return vehicle && _showAdditionalIndicatorsCompass && !isNaN(_headingToNextWP)
60 61
    }

62 63
    function isNoseUpLocked(){
        return _lockNoseUpCompass
64 65
    }

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

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

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

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

85

86
        Image {
87 88
            id:                 cOGPointer
            source:             isCOGAngleOK() ? "/qmlimages/cOGPointer.svg" : ""
89 90 91 92 93 94
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
            sourceSize.height:  parent.height

            transform: Rotation {
95
                property var _angle:isNoseUpLocked()?_courseOverGround-_heading:_courseOverGround
96 97
                origin.x:       cOGPointer.width  / 2
                origin.y:       cOGPointer.height / 2
98
                angle:         _angle
99 100 101
            }
        }

102
        Image {
103 104
            id:                 nextWPPointer
            source:             isHeadingToNextWPOK() ? "/qmlimages/compassDottedLine.svg":"" 
105 106 107 108 109 110
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
            sourceSize.height:  parent.height

            transform: Rotation {
111
                property var _angle: isNoseUpLocked()?_headingToNextWP-_heading:_headingToNextWP
112 113
                origin.x:       cOGPointer.width  / 2
                origin.y:       cOGPointer.height / 2
114
                angle:         _angle
115 116 117
            }
        }

118 119 120
        Image {
            id:                     homePointer
            width:                  size * 0.1
121
            source:                 isHeadingHomeOK()  ? "/qmlimages/Home.svg" : ""
122 123 124 125 126 127
            mipmap:                 true
            fillMode:               Image.PreserveAspectFit
            anchors.centerIn:   	parent
            sourceSize.width:       width

            transform: Translate {
128
                property double _angle: isNoseUpLocked()?-_heading+_headingToHome:_headingToHome
129 130
                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
131 132 133
            }
        }

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


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

dogmaphobic's avatar
dogmaphobic committed
165 166 167 168 169

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

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

                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
184
            }
185 186
        }
    }
dogmaphobic's avatar
dogmaphobic committed
187

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

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

202
}