diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-30 09:14:24 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-11-30 09:14:24 (GMT) |
commit | e927cdd850053bd59c57056b72607853783bf35f (patch) | |
tree | 168df2ed5706db8e5871d7ff01870754be248603 /examples/declarative | |
parent | bd2ba54d85415047a581b7b441309572a756dcc5 (diff) | |
download | Qt-e927cdd850053bd59c57056b72607853783bf35f.zip Qt-e927cdd850053bd59c57056b72607853783bf35f.tar.gz Qt-e927cdd850053bd59c57056b72607853783bf35f.tar.bz2 |
Two way WorkerScript communications
Diffstat (limited to 'examples/declarative')
-rw-r--r-- | examples/declarative/workerscript/workerscript.js | 16 | ||||
-rw-r--r-- | examples/declarative/workerscript/workerscript.qml | 6 |
2 files changed, 19 insertions, 3 deletions
diff --git a/examples/declarative/workerscript/workerscript.js b/examples/declarative/workerscript/workerscript.js index 060c04a..f76471f 100644 --- a/examples/declarative/workerscript/workerscript.js +++ b/examples/declarative/workerscript/workerscript.js @@ -1,5 +1,15 @@ -onmessage = function(message) { - print ("You clicked the " + message.rectangle + " rectangle."); - print ("The coordinates were: " + message.x + "," + message.y); +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/workerscript/workerscript.qml b/examples/declarative/workerscript/workerscript.qml index 3729022..e36d4d4 100644 --- a/examples/declarative/workerscript/workerscript.qml +++ b/examples/declarative/workerscript/workerscript.qml @@ -6,6 +6,12 @@ Rectangle { WorkerScript { id: myWorker source: "workerscript.js" + + onMessage: { + print("Moved " + messageObject.xmove + " along the X axis."); + print("Moved " + messageObject.ymove + " along the Y axis."); + print("Moved " + messageObject.move + " pixels."); + } } Rectangle { |