import QtQuick 2.0
Rectangle
{
id: root
width: 200
height: 100
color: "red"
Canvas
{
id: canvas
anchors.fill: parent
onPaint:
{
var top_gap = 10;
var top_radius = 10
var bottom_gap = 15; //==bottom_radius;
var x0 = 0;
var y0 = canvas.height;
var x1 = bottom_gap;
var y1 = canvas.height;
var x2 = bottom_gap;
var y2 = canvas.height-bottom_gap;
var ctx = getContext('2d');
ctx.strokeStyle = "black"
ctx.beginPath();
ctx.moveTo(x0,y0);
ctx.arcTo(x1,y1,x2,y2,bottom_gap); x0=bottom_gap; y0=top_gap+top_radius;
ctx.lineTo(x0,y0); x1=x0; y1=top_gap; x2=x1+top_radius; y2=y1;
ctx.arcTo(x1,y1,x2,y2,top_radius); x0=canvas.width-bottom_gap-top_radius; y0=y2;
ctx.lineTo(x0,y0); x1=x0+top_radius; y1=y0; x2=x1; y2=y1+top_radius;
ctx.arcTo(x1,y1,x2,y2,top_radius); x0=x2; y0=canvas.height-bottom_gap;
ctx.lineTo(x0,y0); x1=x0; y1=canvas.height; x2=canvas.width; y2=y1;
ctx.arcTo(x1,y1,x2,y2,bottom_gap);
ctx.closePath();
ctx.stroke();
}
}
}
评论