SetupPage.qml 4.25 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2 3 4 5 6 7 8 9
/****************************************************************************
 *
 *   (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.
 *
 ****************************************************************************/

10 11
import QtQuick          2.3
import QtQuick.Controls 1.2
Don Gagne's avatar
Don Gagne committed
12
import QtQuick.Dialogs  1.2
DonLakeFlyer's avatar
DonLakeFlyer committed
13
import QtQuick.Layouts  1.2
Don Gagne's avatar
Don Gagne committed
14 15 16 17 18 19 20 21 22 23

import QGroundControl               1.0
import QGroundControl.FactSystem    1.0
import QGroundControl.FactControls  1.0
import QGroundControl.Palette       1.0
import QGroundControl.Controls      1.0
import QGroundControl.ScreenTools   1.0
import QGroundControl.Controllers   1.0

/// Base view control for all Setup pages
24
Item {
Gus Grubba's avatar
Gus Grubba committed
25
    id:             setupView
26
    enabled:        !_disableDueToArmed && !_disableDueToFlying
Don Gagne's avatar
Don Gagne committed
27

28 29 30 31 32 33 34 35
    property alias  pageComponent:          pageLoader.sourceComponent
    property string pageName:               vehicleComponent ? vehicleComponent.name : ""
    property string pageDescription:        vehicleComponent ? vehicleComponent.description : ""
    property real   availableWidth:         width - pageLoader.x
    property real   availableHeight:        height - pageLoader.y
    property bool   showAdvanced:           false
    property alias  advanced:               advancedCheckBox.checked
    property bool   setupPageCompleted:     false
Don Gagne's avatar
Don Gagne committed
36

37 38 39
    property bool   _vehicleIsRover:        activeVehicle ? activeVehicle.rover : false
    property bool   _vehicleArmed:          activeVehicle ? activeVehicle.armed : false
    property bool   _vehicleFlying:         activeVehicle ? activeVehicle.flying : false
40
    property bool   _disableDueToArmed:     vehicleComponent ? (!vehicleComponent.allowSetupWhileArmed && _vehicleArmed) : false
41
    // FIXME: The _vehicleIsRover checkl is a hack to work around https://github.com/PX4/Firmware/issues/10969
Don Gagne's avatar
Don Gagne committed
42
    property bool   _disableDueToFlying:    vehicleComponent ? (!_vehicleIsRover && !vehicleComponent.allowSetupWhileFlying && _vehicleFlying) : false
43
    property string _disableReason:         _disableDueToArmed ? qsTr("armed") : qsTr("flying")
44 45
    property real   _margins:               ScreenTools.defaultFontPixelHeight * 0.5
    property string _pageTitle:             qsTr("%1 Setup").arg(pageName)
Don Gagne's avatar
Don Gagne committed
46

47 48 49 50
    Component.onCompleted: {
        setupPageCompleted = true
    }

51
    QGCFlickable {
Don Gagne's avatar
Don Gagne committed
52
        anchors.fill:   parent
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
        contentWidth:   pageLoader.x + pageLoader.item.width
        contentHeight:  pageLoader.y + pageLoader.item.height
        clip:           true

        RowLayout {
            id:                 headingRow
            anchors.left:       parent.left
            anchors.right:      parent.right
            spacing:            _margins
            layoutDirection:    Qt.RightToLeft

            QGCCheckBox {
                id:         advancedCheckBox
                text:       qsTr("Advanced")
                visible:    showAdvanced
            }
Don Gagne's avatar
Don Gagne committed
69

70
            Column {
Gus Grubba's avatar
Gus Grubba committed
71
                spacing:            _margins
72
                Layout.fillWidth:   true
Don Gagne's avatar
Don Gagne committed
73

74 75 76 77
                QGCLabel {
                    font.pointSize: ScreenTools.largeFontPointSize
                    text:           !setupView.enabled ? _pageTitle + "<font color=\"red\">" + qsTr(" (Disabled while the vehicle is %1)").arg(_disableReason) + "</font>" : _pageTitle
                    visible:        !ScreenTools.isShortScreen
Don Gagne's avatar
Don Gagne committed
78 79
                }

80 81 82 83 84 85
                QGCLabel {
                    anchors.left:   parent.left
                    anchors.right:  parent.right
                    wrapMode:       Text.WordWrap
                    text:           pageDescription
                    visible:        pageDescription !== "" && !ScreenTools.isShortScreen
Don Gagne's avatar
Don Gagne committed
86 87
                }
            }
88 89 90 91 92 93 94 95 96 97 98 99 100
        }
        Loader {
            id:                 pageLoader
            anchors.topMargin:  _margins
            anchors.top:        headingRow.bottom
        }
        // Overlay to display when vehicle is armed and this setup page needs
        // to be disabled
        Rectangle {
            visible:            !setupView.enabled
            anchors.fill:       pageLoader
            color:              "black"
            opacity:            0.5
Don Gagne's avatar
Don Gagne committed
101 102 103
        }
    }
}