2
* This file is part of Checkbox.
4
* Copyright 2015 Canonical Ltd.
6
* Maciej Kisielewski <maciej.kisielewski@canonical.com>
8
* Checkbox is free software: you can redistribute it and/or modify
9
* it under the terms of the GNU General Public License version 3,
10
* as published by the Free Software Foundation.
12
* Checkbox is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with Checkbox. If not, see <http://www.gnu.org/licenses/>.
21
import Ubuntu.Components 1.1
22
import QtGraphicalEffects 1.0
23
import QtQuick.Window 2.1
24
import QtQuick.Layouts 1.1
37
property var state: "preparing"
38
property var visited: []
39
property var radius: Screen.pixelDensity * 20
40
property var visitedRadius: Math.round(radius / 1.3)
41
property var pixelsLeft: Math.round(canvas.height / visitedRadius * canvas.width / visitedRadius)
44
function textFillWrap(text, textX, textY, maxWidth, textHeight) {
45
// print text at textX and textY and split into multiple
46
// lines if text would exceed maxWidth. Every next line is
47
// drawn textHeight lower.
48
var words = text.split(' ');
50
for (var i = 0; i< words.length; i++) {
51
var currentLine = fittingLine + words[i] + ' ';
52
var currentWidth = ctx.measureText(currentLine).width;
53
if (i > 0 && currentWidth > maxWidth) {
54
ctx.fillText(fittingLine, textX, textY);
55
fittingLine = words[i] + ' ';
58
fittingLine = currentLine;
61
ctx.fillText(fittingLine, textX, textY);
63
var ctx = getContext('2d');
64
var textX = canvas.width / 2, textY = canvas.height / 2;
65
var fontSize = radius / 2;
66
ctx.font="%1px sans-serif".arg(fontSize);
67
ctx.textAlign = "center"
68
if (state==="preparing") {
70
ctx.fillStyle = "black";
71
ctx.fillRect(0, 0, canvas.width, canvas.height);
72
// draw the intruction text
73
ctx.fillStyle = "white";
74
textFillWrap(i18n.tr("Paint on the screen until fully covered with pink. Triple tap to quit"), textX, textY, canvas.width, fontSize);
76
if (state==="painting") {
77
var x = area.mouseX, y = area.mouseY;
78
// it's possible to go to negative values, or values beyond
79
// canvas size, by pressing and dragging outside the
80
// window (desktop). Let's cap the values
81
x = Math.max(0, x); x = Math.min(x, canvas.width);
82
y = Math.max(0, y); y = Math.min(y, canvas.height);
83
var visitedX = Math.floor(x / visitedRadius);
84
var visitedY = Math.floor(y / visitedRadius);
85
var visitedWidth = canvas.width / visitedRadius;
86
if (!visited[visitedWidth * visitedY + visitedX]) {
87
visited[visitedWidth * visitedY + visitedX] = true;
90
var grd=ctx.createRadialGradient(x, y, 0, x, y, radius);
91
grd.addColorStop(0, "#FF00FF");
92
grd.addColorStop(1, Qt.rgba(255, 0, 255, 0));
95
ctx.fillRect(x-radius, y-radius, radius*2, radius*2);
101
if (state==="finished") {
102
ctx.shadowColor = "black"
104
ctx.fillStyle = "green"
105
ctx.strokeStyle = "green"
106
ctx.fillText(i18n.tr("Done"), textX, textY);
107
closingDelay.start();
115
testDone({'outcome':'pass'});
122
if (canvas.state === "preparing") {
123
canvas.state = "painting";
125
canvas.requestPaint();
128
id: tripleClickTimeout
131
property var clickCount: 0
138
tripleClickTimeout.restart();
139
if (++tripleClickTimeout.clickCount > 2) {
140
testDone({'outcome':'fail'});
141
tripleClickTimeout.stop();
142
tripleClickTimeout.clickCount = 0;