QGCPitchIndicator.qml 3.38 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 13 14 15 16 17


/**
 * @file
 *   @brief QGC Pitch Indicator
 *   @author Gus Grubba <mavlink@grubba.com>
 */

import QtQuick 2.1
18
import QGroundControl.ScreenTools 1.0
19
import QGroundControl.Controls 1.0
dogmaphobic's avatar
dogmaphobic committed
20 21

Rectangle {
22 23
    property real pitchAngle:       0
    property real rollAngle:        0
dogmaphobic's avatar
dogmaphobic committed
24
    property real size:             _defaultSize
25 26 27 28 29
    property real _reticleHeight:   1
    property real _reticleSpacing:  size * 0.15
    property real _reticleSlot:     _reticleSpacing + _reticleHeight
    property real _longDash:        size * 0.40
    property real _shortDash:       size * 0.25
30
    property real _fontSize:        ScreenTools.defaultFontPointSize * (size / _defaultSize)
dogmaphobic's avatar
dogmaphobic committed
31 32

    property real _defaultSize:     ScreenTools.isAndroid ? 300 : 100
dogmaphobic's avatar
dogmaphobic committed
33

dogmaphobic's avatar
dogmaphobic committed
34
    height: size
35
    width:  size
dogmaphobic's avatar
dogmaphobic committed
36 37 38 39 40 41 42 43
    anchors.horizontalCenter: parent.horizontalCenter
    anchors.verticalCenter:   parent.verticalCenter
    clip: true
    Item {
        height: parent.height
        width:  parent.width
        Column{
            anchors.horizontalCenter: parent.horizontalCenter
dogmaphobic's avatar
dogmaphobic committed
44
            anchors.verticalCenter:   parent.verticalCenter
dogmaphobic's avatar
dogmaphobic committed
45 46 47 48
            spacing: _reticleSpacing
            Repeater {
                model: 36
                Rectangle {
dogmaphobic's avatar
dogmaphobic committed
49
                    property int _pitch: -(modelData * 5 - 90)
dogmaphobic's avatar
dogmaphobic committed
50
                    anchors.horizontalCenter: parent.horizontalCenter
51
                    width: (_pitch % 10) === 0 ? _longDash : _shortDash
dogmaphobic's avatar
dogmaphobic committed
52 53 54 55
                    height: _reticleHeight
                    color: "white"
                    antialiasing: true
                    smooth: true
56
                    QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
57
                        anchors.horizontalCenter: parent.horizontalCenter
58
                        anchors.horizontalCenterOffset: -(_longDash * 0.8)
dogmaphobic's avatar
dogmaphobic committed
59 60
                        anchors.verticalCenter: parent.verticalCenter
                        smooth: true
61
                        font.family: ScreenTools.demiboldFontFamily
62
                        font.pointSize: _fontSize < 1 ? 1 : _fontSize;
dogmaphobic's avatar
dogmaphobic committed
63
                        text: _pitch
dogmaphobic's avatar
dogmaphobic committed
64
                        color: "white"
dogmaphobic's avatar
dogmaphobic committed
65
                        visible: (_pitch != 0) && ((_pitch % 10) === 0)
dogmaphobic's avatar
dogmaphobic committed
66
                    }
67
                    QGCLabel {
dogmaphobic's avatar
dogmaphobic committed
68
                        anchors.horizontalCenter: parent.horizontalCenter
69
                        anchors.horizontalCenterOffset: (_longDash * 0.8)
dogmaphobic's avatar
dogmaphobic committed
70 71
                        anchors.verticalCenter: parent.verticalCenter
                        smooth: true
72
                        font.family: ScreenTools.demiboldFontFamily
73
                        font.pointSize: _fontSize < 1 ? 1 : _fontSize;
dogmaphobic's avatar
dogmaphobic committed
74
                        text: _pitch
dogmaphobic's avatar
dogmaphobic committed
75
                        color: "white"
dogmaphobic's avatar
dogmaphobic committed
76
                        visible: (_pitch != 0) && ((_pitch % 10) === 0)
dogmaphobic's avatar
dogmaphobic committed
77 78 79 80 81 82 83 84 85 86
                    }
                }
            }
        }
        transform: [ Translate {
                y: (pitchAngle * _reticleSlot / 5) - (_reticleSlot / 2)
                }]
    }
    transform: [
        Rotation {
87
            origin.x: width  / 2
dogmaphobic's avatar
dogmaphobic committed
88 89 90 91 92
            origin.y: height / 2
            angle:    -rollAngle
            }
    ]
}