SetupPage.qml 4.3 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
    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
Don Gagne's avatar
Don Gagne committed
35

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

46
    Component.onCompleted: {
47 48 49
        if(pageLoader.item && pageLoader.item.setupPageCompleted) {
            pageLoader.item.setupPageCompleted()
        }
50 51
    }

52
    QGCFlickable {
Don Gagne's avatar
Don Gagne committed
53
        anchors.fill:   parent
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
        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
70

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

75 76 77 78
                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
79 80
                }

81 82 83 84 85 86
                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
87 88
                }
            }
89 90 91 92 93 94 95 96 97 98 99 100 101
        }
        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
102 103 104
        }
    }
}