QGCCompassWidget.qml 7.12 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 39 40 41 42
    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
43

44 45
    property bool usedByMultipleVehicleList:  false

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

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

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

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

67
    readonly property bool _showAdditionalIndicatorsCompass:     QGroundControl.settingsManager.flyViewSettings.showAdditionalIndicatorsCompass.value && !usedByMultipleVehicleList
68
    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
        Image {
88 89
            id:                 cOGPointer
            source:             isCOGAngleOK() ? "/qmlimages/cOGPointer.svg" : ""
90 91 92 93 94 95
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
            sourceSize.height:  parent.height

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

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

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

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

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

135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
        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
            }
        }


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
            transform: Rotation {
                origin.x:       compassDial.width  / 2
                origin.y:       compassDial.height / 2
162
                angle:          isNoseUpLocked()?-_heading:0
163 164 165
            }
        }

dogmaphobic's avatar
dogmaphobic committed
166 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
}