FlightModesComponent.qml 41.6 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/>.

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

Don Gagne's avatar
Don Gagne committed
24 25 26 27 28 29 30 31 32
import QtQuick 2.2
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2

import QGroundControl.FactSystem 1.0
import QGroundControl.FactControls 1.0
import QGroundControl.Palette 1.0
import QGroundControl.Controls 1.0
import QGroundControl.Controllers 1.0
33
import QGroundControl.ScreenTools 1.0
Don Gagne's avatar
Don Gagne committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61

Item {
    Loader {
        property FlightModesComponentController controller: FlightModesComponentController { }
        property QGCPalette qgcPal: QGCPalette { colorGroupEnabled: true }
        property bool loading: true

        anchors.fill: parent
        sourceComponent: controller.validConfiguration ? validComponent : invalidComponent

        onLoaded: loading = false
    }

    Component {
        id: validComponent

        Rectangle {
            Fact { id: rc_map_throttle;     name: "RC_MAP_THROTTLE" }
            Fact { id: rc_map_yaw;          name: "RC_MAP_YAW" }
            Fact { id: rc_map_pitch;        name: "RC_MAP_PITCH" }
            Fact { id: rc_map_roll;         name: "RC_MAP_ROLL" }
            Fact { id: rc_map_flaps;        name: "RC_MAP_FLAPS" }
            Fact { id: rc_map_aux1;         name: "RC_MAP_AUX1" }
            Fact { id: rc_map_aux2;         name: "RC_MAP_AUX2" }

            Fact { id: rc_map_mode_sw;      name: "RC_MAP_MODE_SW" }
            Fact { id: rc_map_posctl_sw;    name: "RC_MAP_POSCTL_SW" }
            Fact { id: rc_map_return_sw;    name: "RC_MAP_RETURN_SW" }
62
            Fact { id: rc_map_offboard_sw;  name: "RC_MAP_OFFB_SW" }
Don Gagne's avatar
Don Gagne committed
63 64 65 66 67 68 69
            Fact { id: rc_map_loiter_sw;    name: "RC_MAP_LOITER_SW" }

            Fact { id: rc_assist_th;        name: "RC_ASSIST_TH" }
            Fact { id: rc_posctl_th;        name: "RC_POSCTL_TH" }
            Fact { id: rc_auto_th;          name: "RC_AUTO_TH" }
            Fact { id: rc_loiter_th;        name: "RC_LOITER_TH" }
            Fact { id: rc_return_th;        name: "RC_RETURN_TH" }
70
            Fact { id: rc_offboard_th;      name: "RC_OFFB_TH" }
Don Gagne's avatar
Don Gagne committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84

            Fact { id: rc_th_user;          name: "RC_TH_USER" }

            property int throttleChannel:   rc_map_throttle.value
            property int yawChannel:        rc_map_yaw.value
            property int pitchChannel:      rc_map_pitch.value
            property int rollChannel:       rc_map_roll.value
            property int flapsChannel:      rc_map_flaps.value
            property int aux1Channel:       rc_map_aux1.value
            property int aux2Channel:       rc_map_aux2.value

            property int modeChannel:       rc_map_mode_sw.value
            property int posCtlChannel:     rc_map_posctl_sw.value
            property int returnChannel:     rc_map_return_sw.value
85
            property int offboardChannel:   rc_map_offboard_sw.value
Don Gagne's avatar
Don Gagne committed
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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 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
            property int loiterChannel:     rc_map_loiter_sw.value

            property real rcThUserValue: rc_th_user.value

            readonly property int channelCount: controller.channelCount

            property bool inRedistribution: false

            readonly property int tileWidth: 150
            readonly property int tileHeight: 30

            readonly property int progressBarHeight: 200

            anchors.fill: parent


            color: qgcPal.window

            Component {
                id: dragHandle

                Item {
                    id:     outerItem
                    width:  parent.width
                    height: parent.height

                    Column {
                        x: 4
                        y: 4
                        spacing: 3

                        Repeater {
                            model: (outerItem.height - 8) / 4
                            Rectangle {
                                color: qgcPal.text
                                width: 15
                                height: 1
                            }
                        }
                    }
                }
            }

            // This component is used to create draggable tiles for unassigned mode switches. It also
            // creates the drop area for dragging an assigned mode switch tile back to an unassigned state.
            // The following properties must be set in the Loader:
            //  tileLabel - label for tile
            //  tileParam - parameter to load from
            //  tileDragEnabled - true: this tile can be dragged
            Component {
                id: unassignedModeTileComponent

                Rectangle {
                    Fact { id: fact; name: tileParam }
                    property bool dragEnabled: fact.value == 0

                    id:             outerRect
                    width:          tileWidth
                    height:         tileHeight
                    color:          qgcPal.windowShadeDark
                    border.width:   dragEnabled ? 1 : 0
                    border.color:   qgcPal.text

                    Drag.active:    mouseArea.drag.active
                    Drag.hotSpot.x: width / 2
                    Drag.hotSpot.y: height / 2
                    Drag.keys:      [ "unassigned"]

                    states: [
                        State {
                            when: dropArea.containsDrag
                            PropertyChanges {
                                target: outerRect
                                color: "red"
                            }
                        }
                    ]

                    Loader {
                        width: parent.width
                        height: parent.height
                        visible: dragEnabled
                        sourceComponent: dragHandle
                    }

                    QGCLabel {
                        width:                  parent.width
                        height:                 parent.height
                        text:                   tileLabel
                        enabled:                dragEnabled
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                    }

                    MouseArea {
                        id:             mouseArea
                        width:          parent.width
                        height:         parent.height
                        drag.target:    dragEnabled ? parent : null

                        onReleased: {
                            // Move tile back to original position
                            parent.x = 0; parent.y = 0;

                            // If dropped over a channel target remap switch
                            if (parent.Drag.target && parent.Drag.target.dropAllowed) {
192 193 194
                                if (!singleSwitchRequired || parent.Drag.target.unassignedChannel) {
                                    fact.value = parent.Drag.target.channel
                                }
Don Gagne's avatar
Don Gagne committed
195 196 197 198 199 200
                            }
                        }
                    }

                    DropArea {
                        // This will cause to tile to go back to unassigned if dropped here
201 202 203 204
                        readonly property int channel:      0
                        property bool dropAllowed:          true
                        property bool unassignedChannel:    true

Don Gagne's avatar
Don Gagne committed
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

                        id:     dropArea
                        width:  parent.width
                        height: parent.height

                        keys: [ "assigned" ]
                    }
                }
            }

            // This component is used to create draggable tiles for currently assigned mode switches. The following
            // properties must be set in the Loader:
            //  tileLabel - label for tile
            //  tileVisible - visibility for tile
            //  tileDragEnabled - true: this tile can be dragged
            //  tileParam - parameter to load from
            Component {
                id: assignedModeTileComponent

                Rectangle {
                    Fact { id: fact; name: tileDragEnabled ? tileParam : "" }

                    width:          tileWidth
                    height:         tileHeight
                    color:          qgcPal.windowShadeDark
                    border.width:   tileDragEnabled ? 1 : 0
                    border.color:   qgcPal.text
                    visible:        tileVisible

                    Drag.active:    mouseArea.drag.active
                    Drag.hotSpot.x: width / 2
                    Drag.hotSpot.y: height / 2
                    Drag.keys:      [ "assigned" ]

                    Loader {
                        width: parent.width
                        height: parent.height
                        visible: tileDragEnabled
                        sourceComponent: dragHandle
                    }

                    QGCLabel {
                        width:                  parent.width
                        height:                 parent.height
                        enabled:                tileDragEnabled
                        horizontalAlignment:    Text.AlignHCenter
                        verticalAlignment:      Text.AlignVCenter
                        text:                   tileLabel
                    }

                    MouseArea {
                        id:             mouseArea
                        width:          parent.width
                        height:         parent.height
                        drag.target:    tileDragEnabled ? parent : null

                        onReleased: {
                            // Move tile back to original position
                            parent.x = 0; parent.y = 0;

                            // If dropped over a channel target remap switch
                            if (parent.Drag.target && parent.Drag.target.dropAllowed) {
267 268 269
                                if (!singleSwitchRequired || parent.Drag.target.unassignedChannel) {
                                    fact.value = parent.Drag.target.channel
                                }
Don Gagne's avatar
Don Gagne committed
270 271 272 273 274 275 276 277
                            }
                        }
                    }
                }
            }

            onModeChannelChanged: if (!inRedistribution) redistributeThresholds()
            onReturnChannelChanged: if (!inRedistribution) redistributeThresholds()
278
            onOffboardChannelChanged: if (!inRedistribution) redistributeThresholds()
Don Gagne's avatar
Don Gagne committed
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
            onLoiterChannelChanged: if (!inRedistribution) redistributeThresholds()
            onPosCtlChannelChanged: if (!inRedistribution) redistributeThresholds()
            onRcThUserValue: if (!inRedistribution) redistributeThresholds()

            function redistributeThresholds() {
                if (loading || rcThUserValue != 0) {
                    // User is specifying thresholds, do not auto-calculate
                    return
                }

                if (modeChannel != 0) {
                    var positions = 3  // Manual/Assist/Auto always exist

                    var loiterOnModeSwitch = modeChannel == loiterChannel
                    var posCtlOnModeSwitch = modeChannel == posCtlChannel

                    positions += loiterOnModeSwitch ? 1 : 0
                    positions += posCtlOnModeSwitch ? 1 : 0

                    var increment = 1.0 / positions
                    var currentThreshold = 0.0

                    // Make sure we don't re-enter
                    inRedistribution = true

                    currentThreshold += increment
                    rc_assist_th.value = currentThreshold
                    if (posCtlOnModeSwitch) {
                        currentThreshold += increment
                        rc_posctl_th.value = currentThreshold
                    }
                    currentThreshold += increment
                    rc_auto_th.value = currentThreshold
                    if (loiterOnModeSwitch) {
                        currentThreshold += increment
                        rc_loiter_th.value = currentThreshold
                    }

                    inRedistribution = false
                }

320
                if (returnChannel != 0) {
Don Gagne's avatar
Don Gagne committed
321 322
                    inRedistribution = true

323 324 325
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
                    rc_return_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
326 327 328 329

                    inRedistribution = false
                }

330 331 332
                if (offboardChannel != 0) {
                    inRedistribution = true

Don Gagne's avatar
Don Gagne committed
333 334
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
335
                    rc_offboard_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
336

337 338
                    inRedistribution = false
                }
Don Gagne's avatar
Don Gagne committed
339

340
                if (loiterChannel != 0 && loiterChannel != modeChannel) {
Don Gagne's avatar
Don Gagne committed
341 342
                    inRedistribution = true

343 344 345
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
                    rc_loiter_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
346 347 348 349 350 351 352

                    inRedistribution = false
                }

                if (posCtlChannel != 0 & posCtlChannel != modeChannel) {
                    inRedistribution = true

353 354 355
                    // If only two positions don't set threshold at midrange. Setting to 0.25
                    // allows for this channel to work with either two or three position switch
                    rc_posctl_th.value = 0.25
Don Gagne's avatar
Don Gagne committed
356 357 358 359 360 361 362 363 364 365

                    inRedistribution = false
                }
            }

            Column {
                anchors.fill: parent

                QGCLabel {
                    text: "FLIGHT MODES CONFIG"
366
                    font.pointSize: ScreenTools.fontPointFactor * (20);
Don Gagne's avatar
Don Gagne committed
367 368 369 370 371 372
                }

                Item { height: 20; width: 10 } // spacer

                QGCLabel {
                    width: parent.width
373 374 375 376
                    text: "The Main Mode, Loiter and PostCtl switches can be assigned to any channel which is not currently being used for attitude control. The Return and Offboard switches must be assigned to their seperate channel. " +
                            "All channels are displayed below. " +
                            "You can drag Flight Modes from the Flight Modes section below to a channel and drop it there. You can also drag switches assigned to a channel " +
                            "to another channel or back to the Unassigned Switches section. The Switch Display section at the very bottom will show you the results of your Flight Mode setup."
Don Gagne's avatar
Don Gagne committed
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
                    wrapMode: Text.WordWrap
                }

                Item { height: 20; width: 10 } // spacer

                QGCLabel {
                    text: "Channel Assignments"
                }
                Flow {
                    width: parent.width
                    spacing: 5

                    Repeater {
                        model: channelCount

                        Rectangle {
                            property int channel:           modelData + 1
                            property bool throttleMapped:   channel == throttleChannel
                            property bool yawMapped:        channel == yawChannel
                            property bool pitchMapped:      channel == pitchChannel
                            property bool rollMapped:       channel == rollChannel
                            property bool flapsMapped:      channel == flapsChannel
                            property bool aux1Mapped:       channel == aux1Channel
                            property bool aux2Mapped:       channel == aux2Channel

                            property bool modeMapped:       channel == modeChannel
                            property bool posCtlMapped:     channel == posCtlChannel
                            property bool returnMapped:     channel == returnChannel
405
                            property bool offboardMapped:   channel == offboardChannel
Don Gagne's avatar
Don Gagne committed
406 407 408
                            property bool loiterMapped:     channel == loiterChannel

                            property bool nonFlightModeMapping: throttleMapped | yawMapped | pitchMapped | rollMapped | flapsMapped | aux1Mapped | aux2Mapped
409 410
                            property bool unassignedMapping: !(nonFlightModeMapping | modeMapped | posCtlMapped | returnMapped | offboardMapped | loiterMapped)
                            property bool singleSwitchMapping: returnMapped | offboardMapped
Don Gagne's avatar
Don Gagne committed
411 412 413 414 415 416 417 418 419

                            id:     channelTarget
                            width:  tileWidth
                            height: channelCol.implicitHeight

                            color:  qgcPal.windowShadeDark

                            states: [
                                State {
420
                                    when: dropArea.containsDrag && dropArea.dropAllowed && (!dropArea.drag.source.singleSwitchRequired || dropArea.unassignedChannel)
Don Gagne's avatar
Don Gagne committed
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 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508
                                    PropertyChanges {
                                        target: channelHeader
                                        color: "red"
                                    }
                                }
                            ]

                            Column {
                                id:         channelCol
                                spacing:    3

                                Rectangle {
                                    id: channelHeader
                                    width:  tileWidth
                                    height: tileHeight
                                    color:  qgcPal.windowShade

                                    QGCLabel {
                                        verticalAlignment:      Text.AlignVCenter
                                        horizontalAlignment:    Text.AlignHCenter
                                        text:                   "Channel " + (modelData + 1) + (nonFlightModeMapping ? ": Unavailable" : "")
                                    }
                                }
                                Loader {
                                    property string tileLabel:      "Available"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            unassignedMapping
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Throttle"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            throttleMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Yaw"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            yawMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Pitch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            pitchMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Roll"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            rollMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Flaps Switch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            flapsMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Aux1 Switch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            aux1Mapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:      "Aux2 Switch"
                                    property bool tileVisible:      visible
                                    property bool tileDragEnabled:  false

                                    visible:            aux2Mapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
509 510 511 512 513
                                    property string tileLabel:          "Main Mode"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_MODE_SW"
                                    property bool singleSwitchRequired: false
Don Gagne's avatar
Don Gagne committed
514 515 516 517 518

                                    visible:            modeMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
519 520 521 522 523
                                    property string tileLabel:          "Return"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_RETURN_SW"
                                    property bool singleSwitchRequired: true
Don Gagne's avatar
Don Gagne committed
524 525 526 527 528

                                    visible:            returnMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543
                                    property string tileLabel:          "Offboard"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_OFFB_SW"
                                    property bool singleSwitchRequired: true

                                    visible:            offboardMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
                                    property string tileLabel:          "Loiter"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_LOITER_SW"
                                    property bool singleSwitchRequired: false
Don Gagne's avatar
Don Gagne committed
544 545 546 547 548

                                    visible:            loiterMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                                Loader {
549 550 551 552 553
                                    property string tileLabel:          "PosCtl"
                                    property bool tileVisible:          visible
                                    property bool tileDragEnabled:      true
                                    property string tileParam:          "RC_MAP_POSCTL_SW"
                                    property bool singleSwitchRequired: false
Don Gagne's avatar
Don Gagne committed
554 555 556 557 558 559 560 561

                                    visible:            posCtlMapped
                                    sourceComponent:    assignedModeTileComponent
                                }
                            }

                            DropArea {
                                // Drops are not allowed on channels which are mapped to non-flight mode switches
562 563
                                property bool dropAllowed: !nonFlightModeMapping && !singleSwitchMapping
                                property bool unassignedChannel: unassignedMapping
Don Gagne's avatar
Don Gagne committed
564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593
                                property int channel: parent.channel

                                id:     dropArea
                                width:  parent.width
                                height: parent.height

                                keys: [ "unassigned", "assigned" ]
                            }
                        }
                    }
                }

                Item { height: 20; width: 10 } // spacer

                Row {
                    spacing: 5

                    QGCLabel {
                        text: "Flight Modes"
                    }
                    QGCLabel {
                        text: "(Mode Switch must be assigned to channel before flight is allowed)"
                        visible: rc_map_mode_sw.value == 0
                    }
                }
                Flow {
                    width: parent.width
                    spacing: 5

                    Loader {
594 595 596 597 598 599 600 601 602 603
                        property string tileLabel:          "Main Mode"
                        property string tileParam:          "RC_MAP_MODE_SW"
                        property bool singleSwitchRequired: false
                        sourceComponent:                    unassignedModeTileComponent
                    }
                    Loader {
                        property string tileLabel:          "Loiter"
                        property string tileParam:          "RC_MAP_LOITER_SW"
                        property bool singleSwitchRequired: false
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
604 605
                    }
                    Loader {
606 607 608 609
                        property string tileLabel:          "PosCtl"
                        property string tileParam:          "RC_MAP_POSCTL_SW"
                        property bool singleSwitchRequired: false
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
610 611
                    }
                    Loader {
612 613 614 615
                        property string tileLabel:          "Return"
                        property string tileParam:          "RC_MAP_RETURN_SW"
                        property bool singleSwitchRequired: true
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
616 617
                    }
                    Loader {
618 619 620 621
                        property string tileLabel:          "Offboard"
                        property string tileParam:          "RC_MAP_OFFB_SW"
                        property bool singleSwitchRequired: true
                        sourceComponent:                    unassignedModeTileComponent
Don Gagne's avatar
Don Gagne committed
622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
                    }
                }

                Item { height: 20; width: 10 } // spacer

                FactCheckBox {
                    checkedValue: 0
                    uncheckedValue: 1
                    fact: rc_th_user
                    text: "Allow setup to generate the thresholds for the flight mode positions within a switch (recommended)"
                }

                Item { height: 20; width: 10 } // spacer

                Row {
                spacing: 20

                    QGCLabel {
                        text: "Switch Display"
                    }
                    QGCCheckBox {
                        checked: controller.sendLiveRCSwitchRanges
                        text: "Show live RC display"
                        onClicked: {
                            controller.sendLiveRCSwitchRanges = checked
                        }
                    }
                }

                Item { height: 20; width: 10 } // spacer

                Row {
                    property bool modeSwitchVisible: modeChannel != 0
                    property bool loiterSwitchVisible: loiterChannel != 0 && loiterChannel != modeChannel && loiterChannel != returnChannel
                    property bool posCtlSwitchVisible: posCtlChannel != 0 && posCtlChannel != modeChannel
657 658
                    property bool returnSwitchVisible: returnChannel != 0
                    property bool offboardSwitchVisible: offboardChannel != 0
Don Gagne's avatar
Don Gagne committed
659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745

                    width:      parent.width
                    spacing:    20

                    Column {
                        visible: parent.modeSwitchVisible

                        QGCLabel { text: "Mode Switch" }

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_auto_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel != returnChannel && modeChannel != loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_loiter_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto: Loiter"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_auto_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto: Mission"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_auto_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == returnChannel && modeChannel != loiterChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Auto: Loiter/Mission"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_assist_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel != posCtlChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Assist"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_posctl_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == posCtlChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Assist: PosCtl"
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      (parent.height * (1.0 - rc_assist_th.value)) - (implicitHeight / 2)
                                    visible:                modeChannel == posCtlChannel
                                    horizontalAlignment:    Text.AlignRight
                                    text:                   "Assist: AltCtl"
                                }

                                QGCLabel {
                                    width:              parent.width
                                    y:                  parent.height - (implicitHeight / 2)
                                    text:               "Manual"
                                    horizontalAlignment: Text.AlignRight
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
                                value:          controller.modeSwitchLiveRange
                            }
                        }
                    }

                    Column {
746
                        visible: parent.loiterSwitchVisible
Don Gagne's avatar
Don Gagne committed
747

748
                        QGCLabel { text: "Loiter Switch" }
Don Gagne's avatar
Don Gagne committed
749 750 751 752 753 754 755 756

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
757
                                    y:                      (parent.height * (1.0 - rc_loiter_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
758
                                    horizontalAlignment:    Text.AlignRight
759
                                    text:                   "Auto: Loiter"
Don Gagne's avatar
Don Gagne committed
760 761 762 763
                                }

                                QGCLabel {
                                    width:                  parent.width
764
                                    y:                      parent.height - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
765
                                    horizontalAlignment:    Text.AlignRight
766
                                    text:                   "Auto: Mission"
Don Gagne's avatar
Don Gagne committed
767
                                }
768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
                                value:          controller.loiterSwitchLiveRange
                            }
                        }
                    }

                    Column {
                        visible: parent.posCtlSwitchVisible

                        QGCLabel { text: "PosCtl Switch" }

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150
Don Gagne's avatar
Don Gagne committed
787 788 789

                                QGCLabel {
                                    width:                  parent.width
790
                                    y:                      (parent.height * (1.0 - rc_posctl_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
791
                                    horizontalAlignment:    Text.AlignRight
792
                                    text:                   "Assist: PosCtl"
Don Gagne's avatar
Don Gagne committed
793 794 795 796 797 798
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      parent.height - (implicitHeight / 2)
                                    horizontalAlignment:    Text.AlignRight
799
                                    text:                   "Assist: AltCtl"
Don Gagne's avatar
Don Gagne committed
800 801 802 803 804 805
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
806
                                value:          controller.posCtlSwitchLiveRange
Don Gagne's avatar
Don Gagne committed
807 808 809 810 811
                            }
                        }
                    }

                    Column {
812
                        visible: parent.returnSwitchVisible
Don Gagne's avatar
Don Gagne committed
813

814
                        QGCLabel { text: "Return Switch" }
Don Gagne's avatar
Don Gagne committed
815 816 817 818 819 820 821 822

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
823
                                    y:                      (parent.height * (1.0 - rc_return_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
824
                                    horizontalAlignment:    Text.AlignRight
825
                                    text:                   "Return"
Don Gagne's avatar
Don Gagne committed
826 827 828 829 830
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      parent.height - (implicitHeight / 2)
831
                                    visible:                returnChannel != loiterChannel
Don Gagne's avatar
Don Gagne committed
832
                                    horizontalAlignment:    Text.AlignRight
833
                                    text:                   "Return Off"
Don Gagne's avatar
Don Gagne committed
834 835 836 837 838 839
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
840
                                value:          controller.returnSwitchLiveRange
Don Gagne's avatar
Don Gagne committed
841 842 843 844 845
                            }
                        }
                    }

                    Column {
846
                        visible: parent.offboardSwitchVisible
Don Gagne's avatar
Don Gagne committed
847

848
                        QGCLabel { text: "Offboard Switch" }
Don Gagne's avatar
Don Gagne committed
849 850 851 852 853 854 855 856

                        Row {
                            Item {
                                height: progressBarHeight
                                width:  150

                                QGCLabel {
                                    width:                  parent.width
857
                                    y:                      (parent.height * (1.0 - rc_return_th.value)) - (implicitHeight / 2)
Don Gagne's avatar
Don Gagne committed
858
                                    horizontalAlignment:    Text.AlignRight
859
                                    text:                   "Offboad"
Don Gagne's avatar
Don Gagne committed
860 861 862 863 864
                                }

                                QGCLabel {
                                    width:                  parent.width
                                    y:                      parent.height - (implicitHeight / 2)
865
                                    visible:                returnChannel != loiterChannel
Don Gagne's avatar
Don Gagne committed
866
                                    horizontalAlignment:    Text.AlignRight
867
                                    text:                   "Offboard Off"
Don Gagne's avatar
Don Gagne committed
868 869 870 871 872 873
                                }
                            }

                            ProgressBar {
                                height:         progressBarHeight
                                orientation:    Qt.Vertical
874
                                value:          controller.offboardSwitchLiveRange
Don Gagne's avatar
Don Gagne committed
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895
                            }
                        }
                    }
                }
            }
        }
    }

    Component {
        id: invalidComponent

        Rectangle {
            anchors.fill: parent
            color: qgcPal.window

            Column {
                width: parent.width
                spacing: 20

                QGCLabel {
                    text: "FLIGHT MODES CONFIG"
896
                    font.pointSize: ScreenTools.fontPointFactor * (20);
Don Gagne's avatar
Don Gagne committed
897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914
                }

                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    text:       "There are errors in your current configuration which will need to be fixed before you can used Flight Config setup. " +
                                "You will need to change Parameters directly using Parameters Setup to remove these errors."
                }

                QGCLabel {
                    width:      parent.width
                    wrapMode:   Text.WordWrap
                    text:       controller.configurationErrors
                }
            }
        }
    }
}