QGCCompassWidget.qml 6.39 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 48 49 50 51 52 53 54 55
    function isCOGAngleOK(){
        if(_groundSpeed < 0.5 && _showCOGAngleCompass){
            return false
        }
        else{
            return true
        }
    }

    function isHeadingAngleOK(){
        return _showHomeHeadingCompass && !isNaN(_headingToHome)
    }

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

60
    readonly property bool _showHomeHeadingCompass:     QGroundControl.settingsManager.flyViewSettings.showHomeHeadingCompass.value
61 62
    readonly property bool _showCOGAngleCompass:        QGroundControl.settingsManager.flyViewSettings.showCOGAngleCompass.value

63
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
dogmaphobic's avatar
dogmaphobic committed
64

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

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

79 80 81 82 83 84 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 {
                origin.x:       cOGPointer.width  / 2
                origin.y:       cOGPointer.height / 2
                angle:         _headingToNextWP - _heading
            }
        }

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

            transform: Rotation {
                origin.x:       cOGPointer.width  / 2
                origin.y:       cOGPointer.height / 2
                angle:         _courseOverGround - _heading
            }
        }

dogmaphobic's avatar
dogmaphobic committed
109 110
        Image {
            id:                 pointer
111
            width:              size * 0.65
112
            source:             vehicle ? vehicle.vehicleImageCompass : ""
dogmaphobic's avatar
dogmaphobic committed
113
            mipmap:             true
dogmaphobic's avatar
dogmaphobic committed
114
            sourceSize.width:   width
dogmaphobic's avatar
dogmaphobic committed
115 116
            fillMode:           Image.PreserveAspectFit
            anchors.centerIn:   parent
117 118 119 120 121
        }

        Image {
            id:                     homePointer
            width:                  size * 0.1
122
            source:                 isHeadingAngleOK()  ? "/qmlimages/Home.svg" : ""
123 124 125 126
            mipmap:                 true
            fillMode:               Image.PreserveAspectFit
            anchors.centerIn:   	parent
            sourceSize.width:       width
127
            visible:                _showHomeHeadingCompass
128 129 130 131

            transform: Translate {
                x: size/2.3 * Math.sin((-_heading + _headingToHome)*(3.14/180))
                y: - size/2.3 * Math.cos((-_heading + _headingToHome)*(3.14/180))
dogmaphobic's avatar
dogmaphobic committed
132 133 134
            }
        }

135
        QGCColoredImage {
dogmaphobic's avatar
dogmaphobic committed
136 137 138 139 140
            id:                 compassDial
            source:             "/qmlimages/compassInstrumentDial.svg"
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
dogmaphobic's avatar
dogmaphobic committed
141
            sourceSize.height:  parent.height
142
            color:              qgcPal.text
143 144 145 146 147 148 149
            transform: Rotation {
                origin.x:       compassDial.width  / 2
                origin.y:       compassDial.height / 2
                angle:          -_heading
            }
        }

dogmaphobic's avatar
dogmaphobic committed
150 151 152 153 154

        Rectangle {
            anchors.centerIn:   parent
            width:              size * 0.35
            height:             size * 0.2
155 156 157
            border.color:       qgcPal.text
            color:              qgcPal.window
            opacity:            0.65
dogmaphobic's avatar
dogmaphobic committed
158 159

            QGCLabel {
160 161 162 163 164
                text:               _headingString3
                font.family:        vehicle ? ScreenTools.demiboldFontFamily : ScreenTools.normalFontFamily
                font.pointSize:     _fontSize < 8 ? 8 : _fontSize;
                color:              qgcPal.text
                anchors.centerIn:   parent
165 166 167 168

                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
169
            }
170 171
        }
    }
dogmaphobic's avatar
dogmaphobic committed
172

173
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
174 175 176 177 178
        id:             mask
        anchors.fill:   instrument
        radius:         width / 2
        color:          "black"
        visible:        false
179
    }
dogmaphobic's avatar
dogmaphobic committed
180 181 182 183 184 185 186

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

187
}