QGCCompassWidget.qml 3.12 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
import QGroundControl.Controls 1.0
21 22
import QGroundControl.ScreenTools 1.0

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

dogmaphobic's avatar
dogmaphobic committed
26 27
    property bool active:   false  ///< true: actively connected to data provider, false: show inactive control
    property real heading:  0
dogmaphobic's avatar
dogmaphobic committed
28
    property real size:     _defaultSize
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

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

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

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

        Image {
            id:                 pointer
            source:             "/qmlimages/compassInstrumentAirplane.svg"
            mipmap:             true
            width:              size * 0.75
dogmaphobic's avatar
dogmaphobic committed
54
            sourceSize.width:   width
dogmaphobic's avatar
dogmaphobic committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
            fillMode:           Image.PreserveAspectFit
            anchors.centerIn:   parent
            transform: Rotation {
                origin.x:       pointer.width  / 2
                origin.y:       pointer.height / 2
                angle:          heading
            }
        }

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

        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 {
81
                text:           active ? heading.toFixed(0) : qsTr("OFF")
82
                font.family:    active ? ScreenTools.demiboldFontFamily : ScreenTools.normalFontFamily
83
                font.pointSize: _fontSize < 8 ? 8 : _fontSize;
dogmaphobic's avatar
dogmaphobic committed
84 85 86
                color:          "white"
                anchors.centerIn: parent
            }
87 88
        }
    }
dogmaphobic's avatar
dogmaphobic committed
89

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

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

104
}