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