summaryrefslogtreecommitdiff
path: root/nekowatchlet/liveview.qml
blob: c1afdbccf87898bf3d1345f780240199de4df977 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import QtQuick 1.0

Rectangle {
	color: "black"

	Neko {
		id: neko
		imageSource: "neko-inv.png"
		running: watch.active

		targetX: goal.x
		targetY: goal.y
	}

	Rectangle {
		id: goal
		width: 2
		height: 2
		color: "white"

		Behavior on x { SmoothedAnimation { velocity: 80; }}
		Behavior on y { SmoothedAnimation { velocity: 80; }}
	}

	function goToRandomPosition() {
		goal.x = 16 + Math.floor(Math.random() * (width - 32));
		goal.y = 16 + Math.floor(Math.random() * (height - 32));
	}

	function goToSleep() {
		neko.state = "SLEEPING";
	}

	Connections {
		target: watch
		onActiveChanged: {
			if (watch.active) {
				goToSleep();
			}
		}

		onButtonPressed : {
			switch (button) {
			case 1:
			case 2:
			case 3:
			case 4:
				goToRandomPosition();
				break;
			}
		}
	}
}