LinkSettings.qml 18.2 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 27 28 29 30 31 32

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

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

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

    ExclusiveGroup { id: linkGroup }

    QGCPalette {
        id:                 qgcPal
        colorGroupEnabled:  enabled
    }

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

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

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    Flickable {
        clip:               true
        anchors.top:        parent.top
        width:              parent.width
        height:             parent.height - buttonRow.height
        contentHeight:      settingsColumn.height
        contentWidth:       _linkRoot.width
        flickableDirection: Flickable.VerticalFlick
        boundsBehavior:     Flickable.StopAtBounds

        Column {
            id:                 settingsColumn
            width:              _linkRoot.width
            anchors.margins:    ScreenTools.defaultFontPixelWidth
            spacing:            ScreenTools.defaultFontPixelHeight / 2
            QGCLabel {
76 77 78 79 80 81 82
                text:   "Comm Link Settings (WIP)"
                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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
            }
            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
                    anchors.horizontalCenter: parent.horizontalCenter
                    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
            text:       "Delete"
114
            enabled:    _currentSelection && !_currentSelection.link
115 116 117 118 119 120
            onClicked: {
            }
        }
        QGCButton {
            width:      ScreenTools.defaultFontPixelWidth * 10
            text:       "Edit"
121
            enabled:    _currentSelection && !_currentSelection.link
122
            onClicked: {
123
                _linkRoot.openCommSettings(_currentSelection)
124 125 126 127 128 129
            }
        }
        QGCButton {
            width:      ScreenTools.defaultFontPixelWidth * 10
            text:       "Add"
            onClicked: {
130
                _linkRoot.openCommSettings(null)
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
            }
        }
        QGCButton {
            width:      ScreenTools.defaultFontPixelWidth * 10
            text:       "Connect"
            enabled:    _currentSelection && !_currentSelection.link
            onClicked: {
                QGroundControl.linkManager.createConnectedLink(_currentSelection)
                settingsMenu.closeSettings()
            }
        }
        QGCButton {
            width:      ScreenTools.defaultFontPixelWidth * 10
            text:       "Disconnect"
            enabled:    _currentSelection && _currentSelection.link
            onClicked: {
                QGroundControl.linkManager.disconnectLink(_currentSelection.link, false)
            }
        }
    }
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 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 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484

    Loader {
        id:             settingLoader
        anchors.fill:   parent
        visible:        false
        property var linkConfig: null
    }

    //---------------------------------------------
    // Comm Settings
    Component {
        id: commSettings
        Rectangle {
            color:          __qgcPal.window
            anchors.fill:   parent
            Flickable {
                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 {
                        text:   linkConfig ? "Edit Link Configuration Settings (WIP)" : "Create New Link Configuration (WIP)"
                        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 {
                            text:   "Name:"
                            width:  _firstColumn
                            anchors.verticalCenter: parent.verticalCenter
                        }
                        QGCTextField {
                            text:   linkConfig ? linkConfig.name : "Untitled"
                            width:  _secondColumn
                            anchors.verticalCenter: parent.verticalCenter
                        }
                    }
                    Row {
                        spacing:        ScreenTools.defaultFontPixelWidth
                        QGCLabel {
                            text:       "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) {
                                    if(linkConfig.linkType === LinkConfiguration.TypeSerial)
                                        linkSettingLoader.sourceComponent = serialLinkSettings
                                    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: {
                                if (index != -1) {
                                    linkSettingLoader.sourceComponent = null
                                    if(index === LinkConfiguration.TypeSerial)
                                        linkSettingLoader.sourceComponent = serialLinkSettings
                                    if(index === LinkConfiguration.TypeUdp)
                                        linkSettingLoader.sourceComponent = udpLinkSettings
                                    if(index === LinkConfiguration.TypeTcp)
                                        linkSettingLoader.sourceComponent = tcpLinkSettings
                                    if(index === LinkConfiguration.TypeMock)
                                        linkSettingLoader.sourceComponent = mockLinkSettings
                                    if(index === LinkConfiguration.TypeLogReplay)
                                        linkSettingLoader.sourceComponent = logLinkSettings
                                }
                            }
                            Component.onCompleted: {
                                if(linkConfig == null) {
                                    linkTypeCombo.currentIndex = 0
                                    linkSettingLoader.sourceComponent = serialLinkSettings
                                    linkSettingLoader.visible = true
                                }
                            }
                        }
                    }
                    Item {
                        height: ScreenTools.defaultFontPixelHeight
                        width:  parent.width
                    }
                    Loader {
                        id:             linkSettingLoader
                        width:          parent.width
                        visible:        false
                        property var config: linkConfig
                    }
                }
            }
            Row {
                id:                 commButtonRow
                spacing:            ScreenTools.defaultFontPixelWidth
                anchors.margins:    ScreenTools.defaultFontPixelWidth
                anchors.bottom:     parent.bottom
                anchors.horizontalCenter: parent.horizontalCenter
                QGCButton {
                    width:      ScreenTools.defaultFontPixelWidth * 10
                    text:       "OK"
                    onClicked: {
                        _linkRoot.closeCommSettings()
                    }
                }
                QGCButton {
                    width:      ScreenTools.defaultFontPixelWidth * 10
                    text:       "Cancel"
                    onClicked: {
                        _linkRoot.closeCommSettings()
                    }
                }
            }
        }
    }
    //---------------------------------------------
    // Serial Link Settings
    Component {
        id: serialLinkSettings
        Column {
            width:              parent.width
            spacing:            ScreenTools.defaultFontPixelHeight / 2
            QGCLabel {
                id:     serialLabel
                text:   "Serial Link Settings"
            }
            Rectangle {
                height: 1
                width:  serialLabel.width
                color:  qgcPal.button
            }
            Item {
                height: ScreenTools.defaultFontPixelHeight / 2
                width:  parent.width
            }
            Row {
                spacing:    ScreenTools.defaultFontPixelWidth
                QGCLabel {
                    text:   "Serial Port:"
                    width:  _firstColumn
                    anchors.verticalCenter: parent.verticalCenter
                }
                QGCComboBox {
                    id:             commPortCombo
                    width:          _secondColumn
                    model:          QGroundControl.linkManager.serialPortStrings
                    anchors.verticalCenter: parent.verticalCenter
                    onActivated: {
                        if (index != -1) {
                        }
                    }
                    Component.onCompleted: {
                        if(config != null) {
                        }
                    }
                }
            }
            Row {
                spacing:    ScreenTools.defaultFontPixelWidth
                QGCLabel {
                    text:   "Baud Rate:"
                    width:  _firstColumn
                    anchors.verticalCenter: parent.verticalCenter
                }
                QGCComboBox {
                    id:             baudCombo
                    width:          _secondColumn
                    model:          QGroundControl.linkManager.serialBaudRates
                    anchors.verticalCenter: parent.verticalCenter
                    onActivated: {
                        if (index != -1) {
                        }
                    }
                    Component.onCompleted: {
                        var baud = "57600"
                        if(config != null) {
                            // Get baud from config
                        }
                        var index = baudCombo.find(baud)
                        if (index == -1) {
                            console.warn("Baud rate name not in combo box", baud)
                        } else {
                            baudCombo.currentIndex = index
                        }
                    }
                }
            }
        }
    }
    //---------------------------------------------
    // UDP Link Settings
    Component {
        id: udpLinkSettings
        Column {
            width:              parent.width
            spacing:            ScreenTools.defaultFontPixelHeight / 2
            QGCLabel {
                id:     udpLabel
                text:   "UDP Link Settings"
            }
            Rectangle {
                height: 1
                width:  udpLabel.width
                color:  qgcPal.button
            }
            Item {
                height: ScreenTools.defaultFontPixelHeight / 2
                width:  parent.width
            }
            Row {
                spacing:    ScreenTools.defaultFontPixelWidth
                QGCLabel {
                    text:   "Listening Port:"
                    width:  _firstColumn
                }
                QGCLabel {
                    text:   "14550"
                    width:  _secondColumn
                }
            }
            QGCLabel {
                text:   "Target Hosts:"
            }
        }
    }
    //---------------------------------------------
    // TCP Link Settings
    Component {
        id: tcpLinkSettings
        Column {
            width:              parent.width
            spacing:            ScreenTools.defaultFontPixelHeight / 2
            QGCLabel {
                id:     tcpLabel
                text:   "TCP Link Settings"
            }
            Rectangle {
                height: 1
                width:  tcpLabel.width
                color:  qgcPal.button
            }
            Item {
                height: ScreenTools.defaultFontPixelHeight / 2
                width:  parent.width
            }
            Row {
                spacing:    ScreenTools.defaultFontPixelWidth
                QGCLabel {
                    text:   "TCP Port:"
                    width:  _firstColumn
                }
                QGCLabel {
                    text:   "5760"
                    width:  _secondColumn
                }
            }
            Row {
                spacing:    ScreenTools.defaultFontPixelWidth
                QGCLabel {
                    text:   "Host Address:"
                    width:  _firstColumn
                }
                QGCLabel {
                    text:   "0.0.0.0"
                    width:  _secondColumn
                }
            }
        }
    }
    //---------------------------------------------
    // Log Replay Settings
    Component {
        id: logLinkSettings
        Column {
            width:              parent.width
            spacing:            ScreenTools.defaultFontPixelHeight / 2
            QGCLabel {
                text:   "Log Replay Link Settings"
            }
            Item {
                height: ScreenTools.defaultFontPixelHeight / 2
                width:  parent.width
            }
            QGCButton {
                text:   "Select Log File"
            }
        }
    }
    //---------------------------------------------
    // Mock Link Settings
    Component {
        id: mockLinkSettings
        Column {
            width:              parent.width
            spacing:            ScreenTools.defaultFontPixelHeight / 2
            QGCLabel {
                text:   "Mock Link Settings"
            }
            Item {
                height: ScreenTools.defaultFontPixelHeight / 2
                width:  parent.width
            }
        }
    }
485
}