LinkSettings.qml 15.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*=====================================================================

 QGroundControl Open Source Ground Control Station

 (c) 2009 - 2015 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>

 This file is part of the QGROUNDCONTROL project

 QGROUNDCONTROL 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.

 QGROUNDCONTROL 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 QGROUNDCONTROL. If not, see <http://www.gnu.org/licenses/>.

 ======================================================================*/

24 25
import QtQuick          2.5
import QtQuick.Controls 1.4
26
import QtQuick.Dialogs  1.1
27 28 29 30 31 32 33

import QGroundControl                       1.0
import QGroundControl.Controls              1.0
import QGroundControl.ScreenTools           1.0
import QGroundControl.Palette               1.0

Rectangle {
34
    id:                 _linkRoot
35
    color:              qgcPal.window
36 37
    anchors.fill:       parent
    anchors.margins:    ScreenTools.defaultFontPixelWidth
38 39

    property var _currentSelection: null
40 41
    property int _firstColumn:      ScreenTools.defaultFontPixelWidth * 12
    property int _secondColumn:     ScreenTools.defaultFontPixelWidth * 30
42 43 44 45 46 47 48 49

    ExclusiveGroup { id: linkGroup }

    QGCPalette {
        id:                 qgcPal
        colorGroupEnabled:  enabled
    }

50 51 52 53 54 55 56 57 58 59 60
    function openCommSettings(lconf) {
        settingLoader.linkConfig = lconf
        settingLoader.sourceComponent = commSettings
        settingLoader.visible = true
    }

    function closeCommSettings() {
        settingLoader.visible = false
        settingLoader.sourceComponent = null
    }

Don Gagne's avatar
Don Gagne committed
61
    QGCFlickable {
62 63 64 65 66 67 68 69 70 71 72 73 74 75
        clip:               true
        anchors.top:        parent.top
        width:              parent.width
        height:             parent.height - buttonRow.height
        contentHeight:      settingsColumn.height
        contentWidth:       _linkRoot.width
        flickableDirection: Flickable.VerticalFlick

        Column {
            id:                 settingsColumn
            width:              _linkRoot.width
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            spacing:            ScreenTools.defaultFontPixelHeight / 2
            QGCLabel {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
76
                text:   qsTr("Comm Link Settings")
77 78 79 80 81 82
                font.pixelSize: ScreenTools.mediumFontPixelSize
            }
            Rectangle {
                height: 1
                width:  parent.width
                color:  qgcPal.button
83 84 85 86 87 88 89 90 91 92 93 94
            }
            Item {
                height: ScreenTools.defaultFontPixelHeight / 2
                width:  parent.width
            }
            Repeater {
                model: QGroundControl.linkManager.linkConfigurations
                delegate:
                QGCButton {
                    text:   object.name
                    width:  _linkRoot.width * 0.5
                    exclusiveGroup: linkGroup
95
                    anchors.horizontalCenter: settingsColumn.horizontalCenter
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
                    onClicked: {
                        checked = true
                        _currentSelection = object
                    }
                }
            }
        }
    }

    Row {
        id:                 buttonRow
        spacing:            ScreenTools.defaultFontPixelWidth
        anchors.bottom:     parent.bottom
        anchors.margins:    ScreenTools.defaultFontPixelWidth
        anchors.horizontalCenter: parent.horizontalCenter
        QGCButton {
            width:      ScreenTools.defaultFontPixelWidth * 10
Tomaz Canabrava's avatar
Tomaz Canabrava committed
113
            text:       qsTr("Delete")
114
            enabled:    _currentSelection && !_currentSelection.dynamic
115
            onClicked: {
116 117 118 119 120 121 122 123
                if(_currentSelection)
                    deleteDialog.visible = true
            }
            MessageDialog {
                id:         deleteDialog
                visible:    false
                icon:       StandardIcon.Warning
                standardButtons: StandardButton.Yes | StandardButton.No
Tomaz Canabrava's avatar
Tomaz Canabrava committed
124 125
                title:      qsTr("Remove Link Configuration")
                text:       _currentSelection ? qsTr("Remove %1. Is this really what you want?").arg(_currentSelection.name) : ""
126 127 128 129 130 131 132 133
                onYes: {
                    if(_currentSelection)
                        QGroundControl.linkManager.removeConfiguration(_currentSelection)
                    deleteDialog.visible = false
                }
                onNo: {
                    deleteDialog.visible = false
                }
134 135 136
            }
        }
        QGCButton {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
137
            text:       qsTr("Edit")
138
            enabled:    _currentSelection && !_currentSelection.link
139
            onClicked: {
140
                _linkRoot.openCommSettings(_currentSelection)
141 142 143
            }
        }
        QGCButton {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
144
            text:       qsTr("Add")
145
            onClicked: {
146
                _linkRoot.openCommSettings(null)
147 148 149
            }
        }
        QGCButton {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
150
            text:       qsTr("Connect")
151 152 153 154 155 156 157
            enabled:    _currentSelection && !_currentSelection.link
            onClicked: {
                QGroundControl.linkManager.createConnectedLink(_currentSelection)
                settingsMenu.closeSettings()
            }
        }
        QGCButton {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
158
            text:       qsTr("Disconnect")
159 160 161 162 163 164
            enabled:    _currentSelection && _currentSelection.link
            onClicked: {
                QGroundControl.linkManager.disconnectLink(_currentSelection.link, false)
            }
        }
    }
165 166 167 168 169 170

    Loader {
        id:             settingLoader
        anchors.fill:   parent
        visible:        false
        property var linkConfig: null
171
        property var editConfig: null
172 173 174 175 176 177 178
    }

    //---------------------------------------------
    // Comm Settings
    Component {
        id: commSettings
        Rectangle {
179
            color:          qgcPal.window
180
            anchors.fill:   parent
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
            Component.onCompleted: {
                // If editing, create copy for editing
                if(linkConfig) {
                    editConfig = QGroundControl.linkManager.startConfigurationEditing(linkConfig)
                } else {
                    // Create new link configuration
                    if(ScreenTools.isiOS)
                        editConfig = QGroundControl.linkManager.createConfiguration(LinkConfiguration.TypeUdp, "Unnamed")
                    else
                        editConfig = QGroundControl.linkManager.createConfiguration(LinkConfiguration.TypeSerial, "Unnamed")
                }
            }
            Component.onDestruction: {
                if(editConfig) {
                    QGroundControl.linkManager.cancelConfigurationEditing(editConfig)
                    editConfig = null
                }
            }
Don Gagne's avatar
Don Gagne committed
199
            QGCFlickable {
200
                id:                 settingsFlick
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
                clip:               true
                anchors.top:        parent.top
                width:              parent.width
                height:             parent.height - commButtonRow.height
                anchors.margins:    ScreenTools.defaultFontPixelWidth
                contentHeight:      commSettingsColumn.height
                contentWidth:       _linkRoot.width
                flickableDirection: Flickable.VerticalFlick
                boundsBehavior:     Flickable.StopAtBounds
                Column {
                    id:                 commSettingsColumn
                    width:              _linkRoot.width
                    anchors.margins:    ScreenTools.defaultFontPixelWidth
                    spacing:            ScreenTools.defaultFontPixelHeight / 2
                    QGCLabel {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
216
                        text:   linkConfig ? qsTr("Edit Link Configuration Settings (WIP)") : qsTr("Create New Link Configuration (WIP)")
217 218 219 220 221 222 223 224 225 226 227 228 229 230
                        font.pixelSize: ScreenTools.mediumFontPixelSize
                    }
                    Rectangle {
                        height: 1
                        width:  parent.width
                        color:  qgcPal.button
                    }
                    Item {
                        height: ScreenTools.defaultFontPixelHeight / 2
                        width:  parent.width
                    }
                    Row {
                        spacing:    ScreenTools.defaultFontPixelWidth
                        QGCLabel {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
231
                            text:   qsTr("Name:")
232 233 234 235
                            width:  _firstColumn
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        QGCTextField {
236 237
                            id:     nameField
                            text:   editConfig ? editConfig.name : ""
238 239 240 241 242 243 244
                            width:  _secondColumn
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }
                    Row {
                        spacing:        ScreenTools.defaultFontPixelWidth
                        QGCLabel {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
245
                            text:       qsTr("Type:")
246 247 248 249 250 251 252 253 254 255 256 257
                            width:      _firstColumn
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        //-----------------------------------------------------
                        // When editing, you can't change the link type
                        QGCLabel {
                            text:       linkConfig ? QGroundControl.linkManager.linkTypeStrings[linkConfig.linkType] : ""
                            visible:    linkConfig != null
                            width:      _secondColumn
                            anchors.verticalCenter: parent.verticalCenter
                            Component.onCompleted: {
                                if(linkConfig != null) {
258
                                    linkSettingLoader.source  = linkConfig.settingsURL
259 260 261 262 263 264 265 266 267 268 269 270 271
                                    linkSettingLoader.visible = true
                                }
                            }
                        }
                        //-----------------------------------------------------
                        // When creating, select a link type
                        QGCComboBox {
                            id:             linkTypeCombo
                            width:          _secondColumn
                            visible:        linkConfig == null
                            model:          QGroundControl.linkManager.linkTypeStrings
                            anchors.verticalCenter: parent.verticalCenter
                            onActivated: {
272
                                if (index != -1 && index !== editConfig.linkType) {
273 274 275
                                    // Destroy current panel
                                    linkSettingLoader.source = ""
                                    linkSettingLoader.visible = false
276 277 278 279 280 281 282
                                    // Save current name
                                    var name = editConfig.name
                                    // Discard link configuration (old type)
                                    QGroundControl.linkManager.cancelConfigurationEditing(editConfig)
                                    // Create new link configuration
                                    editConfig = QGroundControl.linkManager.createConfiguration(index, name)
                                    // Load appropriate configuration panel
283
                                    linkSettingLoader.source  = editConfig.settingsURL
284
                                    linkSettingLoader.visible = true
285 286 287 288 289
                                }
                            }
                            Component.onCompleted: {
                                if(linkConfig == null) {
                                    linkTypeCombo.currentIndex = 0
290 291
                                    linkSettingLoader.source   = editConfig.settingsURL
                                    linkSettingLoader.visible  = true
292 293 294 295
                                }
                            }
                        }
                    }
296 297 298 299
                    Item {
                        height: ScreenTools.defaultFontPixelHeight * 0.5
                        width:  parent.width
                    }
300
                    /*
301 302 303 304
                    //-- Auto Connect
                    QGCCheckBox {
                        text:       "Automatically Connect on Start"
                        checked:    false
305
                        enabled:    editConfig ? editConfig.autoConnectAllowed : false
306 307 308 309 310 311 312 313 314 315
                        onCheckedChanged: {
                            if(editConfig) {
                                editConfig.autoConnect = checked
                            }
                        }
                        Component.onCompleted: {
                            if(editConfig)
                                checked = editConfig.autoConnect
                        }
                    }
316
                    */
317 318 319 320 321 322 323 324
                    Item {
                        height: ScreenTools.defaultFontPixelHeight
                        width:  parent.width
                    }
                    Loader {
                        id:             linkSettingLoader
                        width:          parent.width
                        visible:        false
325
                        property var subEditConfig: editConfig
326 327 328 329 330 331 332 333
                    }
                }
            }
            Row {
                id:                 commButtonRow
                spacing:            ScreenTools.defaultFontPixelWidth
                anchors.margins:    ScreenTools.defaultFontPixelWidth
                anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
334
                anchors.right:      parent.right
335 336
                QGCButton {
                    width:      ScreenTools.defaultFontPixelWidth * 10
Tomaz Canabrava's avatar
Tomaz Canabrava committed
337
                    text:       qsTr("OK")
338
                    enabled:    nameField.text !== ""
339
                    onClicked: {
340
                        // Save editting
341
                        linkSettingLoader.item.saveSettings()
342 343 344 345 346 347 348 349
                        editConfig.name = nameField.text
                        if(linkConfig) {
                            QGroundControl.linkManager.endConfigurationEditing(linkConfig, editConfig)
                        } else {
                            // If it was edited, it's no longer "dynamic"
                            editConfig.dynamic = false
                            QGroundControl.linkManager.endCreateConfiguration(editConfig)
                        }
350
                        linkSettingLoader.source = ""
351
                        editConfig = null
352 353 354 355 356
                        _linkRoot.closeCommSettings()
                    }
                }
                QGCButton {
                    width:      ScreenTools.defaultFontPixelWidth * 10
Tomaz Canabrava's avatar
Tomaz Canabrava committed
357
                    text:       qsTr("Cancel")
358
                    onClicked: {
359 360
                        QGroundControl.linkManager.cancelConfigurationEditing(editConfig)
                        editConfig = null
361 362 363 364 365 366
                        _linkRoot.closeCommSettings()
                    }
                }
            }
        }
    }
367
}