diff options
Diffstat (limited to 'examples/declarative/workerscript')
-rw-r--r-- | examples/declarative/workerscript/workerscript.js | 5 | ||||
-rw-r--r-- | examples/declarative/workerscript/workerscript.qml | 41 |
2 files changed, 46 insertions, 0 deletions
diff --git a/examples/declarative/workerscript/workerscript.js b/examples/declarative/workerscript/workerscript.js new file mode 100644 index 0000000..060c04a --- /dev/null +++ b/examples/declarative/workerscript/workerscript.js @@ -0,0 +1,5 @@ +onmessage = function(message) { + print ("You clicked the " + message.rectangle + " rectangle."); + print ("The coordinates were: " + message.x + "," + message.y); +} + diff --git a/examples/declarative/workerscript/workerscript.qml b/examples/declarative/workerscript/workerscript.qml new file mode 100644 index 0000000..3729022 --- /dev/null +++ b/examples/declarative/workerscript/workerscript.qml @@ -0,0 +1,41 @@ +import Qt 4.6 + +Rectangle { + width: 480; height: 320; + + WorkerScript { + id: myWorker + source: "workerscript.js" + } + + Rectangle { + width: 200; height: 200 + anchors.left: parent.left + anchors.leftMargin: 20 + color: "red" + + MouseRegion { + 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" + + MouseRegion { + anchors.fill: parent + onClicked: myWorker.sendMessage( { rectangle: "blue", x: mouse.x, y: mouse.y } ); + } + } + + Text { + text: "Click a Rectangle!" + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom + anchors.bottomMargin: 50 + } +} |