Debian Codegraph @

src/imports/Lomiri/Contacts/Triangle.qml

raw
1 /*
2 * Copyright (C) 2016 Canonical, Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 import QtQuick 2.4
18
19 Canvas {
20 id: triangle
21 antialiasing: true
22
23 property color color: "#ffffff"
24 property int lineWidth: 3
25 property bool fill: false
26
27 onLineWidthChanged:requestPaint();
28 onFillChanged:requestPaint();
29
30 onPaint: {
31 var ctx = getContext("2d");
32 ctx.save();
33 ctx.clearRect(0,0,triangle.width, triangle.height);
34 ctx.strokeStyle = triangle.color;
35 ctx.lineWidth = triangle.lineWidth
36 ctx.fillStyle = triangle.color
37 ctx.globalAlpha = 1.0
38 ctx.lineJoin = "round";
39 ctx.beginPath();
40
41 ctx.translate(0, 0);
42 ctx.lineTo(0, triangle.height);
43 ctx.lineTo(triangle.width, 0.5 * triangle.height);
44 ctx.lineTo(0, 0);
45
46 if (triangle.fill)
47 ctx.fill();
48 if (triangle.stroke)
49 ctx.stroke();
50 ctx.restore();
51 }
52 }