From 08c7707782339c91f62ae6319aa220b2e3bf0dbe Mon Sep 17 00:00:00 2001 From: James Turner Date: Mon, 2 Jul 2018 16:45:17 +0100 Subject: [PATCH] Launcher: altitude entry for runway-approach --- src/GUI/LocationController.cxx | 41 +++++---- src/GUI/LocationController.hxx | 1 + src/GUI/qml/LocationAirportView.qml | 134 ++++++++++++++++------------ src/GUI/qml/LocationAltitudeRow.qml | 66 ++++++++++++++ src/GUI/qml/LocationNavaidView.qml | 57 +----------- src/GUI/qml/PopupChoice.qml | 1 + src/GUI/qml/RadioButton.qml | 12 ++- src/GUI/qml/ToggleBox.qml | 25 ++++++ src/GUI/resources.qrc | 2 + 9 files changed, 205 insertions(+), 134 deletions(-) create mode 100644 src/GUI/qml/LocationAltitudeRow.qml create mode 100644 src/GUI/qml/ToggleBox.qml diff --git a/src/GUI/LocationController.cxx b/src/GUI/LocationController.cxx index 654a3baf6..909e6d1ae 100644 --- a/src/GUI/LocationController.cxx +++ b/src/GUI/LocationController.cxx @@ -958,10 +958,31 @@ void LocationController::setLocationProperties() static_cast(m_location->guid())); applyPositionOffset(); + applyAltitude(); } // of navaid location } void LocationController::applyPositionOffset() +{ + if (m_speedEnabled) { + m_config->setArg("vc", QString::number(m_airspeedKnots)); + } + + if (m_headingEnabled) { + m_config->setArg("heading", QString::number(m_headingDeg)); + } + + if (m_offsetEnabled) { + // flip direction of azimuth to balance the flip done in fgApplyStartOffset + // I don't know why that flip exists but changing it there will break + // command-line compatability so compensating here instead + int offsetAzimuth = m_offsetRadial - 180; + m_config->setArg("offset-azimuth", QString::number(offsetAzimuth)); + m_config->setArg("offset-distance", QString::number(m_offsetNm)); + } +} + +void LocationController::applyAltitude() { switch (m_altitudeType) { case Off: @@ -980,23 +1001,6 @@ void LocationController::applyPositionOffset() m_config->setArg("altitude", QString::number(m_flightLevel * 100)); break; } - - if (m_speedEnabled) { - m_config->setArg("vc", QString::number(m_airspeedKnots)); - } - - if (m_headingEnabled) { - m_config->setArg("heading", QString::number(m_headingDeg)); - } - - if (m_offsetEnabled) { - // flip direction of azimuth to balance the flip done in fgApplyStartOffset - // I don't know why that flip exists but changing it there will break - // command-line compatability so compensating here instead - int offsetAzimuth = m_offsetRadial - 180; - m_config->setArg("offset-azimuth", QString::number(offsetAzimuth)); - m_config->setArg("offset-distance", QString::number(m_offsetNm)); - } } void LocationController::onCollectConfig() @@ -1043,6 +1047,8 @@ void LocationController::onCollectConfig() if (m_speedEnabled) { m_config->setArg("vc", QString::number(m_airspeedKnots)); } + + applyAltitude(); } } else if (m_airportLocation->type() == FGPositioned::HELIPORT) { m_config->setArg("runway", QString::fromStdString(m_detailLocation->ident())); @@ -1079,6 +1085,7 @@ void LocationController::onCollectConfig() // set disambiguation property m_config->setProperty("/sim/presets/navaid-id", QString::number(m_location->guid())); applyPositionOffset(); + applyAltitude(); } // of navaid location } diff --git a/src/GUI/LocationController.hxx b/src/GUI/LocationController.hxx index 6878fdccd..a0a0af2ef 100644 --- a/src/GUI/LocationController.hxx +++ b/src/GUI/LocationController.hxx @@ -211,6 +211,7 @@ private: void setNavRadioOption(); void applyPositionOffset(); + void applyAltitude(); NavSearchModel* m_searchModel = nullptr; diff --git a/src/GUI/qml/LocationAirportView.qml b/src/GUI/qml/LocationAirportView.qml index 1341bece1..aef264611 100644 --- a/src/GUI/qml/LocationAirportView.qml +++ b/src/GUI/qml/LocationAirportView.qml @@ -35,12 +35,11 @@ Item { // not very declarative, try to remove this over time function syncUIFromController() { - runwayRadio.selected = (_location.detail.isRunwayType); - parkingRadio.selected = (_location.detail.type == Positioned.Parking); - if (_location.detail.isRunwayType) { + runwayRadio.select(); runwayChoice.syncCurrentIndex(); } else if (_location.detail.type == Positioned.Parking) { + parkingRadio.select() parkingChoice.syncCurrentIndex(); } } @@ -59,6 +58,7 @@ Item { color: "transparent" border.width: 1 border.color: Style.frameColor + clip: true anchors { left: parent.left @@ -154,73 +154,91 @@ Item { } } - // runway offset row - Row { - x: Style.strutSize + // runway offset + ToggleBox { + id: onFinalBox + + anchors.left: parent.left + anchors.leftMargin: Style.strutSize + height: onFinalContents.height + onFinalContents.y + Style.margin + anchors.right: parent.right + anchors.rightMargin: Style.margin // no offset for helipads visible: !isHeliport - readonly property bool enableOnFinal: runwayRadio.selected && _location.onFinal + enabled: runwayRadio.selected + selected: _location.onFinal - ToggleSwitch { - id: onFinalToggle - label: qsTr("On final approach at ") - anchors.verticalCenter: parent.verticalCenter - checked: _location.onFinal - enabled:runwayRadio.selected - onCheckedChanged: _location.onFinal = checked - } + label: qsTr("On final approach") - DoubleSpinbox { - id: offsetNmEdit - value: _location.offsetNm - onCommit: _location.offsetNm = newValue; + onSelectedChanged: _location.onFinal = selected + readonly property bool enableOnFinal: enabled && selected - suffix: "Nm" - min: 0.0 - max: 40.0 - decimals: 1 - maxDigits: 5 - live: true + Column { + id: onFinalContents + y: parent.contentVerticalOffset + spacing: Style.margin + width: parent.width - anchors.verticalCenter: parent.verticalCenter - enabled: parent.enableOnFinal - } + Row { + height: offsetNmEdit.height + DoubleSpinbox { + id: offsetNmEdit + value: _location.offsetNm + onCommit: _location.offsetNm = newValue; + label: qsTr("At") + suffix: "Nm" + min: 0.0 + max: 40.0 + decimals: 1 + maxDigits: 5 + live: true + anchors.verticalCenter: parent.verticalCenter + enabled: onFinalBox.enableOnFinal + } - StyledText { - text: qsTr(" from the threshold") - anchors.verticalCenter: parent.verticalCenter - enabled: parent.enableOnFinal - } + StyledText { + text: qsTr(" from the threshold") + anchors.verticalCenter: parent.verticalCenter + enabled: onFinalBox.enableOnFinal + } - Item { - // padding - width: Style.strutSize - height: 1 - } + Item { + height: 1; width: Style.strutSize + } - ToggleSwitch { - id: airspeedToggle - enabled: parent.enableOnFinal - checked: _location.speedEnabled - onCheckedChanged: _location.speedEnabled = checked; - anchors.verticalCenter: parent.verticalCenter - } + ToggleSwitch { + id: airspeedToggle + enabled: onFinalBox.enableOnFinal + checked: _location.speedEnabled + onCheckedChanged: _location.speedEnabled = checked; + anchors.verticalCenter: parent.verticalCenter + } + + IntegerSpinbox { + id: airspeedSpinbox + label: qsTr("Airspeed:") + suffix: "kts" + min: 0 + max: 10000 // more for spaceships? + step: 5 + maxDigits: 5 + enabled: _location.speedEnabled && onFinalBox.enableOnFinal + value: _location.airspeedKnots + onCommit: _location.airspeedKnots = newValue + anchors.verticalCenter: parent.verticalCenter + } + } + + LocationAltitudeRow + { + enabled: onFinalBox.enableOnFinal + width: parent.width + } + } // of column + } // of runway offset group - IntegerSpinbox { - label: qsTr("Airspeed:") - suffix: "kts" - min: 0 - max: 10000 // more for spaceships? - step: 5 - maxDigits: 5 - enabled: _location.speedEnabled && parent.enableOnFinal - value: _location.airspeedKnots - onCommit: _location.airspeedKnots = newValue - anchors.verticalCenter: parent.verticalCenter - } - } ToggleSwitch { x: Style.strutSize diff --git a/src/GUI/qml/LocationAltitudeRow.qml b/src/GUI/qml/LocationAltitudeRow.qml new file mode 100644 index 000000000..a533b02d1 --- /dev/null +++ b/src/GUI/qml/LocationAltitudeRow.qml @@ -0,0 +1,66 @@ +import QtQuick 2.4 +import "." +import FlightGear.Launcher 1.0 + +Row { + id: root + height: childrenRect.height + spacing: Style.margin + property bool enabled: true + + ToggleSwitch { + id: altitudeToggle + checked: _location.altitudeType !== LocationController.Off + + function toggle(newChecked) { + _location.altitudeType = (newChecked ? LocationController.MSL_Feet + : LocationController.Off) + } + + enabled: parent.enabled + } + + readonly property bool __rowEnabled: root.enabled && altitudeToggle.checked + + IntegerSpinbox { + label: qsTr("Altitude:") + suffix: "ft" + min: -1000 // Dead Sea, Schiphol + max: 200000 + step: 100 + maxDigits: 6 + enabled: __rowEnabled + visible: !altitudeTypeChoice.isFlightLevel + value: _location.altitudeFt + onCommit: _location.altitudeFt = newValue + } + + IntegerSpinbox { + label: qsTr("Altitude:") + prefix: "FL" + min: 0 + max: 1000 + step: 10 + maxDigits: 3 + enabled: __rowEnabled + visible: altitudeTypeChoice.isFlightLevel + value: _location.flightLevel + onCommit: _location.flightLevel = newValue + } + + PopupChoice { + id: altitudeTypeChoice + enabled: __rowEnabled && (location.altitudeType !== LocationController.Off) + currentIndex: Math.max(0, _location.altitudeType - 1) + readonly property bool isFlightLevel: (currentIndex == 2) + + model: [qsTr("Above mean sea-level (MSL)"), + qsTr("Above ground (AGL)"), + qsTr("Flight-level")] + + function select(index) + { + _location.altitudeType = index + 1; + } + } +} diff --git a/src/GUI/qml/LocationNavaidView.qml b/src/GUI/qml/LocationNavaidView.qml index 9fd8116bf..b64109f81 100644 --- a/src/GUI/qml/LocationNavaidView.qml +++ b/src/GUI/qml/LocationNavaidView.qml @@ -120,62 +120,9 @@ Item { } } - Row { - height: childrenRect.height + LocationAltitudeRow + { width: parent.width - spacing: Style.margin - - ToggleSwitch { - id: altitudeToggle - checked: _location.altitudeType !== LocationController.Off - - function toggle(newChecked) { - _location.altitudeType = (newChecked ? LocationController.MSL_Feet - : LocationController.Off) - } - } - - IntegerSpinbox { - label: qsTr("Altitude:") - suffix: "ft" - min: -1000 // Dead Sea, Schiphol - max: 200000 - step: 100 - maxDigits: 6 - enabled: altitudeToggle.checked - visible: !altitudeTypeChoice.isFlightLevel - value: _location.altitudeFt - onCommit: _location.altitudeFt = newValue - } - - IntegerSpinbox { - label: qsTr("Altitude:") - prefix: "FL" - min: 0 - max: 1000 - step: 10 - maxDigits: 3 - enabled: altitudeToggle.checked - visible: altitudeTypeChoice.isFlightLevel - value: _location.flightLevel - onCommit: _location.flightLevel = newValue - } - - PopupChoice { - id: altitudeTypeChoice - enabled: _location.altitudeType !== LocationController.Off - currentIndex: Math.max(0, _location.altitudeType - 1) - readonly property bool isFlightLevel: (currentIndex == 2) - - model: [qsTr("Above mean sea-level (MSL)"), - qsTr("Above ground (AGL)"), - qsTr("Flight-level")] - - function select(index) - { - _location.altitudeType = index + 1; - } - } } // offset row diff --git a/src/GUI/qml/PopupChoice.qml b/src/GUI/qml/PopupChoice.qml index ab4caf013..ee54a88b3 100644 --- a/src/GUI/qml/PopupChoice.qml +++ b/src/GUI/qml/PopupChoice.qml @@ -96,6 +96,7 @@ Item { anchors.verticalCenter: parent.verticalCenter StyledText { + enabled: root.enabled id: currentChoiceText anchors.verticalCenter: parent.verticalCenter anchors.left: parent.left diff --git a/src/GUI/qml/RadioButton.qml b/src/GUI/qml/RadioButton.qml index 4b4d6e66a..6dd853874 100644 --- a/src/GUI/qml/RadioButton.qml +++ b/src/GUI/qml/RadioButton.qml @@ -13,6 +13,13 @@ Item { implicitHeight: outerRing.height + Style.margin implicitWidth: outerRing.width + Style.margin + function select() + { + if (root.group) { + root.group.selected = root; + } + } + Binding { when: root.group != null target: root @@ -58,10 +65,7 @@ Item { anchors.fill: parent hoverEnabled: true onClicked: { - if (root.group) { - root.group.selected = root; - } - + root.select(); root.clicked() } } diff --git a/src/GUI/qml/ToggleBox.qml b/src/GUI/qml/ToggleBox.qml new file mode 100644 index 000000000..d79958e8e --- /dev/null +++ b/src/GUI/qml/ToggleBox.qml @@ -0,0 +1,25 @@ +import QtQuick 2.4 +import "." + +Item { + property bool enabled: true + property alias label: switchToggle.label + property alias selected: switchToggle.checked + + readonly property int contentVerticalOffset: switchToggle.height + Style.margin + readonly property int __lineTop: switchToggle.height * 0.5 + + ToggleSwitch { + enabled: parent.enabled + id: switchToggle + x: Style.strutSize + } + + readonly property string lineColor: enabled ? Style.themeColor : Style.disabledThemeColor + + // we want to show a border, but with a cut out. Easiest is to use + // 1px rectangles as lines + Rectangle { height: 1; color: lineColor; y: __lineTop; width: switchToggle.x } + Rectangle { height: 1; color: lineColor; y: __lineTop; anchors { left: switchToggle.right; right: parent.right;} } + Rectangle { height: 1; color: lineColor; width: parent.width; anchors.bottom: parent.bottom } +} diff --git a/src/GUI/resources.qrc b/src/GUI/resources.qrc index 6d0cf1658..b6b6ab311 100644 --- a/src/GUI/resources.qrc +++ b/src/GUI/resources.qrc @@ -104,6 +104,8 @@ qml/BaseMenuItem.qml qml/MenuItem.qml qml/MenuDivider.qml + qml/ToggleBox.qml + qml/LocationAltitudeRow.qml preview-close.png