improved desktop UI
[mardrone] / mardrone / ardrone_android.qml
1 // uiName:Android
2 import QtQuick 1.0
3 import com.nokia.android 1.1
4 import Drone 1.0
5 //import gauges 1.0
6 import JoyStick 1.0
7
8 PageStackWindow {
9     id:mainWindow
10     initialPage: mainpageComponent
11     showStatusBar: false
12 //    fullscreen:true
13     property Component dialogComponent
14 // property alias m: mainPage
15
16     ToolBarLayout {
17         id: commonTools
18         ToolButton {
19             flat: true
20             iconSource: "toolbar-back"
21             onClicked: mainWindow.pageStack.depth <= 1 ? Qt.quit() : mainWindow.pageStack.pop()
22         }
23    }
24   DroneControl {
25         id:drone
26     }
27   JoyStick {
28       id:js
29       onElevatorChanged:{if(drone.confUseJoyStick) drone.pitch=elevator;}
30       onAileronChanged: {if(drone.confUseJoyStick) drone.roll=-1.0*aileron;}
31       onThrotleChanged: {if(drone.confUseJoyStick) drone.vVelocity=throtle;}
32       onRudderChanged:  {if(drone.confUseJoyStick) drone.yaw=rudder;}
33
34   }
35   Keys.onUpPressed: {
36                 console.debug("QML:Keys.onUpPressed",event.key)
37                 if (event.key == Qt.Key_TopMenu)
38                     console.debug("QML: opening menu!")
39                 else if (event.key == Qt.Key_MediaPrevious) {
40                     console.debug("QML: closing! (maybe)")
41                     pageStack.depth <= 1 ? Qt.quit() : pageStack.pop()
42                 }
43             }
44   Keys.onPressed: {
45                 console.debug("QML:Keys.onPressed",event.key)
46                 if (event.key == Qt.Key_TopMenu)
47                     console.debug("QML: opening menu!")
48                 else if (event.key == Qt.Key_MediaPrevious) {
49                     console.debug("QML: closing! (maybe)")
50                     pageStack.depth <= 1 ? Qt.quit() : pageStack.pop()
51                 }
52             }
53
54   function backKey() {
55        console.debug("QML: backKey")
56       pageStack.depth <= 1 ? Qt.quit() : pageStack.pop()
57     }
58
59
60     Component {
61       id: mainpageComponent
62
63       Page {
64         id:mainPage
65         property bool connectingBoxVisible:true
66         //onEntered:(mainWindow.fullscreen=true)
67
68         state:"Landscape"
69         DroneVideo {
70             id:droneVideo
71             y:0
72             x:0
73            // anchors.horizontalCenter:parent.horizontalCenter
74             width:drone.confFullScreen? parent.width:640 ;height:480*width/640;
75         }
76         Binding {
77           target:drone
78           property:"logSeq"
79           value: droneVideo.frameSeq;
80         }
81         EfisPFD {
82             id:hudPDF
83             y:0
84             anchors.horizontalCenter: parent.horizontalCenter
85             visible:drone.confShowHorizon
86             roll:drone.droneRoll
87             pitch:drone.dronePitch
88             ias:drone.droneSpeed
89             alt:drone.droneAltitude
90             indicatorColor:"#00FF00"
91             skyColor:"#00000000"
92             groundColor:"#00000000"
93             width:500;height:400;
94         }
95
96         Text {
97             y:50
98             visible:drone.confShowDebug
99             color: "#00FF00"
100             id: droneCtrlValues
101             font.pixelSize:25
102             text: "cmd:pitch=" + drone.pitch.toFixed(2) + " roll= " +  drone.roll.toFixed(2) + " yaw=" + drone.yaw.toFixed(2) + " vv= " + drone.vVelocity.toFixed(2)
103         }
104
105         Text {
106             y:70
107             visible:drone.confShowDebug
108             color: "#00FF00"
109             id: droneNavData
110             font.pixelSize:25
111             text: "pitch=" + drone.dronePitch.toFixed(2) + " roll= " +  drone.droneRoll.toFixed(2) + "yaw=" + drone.droneYaw.toFixed(2) + " alt= " +  drone.droneAltitude.toFixed(2)
112         }
113
114         Text {
115             y:100
116             visible:drone.confShowDebug
117             color: "#00FF00"
118             id: droneStatus
119             font.pixelSize:20
120             text: drone.decodedStatus
121         }
122         Button {
123             y:150;x:0
124             height: 50
125             width: 50
126             z:2 // This is visible even connecting to drone
127             iconSource: "gear32x32.png"
128             onClicked:{   //mainWindow.fullscreen = false ;
129                      pageStack.push(dialogComponent);
130             }
131         }
132
133         JoyStickIndicator {
134             x:200;y:350
135             visible:drone.confShowJSIndicators&js.haveJoyStick&drone.confUseJoyStick
136             border.width:1
137             color:"transparent"
138             width:100;height:100
139             xvalue:js.axis4
140             yvalue:js.axis3
141             Text {
142                 anchors.bottom: parent.bottom
143                 font.pixelSize: 10
144                 text:"       rudder"
145             }
146             Text {
147                 x:-10;y:50
148                 rotation:90
149                 font.pixelSize: 10
150                 text:"Throtle"
151             }
152         }
153
154
155         JoyStickIndicator {
156             x:500;y:350
157             visible:drone.confShowJSIndicators&js.haveJoyStick&drone.confUseJoyStick
158             border.width:1
159             color:"transparent"
160             width:100;height:100
161             xvalue:js.axis1
162             yvalue:js.axis2
163             Text {
164                 anchors.bottom: parent.bottom
165                 font.pixelSize: 10
166                 text:"      Aileron"
167             }
168             Text {
169                 x:-15;y:50
170                 rotation:90
171                 font.pixelSize: 10
172                 text:"Elevator"
173             }
174         }
175
176         JoyStickTouch {
177             id:lj
178             width:200;height:200;
179
180             visible: !drone.confUseAccel & !drone.confUseJoyStick
181             anchors.left:parent.left
182             anchors.bottom:parent.bottom
183             anchors.margins:10
184             joyBackground: ""
185             onYvChanged:{drone.vVelocity=-1*yv/200.0;}
186             onXvChanged:{drone.yaw=xv/200.0;}
187             onPressedChanged: { drone.ctrlActive=pressed;}
188         }
189
190         JoyStickTouch {
191              visible: !drone.confUseJoyStick
192             id:rj
193             joyBackground: ""
194             anchors.right:parent.right
195             anchors.bottom:parent.bottom
196             width:200;height:200;
197             anchors.margins:10
198             onYvChanged:{drone.pitch=yv/200.0;}
199             onXvChanged:{drone.roll=xv/200.0;}
200         }
201
202         Row {
203             spacing: 5
204             anchors.right:parent.right
205             anchors.rightMargin: 10
206             y:100
207             height:100
208         BarGauge {
209            val:drone.pwm_motor1;
210            max: 255
211            height:100
212         }
213         BarGauge {
214             val:drone.pwm_motor2;
215             max: 255
216             height:100
217         }
218         BarGauge {
219             val:drone.pwm_motor3;
220             max: 255
221             height:100
222         }
223         BarGauge {
224             val:drone.pwm_motor4;
225             max: 255
226             height:100
227         }
228         BarGauge {
229             val:drone.droneVBat
230             max: 100
231             height:100
232         }
233         }
234
235         Button {
236             x:400
237             width:80
238             height:50
239             id:flyButton
240             anchors.bottom:parent.bottom
241             anchors.margins:15
242             text:"Fly";
243             checkable:true
244             onClicked:{drone.fly=checked;
245             // mainWindow.fullsecreen=checked;
246             }
247         }
248         Button {
249             x:500;
250             width:90
251             height:50
252             id:emergencyButton
253             anchors.bottom:parent.bottom
254             anchors.margins:15
255             text:"Emrg";
256             checkable:true
257             onClicked:{drone.emergency=checked;}
258         }
259
260         Button {
261             x:600;
262             width:100
263             height:50
264             id:recordButton
265             anchors.bottom:parent.bottom
266             anchors.margins:15
267             text:"Rec";
268             checkable:true
269             onClicked:{droneVideo.recVideo=checked; drone.logFileName=droneVideo.videoFileName; drone.recordLog=checked;}
270         }
271         Text {
272             y:700
273             anchors.bottom:parent.bottom
274        //     visible:droneVideo.recVideo
275             color: "#00FF00"
276             id: droneFrameSeq
277             font.pixelSize:25
278             text: droneVideo.videoFileName+ " "+droneVideo.frameSeq
279         }
280
281
282             Connections {
283                 target:drone
284                 onConnectedChanged:{
285                     console.log("Connected to drone");
286                     connectingDialog.accept();}
287             }
288             QueryDialog {
289                 id:connectingDialog
290                 titleText:"Connecting to Drone"
291                 message:"Connecting to Drone "+ drone.confDroneIp
292                 acceptButtonText:"OK"
293                 Component.onCompleted: {
294                     console.log("ConectionDialog Opened");
295                     if(!drone.connected) open(); }
296             }
297         } // Main page
298     }
299
300      Component.onCompleted: {
301          if (mainpageComponent.status != Component.Ready)
302              //        pageStack.push(mainpageComponent);
303              //  else
304                      console.log("Error loading component:", mainpageComponent.errorString());
305          dialogComponent = Qt.createComponent("ConfigDialogAndroid.qml");
306
307         }
308  }