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
|
import QtQuick
import "." as Countdown
import ".."
// The timer's glyph: a ring with clock hands while no timer is set, a pie
// of what is left while one runs, a full one once it ran out.
Canvas {
id: root
property real size: 14
width: size
height: size
readonly property string phase: Countdown.State.phase
readonly property real fraction: phase === "done" ? 1 : Countdown.State.fraction
onFractionChanged: requestPaint()
onPhaseChanged: requestPaint()
onSizeChanged: requestPaint()
onPaint: {
const g = getContext("2d");
g.reset();
const c = width / 2, r = c - 1, line = Math.max(1.5, size / 10);
g.strokeStyle = Theme.colors.text;
g.fillStyle = Theme.colors.text;
g.lineWidth = line;
g.lineCap = "round";
g.beginPath();
g.arc(c, c, r - line / 2 + 0.5, 0, 2 * Math.PI);
g.stroke();
if (phase === "idle") {
g.beginPath();
g.moveTo(c, c); g.lineTo(c, c - r * 0.55);
g.moveTo(c, c); g.lineTo(c + r * 0.4, c);
g.stroke();
return;
}
if (fraction <= 0) return;
g.beginPath();
g.moveTo(c, c);
g.arc(c, c, r - line - size / 14, -Math.PI / 2, -Math.PI / 2 + 2 * Math.PI * fraction);
g.closePath();
g.fill();
}
}
|