-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimelineRuler.qml
50 lines (41 loc) · 1.24 KB
/
TimelineRuler.qml
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
import QtQuick 2.15
Rectangle {
width: 400
height: 100
property int startYear: 0
property int endYear: 20
Canvas {
anchors.fill: parent
onPaint: {
var ctx = getContext("2d");
var w = width;
var h = height;
// 绘制背景
ctx.fillStyle = "#f8f8f8";
ctx.fillRect(0, 0, w, h);
// 绘制时间轴
ctx.strokeStyle = "#aaa";
ctx.lineWidth = 2;
ctx.beginPath();
ctx.moveTo(0, h-5);
ctx.lineTo(w, h-5);
ctx.stroke();
// 绘制刻度线
var yearCount = endYear - startYear;
var tickSpacing = w / yearCount;
for (var i = 0; i <= yearCount; i++) {
var x = i * tickSpacing;
ctx.beginPath();
ctx.moveTo(x, h - 20);
ctx.lineTo(x, h - 5);
ctx.stroke();
// 绘制年份标签
var year = startYear + i;
ctx.fillStyle = "#666";
ctx.font = "12px sans-serif";
ctx.textAlign = "center";
ctx.fillText(year.toString(), x, h/2-5);
}
}
}
}