Refactor code quite heavily.
authorRuediger Gad <rgad@fb2.fh-frankfurt.de>
Mon, 16 Apr 2012 10:06:22 +0000 (12:06 +0200)
committerRuediger Gad <rgad@fb2.fh-frankfurt.de>
Mon, 16 Apr 2012 10:06:22 +0000 (12:06 +0200)
QZeeControl.pro.user
btconnector.cpp
btconnector.h
build.sh
qml/QZeeControl/MainPage.qml
qml/QZeeControl/ZeeRemoteControl.qml [new file with mode: 0644]

index 9f3ca1a..c4024f5 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by Qt Creator 2.4.1, 2012-04-16T09:26:38. -->
+<!-- Written by Qt Creator 2.4.1, 2012-04-16T11:56:51. -->
 <qtcreator>
  <data>
   <variable>ProjectExplorer.Project.ActiveTarget</variable>
index 17f978f..57fafb6 100644 (file)
@@ -73,14 +73,21 @@ void BtConnector::readData(){
      * first seems to suffice.
      */
     if(data.at(0) == 5){
-        // Joystick movement
-        _x = (int)(signed char) data.at(4);
-        _y = (int)(signed char) data.at(5);
+        /*
+         * Joystick movement
+         *
+         * X-Axis: positive values -> right, negative values -> left
+         * Y-Axis: positive values -> down, negative values -> up
+         */
+
+        setX((int)(signed char) data.at(4));
+        setY((int)(signed char) data.at(5));
 
-        emit(xChanged(_x));
-        emit(yChanged(_y));
         emit(stickMoved(_x, _y));
 
+        /*
+         * Emulate a digital joystick.
+         */
         if(_up && (_y > -threshold())){
             setUp(false);
         }else if(!_up && (_y < -threshold())){
@@ -104,9 +111,10 @@ void BtConnector::readData(){
         }else if(!_right && (_x > threshold())){
             setRight(true);
         }
-    }else if(data.at(0) == 8){
-        // Button press
+    }else if(data.at(0) == 8){ 
         /*
+         * Button presses
+         *
          * A -> 0, B -> 1, C -> 2, D ->3
          * At index 3 to 6 (inclusive)
          */
@@ -129,20 +137,16 @@ void BtConnector::readData(){
                 bool val = (buttonMap & (1 << i)) > 0;
                 switch (i){
                 case 0:
-                    _a = val;
-                    emit (aChanged(val));
+                    setA(val);
                     break;
                 case 1:
-                    _b = val;
-                    emit (bChanged(val));
+                    setB(val);
                     break;
                 case 2:
-                    _c = val;
-                    emit (cChanged(val));
+                    setC(val);
                     break;
                 case 3:
-                    _d = val;
-                    emit (dChanged(val));
+                    setD(val);
                     break;
                 }
             }
index 4d9ecb4..b98c4b6 100644 (file)
@@ -59,23 +59,6 @@ public:
         thresholdChanged(_threshold);
     }
 
-    void setUp(bool val){
-        _up = val;
-        upChanged(_up);
-    }
-    void setDown(bool val){
-        _down = val;
-        downChanged(_down);
-    }
-    void setLeft(bool val){
-        _left = val;
-        leftChanged(_left);
-    }
-    void setRight(bool val){
-        _right = val;
-        rightChanged(_right);
-    }
-
     bool up(){return _up;}
     bool down(){return _down;}
     bool left(){return _left;}
@@ -144,7 +127,52 @@ private:
 
     int _x;
     int _y;
+
     char oldButtonMap;
+
+    void setA(bool val){
+        _a = val;
+        aChanged(_a);
+    }
+    void setB(bool val){
+        _b = val;
+        bChanged(_b);
+    }
+    void setC(bool val){
+        _c = val;
+        cChanged(_c);
+    }
+    void setD(bool val){
+        _d = val;
+        dChanged(_d);
+    }
+
+    void setX(int val){
+        _x = val;
+        xChanged(_x);
+    }
+    void setY(int val){
+        _y = val;
+        yChanged(_y);
+    }
+
+    void setUp(bool val){
+        _up = val;
+        upChanged(_up);
+    }
+    void setDown(bool val){
+        _down = val;
+        downChanged(_down);
+    }
+    void setLeft(bool val){
+        _left = val;
+        leftChanged(_left);
+    }
+    void setRight(bool val){
+        _right = val;
+        rightChanged(_right);
+    }
+
 };
 
 #endif // BTCONNECTOR_H
index 2312985..dbf766b 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -1,5 +1,8 @@
 #!/bin/bash
 
+rm -rf .git
+rm -rf www
+rm -rf ovi
 mv qtc_packaging/debian_harmattan debian
 rm -rf qtc_packaging
 fakeroot dpkg-buildpackage -sa
index e4e108c..ec84eb6 100644 (file)
@@ -68,15 +68,15 @@ Page {
 
     function loadKeyBindings(){
         console.log("Loading key bindings.")
-        btConn.keyBindingA = SettingsStorage.getSetting("A")
-        btConn.keyBindingB = SettingsStorage.getSetting("B")
-        btConn.keyBindingC = SettingsStorage.getSetting("C")
-        btConn.keyBindingD = SettingsStorage.getSetting("D")
-
-        btConn.keyBindingUp = SettingsStorage.getSetting("Up")
-        btConn.keyBindingDown = SettingsStorage.getSetting("Down")
-        btConn.keyBindingLeft = SettingsStorage.getSetting("Left")
-        btConn.keyBindingRight = SettingsStorage.getSetting("Right")
+        zeeRemoteControl.keyBindingA = SettingsStorage.getSetting("A")
+        zeeRemoteControl.keyBindingB = SettingsStorage.getSetting("B")
+        zeeRemoteControl.keyBindingC = SettingsStorage.getSetting("C")
+        zeeRemoteControl.keyBindingD = SettingsStorage.getSetting("D")
+
+        zeeRemoteControl.keyBindingUp = SettingsStorage.getSetting("Up")
+        zeeRemoteControl.keyBindingDown = SettingsStorage.getSetting("Down")
+        zeeRemoteControl.keyBindingLeft = SettingsStorage.getSetting("Left")
+        zeeRemoteControl.keyBindingRight = SettingsStorage.getSetting("Right")
     }
 
     function updateConnectAndScanButton(){
@@ -107,24 +107,24 @@ Page {
             name: "active"
             PropertyChanges {
                 target: cursorRectangle
-                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)
+                x: moveArea.x + (moveArea.width * 0.5) + zeeRemoteControl.x - (cursorRectangle.width * 0.5)
+                y: moveArea.y + (moveArea.height * 0.5) + zeeRemoteControl.y - (cursorRectangle.height * 0.5)
             }
             PropertyChanges {
                 target: labelA
-                color: btConn.a ? "red" : "blue"
+                color: zeeRemoteControl.a ? "red" : "blue"
             }
             PropertyChanges {
                 target: labelB
-                color: btConn.b ? "red" : "blue"
+                color: zeeRemoteControl.b ? "red" : "blue"
             }
             PropertyChanges {
                 target: labelC
-                color: btConn.c ? "red" : "blue"
+                color: zeeRemoteControl.c ? "red" : "blue"
             }
             PropertyChanges {
                 target: labelD
-                color: btConn.d ? "red" : "blue"
+                color: zeeRemoteControl.d ? "red" : "blue"
             }
         },
         State {
@@ -323,7 +323,7 @@ Page {
 
                 onClicked: {
                     mainPage.state = "connecting"
-                    btConn.connect(addressField.text, parseInt(portField.text))
+                    zeeRemoteControl.connect(addressField.text, parseInt(portField.text))
                 }
             }
 
@@ -334,7 +334,7 @@ Page {
                 text: "Disconnect"
 
                 onClicked: {
-                    btConn.disconnect()
+                    zeeRemoteControl.disconnect()
                 }
             }
 
@@ -347,22 +347,22 @@ Page {
                 Label{
                     id: labelA
                     text: "A"
-                    color: btConn.a ? "red" : "blue"
+                    color: zeeRemoteControl.a ? "red" : "blue"
                 }
                 Label{
                     id: labelB
                     text: "B"
-                    color: btConn.b ? "red" : "blue"
+                    color: zeeRemoteControl.b ? "red" : "blue"
                 }
                 Label{
                     id: labelC
                     text: "C"
-                    color: btConn.c ? "red" : "blue"
+                    color: zeeRemoteControl.c ? "red" : "blue"
                 }
                 Label{
                     id: labelD
                     text: "D"
-                    color: btConn.d ? "red" : "blue"
+                    color: zeeRemoteControl.d ? "red" : "blue"
                 }
             }
 
@@ -386,8 +386,8 @@ Page {
                     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)
+                    x: moveArea.x + (moveArea.width * 0.5) + zeeRemoteControl.x - (cursorRectangle.width * 0.5)
+                    y: moveArea.y + (moveArea.height * 0.5) + zeeRemoteControl.y - (cursorRectangle.height * 0.5)
                 }
             }
         }
