QGCAttitudeWidget.qml 4.32 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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9 10 11 12


/**
 * @file
13
 *   @brief QGC Attitude Instrument
dogmaphobic's avatar
dogmaphobic committed
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
import QGroundControl               1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
dogmaphobic's avatar
dogmaphobic committed
23

dogmaphobic's avatar
dogmaphobic committed
24
Item {
dogmaphobic's avatar
dogmaphobic committed
25
    id: root
26

27
    property bool showPitch:    true
28
    property var  vehicle:      null
29
    property real size
30
    property bool showHeading:  false
dogmaphobic's avatar
dogmaphobic committed
31

32 33
    property real _rollAngle:   vehicle ? vehicle.roll.rawValue  : 0
    property real _pitchAngle:  vehicle ? vehicle.pitch.rawValue : 0
34

35 36 37
    width:  size
    height: size

dogmaphobic's avatar
dogmaphobic committed
38 39
    Item {
        id:             instrument
40
        anchors.fill:   parent
dogmaphobic's avatar
dogmaphobic committed
41 42 43 44 45
        visible:        false

        //----------------------------------------------------
        //-- Artificial Horizon
        QGCArtificialHorizon {
dogmaphobic's avatar
dogmaphobic committed
46 47 48
            rollAngle:          _rollAngle
            pitchAngle:         _pitchAngle
            anchors.fill:       parent
dogmaphobic's avatar
dogmaphobic committed
49 50 51 52
        }
        //----------------------------------------------------
        //-- Pointer
        Image {
dogmaphobic's avatar
dogmaphobic committed
53 54 55 56 57 58
            id:                 pointer
            source:             "/qmlimages/attitudePointer.svg"
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
            sourceSize.height:  parent.height
dogmaphobic's avatar
dogmaphobic committed
59 60 61 62
        }
        //----------------------------------------------------
        //-- Instrument Dial
        Image {
dogmaphobic's avatar
dogmaphobic committed
63 64 65 66 67 68
            id:                 instrumentDial
            source:             "/qmlimages/attitudeDial.svg"
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
            sourceSize.height:  parent.height
dogmaphobic's avatar
dogmaphobic committed
69
            transform: Rotation {
dogmaphobic's avatar
dogmaphobic committed
70 71 72
                origin.x:       root.width  / 2
                origin.y:       root.height / 2
                angle:          -_rollAngle
dogmaphobic's avatar
dogmaphobic committed
73 74 75 76 77 78 79
            }
        }
        //----------------------------------------------------
        //-- Pitch
        QGCPitchIndicator {
            id:                 pitchWidget
            visible:            root.showPitch
dogmaphobic's avatar
dogmaphobic committed
80
            size:               root.size * 0.5
dogmaphobic's avatar
dogmaphobic committed
81 82 83 84 85 86 87 88 89 90 91 92 93
            anchors.verticalCenter: parent.verticalCenter
            pitchAngle:         _pitchAngle
            rollAngle:          _rollAngle
            color:              Qt.rgba(0,0,0,0)
        }
        //----------------------------------------------------
        //-- Cross Hair
        Image {
            id:                 crossHair
            anchors.centerIn:   parent
            source:             "/qmlimages/crossHair.svg"
            mipmap:             true
            width:              size * 0.75
dogmaphobic's avatar
dogmaphobic committed
94
            sourceSize.width:   width
dogmaphobic's avatar
dogmaphobic committed
95
            fillMode:           Image.PreserveAspectFit
96
        }
dogmaphobic's avatar
dogmaphobic committed
97
    }
dogmaphobic's avatar
dogmaphobic committed
98 99 100 101 102 103 104

    Rectangle {
        id:             mask
        anchors.fill:   instrument
        radius:         width / 2
        color:          "black"
        visible:        false
105
    }
dogmaphobic's avatar
dogmaphobic committed
106 107 108 109 110

    OpacityMask {
        anchors.fill: instrument
        source: instrument
        maskSource: mask
111
    }
dogmaphobic's avatar
dogmaphobic committed
112 113 114

    Rectangle {
        id:             borderRect
115
        anchors.fill:   parent
dogmaphobic's avatar
dogmaphobic committed
116 117 118 119
        radius:         width / 2
        color:          Qt.rgba(0,0,0,0)
        border.color:   "black"
        border.width:   2
120
    }
dogmaphobic's avatar
dogmaphobic committed
121

122 123 124 125 126 127 128 129 130 131 132 133
    QGCLabel {
        anchors.bottomMargin:       Math.round(ScreenTools.defaultFontPixelHeight * .75)
        anchors.bottom:             parent.bottom
        anchors.horizontalCenter:   parent.horizontalCenter
        text:                       _headingString3
        color:                      "white"
        visible:                    showHeading

        property string _headingString: vehicle ? vehicle.heading.rawValue.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
134
}