LinkSettings.qml 19 KB
Newer Older
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
4 5 6 7 8
 *
 * 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.3
import QtQuick.Controls 1.2
13
import QtQuick.Dialogs  1.2
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

    QGCPalette {
        id:                 qgcPal
        colorGroupEnabled:  enabled
    }

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

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

    //---------------------------------------------
    // Comm Settings
    Component {
        id: commSettings
        Rectangle {
151
            id:             settingsRect
152
            color:          qgcPal.window
153
            anchors.fill:   parent
154
            property real   _panelWidth:    width * 0.8
155 156 157 158 159 160
            Component.onCompleted: {
                // If editing, create copy for editing
                if(linkConfig) {
                    editConfig = QGroundControl.linkManager.startConfigurationEditing(linkConfig)
                } else {
                    // Create new link configuration
161
                    if(ScreenTools.isSerialAvailable) {
162
                        editConfig = QGroundControl.linkManager.createConfiguration(LinkConfiguration.TypeSerial, "Unnamed")
163 164 165
                    } else {
                        editConfig = QGroundControl.linkManager.createConfiguration(LinkConfiguration.TypeUdp,    "Unnamed")
                    }
166 167 168 169 170 171 172 173
                }
            }
            Component.onDestruction: {
                if(editConfig) {
                    QGroundControl.linkManager.cancelConfigurationEditing(editConfig)
                    editConfig = null
                }
            }
174 175 176 177 178 179 180 181 182 183 184 185 186
            Column {
                id:                 settingsTitle
                spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                QGCLabel {
                    text:   linkConfig ? qsTr("Edit Link Configuration Settings") : qsTr("Create New Link Configuration")
                    font.pointSize: ScreenTools.mediumFontPointSize
                }
                Rectangle {
                    height: 1
                    width:  settingsRect.width
                    color:  qgcPal.button
                }
            }
Don Gagne's avatar
Don Gagne committed
187
            QGCFlickable {
188
                id:                 settingsFlick
189
                clip:               true
190 191
                anchors.top:        settingsTitle.bottom
                anchors.bottom:     commButtonRow.top
192 193 194 195 196 197 198 199 200 201
                width:              parent.width
                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
202 203 204
                    spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                    //-----------------------------------------------------------------
                    //-- General
205
                    Item {
206 207 208 209
                        width:                      _panelWidth
                        height:                     generalLabel.height
                        anchors.margins:            ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter:   parent.horizontalCenter
210
                        QGCLabel {
211 212 213
                            id:                     generalLabel
                            text:                   qsTr("General")
                            font.family:            ScreenTools.demiboldFontFamily
214 215
                        }
                    }
216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
                    Rectangle {
                        height:                     generalCol.height + (ScreenTools.defaultFontPixelHeight * 2)
                        width:                      _panelWidth
                        color:                      qgcPal.windowShade
                        anchors.margins:            ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter:   parent.horizontalCenter
                        Column {
                            id:                     generalCol
                            anchors.centerIn:       parent
                            anchors.margins:        ScreenTools.defaultFontPixelWidth
                            spacing:                ScreenTools.defaultFontPixelHeight * 0.5
                            Row {
                                spacing:    ScreenTools.defaultFontPixelWidth
                                QGCLabel {
                                    text:   qsTr("Name:")
                                    width:  _firstColumn
                                    anchors.verticalCenter: parent.verticalCenter
                                }
                                QGCTextField {
                                    id:     nameField
                                    text:   editConfig ? editConfig.name : ""
                                    width:  _secondColumn
                                    anchors.verticalCenter: parent.verticalCenter
239 240
                                }
                            }
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260
                            Row {
                                spacing:            ScreenTools.defaultFontPixelWidth
                                QGCLabel {
                                    text:           qsTr("Type:")
                                    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) {
                                            linkSettingLoader.source  = linkConfig.settingsURL
                                            linkSettingLoader.visible = true
                                        }
                                    }
261
                                }
262 263 264 265 266 267 268 269 270 271 272 273 274 275
                                //-----------------------------------------------------
                                // When creating, select a link type
                                QGCComboBox {
                                    id:             linkTypeCombo
                                    width:          _secondColumn
                                    visible:        linkConfig == null
                                    model:          QGroundControl.linkManager.linkTypeStrings
                                    anchors.verticalCenter: parent.verticalCenter
                                    onActivated: {
                                        if (index != -1 && index !== editConfig.linkType) {
                                            // Destroy current panel
                                            linkSettingLoader.source = ""
                                            linkSettingLoader.visible = false
                                            // Save current name
276
                                            var name = nameField.text
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
                                            // Discard link configuration (old type)
                                            QGroundControl.linkManager.cancelConfigurationEditing(editConfig)
                                            // Create new link configuration
                                            editConfig = QGroundControl.linkManager.createConfiguration(index, name)
                                            // Load appropriate configuration panel
                                            linkSettingLoader.source  = editConfig.settingsURL
                                            linkSettingLoader.visible = true
                                        }
                                    }
                                    Component.onCompleted: {
                                        if(linkConfig == null) {
                                            linkTypeCombo.currentIndex = 0
                                            linkSettingLoader.source   = editConfig.settingsURL
                                            linkSettingLoader.visible  = true
                                        }
                                    }
                                }
                            }
                            Item {
                                height: ScreenTools.defaultFontPixelHeight * 0.5
                                width:  parent.width
298
                            }
299 300 301 302 303 304 305 306 307 308 309 310
                            //-- Auto Connect on Start
                            QGCCheckBox {
                                text:               qsTr("Automatically Connect on Start")
                                checked:            false
                                onCheckedChanged: {
                                    if(editConfig) {
                                        editConfig.autoConnect = checked
                                    }
                                }
                                Component.onCompleted: {
                                    if(editConfig)
                                        checked = editConfig.autoConnect
311 312
                                }
                            }
313 314 315 316 317 318 319 320 321 322 323 324
                            QGCCheckBox {
                                text:               qsTr("High Latency")
                                checked:            false
                                onCheckedChanged: {
                                    if(editConfig) {
                                        editConfig.highLatency = checked
                                    }
                                }
                                Component.onCompleted: {
                                    if(editConfig)
                                        checked = editConfig.highLatency
                                }
325 326 327
                            }
                        }
                    }
328 329 330 331
                    Item {
                        height: ScreenTools.defaultFontPixelHeight
                        width:  parent.width
                    }
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361
                    //-----------------------------------------------------------------
                    //-- Link Specific Settings
                    Item {
                        width:                      _panelWidth
                        height:                     linkLabel.height
                        anchors.margins:            ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter:   parent.horizontalCenter
                        QGCLabel {
                            id:                     linkLabel
                            text:                   editConfig ? editConfig.settingsTitle : ""
                            visible:                linkSettingLoader.source != ""
                            font.family:            ScreenTools.demiboldFontFamily
                        }
                    }
                    Rectangle {
                        height:                     linkSettingLoader.height + (ScreenTools.defaultFontPixelHeight * 2)
                        width:                      _panelWidth
                        color:                      qgcPal.windowShade
                        anchors.margins:            ScreenTools.defaultFontPixelWidth
                        anchors.horizontalCenter:   parent.horizontalCenter
                        Item {
                            height:                 linkSettingLoader.height
                            width:                  linkSettingLoader.width
                            anchors.centerIn:       parent
                            Loader {
                                id:                 linkSettingLoader
                                visible:            false
                                property var subEditConfig: editConfig
                            }
                        }
362 363 364 365 366 367 368 369
                    }
                }
            }
            Row {
                id:                 commButtonRow
                spacing:            ScreenTools.defaultFontPixelWidth
                anchors.margins:    ScreenTools.defaultFontPixelWidth
                anchors.bottom:     parent.bottom
dogmaphobic's avatar
dogmaphobic committed
370
                anchors.right:      parent.right
371 372
                QGCButton {
                    width:      ScreenTools.defaultFontPixelWidth * 10
Tomaz Canabrava's avatar
Tomaz Canabrava committed
373
                    text:       qsTr("OK")
374
                    enabled:    nameField.text !== ""
375
                    onClicked: {
376
                        // Save editting
377
                        linkSettingLoader.item.saveSettings()
378 379 380 381 382 383 384 385
                        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)
                        }
386
                        linkSettingLoader.source = ""
387
                        editConfig = null
388 389 390 391 392
                        _linkRoot.closeCommSettings()
                    }
                }
                QGCButton {
                    width:      ScreenTools.defaultFontPixelWidth * 10
Tomaz Canabrava's avatar
Tomaz Canabrava committed
393
                    text:       qsTr("Cancel")
394
                    onClicked: {
395 396
                        QGroundControl.linkManager.cancelConfigurationEditing(editConfig)
                        editConfig = null
397 398 399 400 401 402
                        _linkRoot.closeCommSettings()
                    }
                }
            }
        }
    }
403
}