| 1 |
/* |
| 2 |
* Copyright 2014-2015 Canonical Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU Lesser 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 Lesser General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU Lesser General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
import QtQuick 2.15 |
| 18 |
|
| 19 |
Rectangle { |
| 20 |
id: root |
| 21 |
color: "pink" |
| 22 |
|
| 23 |
property alias screenshotSource: screenshotImage.source |
| 24 |
property int orientationAngle |
| 25 |
|
| 26 |
property var touchTrail |
| 27 |
onTouchTrailChanged: canvas.requestPaint() |
| 28 |
|
| 29 |
Image { |
| 30 |
id: screenshotImage |
| 31 |
anchors.fill: parent |
| 32 |
fillMode: Image.Stretch |
| 33 |
} |
| 34 |
|
| 35 |
Text { |
| 36 |
text: surfaceText.text |
| 37 |
color: "black" |
| 38 |
font: surfaceText.font |
| 39 |
fontSizeMode: Text.Fit |
| 40 |
minimumPixelSize: 10 |
| 41 |
verticalAlignment: Text.AlignVCenter |
| 42 |
rotation: surfaceText.rotation |
| 43 |
x: surfaceText.x |
| 44 |
y: surfaceText.y |
| 45 |
width: surfaceText.width |
| 46 |
height: surfaceText.height |
| 47 |
clip: true |
| 48 |
|
| 49 |
transform: Translate { x: -2; y: -2 } |
| 50 |
} |
| 51 |
Text { |
| 52 |
id: surfaceText |
| 53 |
text: "SURFACE " + root.width + "," + root.height |
| 54 |
color: root.parent && root.parent.activeFocus ? "yellow" : "blue" |
| 55 |
font.bold: true |
| 56 |
fontSizeMode: Text.Fit |
| 57 |
minimumPixelSize: 10; font.pixelSize: 200 |
| 58 |
verticalAlignment: Text.AlignVCenter |
| 59 |
clip: true |
| 60 |
|
| 61 |
rotation: root.orientationAngle |
| 62 |
x: (parent.width - width) / 2 |
| 63 |
y: (parent.height - height) / 2 |
| 64 |
width: (rotation == 0 || rotation == 180 ? parent.width : parent.height) |
| 65 |
height:(rotation == 0 || rotation == 180 ? parent.height : parent.width) |
| 66 |
} |
| 67 |
|
| 68 |
Canvas { |
| 69 |
id: canvas |
| 70 |
anchors.fill: parent |
| 71 |
onPaint: { |
| 72 |
// get context to draw with |
| 73 |
var ctx = getContext("2d") |
| 74 |
ctx.reset(0, 0, canvas.width, canvas.height); |
| 75 |
ctx.lineWidth = 20; |
| 76 |
|
| 77 |
if (touchTrail === undefined) return; |
| 78 |
|
| 79 |
var i = 0; |
| 80 |
for (var prop in touchTrail) { |
| 81 |
var trail = touchTrail[prop]; |
| 82 |
|
| 83 |
if (trail.length > 0) { |
| 84 |
ctx.fillStyle = Qt.rgba(0, 0, 1, 0.3); |
| 85 |
ctx.strokeStyle = Qt.rgba(0, 0, 1, 0.3); |
| 86 |
ctx.beginPath(); |
| 87 |
ctx.moveTo(trail[0].x, trail[0].y); |
| 88 |
ctx.ellipse(trail[0].x-1, trail[0].y-1, 2, 2); |
| 89 |
ctx.stroke(); |
| 90 |
|
| 91 |
ctx.beginPath(); |
| 92 |
if (i == 0) { |
| 93 |
ctx.strokeStyle = Qt.rgba(1, 1, 0, 0.3); |
| 94 |
} else if (i == 1) { |
| 95 |
ctx.strokeStyle = Qt.rgba(0, 1, 1, 0.3); |
| 96 |
|
| 97 |
} else if (i == 2) { |
| 98 |
ctx.strokeStyle = Qt.rgba(1, 0, 1, 0.3); |
| 99 |
|
| 100 |
} else if (i == 3) { |
| 101 |
ctx.strokeStyle = Qt.rgba(0, 0.5, 0.5, 0.3); |
| 102 |
|
| 103 |
} else { |
| 104 |
ctx.strokeStyle = Qt.rgba(0.7, 0.5, 0, 0.3); |
| 105 |
} |
| 106 |
|
| 107 |
for (var i = 1; i < trail.length; i++) { |
| 108 |
ctx.lineTo(trail[i].x, trail[i].y) |
| 109 |
} |
| 110 |
ctx.stroke(); |
| 111 |
|
| 112 |
ctx.beginPath(); |
| 113 |
ctx.fillStyle = Qt.rgba(1, 0, 0, 0.3); |
| 114 |
ctx.strokeStyle = Qt.rgba(1, 0, 0, 0.3); |
| 115 |
ctx.ellipse(trail[i-1].x-1, trail[i-1].y-1, 2, 2); |
| 116 |
ctx.stroke(); |
| 117 |
} |
| 118 |
i++; |
| 119 |
} |
| 120 |
|
| 121 |
} |
| 122 |
} |
| 123 |
} |