QGCCompassWidget.qml 3.14 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 17
 *   @author Gus Grubba <mavlink@grubba.com>
 */

import QtQuick 2.4
dogmaphobic's avatar
dogmaphobic committed
18 19
import QtGraphicalEffects 1.0

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 54
            mipmap:             true
            width:              size * 0.75
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:           vehicle ? _heading.toFixed(0) : qsTr("OFF")
83
                font.family:    vehicle ? ScreenTools.demiboldFontFamily : ScreenTools.normalFontFamily
84
                font.pointSize: _fontSize < 8 ? 8 : _fontSize;
dogmaphobic's avatar
dogmaphobic committed
85 86 87
                color:          "white"
                anchors.centerIn: parent
            }
88 89
        }
    }
dogmaphobic's avatar
dogmaphobic committed
90

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

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

105
}