summaryrefslogtreecommitdiffstats
path: root/examples/declarative/threading/workerscript
diff options
context:
space:
mode:
Diffstat (limited to 'examples/declarative/threading/workerscript')
-rw-r--r--examples/declarative/threading/workerscript/workerscript.js15
-rw-r--r--examples/declarative/threading/workerscript/workerscript.qml43
-rw-r--r--examples/declarative/threading/workerscript/workerscript.qmlproject16
3 files changed, 74 insertions, 0 deletions
diff --git a/examples/declarative/threading/workerscript/workerscript.js b/examples/declarative/threading/workerscript/workerscript.js
new file mode 100644
index 0000000..f76471f
--- /dev/null
+++ b/examples/declarative/threading/workerscript/workerscript.js
@@ -0,0 +1,15 @@
+var lastx = 0;
+var lasty = 0;
+
+WorkerScript.onMessage = function(message) {
+ var ydiff = message.y - lasty;
+ var xdiff = message.x - lastx;
+
+ var total = Math.sqrt(ydiff * ydiff + xdiff * xdiff);
+
+ lastx = message.x;
+ lasty = message.y;
+
+ WorkerScript.sendMessage( {xmove: xdiff, ymove: ydiff, move: total} );
+}
+
diff --git a/examples/declarative/threading/workerscript/workerscript.qml b/examples/declarative/threading/workerscript/workerscript.qml
new file mode 100644
index 0000000..2294a81
--- /dev/null
+++ b/examples/declarative/threading/workerscript/workerscript.qml
@@ -0,0 +1,43 @@
+import Qt 4.7
+
+Rectangle {
+ width: 480; height: 320
+
+ WorkerScript {
+ id: myWorker
+ source: "workerscript.js"
+
+ onMessage: {
+ console.log("Moved " + messageObject.xmove + " along the X axis.");
+ console.log("Moved " + messageObject.ymove + " along the Y axis.");
+ console.log("Moved " + messageObject.move + " pixels.");
+ }
+ }
+
+ Rectangle {
+ width: 200; height: 200
+ anchors.left: parent.left; anchors.leftMargin: 20
+ color: "red"
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: myWorker.sendMessage( { rectangle: "red", x: mouse.x, y: mouse.y } );
+ }
+ }
+
+ Rectangle {
+ width: 200; height: 200
+ anchors.right: parent.right; anchors.rightMargin: 20
+ color: "blue"
+
+ MouseArea {
+ anchors.fill: parent
+ onClicked: myWorker.sendMessage( { rectangle: "blue", x: mouse.x, y: mouse.y } );
+ }
+ }
+
+ Text {
+ text: "Click a Rectangle!"
+ anchors { horizontalCenter: parent.horizontalCenter; bottom: parent.bottom; bottomMargin: 50 }
+ }
+}
diff --git a/examples/declarative/threading/workerscript/workerscript.qmlproject b/examples/declarative/threading/workerscript/workerscript.qmlproject
new file mode 100644
index 0000000..d4909f8
--- /dev/null
+++ b/examples/declarative/threading/workerscript/workerscript.qmlproject
@@ -0,0 +1,16 @@
+import QmlProject 1.0
+
+Project {
+ /* Include .qml, .js, and image files from current directory and subdirectories */
+ QmlFiles {
+ directory: "."
+ }
+ JavaScriptFiles {
+ directory: "."
+ }
+ ImageFiles {
+ directory: "."
+ }
+ /* List of plugin directories passed to QML runtime */
+ // importPaths: [ " ../exampleplugin " ]
+}