FlightDetails.qml 11.3 KB
Newer Older
1 2 3 4
import QtQuick                  2.3
import QtQuick.Controls         1.2
import QtQuick.Controls.Styles  1.4
import QtQuick.Dialogs          1.2
Gus Grubba's avatar
Gus Grubba committed
5
import QtQuick.Layouts          1.2
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
import QtQml                    2.2

import QGroundControl                   1.0
import QGroundControl.Airmap            1.0
import QGroundControl.Airspace          1.0
import QGroundControl.Controls          1.0
import QGroundControl.Palette           1.0
import QGroundControl.ScreenTools       1.0
import QGroundControl.SettingsManager   1.0

Item {
    id:                 _root
    implicitHeight:     detailCol.height
    implicitWidth:      detailCol.width
    property real baseHeight:  ScreenTools.defaultFontPixelHeight * 22
    property real baseWidth:   ScreenTools.defaultFontPixelWidth  * 40
Gus Grubba's avatar
Gus Grubba committed
22 23 24 25 26 27 28
    function setEndTime() {
        _dirty = true
        var endTime = QGroundControl.airspaceManager.flightPlan.flightStartTime
        endTime.setTime(endTime.getTime() + (Math.floor(durationSlider.value * 0.25) * 60 * 60 * 1000))
        endTime.setTime(endTime.getTime() + ((durationSlider.value * 15) % 60) * 60 * 1000)
        QGroundControl.airspaceManager.flightPlan.flightEndTime = endTime
    }
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
    Column {
        id:             detailCol
        spacing:        ScreenTools.defaultFontPixelHeight * 0.25
        Rectangle {
            color:          qgcPal.windowShade
            anchors.right:  parent.right
            anchors.left:   parent.left
            height:         detailsLabel.height + ScreenTools.defaultFontPixelHeight
            QGCLabel {
                id:             detailsLabel
                text:           qsTr("Flight Details")
                font.pointSize: ScreenTools.mediumFontPointSize
                font.family:    ScreenTools.demiboldFontFamily
                anchors.centerIn: parent
            }
        }
        Item { width: 1; height: ScreenTools.defaultFontPixelHeight * 0.5; }
        Flickable {
            clip:           true
            width:          baseWidth
            height:         baseHeight
            contentHeight:  flContextCol.height
            flickableDirection: Flickable.VerticalFlick
            Column {
                id:                 flContextCol
Gus Grubba's avatar
Gus Grubba committed
54
                spacing:            ScreenTools.defaultFontPixelHeight * 0.25
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
                anchors.right:      parent.right
                anchors.left:       parent.left
                QGCLabel {
                    text:           qsTr("Flight Date & Time")
                }
                Rectangle {
                    id:             dateRect
                    color:          qgcPal.windowShade
                    anchors.right:  parent.right
                    anchors.left:   parent.left
                    height:         datePickerCol.height + (ScreenTools.defaultFontPixelHeight * 2)
                    Column {
                        id:                 datePickerCol
                        spacing:            ScreenTools.defaultFontPixelHeight * 0.5
                        anchors.margins:    ScreenTools.defaultFontPixelWidth
                        anchors.right:      parent.right
                        anchors.left:       parent.left
                        anchors.verticalCenter: parent.verticalCenter
Gus Grubba's avatar
Gus Grubba committed
73 74
                        RowLayout {
                            spacing:        ScreenTools.defaultFontPixelWidth * 0.5
75 76
                            anchors.right:  parent.right
                            anchors.left:   parent.left
Gus Grubba's avatar
Gus Grubba committed
77 78 79 80 81 82 83 84 85 86 87
                            QGCButton {
                                text:       qsTr("Now")
                                onClicked: {
                                    _dirty = true
                                    var today = new Date()
                                    QGroundControl.airspaceManager.flightPlan.flightStartTime = today
                                    timeSlider.updateTime()
                                }
                            }
                            QGCButton {
                                text: {
Gus Grubba's avatar
Gus Grubba committed
88 89 90
                                    var nowTime = new Date()
                                    var setTime = QGroundControl.airspaceManager.flightPlan.flightStartTime
                                    if(setTime.setHours(0,0,0,0) === nowTime.setHours(0,0,0,0)) {
Gus Grubba's avatar
Gus Grubba committed
91 92
                                        return qsTr("Today")
                                    } else {
Gus Grubba's avatar
Gus Grubba committed
93
                                        return setTime.toLocaleDateString(Qt.locale())
Gus Grubba's avatar
Gus Grubba committed
94 95 96 97 98 99 100 101
                                    }
                                }
                                Layout.fillWidth:   true
                                iconSource:         "qrc:/airmap/expand.svg"
                                onClicked: {
                                    _dirty = true
                                    datePicker.visible = true
                                }
102 103
                            }
                        }
Gus Grubba's avatar
Gus Grubba committed
104 105 106
                        QGCLabel {
                            text:   qsTr("Flight Start Time")
                        }
107 108 109 110 111 112 113 114 115 116
                        Item {
                            anchors.right:  parent.right
                            anchors.left:   parent.left
                            height:         timeSlider.height
                            QGCSlider {
                                id:             timeSlider
                                width:          parent.width - timeLabel.width - ScreenTools.defaultFontPixelWidth
                                stepSize:       1
                                minimumValue:   0
                                maximumValue:   95 // 96 blocks of 15 minutes in 24 hours
Gus Grubba's avatar
Gus Grubba committed
117
                                anchors.left:   parent.left
118 119 120
                                anchors.verticalCenter: parent.verticalCenter
                                onValueChanged: {
                                    _dirty = true
Gus Grubba's avatar
Gus Grubba committed
121 122 123 124
                                    var today = QGroundControl.airspaceManager.flightPlan.flightStartTime
                                    today.setHours(Math.floor(timeSlider.value * 0.25))
                                    today.setMinutes((timeSlider.value * 15) % 60)
                                    today.setSeconds(0)
Gus Grubba's avatar
Gus Grubba committed
125
                                    today.setMilliseconds(0)
Gus Grubba's avatar
Gus Grubba committed
126
                                    QGroundControl.airspaceManager.flightPlan.flightStartTime = today
Gus Grubba's avatar
Gus Grubba committed
127
                                    setEndTime()
128 129
                                }
                                Component.onCompleted: {
Gus Grubba's avatar
Gus Grubba committed
130 131 132 133
                                    updateTime()
                                }
                                function updateTime() {
                                    var today = QGroundControl.airspaceManager.flightPlan.flightStartTime
134 135
                                    var val = (((today.getHours() * 60) + today.getMinutes()) * (96/1440)) + 1
                                    if(val > 95) val = 95
Gus Grubba's avatar
Gus Grubba committed
136
                                    timeSlider.value = Math.ceil(val)
137 138
                                }
                            }
Gus Grubba's avatar
Gus Grubba committed
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
                            QGCLabel {
                                id:             timeLabel
                                text:           ('00' + hour).slice(-2) + ":" + ('00' + minute).slice(-2)
                                width:          ScreenTools.defaultFontPixelWidth * 5
                                anchors.right:  parent.right
                                anchors.verticalCenter: parent.verticalCenter
                                property int hour:   Math.floor(timeSlider.value * 0.25)
                                property int minute: (timeSlider.value * 15) % 60
                            }
                        }
                        QGCLabel {
                            text:   qsTr("Duration")
                        }
                        Item {
                            anchors.right:  parent.right
                            anchors.left:   parent.left
                            height:         durationSlider.height
                            QGCSlider {
                                id:             durationSlider
                                width:          parent.width - durationLabel.width - ScreenTools.defaultFontPixelWidth
                                stepSize:       1
                                minimumValue:   1
                                maximumValue:   24 // 24 blocks of 15 minutes in 6 hours
                                anchors.left:  parent.left
                                anchors.verticalCenter: parent.verticalCenter
                                onValueChanged: {
                                    setEndTime()
                                }
                                Component.onCompleted: {
                                    updateTime()
                                }
                                function updateTime() {
                                    var startTime = QGroundControl.airspaceManager.flightPlan.flightStartTime
                                    var endTime = QGroundControl.airspaceManager.flightPlan.flightEndTime
                                    var val = (endTime.getTime() - startTime.getTime()) / 1000 / 60
                                    val = (val * (96/360)) + 1
                                    if(val > 24) val = 24
                                    durationSlider.value = Math.ceil(val)
                                }
                            }
                            QGCLabel {
                                id:             durationLabel
                                text:           ('00' + hour).slice(-2) + ":" + ('00' + minute).slice(-2)
                                width:          ScreenTools.defaultFontPixelWidth * 5
                                anchors.right:  parent.right
                                anchors.verticalCenter: parent.verticalCenter
                                property int hour:   Math.floor(durationSlider.value * 0.25)
                                property int minute: (durationSlider.value * 15) % 60
                            }
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
                        }
                    }
                }
                Item { width: 1; height: ScreenTools.defaultFontPixelHeight * 0.25; }
                QGCLabel {
                    text:           qsTr("Flight Context")
                    visible:        QGroundControl.airspaceManager.flightPlan.briefFeatures.count > 0
                }
                Repeater {
                    model:          QGroundControl.airspaceManager.flightPlan.briefFeatures
                    visible:        QGroundControl.airspaceManager.flightPlan.briefFeatures.count > 0
                    delegate:       FlightFeature {
                        feature:    object
                        visible:     object && object.type !== AirspaceRuleFeature.Unknown && object.description !== "" && object.name !== ""
                        anchors.right:  parent.right
                        anchors.left:   parent.left
                    }
                }
            }
        }
    }
    Calendar {
        id: datePicker
Gus Grubba's avatar
Gus Grubba committed
211 212 213
        anchors.centerIn:   parent
        visible:            false;
        minimumDate:        QGroundControl.airspaceManager.flightPlan.flightStartTime
214
        onClicked: {
Gus Grubba's avatar
Gus Grubba committed
215
            QGroundControl.airspaceManager.flightPlan.flightStartTime = datePicker.selectedDate
216 217 218 219
            visible = false;
        }
    }
}