Add properties for x and y. Why the hell is the cursor not being shown?
[qzeecontrol] / qml / QZeeControl / MainPage.qml
1 /*
2  *  Copyright 2012 Ruediger Gad
3  *
4  *  This file is part of QZeeControl.
5  *
6  *  QZeeControl is free software: you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation, either version 3 of the License, or
9  *  (at your option) any later version.
10  *
11  *  QZeeControl is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with QZeeControl.  If not, see <http://www.gnu.org/licenses/>.
18  */
19
20 import QtQuick 1.1
21 import com.nokia.meego 1.0
22 import QtMobility.connectivity 1.2
23 import qzeecontrol 1.0
24
25 Page {
26     tools: commonTools
27
28     Label {
29         id: label
30         anchors{bottom: connectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
31
32         text: "Press to connect."
33     }
34
35     Button{
36         id: connectButton
37         anchors{bottom: disconnectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
38
39         text: "Connect"
40
41         onClicked: {
42             btDiscovery.discovery = true
43         }
44     }
45
46     Button{
47         id: disconnectButton
48         anchors{bottom: buttonRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
49
50         text: "Disconnect"
51
52         onClicked: {
53             btConn.disconnect()
54         }
55     }
56
57     Row{
58         id: buttonRow
59         anchors.centerIn: parent
60         spacing: 20
61
62         Label{
63             id: labelA
64             text: "A"
65             color: "blue"
66         }
67         Label{
68             id: labelB
69             text: "B"
70             color: "blue"
71         }
72         Label{
73             id: labelC
74             text: "C"
75             color: "blue"
76         }
77         Label{
78             id: labelD
79             text: "D"
80             color: "blue"
81         }
82     }
83
84     Rectangle{
85         id: moveArea
86         anchors{top: buttonRow.bottom; topMargin: 10; horizontalCenter: parent.horizontalCenter}
87         color: "gray"
88
89         width: 256
90         height: 256
91
92         Rectangle{
93             id: cursor
94             width: 10
95             height: 10
96             color: "red"
97             z: 32
98
99             x: moveArea.x + (moveArea.width * 0.5) + btConn.x
100             y: moveArea.y + (moveArea.height * 0.5) + btConn.y
101
102             onXChanged: console.log("New x: " + x)
103             onYChanged: console.log("New y: " + y)
104         }
105     }
106
107
108     BluetoothDiscoveryModel{
109         id: btDiscovery
110
111         discovery: false
112         minimalDiscovery: true
113
114         onDiscoveryChanged: {
115             if(discovery){
116                 label.text = "Scanning for devices..."
117                 connectButton.enabled = false
118                 disconnectButton.enabled = false
119             }else{
120                 connectButton.enabled = true
121                 disconnectButton.enabled = false
122             }
123         }
124
125         onNewServiceDiscovered: {
126             console.log("Service " + service.serviceName + " found on " + service.deviceName + " at address " + service.deviceAddress + " on port " + service.servicePort + ".")
127             //btSocket.service = service
128             btConn.connect(service.deviceAddress, service.servicePort)
129         }
130     }
131
132     /*
133     BluetoothSocket{
134         id: btSocket
135
136         onDataAvailable: {
137             console.log("Data available: " + stringData.charCodeAt(0) + data)
138         }
139
140         onServiceChanged: {
141             console.log("Service changed. Connecting...")
142             connected = true
143         }
144
145         onConnectedChanged: {
146             console.log("Connected.")
147         }
148     }*/
149
150     BtConnector{
151         id: btConn
152
153         onConnected: {
154             connectButton.enabled = false
155             disconnectButton.enabled = true
156             label.text = "Connected."
157         }
158
159         onDisconnected: {
160             connectButton.enabled = true
161             disconnectButton.enabled = false
162             label.text = "Press to connect."
163         }
164
165         onStickMoved: {
166             console.log("Stick moved. x: " + x + " y: " + y)
167         }
168
169         onButtonsChanged: {
170             console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
171             labelA.color = a ? "red" : "blue"
172             labelB.color = b ? "red" : "blue"
173             labelC.color = c ? "red" : "blue"
174             labelD.color = d ? "red" : "blue"
175         }
176     }
177 }