QGCCompassWidget.qml 6.92 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 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.
 *
 ****************************************************************************/
9 10 11 12


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

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
    function isCOGAngleOK(){
44
        if(_groundSpeed < 0.5 && _showAdditionalIndicatorsCompass){
45 46 47
            return false
        }
        else{
48
            return vehicle
49 50 51
        }
    }

52 53
    function isHeadingHomeOK(){
        return vehicle && _showAdditionalIndicatorsCompass && !isNaN(_headingToHome)
54 55
    }

56
    function isHeadingToNextWPOK(){
57
        return vehicle && _showAdditionalIndicatorsCompass && !isNaN(_headingToNextWP)
58 59
    }

60 61
    function isNoseUpLocked(){
        return _lockNoseUpCompass
62 63
    }

64
    readonly property bool _showAdditionalIndicatorsCompass:     QGroundControl.settingsManager.flyViewSettings.showAdditionalIndicatorsCompass.value
65
    readonly property bool _lockNoseUpCompass:        QGroundControl.settingsManager.flyViewSettings.lockNoseUpCompass.value
66

67
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
dogmaphobic's avatar
dogmaphobic committed
68

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

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

83

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

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

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

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

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

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

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
        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
            }
        }


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

dogmaphobic's avatar
dogmaphobic committed
163 164 165 166 167

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

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

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

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

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

200
}