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

    function isHeadingAngleOK(){
53
        return vehicle && _showHomeHeadingCompass && !isNaN(_headingToHome)
54 55
    }

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

    function isNorthUpLocked(){
        return _lockNorthUpCompass
62 63
    }

64
    readonly property bool _showHomeHeadingCompass:     QGroundControl.settingsManager.flyViewSettings.showHomeHeadingCompass.value
65
    readonly property bool _showCOGAngleCompass:        QGroundControl.settingsManager.flyViewSettings.showCOGAngleCompass.value
66 67
    readonly property bool _showHeadingToNextWP:        QGroundControl.settingsManager.flyViewSettings.showHeadingToNextWP.value
    readonly property bool _lockNorthUpCompass:        QGroundControl.settingsManager.flyViewSettings.lockNorthUpCompass.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 87 88 89 90 91 92 93
        Image {
            id:                 nextWPPointer
            source:             isHeadingToNextWPOK() ? "/qmlimages/compassDottedLine.svg":"" 
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
            sourceSize.height:  parent.height

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

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

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

dogmaphobic's avatar
dogmaphobic committed
117 118
        Image {
            id:                 pointer
119
            width:              size * 0.65
120
            source:             vehicle ? vehicle.vehicleImageCompass : ""
dogmaphobic's avatar
dogmaphobic committed
121
            mipmap:             true
dogmaphobic's avatar
dogmaphobic committed
122
            sourceSize.width:   width
dogmaphobic's avatar
dogmaphobic committed
123 124
            fillMode:           Image.PreserveAspectFit
            anchors.centerIn:   parent
125 126 127 128 129
            transform: Rotation {
                origin.x:       pointer.width  / 2
                origin.y:       pointer.height / 2
                angle:          isNorthUpLocked()?0:_heading
            }
130 131 132 133 134
        }

        Image {
            id:                     homePointer
            width:                  size * 0.1
135
            source:                 isHeadingAngleOK()  ? "/qmlimages/Home.svg" : ""
136 137 138 139
            mipmap:                 true
            fillMode:               Image.PreserveAspectFit
            anchors.centerIn:   	parent
            sourceSize.width:       width
140
            visible:                _showHomeHeadingCompass
141 142

            transform: Translate {
143 144 145
                property double _angle: isNorthUpLocked()?-_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
146 147 148
            }
        }

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

dogmaphobic's avatar
dogmaphobic committed
164 165 166 167 168

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

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

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

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

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

201
}