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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| import QtQuick 2.4
Canvas {
id: canvas
width: 500; height: 400
transform: Rotation { origin.x: 0; origin.y: height/2; angle: 180; axis { x: 1; y: 0; z: 0 }}
property var myCtx
property real lastX
property real lastY
signal toto
signal mouseChange
signal mouseExit
property var lst : [
{"x":"0","y":"122"},
{"x":"20","y":"120"},
{"x":"40","y":"116"},
{"x":"60","y":"112"},
{"x":"80","y":"104"},
{"x":"100","y":"96"},
{"x":"120","y":"86"},
{"x":"140","y":"76"},
{"x":"160","y":"60"},
{"x":"180","y":"44"},
{"x":"200","y":"20"}]
onToto: {
for (var i = 0; i < lst.length; i++) {
var posiX = lst[i]["x"]
var posiY = lst[i]["y"]
myCtx.lineTo(posiX, posiY)
}
}
Path {
id: myAxis
startX: 20; startY: 20
PathLine { x: 20 ; y: 300 }
PathLine { x: 20 ; y: 20 }
PathLine { x: 450 ; y: 20 }
PathLine { x: 20 ; y: 20 }
}
onPaint: {
lastX = area.mouseX
lastY = area.mouseY
var ctx = getContext("2d")
myCtx = ctx
myCtx.lineWidth = 1
myCtx.strokeStyle = "blue"
myCtx.fillStyle = "transparent"
myCtx.beginPath()
toto()
myCtx.fill()
myCtx.stroke()
context.strokeStyle = Qt.rgba(0,0,1);
context.path = myAxis
context.stroke()
}
MouseArea {
id: area
anchors.fill: parent
hoverEnabled : true
onExited: mouseExit()
onPressed: {
canvas.lastX = mouseX
canvas.lastY = mouseY
}
onPositionChanged: {
canvas.requestPaint()
mouseChange()
}
}
} |
Partager