MissionItemIndexLabel.qml 4.78 KB
Newer Older
DonLakeFlyer's avatar
DonLakeFlyer committed
1 2
import QtQuick          2.3
import QtQuick.Controls 1.2
3 4

import QGroundControl.ScreenTools 1.0
5
import QGroundControl.Palette     1.0
6

7 8
Canvas {
    id:     root
9

DonLakeFlyer's avatar
DonLakeFlyer committed
10
    width:  _width
11
    height: _height
12

13 14
    signal clicked

15
    property string label                       ///< Label to show to the side of the index indicator
16
    property int    index:                  0   ///< Index to show in the indicator, 0 will show single char label instead, -1 first char of label in indicator full label to the side
17 18 19
    property bool   checked:                false
    property bool   small:                  false
    property var    color:                  checked ? "green" : qgcPal.mapButtonHighlight
20 21
    property real   anchorPointX:           _height / 2
    property real   anchorPointY:           _height / 2
22
    property bool   specifiesCoordinate:    true
DonLakeFlyer's avatar
DonLakeFlyer committed
23 24 25
    property real   gimbalYaw
    property real   vehicleYaw
    property bool   showGimbalYaw:          false
26

DonLakeFlyer's avatar
DonLakeFlyer committed
27
    property real   _width:             showGimbalYaw ? Math.max(_gimbalYawWidth, labelControl.visible ? labelControl.width : indicator.width) : (labelControl.visible ? labelControl.width : indicator.width)
28 29 30 31 32 33 34 35
    property real   _height:            showGimbalYaw ? _gimbalYawWidth : (labelControl.visible ? labelControl.height : indicator.height)
    property real   _gimbalYawRadius:   ScreenTools.defaultFontPixelHeight
    property real   _gimbalYawWidth:    _gimbalYawRadius * 2
    property real   _indicatorRadius:   small ? (ScreenTools.defaultFontPixelHeight * ScreenTools.smallFontPointRatio * 1.25 / 2) : (ScreenTools.defaultFontPixelHeight * 0.66)
    property real   _gimbalRadians:     degreesToRadians(vehicleYaw + gimbalYaw - 90)
    property real   _labelMargin:       2
    property real   _labelRadius:       _indicatorRadius + _labelMargin
    property string _label:             index === 0 ? "" : label
36
    property string _index:             index === 0 || index === -1 ? label.charAt(0) : index
37

DonLakeFlyer's avatar
DonLakeFlyer committed
38 39 40 41
    onColorChanged:         requestPaint()
    onShowGimbalYawChanged: requestPaint()
    onGimbalYawChanged:     requestPaint()
    onVehicleYawChanged:    requestPaint()
42 43 44

    QGCPalette { id: qgcPal }

DonLakeFlyer's avatar
DonLakeFlyer committed
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
    function degreesToRadians(degrees) {
        return (Math.PI/180)*degrees
    }

    function paintGimbalYaw(context) {
        if (showGimbalYaw) {
            context.save()
            context.globalAlpha = 0.75
            context.beginPath()
            context.moveTo(anchorPointX, anchorPointY)
            context.arc(anchorPointX, anchorPointY, _gimbalYawRadius,  _gimbalRadians + degreesToRadians(45), _gimbalRadians + degreesToRadians(-45), true /* clockwise */)
            context.closePath()
            context.fillStyle = "white"
            context.fill()
            context.restore()
        }
    }

63 64
    onPaint: {
        var context = getContext("2d")
DonLakeFlyer's avatar
DonLakeFlyer committed
65 66
        context.clearRect(0, 0, width, height)
        paintGimbalYaw(context)
67 68
    }

69
    Rectangle {
DonLakeFlyer's avatar
DonLakeFlyer committed
70 71 72 73 74 75 76
        id:                     labelControl
        anchors.leftMargin:     -((_labelMargin * 2) + indicator.width)
        anchors.rightMargin:    -(_labelMargin * 2)
        anchors.fill:           labelControlLabel
        color:                  "white"
        opacity:                0.5
        radius:                 _labelRadius
77
        visible:                _label.length !== 0 && !small
78 79
    }

80
    QGCLabel {
81
        id:                     labelControlLabel
DonLakeFlyer's avatar
DonLakeFlyer committed
82 83 84 85 86 87
        anchors.topMargin:      -_labelMargin
        anchors.bottomMargin:   -_labelMargin
        anchors.leftMargin:     _labelMargin
        anchors.left:           indicator.right
        anchors.top:            indicator.top
        anchors.bottom:         indicator.bottom
DonLakeFlyer's avatar
DonLakeFlyer committed
88
        color:                  "white"
89
        text:                   _label
DonLakeFlyer's avatar
DonLakeFlyer committed
90 91
        verticalAlignment:      Text.AlignVCenter
        visible:                labelControl.visible
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
    }

    Rectangle {
        id:                             indicator
        anchors.horizontalCenter:       parent.left
        anchors.verticalCenter:         parent.top
        anchors.horizontalCenterOffset: anchorPointX
        anchors.verticalCenterOffset:   anchorPointY
        width:                          _indicatorRadius * 2
        height:                         width
        color:                          root.color
        radius:                         _indicatorRadius

        QGCLabel {
            anchors.fill:           parent
            horizontalAlignment:    Text.AlignHCenter
            verticalAlignment:      Text.AlignVCenter
            color:                  "white"
            font.pointSize:         ScreenTools.defaultFontPointSize
            fontSizeMode:           Text.HorizontalFit
            text:                   _index
        }
114
    }
115

116 117 118
    QGCMouseArea {
        fillItem:   parent
        onClicked:  parent.clicked()
119
    }
120
}