QGCAttitudeWidget.qml 4.41 KB
Newer Older
1 2
/****************************************************************************
 *
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.
 *
 ****************************************************************************/
dogmaphobic's avatar
dogmaphobic committed
9 10 11 12


/**
 * @file
13
 *   @brief QGC Attitude Instrument
14
 *   @author Gus Grubba <gus@auterion.com>
dogmaphobic's avatar
dogmaphobic committed
15 16
 */

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
23
import QGroundControl.Palette       1.0
dogmaphobic's avatar
dogmaphobic committed
24

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

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

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

36 37 38
    width:  size
    height: size

39 40
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }

dogmaphobic's avatar
dogmaphobic committed
41 42
    Item {
        id:             instrument
43
        anchors.fill:   parent
dogmaphobic's avatar
dogmaphobic committed
44 45 46 47 48
        visible:        false

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

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

    OpacityMask {
        anchors.fill: instrument
        source: instrument
        maskSource: mask
114
    }
dogmaphobic's avatar
dogmaphobic committed
115 116 117

    Rectangle {
        id:             borderRect
118
        anchors.fill:   parent
dogmaphobic's avatar
dogmaphobic committed
119 120
        radius:         width / 2
        color:          Qt.rgba(0,0,0,0)
121 122
        border.color:   qgcPal.text
        border.width:   1
123
    }
dogmaphobic's avatar
dogmaphobic committed
124

125 126 127 128 129 130 131 132 133 134 135 136
    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
137
}