QGCCompassWidget.qml 3.44 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

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

dogmaphobic's avatar
dogmaphobic committed
27
    property real size:     _defaultSize
28
    property var  vehicle:  null
29

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

35 36
    width:                  size
    height:                 size
dogmaphobic's avatar
dogmaphobic committed
37

38
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
39 40 41
        id:             borderRect
        anchors.fill:   parent
        radius:         width / 2
dogmaphobic's avatar
dogmaphobic committed
42
        color:          "black"
43
    }
dogmaphobic's avatar
dogmaphobic committed
44 45 46 47 48 49 50 51

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

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

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

        Rectangle {
            anchors.centerIn:   parent
            width:              size * 0.35
            height:             size * 0.2
            border.color:       Qt.rgba(1,1,1,0.15)
            color:              Qt.rgba(0,0,0,0.65)

            QGCLabel {
82
                text:           _headingString3
83
                font.family:    vehicle ? ScreenTools.demiboldFontFamily : ScreenTools.normalFontFamily
84
                font.pointSize: _fontSize < 8 ? 8 : _fontSize;
dogmaphobic's avatar
dogmaphobic committed
85 86
                color:          "white"
                anchors.centerIn: parent
87 88 89 90

                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
91
            }
92 93
        }
    }
dogmaphobic's avatar
dogmaphobic committed
94

95
    Rectangle {
dogmaphobic's avatar
dogmaphobic committed
96 97 98 99 100
        id:             mask
        anchors.fill:   instrument
        radius:         width / 2
        color:          "black"
        visible:        false
101
    }
dogmaphobic's avatar
dogmaphobic committed
102 103 104 105 106 107 108

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

109
}