summaryrefslogtreecommitdiffstats
path: root/examples/declarative/threading/workerscript/workerscript.qml
blob: 2294a81394f16cae67eace85e8a864ae8edbec8e (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
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 }
    }
}