~jocave/checkbox/hybrid-amd-gpu-mods

« back to all changes in this revision

Viewing changes to providers/2015.com.canonical.certification:qml-tests/data/screen-08.qml

  • Committer: Sylvain Pineau
  • Date: 2014-07-29 16:05:54 UTC
  • mto: This revision was merged to the branch mainline in revision 3149.
  • Revision ID: sylvain.pineau@canonical.com-20140729160554-qev8887xbunn9tmi
checkbox-ng:launchers:checkbox-cli: The checkbox-cli launcher

Running the default whitelist (with the suite selection screen skipped)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * This file is part of Checkbox.
3
 
 *
4
 
 * Copyright 2015 Canonical Ltd.
5
 
 * Written by:
6
 
 *   Maciej Kisielewski <maciej.kisielewski@canonical.com>
7
 
 *
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.
11
 
 *
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.
16
 
 *
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/>.
19
 
 */
20
 
import QtQuick 2.0
21
 
import Ubuntu.Components 1.1
22
 
import QtGraphicalEffects 1.0
23
 
import QtQuick.Window 2.1
24
 
import QtQuick.Layouts 1.1
25
 
import Plainbox 0.1
26
 
 
27
 
QmlJob {
28
 
    id: root
29
 
 
30
 
    anchors.fill: parent
31
 
 
32
 
    Page {
33
 
        Canvas {
34
 
            id: canvas
35
 
            anchors.fill: parent
36
 
 
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)
42
 
 
43
 
            onPaint: {
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(' ');
49
 
                    var fittingLine = '';
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] + ' ';
56
 
                            textY += textHeight;
57
 
                        } else {
58
 
                            fittingLine = currentLine;
59
 
                        }
60
 
                    }
61
 
                    ctx.fillText(fittingLine, textX, textY);
62
 
                }
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") {
69
 
                    // clear the canvas
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);
75
 
                }
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;
88
 
                        pixelsLeft--;
89
 
                    }
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));
93
 
                    ctx.fillStyle=grd;
94
 
 
95
 
                    ctx.fillRect(x-radius, y-radius, radius*2, radius*2);
96
 
 
97
 
                    if (pixelsLeft < 1) {
98
 
                        state = "finished";
99
 
                    }
100
 
                }
101
 
                if (state==="finished") {
102
 
                    ctx.shadowColor = "black"
103
 
                    ctx.shadowBlur = 5;
104
 
                    ctx.fillStyle = "green"
105
 
                    ctx.strokeStyle = "green"
106
 
                    ctx.fillText(i18n.tr("Done"), textX, textY);
107
 
                    closingDelay.start();
108
 
                    return;
109
 
                }
110
 
            }
111
 
            Timer {
112
 
                id: closingDelay
113
 
                interval: 2000
114
 
                onTriggered: {
115
 
                    testDone({'outcome':'pass'});
116
 
                }
117
 
            }
118
 
            MouseArea {
119
 
                id: area
120
 
                anchors.fill: parent
121
 
                onPositionChanged: {
122
 
                    if (canvas.state === "preparing") {
123
 
                        canvas.state = "painting";
124
 
                    }
125
 
                    canvas.requestPaint();
126
 
                }
127
 
                Timer {
128
 
                    id: tripleClickTimeout
129
 
                    interval: 250
130
 
 
131
 
                    property var clickCount: 0
132
 
                    onTriggered: {
133
 
                        clickCount = 0;
134
 
                        stop();
135
 
                    }
136
 
                }
137
 
                onPressed: {
138
 
                    tripleClickTimeout.restart();
139
 
                    if (++tripleClickTimeout.clickCount > 2) {
140
 
                        testDone({'outcome':'fail'});
141
 
                        tripleClickTimeout.stop();
142
 
                        tripleClickTimeout.clickCount = 0;
143
 
                    }
144
 
                }
145
 
            }
146
 
        }
147
 
    }
148
 
}