on a6cff49 help sign in
unity8/tests/mocks/Cursor/Cursor.qml
81 lines 2.4 kB history raw
1/*
2 * Copyright (C) 2015-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 */
17import QtQuick 2.4
18import UInput 0.1
20Canvas {
21 id: root
23 property int topBoundaryOffset // effectively panel height
24 property Item confiningItem
26 signal pushedLeftBoundary(real amount, int buttons)
27 signal pushedRightBoundary(real amount, int buttons)
28 signal pushedTopBoundary(real amount, int buttons)
29 signal pushedTopLeftCorner(real amount, int buttons)
30 signal pushedTopRightCorner(real amount, int buttons)
31 signal pushedBottomLeftCorner(real amount, int buttons)
32 signal pushedBottomRightCorner(real amount, int buttons)
33 signal pushStopped()
34 signal mouseMoved()
36 width: units.gu(2)
37 height: units.gu(2)
38 antialiasing: true
40 onPaint: {
41 var ctx = getContext("2d");
42 ctx.save();
43 ctx.clearRect(0,0,width, height);
44 ctx.strokeStyle = "#000000";
45 ctx.lineWidth = 1
46 ctx.fillStyle = "#ffffff";
47 ctx.globalAlpha = 1.0;
48 ctx.lineJoin = "round";
49 ctx.beginPath();
51 // put rectangle in the middle
52 // draw the rectangle
53 ctx.moveTo(width/2,height);
54 ctx.lineTo(width, height/2);
55 ctx.lineTo(0,0);
57 ctx.closePath();
58 ctx.fill();
59 ctx.stroke();
60 ctx.restore();
61 }
63 Connections {
64 target: UInput
65 onMouseMoved: {
66 var newX = root.x;
67 newX += dx;
68 if (newX < 0) newX = 0;
69 else if (newX >= parent.width) newX = parent.width-1;
71 var newY = root.y;
72 newY += dy;
73 if (newY < 0) newY = 0;
74 else if (newY >= parent.height) newY = parent.height-1;
76 root.x = newX;
77 root.y = newY;
78 root.mouseMoved();
79 }
80 }