Add properties for x and y. Why the hell is the cursor not being shown?
authorRuediger Gad <rgad@fb2.fh-frankfurt.de>
Thu, 12 Apr 2012 08:38:51 +0000 (10:38 +0200)
committerRuediger Gad <rgad@fb2.fh-frankfurt.de>
Thu, 12 Apr 2012 08:38:51 +0000 (10:38 +0200)
QZeeControl.pro.user
btconnector.h
qml/QZeeControl/MainPage.qml

index 3953c6a..61540ad 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by Qt Creator 2.4.1, 2012-04-12T09:12:26. -->
+<!-- Written by Qt Creator 2.4.1, 2012-04-12T10:21:41. -->
 <qtcreator>
  <data>
   <variable>ProjectExplorer.Project.ActiveTarget</variable>
index 65c9ce8..f5a3541 100644 (file)
@@ -28,9 +28,13 @@ QTM_USE_NAMESPACE
 class BtConnector : public QObject
 {
     Q_OBJECT
+
+    Q_PROPERTY(int x READ x NOTIFY xChanged)
+    Q_PROPERTY(int y READ y NOTIFY yChanged)
 public:
     explicit BtConnector(QObject *parent = 0){
-
+        _x = 0;
+        _y = 0;
     }
     ~BtConnector(){
         if(socket)
@@ -55,6 +59,9 @@ public:
         QObject::connect(socket, SIGNAL(readyRead()), this, SLOT(readData()));
     }
 
+    int x(){return _x;}
+    int y(){return _y;}
+
 public slots:
     void disconnect(){
         if(!socket)
@@ -75,6 +82,9 @@ signals:
     void stickMoved(int x, int y);
     void buttonsChanged(bool a, bool b, bool c, bool d);
 
+    void xChanged(int);
+    void yChanged(int);
+
 private slots:
     void readData(){
 //        qDebug("readData...");
@@ -94,7 +104,12 @@ private slots:
          */
         if(data.at(0) == 5){
             // Joystick movement
-            emit(stickMoved((int)(signed char) data.at(4), (int)(signed char) data.at(5)));
+            _x = (int)(signed char) data.at(4);
+            _y = (int)(signed char) data.at(5);
+
+            emit(xChanged(_x));
+            emit(yChanged(_y));
+            emit(stickMoved(_x, _y));
         }else if(data.at(0) == 8){
             // Button press
             /*
@@ -120,6 +135,8 @@ private slots:
 private:
     QBluetoothSocket *socket;
 
+    int _x;
+    int _y;
 };
 
 #endif // BTCONNECTOR_H
index aeb5599..ed1bb3d 100644 (file)
@@ -25,39 +25,86 @@ import qzeecontrol 1.0
 Page {
     tools: commonTools
 
+    Label {
+        id: label
+        anchors{bottom: connectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
 
+        text: "Press to connect."
+    }
 
-    Column {
-        anchors.centerIn: parent
-        spacing: 10
+    Button{
+        id: connectButton
+        anchors{bottom: disconnectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
 
-        Label {
-            id: label
+        text: "Connect"
 
-            text: "Press to connect."
+        onClicked: {
+            btDiscovery.discovery = true
         }
+    }
 
-        Button{
-            id: connectButton
+    Button{
+        id: disconnectButton
+        anchors{bottom: buttonRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
 
-            text: "Connect"
+        text: "Disconnect"
 
-            onClicked: {
-                btDiscovery.discovery = true
-            }
+        onClicked: {
+            btConn.disconnect()
         }
+    }
 
-        Button{
-            id: disconnectButton
+    Row{
+        id: buttonRow
+        anchors.centerIn: parent
+        spacing: 20
 
-            text: "Disconnect"
+        Label{
+            id: labelA
+            text: "A"
+            color: "blue"
+        }
+        Label{
+            id: labelB
+            text: "B"
+            color: "blue"
+        }
+        Label{
+            id: labelC
+            text: "C"
+            color: "blue"
+        }
+        Label{
+            id: labelD
+            text: "D"
+            color: "blue"
+        }
+    }
 
-            onClicked: {
-                btConn.disconnect()
-            }
+    Rectangle{
+        id: moveArea
+        anchors{top: buttonRow.bottom; topMargin: 10; horizontalCenter: parent.horizontalCenter}
+        color: "gray"
+
+        width: 256
+        height: 256
+
+        Rectangle{
+            id: cursor
+            width: 10
+            height: 10
+            color: "red"
+            z: 32
+
+            x: moveArea.x + (moveArea.width * 0.5) + btConn.x
+            y: moveArea.y + (moveArea.height * 0.5) + btConn.y
+
+            onXChanged: console.log("New x: " + x)
+            onYChanged: console.log("New y: " + y)
         }
     }
 
+
     BluetoothDiscoveryModel{
         id: btDiscovery
 
@@ -121,6 +168,10 @@ Page {
 
         onButtonsChanged: {
             console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
+            labelA.color = a ? "red" : "blue"
+            labelB.color = b ? "red" : "blue"
+            labelC.color = c ? "red" : "blue"
+            labelD.color = d ? "red" : "blue"
         }
     }
 }