Refine button handling. Change key mappings.
[qzeecontrol] / qml / QZeeControl / MainPage.qml
index 116d223..58cf162 100644 (file)
@@ -27,18 +27,14 @@ Page {
 
     Label {
         id: label
-        anchors.centerIn: parent
+        anchors{bottom: connectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
+
         text: "Press to connect."
     }
 
     Button{
         id: connectButton
-
-        anchors {
-            horizontalCenter: parent.horizontalCenter
-            top: label.bottom
-            topMargin: 10
-        }
+        anchors{bottom: disconnectButton.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
 
         text: "Connect"
 
@@ -49,12 +45,7 @@ Page {
 
     Button{
         id: disconnectButton
-
-        anchors {
-            horizontalCenter: parent.horizontalCenter
-            top: connectButton.bottom
-            topMargin: 10
-        }
+        anchors{bottom: buttonRow.top; bottomMargin: 10; horizontalCenter: parent.horizontalCenter}
 
         text: "Disconnect"
 
@@ -63,6 +54,52 @@ Page {
         }
     }
 
+    Row{
+        id: buttonRow
+        anchors.centerIn: parent
+        spacing: 20
+
+        Label{
+            id: labelA
+            text: "A"
+            color: btConn.a ? "red" : "blue"
+        }
+        Label{
+            id: labelB
+            text: "B"
+            color: btConn.b ? "red" : "blue"
+        }
+        Label{
+            id: labelC
+            text: "C"
+            color: btConn.c ? "red" : "blue"
+        }
+        Label{
+            id: labelD
+            text: "D"
+            color: btConn.d ? "red" : "blue"
+        }
+    }
+
+    Rectangle{
+        id: moveArea
+        anchors{top: buttonRow.bottom; topMargin: 10; horizontalCenter: parent.horizontalCenter}
+        color: "gray"
+
+        width: 256
+        height: 256
+    }
+
+    Rectangle{
+        id: cursorRectangle
+        width: 10
+        height: 10
+        color: "red"
+
+        x: moveArea.x + (moveArea.width * 0.5) + btConn.x - (cursorRectangle.width * 0.5)
+        y: moveArea.y + (moveArea.height * 0.5) + btConn.y - (cursorRectangle.height * 0.5)
+    }
+
     BluetoothDiscoveryModel{
         id: btDiscovery
 
@@ -108,6 +145,8 @@ Page {
     BtConnector{
         id: btConn
 
+        property int joystickThreshold: 50
+
         onConnected: {
             connectButton.enabled = false
             disconnectButton.enabled = true
@@ -127,5 +166,50 @@ Page {
         onButtonsChanged: {
             console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
         }
+
+        onAChanged: {
+            console.log("A changed to: " + val)
+            if(val){
+                xtstAdapter.sendKeyPress("a");
+            }
+        }
+        onBChanged: {
+            console.log("B changed to: " + val)
+            if(val){
+                xtstAdapter.sendKeyPress("b");
+            }
+        }
+        onCChanged: {
+            console.log("C changed to: " + val)
+            if(val){
+                xtstAdapter.sendKeyPress("c");
+            }
+        }
+        onDChanged: {
+            console.log("D changed to: " + val)
+            if(val){
+                xtstAdapter.sendKeyPress("d");
+            }
+        }
+
+        onXChanged: {
+            if(val > joystickThreshold){
+                xtstAdapter.sendKeyPress("Right");
+            }else if(val < -joystickThreshold){
+                xtstAdapter.sendKeyPress("Left");
+            }
+        }
+
+        onYChanged: {
+            if(val > joystickThreshold){
+                xtstAdapter.sendKeyPress("Down");
+            }else if(val < -joystickThreshold){
+                xtstAdapter.sendKeyPress("Up");
+            }
+        }
+    }
+
+    XtstAdapter{
+        id: xtstAdapter
     }
 }