@@ -443,46 +443,16 @@ Page {
         }
     }
 
-    BtConnector{
-        id: btConn
+    ZeeRemoteControl{
+        id: zeeRemoteControl
 
         threshold: 50
 
-        property string keyBindingA
-        property string keyBindingB
-        property string keyBindingC
-        property string keyBindingD
-
-        property string keyBindingUp
-        property string keyBindingDown
-        property string keyBindingLeft
-        property string keyBindingRight
-
         onConnected: {
             disconnectButton.enabled = true
             infoText.text = "Connected. Have fun."
         }
-
-        onDisconnected: {
-            mainPage.state = "disconnected"
-        }
-
-//        onStickMoved: {
-//            console.log("Stick moved. x: " + x + " y: " + y)
-//        }
-//        onButtonsChanged: {
-//            console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
-//        }
-
-        onAChanged: xtstAdapter.sendKey(keyBindingA, val);
-        onBChanged: xtstAdapter.sendKey(keyBindingB, val);
-        onCChanged: xtstAdapter.sendKey(keyBindingC, val);
-        onDChanged: xtstAdapter.sendKey(keyBindingD, val);
-
-        onUpChanged: xtstAdapter.sendKey(keyBindingUp, val)
-        onDownChanged: xtstAdapter.sendKey(keyBindingDown, val)
-        onLeftChanged: xtstAdapter.sendKey(keyBindingLeft, val)
-        onRightChanged: xtstAdapter.sendKey(keyBindingRight, val)
+        onDisconnected: mainPage.state = "disconnected"
     }
 
     XtstAdapter{
diff --git a/qml/QZeeControl/ZeeRemoteControl.qml b/qml/QZeeControl/ZeeRemoteControl.qml
new file mode 100644 (file)
index 0000000..04d7c78
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ *  Copyright 2012 Ruediger Gad
+ *
+ *  This file is part of QZeeControl.
+ *
+ *  QZeeControl is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  QZeeControl is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with QZeeControl.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import QtQuick 1.1
+import qzeecontrol 1.0
+
+BtConnector{
+    id: zeeRemoteControl
+
+    /*
+     * Keybindings
+     */
+    property string keyBindingA
+    property string keyBindingB
+    property string keyBindingC
+    property string keyBindingD
+
+    property string keyBindingUp
+    property string keyBindingDown
+    property string keyBindingLeft
+    property string keyBindingRight
+
+//      Examples on how to use these old signals.
+//        onStickMoved: {
+//            console.log("Stick moved. x: " + x + " y: " + y)
+//        }
+//        onButtonsChanged: {
+//            console.log("Buttons changed. A: " + a + " B: " + b + " C: " + c + " D: " + d)
+//        }
+
+    /*
+     * Do the actual keyboard interaction.
+     */
+    onAChanged: xtstAdapter.sendKey(keyBindingA, val);
+    onBChanged: xtstAdapter.sendKey(keyBindingB, val);
+    onCChanged: xtstAdapter.sendKey(keyBindingC, val);
+    onDChanged: xtstAdapter.sendKey(keyBindingD, val);
+
+    onUpChanged: xtstAdapter.sendKey(keyBindingUp, val)
+    onDownChanged: xtstAdapter.sendKey(keyBindingDown, val)
+    onLeftChanged: xtstAdapter.sendKey(keyBindingLeft, val)
+    onRightChanged: xtstAdapter.sendKey(keyBindingRight, val)
+}
+
+