SetupPage.qml 4.32 KB
Newer Older
Don Gagne's avatar
Don Gagne committed
1 2
/****************************************************************************
 *
Gus Grubba's avatar
Gus Grubba committed
3
 * (c) 2009-2020 QGROUNDCONTROL PROJECT <http://www.qgroundcontrol.org>
Don Gagne's avatar
Don Gagne committed
4 5 6 7 8 9
 *
 * 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
DonLakeFlyer's avatar
DonLakeFlyer committed
54 55
        contentWidth:   Math.max(availableWidth, pageLoader.x + pageLoader.item.width)
        contentHeight:  Math.max(availableHeight, pageLoader.y + pageLoader.item.height)
56 57 58 59
        clip:           true

        RowLayout {
            id:                 headingRow
DonLakeFlyer's avatar
DonLakeFlyer committed
60
            width:              availableWidth
61 62 63 64 65 66 67 68
            spacing:            _margins
            layoutDirection:    Qt.RightToLeft

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

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

74
                QGCLabel {
DonLakeFlyer's avatar
DonLakeFlyer committed
75 76 77 78
                    Layout.fillWidth:   true
                    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
                QGCLabel {
DonLakeFlyer's avatar
DonLakeFlyer committed
82 83 84 85
                    Layout.fillWidth:   true
                    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
        }
        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
DonLakeFlyer's avatar
DonLakeFlyer committed
98
            anchors.fill:       parent
99 100
            color:              "black"
            opacity:            0.5
Don Gagne's avatar
Don Gagne committed
101 102 103
        }
    }
}