Ubuntu Pastebin

Paste from rarara at Wed, 5 Aug 2015 08:22:05 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import QtQuick 2.0
import Ubuntu.Components 1.1

Item {
    id: circleContainer
    property double progress
    property int diameter
    property string text
    property string color
    width: diameter
    height: width

    Rectangle {
        id: circleOfTimeBG
        anchors.centerIn: parent
        // yes, really. The Rectangle.radius takes an absolute value and not a percentage...
        radius: diameter
        width: diameter
        height: width
        color: circleContainer.color
        gradient: circleContainer.gradient
    }

    Label {
        id: progressLabel
        anchors.centerIn: circleContainer
        text: circleContainer.text
    }

    Canvas {
        id: circleProgress
        anchors.fill: parent
        contextType: "2d"
        renderStrategy: Canvas.Immediate

        onPaint: {
            var ctx = getContext("2d")
            circleProgress.requestPaint()
            drawProgressCircle(ctx, progress)
        }

        function drawProgressCircle(ctx, progress) {

            var centreX    = width / 2
            var centreY    = width / 2
            var lineWidth  = diameter / 40
            // to start at top
            var startAngle = 1.5 * Math.PI

            ctx.beginPath()
            ctx.fillStyle = "black"
            ctx.lineWidth = lineWidth
            ctx.lineCap   = "round"
            ctx.moveTo(centreX, centreY - diameter / 2)
            // ctx.moveTo(centreX, 0);
            ctx.arc(centreX, centreY, diameter / 2 - lineWidth / 2, startAngle,
                    startAngle + 2 * progress * Math.PI, false)
            ctx.stroke()
            ctx.closePath()
        }
    }
}
Download as text