Replace the clean property with a function

This commit is contained in:
Andrea Scarpino 2014-11-15 19:01:30 +01:00
parent 57864caac2
commit 8370759608

View file

@ -26,17 +26,15 @@ Page {
property int finishX; property int finishX;
property int finishY; property int finishY;
property bool clear: false
Column { Column {
anchors.fill: parent anchors.fill: parent
Row { Row {
id: menu id: menu
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
spacing: 3
// Workaround: we don't want the Slider animation! // Workaround: we don't want the Slider animation!
height: 95 height: 95
spacing: 3
IconButton { IconButton {
icon.source: "image://theme/icon-camera-focus" icon.source: "image://theme/icon-camera-focus"
@ -79,8 +77,7 @@ Page {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
onClicked: { onClicked: {
clear = true; canvas.clear();
canvas.requestPaint();
} }
} }
} }
@ -99,6 +96,13 @@ Page {
onLineWidthChanged: requestPaint() onLineWidthChanged: requestPaint()
function clear()
{
var ctx = getContext("2d");
ctx.fillRect(0, 0, width, height);
requestPaint();
}
onPaint: { onPaint: {
var ctx = getContext("2d"); var ctx = getContext("2d");
ctx.fillStyle = "#ffffff"; ctx.fillStyle = "#ffffff";
@ -108,10 +112,6 @@ Page {
ctx.miterLimit = 1; ctx.miterLimit = 1;
ctx.strokeStyle = strokeStyle; ctx.strokeStyle = strokeStyle;
if (clear === true) {
ctx.fillRect(0, 0, width, height);
clear = false;
} else {
ctx.beginPath(); ctx.beginPath();
ctx.moveTo(startX, startY); ctx.moveTo(startX, startY);
ctx.lineTo(finishX, finishY); ctx.lineTo(finishX, finishY);
@ -121,7 +121,6 @@ Page {
startX = finishX; startX = finishX;
startY = finishY; startY = finishY;
} }
}
MouseArea { MouseArea {
anchors.fill: parent anchors.fill: parent