LinkSettings.qml 14.3 KB
Newer Older
1 2 3 4 5 6 7 8
/****************************************************************************
 *
 *   (c) 2009-2016 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
 *
 * QGroundControl is licensed according to the terms in the file
 * COPYING.md in the root of the source code directory.
 *
 ****************************************************************************/
9 10


11 12
import QtQuick          2.5
import QtQuick.Controls 1.4
13
import QtQuick.Dialogs  1.1
14 15 16 17 18 19 20

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

Rectangle {
21
    id:                 _linkRoot
22
    color:              qgcPal.window
23 24
    anchors.fill:       parent
    anchors.margins:    ScreenTools.defaultFontPixelWidth
25 26

    property var _currentSelection: null
27 28
    property int _firstColumn:      ScreenTools.defaultFontPixelWidth * 12
    property int _secondColumn:     ScreenTools.defaultFontPixelWidth * 30
29 30 31 32 33 34 35 36

    ExclusiveGroup { id: linkGroup }

    QGCPalette {
        id:                 qgcPal
        colorGroupEnabled:  enabled
    }

37 38 39 40 41 42 43 44 45 46 47
    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
48
    QGCFlickable {
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
        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
            Repeater {
                model: QGroundControl.linkManager.linkConfigurations
                delegate:
                QGCButton {
                    text:   object.name
                    width:  _linkRoot.width * 0.5
                    exclusiveGroup: linkGroup
69
                    anchors.horizontalCenter: settingsColumn.horizontalCenter
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
                    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
87
            text:       qsTr("Delete")
88
            enabled:    _currentSelection && !_currentSelection.dynamic
89
            onClicked: {
90 91 92 93 94 95 96 97
                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
98 99
                title:      qsTr("Remove Link Configuration")
                text:       _currentSelection ? qsTr("Remove %1. Is this really what you want?").arg(_currentSelection.name) : ""
100 101 102 103 104 105 106 107
                onYes: {
                    if(_currentSelection)
                        QGroundControl.linkManager.removeConfiguration(_currentSelection)
                    deleteDialog.visible = false
                }
                onNo: {
                    deleteDialog.visible = false
                }
108 109 110
            }
        }
        QGCButton {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
111
            text:       qsTr("Edit")
112
            enabled:    _currentSelection && !_currentSelection.link
113
            onClicked: {
114
                _linkRoot.openCommSettings(_currentSelection)
115 116 117
            }
        }
        QGCButton {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
118
            text:       qsTr("Add")
119
            onClicked: {
120
                _linkRoot.openCommSettings(null)
121 122 123
            }
        }
        QGCButton {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
124
            text:       qsTr("Connect")
125 126 127 128 129 130
            enabled:    _currentSelection && !_currentSelection.link
            onClicked: {
                QGroundControl.linkManager.createConnectedLink(_currentSelection)
            }
        }
        QGCButton {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
131
            text:       qsTr("Disconnect")
132 133 134 135 136 137
            enabled:    _currentSelection && _currentSelection.link
            onClicked: {
                QGroundControl.linkManager.disconnectLink(_currentSelection.link, false)
            }
        }
    }
138 139 140 141 142 143

    Loader {
        id:             settingLoader
        anchors.fill:   parent
        visible:        false
        property var linkConfig: null
144
        property var editConfig: null
145 146 147 148 149 150 151
    }

    //---------------------------------------------
    // Comm Settings
    Component {
        id: commSettings
        Rectangle {
152
            color:          qgcPal.window
153
            anchors.fill:   parent
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
            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
172
            QGCFlickable {
173
                id:                 settingsFlick
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
                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
189
                        text:   linkConfig ? qsTr("Edit Link Configuration Settings (WIP)") : qsTr("Create New Link Configuration (WIP)")
190
                        font.pointSize: ScreenTools.mediumFontPointSize
191 192 193 194 195 196 197 198 199 200 201 202 203
                    }
                    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
204
                            text:   qsTr("Name:")
205 206 207 208
                            width:  _firstColumn
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        QGCTextField {
209 210
                            id:     nameField
                            text:   editConfig ? editConfig.name : ""
211 212 213 214 215 216 217
                            width:  _secondColumn
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }
                    Row {
                        spacing:        ScreenTools.defaultFontPixelWidth
                        QGCLabel {
Tomaz Canabrava's avatar
Tomaz Canabrava committed
218
                            text:       qsTr("Type:")
219 220 221 222 223 224 225 226 227 228 229 230
                            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) {
231
                                    linkSettingLoader.source  = linkConfig.settingsURL
232 233 234 235 236 237 238 239 240 241 242 243 244
                                    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: {
245
                                if (index != -1 && index !== editConfig.linkType) {
246 247 248
                                    // Destroy current panel
                                    linkSettingLoader.source = ""
                                    linkSettingLoader.visible = false
249 250 251 252 253 254 255
                                    // 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
256
                                    linkSettingLoader.source  = editConfig.settingsURL
257
                                    linkSettingLoader.visible = true
258 259 260 261 262
                                }
                            }
                            Component.onCompleted: {
                                if(linkConfig == null) {
                                    linkTypeCombo.currentIndex = 0
263 264
                                    linkSettingLoader.source   = editConfig.settingsURL
                                    linkSettingLoader.visible  = true
265 266 267 268
                                }
                            }
                        }
                    }
269 270 271 272
                    Item {
                        height: ScreenTools.defaultFontPixelHeight * 0.5
                        width:  parent.width
                    }
273
                    /*
274 275 276 277
                    //-- Auto Connect
                    QGCCheckBox {
                        text:       "Automatically Connect on Start"
                        checked:    false
278
                        enabled:    editConfig ? editConfig.autoConnectAllowed : false
279 280 281 282 283 284 285 286 287 288
                        onCheckedChanged: {
                            if(editConfig) {
                                editConfig.autoConnect = checked
                            }
                        }
                        Component.onCompleted: {
                            if(editConfig)
                                checked = editConfig.autoConnect
                        }
                    }
289
                    */
290 291 292 293 294 295 296 297
                    Item {
                        height: ScreenTools.defaultFontPixelHeight
                        width:  parent.width
                    }
                    Loader {
                        id:             linkSettingLoader
                        width:          parent.width
                        visible:        false
298
                        property var subEditConfig: editConfig
299 300 301 302 303 304 305 306
                    }
                }
            }
            Row {
                id:                 commButtonRow
                spacing:            ScreenTools.defaultFontPixelWidth
                anchors.margins:    ScreenTools.defaultFontPixelWidth
                anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
307
                anchors.right:      parent.right
308 309
                QGCButton {
                    width:      ScreenTools.defaultFontPixelWidth * 10
Tomaz Canabrava's avatar
Tomaz Canabrava committed
310
                    text:       qsTr("OK")
311
                    enabled:    nameField.text !== ""
312
                    onClicked: {
313
                        // Save editting
314
                        linkSettingLoader.item.saveSettings()
315 316 317 318 319 320 321 322
                        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)
                        }
323
                        linkSettingLoader.source = ""
324
                        editConfig = null
325 326 327 328 329
                        _linkRoot.closeCommSettings()
                    }
                }
                QGCButton {
                    width:      ScreenTools.defaultFontPixelWidth * 10
Tomaz Canabrava's avatar
Tomaz Canabrava committed
330
                    text:       qsTr("Cancel")
331
                    onClicked: {
332 333
                        QGroundControl.linkManager.cancelConfigurationEditing(editConfig)
                        editConfig = null
334 335 336 337 338 339
                        _linkRoot.closeCommSettings()
                    }
                }
            }
        }
    }
340
}