MissionItemIndexLabel.qml 4.03 KB
Newer Older
1 2
import QtQuick                  2.3
import QtQuick.Controls         1.2
3
import QtQuick.Controls.Styles  1.4
4 5

import QGroundControl.ScreenTools 1.0
6
import QGroundControl.Palette     1.0
7

8 9
Canvas {
    id:     root
DonLakeFlyer's avatar
DonLakeFlyer committed
10 11
    width:  _width
    height: width
12

13 14
    signal clicked

DonLakeFlyer's avatar
DonLakeFlyer committed
15
    property string label
16 17 18 19
    property bool   checked:                false
    property bool   small:                  false
    property var    color:                  checked ? "green" : qgcPal.mapButtonHighlight
    property real   anchorPointX:           _width / 2
DonLakeFlyer's avatar
DonLakeFlyer committed
20
    property real   anchorPointY:           _width / 2
21
    property bool   specifiesCoordinate:    true
DonLakeFlyer's avatar
DonLakeFlyer committed
22 23 24
    property real   gimbalYaw
    property real   vehicleYaw
    property bool   showGimbalYaw:          false
25

DonLakeFlyer's avatar
DonLakeFlyer committed
26 27 28 29 30
    property real _width:           showGimbalYaw ? _gimbalYawRadius * 2 : _indicatorRadius * 2
    property bool _singleChar:      _label.text.length <= 1
    property real _gimbalYawRadius: ScreenTools.defaultFontPixelHeight
    property real _indicatorRadius: small ? (ScreenTools.defaultFontPixelHeight * ScreenTools.smallFontPointRatio * 1.25 / 2) : (ScreenTools.defaultFontPixelHeight * 0.66)
    property real _gimbalRadians:   degreesToRadians(vehicleYaw + gimbalYaw - 90)
31

DonLakeFlyer's avatar
DonLakeFlyer committed
32 33 34 35
    onColorChanged:         requestPaint()
    onShowGimbalYawChanged: requestPaint()
    onGimbalYawChanged:     requestPaint()
    onVehicleYawChanged:    requestPaint()
36 37 38

    QGCPalette { id: qgcPal }

DonLakeFlyer's avatar
DonLakeFlyer committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
    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()
        }
    }

57
    function paintSingleCoordinate(context) {
DonLakeFlyer's avatar
DonLakeFlyer committed
58
        context.beginPath()
59 60
        context.arc(_width / 2, _width / 2, _width / 2, (Math.PI / 8) * 7, Math.PI / 8);
        context.lineTo(_width / 2, _width * 1.5)
DonLakeFlyer's avatar
DonLakeFlyer committed
61 62 63
        context.closePath()
        context.fillStyle = color
        context.fill()
64 65 66
    }

    function paintSingleNoCoordinate(context) {
DonLakeFlyer's avatar
DonLakeFlyer committed
67 68 69 70 71 72 73 74
        context.save()
        context.beginPath()
        context.translate(anchorPointX, anchorPointY)
        context.arc(0, 0, _indicatorRadius, Math.PI * 2, 0);
        context.closePath()
        context.fillStyle = color
        context.fill()
        context.restore()
75 76 77 78 79 80 81 82 83 84 85 86
    }

    function paintMultipleCoordinate(context) {
        context.arc(_width / 2, _width / 2, _width / 2, (Math.PI / 8) * 7, (Math.PI / 2) * 3);
        context.lineTo(_label.width, 0)
        context.arc(_label.width, _width / 2, _width / 2, (Math.PI / 2) * 3, Math.PI / 2);
        context.lineTo((_width / 4) * 3, _width)
        context.lineTo(_width / 2, _width * 1.5)
    }

    onPaint: {
        var context = getContext("2d")
DonLakeFlyer's avatar
DonLakeFlyer committed
87 88 89
        context.clearRect(0, 0, width, height)
        paintGimbalYaw(context)
        /*
90 91 92 93 94 95 96 97 98
        if (_singleChar) {
            if (specifiesCoordinate) {
                paintSingleCoordinate(context)
            } else {
                paintSingleNoCoordinate(context)
            }
        } else {
            paintMultipleCoordinate(context)
        }
DonLakeFlyer's avatar
DonLakeFlyer committed
99 100
        */
        paintSingleNoCoordinate(context)
101 102
    }

103
    QGCLabel {
DonLakeFlyer's avatar
DonLakeFlyer committed
104 105 106 107 108 109 110 111 112 113
        id:                     _label
        anchors.centerIn:       parent
        width:                  _indicatorRadius * 2
        height:                 width
        horizontalAlignment:    Text.AlignHCenter
        verticalAlignment:      Text.AlignVCenter
        color:                  "white"
        font.pointSize:         ScreenTools.defaultFontPointSize
        fontSizeMode:           Text.HorizontalFit
        text:                   label
114
    }
115

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