diff options
author | Bea Lam <bea.lam@nokia.com> | 2010-05-14 01:32:57 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2010-05-16 23:42:12 (GMT) |
commit | 82d0b03c4f81c2832975d548917c03dbaddeee72 (patch) | |
tree | cb2d7ae0c7c8c5870f4c9439453c938a9423afad /examples/declarative/threading | |
parent | 0aca20bf669ef7e7702ee96d0d0676392cfd1b72 (diff) | |
download | Qt-82d0b03c4f81c2832975d548917c03dbaddeee72.zip Qt-82d0b03c4f81c2832975d548917c03dbaddeee72.tar.gz Qt-82d0b03c4f81c2832975d548917c03dbaddeee72.tar.bz2 |
Restructure the examples. They are now organized into various
subdirectories to make it easier to locate examples for certain
features (e.g. animation) and to distinguish between different types
of examples (e.g. very basic examples vs complex demo-like examples).
Diffstat (limited to 'examples/declarative/threading')
7 files changed, 147 insertions, 0 deletions
diff --git a/examples/declarative/threading/threadedlistmodel/dataloader.js b/examples/declarative/threading/threadedlistmodel/dataloader.js new file mode 100644 index 0000000..d720f09 --- /dev/null +++ b/examples/declarative/threading/threadedlistmodel/dataloader.js @@ -0,0 +1,9 @@ +// ![0] +WorkerScript.onMessage = function(msg) { + if (msg.action == 'appendCurrentTime') { + var data = {'time': new Date().toTimeString()}; + msg.model.append(data); + msg.model.sync(); // updates the changes to the list + } +} +// ![0] diff --git a/examples/declarative/threading/threadedlistmodel/threadedlistmodel.qmlproject b/examples/declarative/threading/threadedlistmodel/threadedlistmodel.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/threading/threadedlistmodel/threadedlistmodel.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 " ] +} diff --git a/examples/declarative/threading/threadedlistmodel/timedisplay.qml b/examples/declarative/threading/threadedlistmodel/timedisplay.qml new file mode 100644 index 0000000..bad7010 --- /dev/null +++ b/examples/declarative/threading/threadedlistmodel/timedisplay.qml @@ -0,0 +1,32 @@ +// ![0] +import Qt 4.7 + +ListView { + width: 200 + height: 300 + + model: listModel + delegate: Component { + Text { text: time } + } + + ListModel { id: listModel } + + WorkerScript { + id: worker + source: "dataloader.js" + } + + Timer { + id: timer + interval: 2000; repeat: true + running: true + triggeredOnStart: true + + onTriggered: { + var msg = {'action': 'appendCurrentTime', 'model': listModel}; + worker.sendMessage(msg); + } + } +} +// ![0] diff --git a/examples/declarative/threading/threading.qmlproject b/examples/declarative/threading/threading.qmlproject new file mode 100644 index 0000000..d4909f8 --- /dev/null +++ b/examples/declarative/threading/threading.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 " ] +} 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 " ] +} |