QGCCompassWidget.qml 3.65 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
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Vehicle       1.0
23
import QGroundControl.Palette       1.0
24

dogmaphobic's avatar
dogmaphobic committed
25
Item {
26 27 28
    id:     root
    width:  size
    height: size
29

dogmaphobic's avatar
dogmaphobic committed
30
    property real size:     _defaultSize
31
    property var  vehicle:  null
32

33
    property real _defaultSize: ScreenTools.defaultFontPixelHeight * (10)
dogmaphobic's avatar
dogmaphobic committed
34
    property real _sizeRatio:   ScreenTools.isTinyScreen ? (size / _defaultSize) * 0.5 : size / _defaultSize
35
    property int  _fontSize:    ScreenTools.defaultFontPointSize * _sizeRatio
36
    property real _heading:     vehicle ? vehicle.heading.rawValue : 0
37

38
    QGCPalette { id: qgcPal; colorGroupEnabled: enabled }
dogmaphobic's avatar
dogmaphobic committed
39

40
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
41 42 43
        id:             borderRect
        anchors.fill:   parent
        radius:         width / 2
44 45 46
        color:          qgcPal.window
        border.color:   qgcPal.text
        border.width:   1
47
    }
dogmaphobic's avatar
dogmaphobic committed
48 49 50 51 52 53 54 55

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

        Image {
            id:                 pointer
56
            width:              size * 0.65
57
            source:             vehicle ? vehicle.vehicleImageCompass : ""
dogmaphobic's avatar
dogmaphobic committed
58
            mipmap:             true
dogmaphobic's avatar
dogmaphobic committed
59
            sourceSize.width:   width
dogmaphobic's avatar
dogmaphobic committed
60 61 62 63 64
            fillMode:           Image.PreserveAspectFit
            anchors.centerIn:   parent
            transform: Rotation {
                origin.x:       pointer.width  / 2
                origin.y:       pointer.height / 2
65
                angle:          _heading
dogmaphobic's avatar
dogmaphobic committed
66 67 68
            }
        }

69
        QGCColoredImage {
dogmaphobic's avatar
dogmaphobic committed
70 71 72 73 74
            id:                 compassDial
            source:             "/qmlimages/compassInstrumentDial.svg"
            mipmap:             true
            fillMode:           Image.PreserveAspectFit
            anchors.fill:       parent
dogmaphobic's avatar
dogmaphobic committed
75
            sourceSize.height:  parent.height
76
            color:              qgcPal.text
dogmaphobic's avatar
dogmaphobic committed
77 78 79 80 81 82
        }

        Rectangle {
            anchors.centerIn:   parent
            width:              size * 0.35
            height:             size * 0.2
83 84 85
            border.color:       qgcPal.text
            color:              qgcPal.window
            opacity:            0.65
dogmaphobic's avatar
dogmaphobic committed
86 87

            QGCLabel {
88 89 90 91 92
                text:               _headingString3
                font.family:        vehicle ? ScreenTools.demiboldFontFamily : ScreenTools.normalFontFamily
                font.pointSize:     _fontSize < 8 ? 8 : _fontSize;
                color:              qgcPal.text
                anchors.centerIn:   parent
93 94 95 96

                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
97
            }
98 99
        }
    }
dogmaphobic's avatar
dogmaphobic committed
100

101
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
102 103 104 105 106
        id:             mask
        anchors.fill:   instrument
        radius:         width / 2
        color:          "black"
        visible:        false
107
    }
dogmaphobic's avatar
dogmaphobic committed
108 109 110 111 112 113 114

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

115
}