From 399f6dc71f3ac8981357f7a9494c8bd034e26ac8 Mon Sep 17 00:00:00 2001 From: Don Gagne Date: Sun, 29 Dec 2024 15:37:20 -0800 Subject: [PATCH] Click on value to type into text field --- src/FlightDisplay/GuidedValueSlider.qml | 61 +++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/src/FlightDisplay/GuidedValueSlider.qml b/src/FlightDisplay/GuidedValueSlider.qml index 447f585a7fc..1b992c0e305 100644 --- a/src/FlightDisplay/GuidedValueSlider.qml +++ b/src/FlightDisplay/GuidedValueSlider.qml @@ -77,16 +77,26 @@ Item { property var _qgcPal: QGroundControl.globalPalette + function setCurrentValue(currentValue, animate = true) { + // Position the slider such that the indicator is pointing to the current value + var contentY = (_firstPixelValue - currentValue) / _sliderValuePerPixel - _indicatorCenterPos + if (animate) { + flickableAnimation.from = sliderFlickable.contentY + flickableAnimation.to = contentY + flickableAnimation.start() + } else { + sliderFlickable.contentY = contentY + } + } + /// Slider values should be in converted app units. function setupSlider(sliderType, minValue, maxValue, currentValue, displayText) { - console.log("setupSlider: sliderType: ", sliderType, " minValue: ", minValue, " maxValue: ", maxValue, " currentValue: ", currentValue, " displayText: ", displayText) + //console.log("setupSlider: sliderType: ", sliderType, " minValue: ", minValue, " maxValue: ", maxValue, " currentValue: ", currentValue, " displayText: ", displayText) _sliderType = sliderType _sliderMinVal = minValue _sliderMaxVal = maxValue _displayText = displayText - - // Position the slider such that the indicator is pointing to the current value - sliderFlickable.contentY = (_firstPixelValue - currentValue) / _sliderValuePerPixel - _indicatorCenterPos + setCurrentValue(currentValue, false) } function _clampedSliderValue(value) { @@ -94,7 +104,7 @@ Item { if (_unitsSettings.verticalDistanceUnits.rawValue === UnitsSettings.VerticalDistanceUnitsMeters) { decimalPlaces = 1 } - return value.toFixed(decimalPlaces) + return Math.min(Math.max(value , _sliderMinVal), _sliderMaxVal).toFixed(decimalPlaces) } function getOutputValue() { @@ -131,6 +141,18 @@ Item { flickDeceleration: 0.5 flickableDirection: Flickable.VerticalFlick + PropertyAnimation on contentY { + id: flickableAnimation + duration: 500 + from: fromValue + to: toValue + easing.type: Easing.OutCubic + running: false + + property real fromValue + property real toValue + } + Item { id: sliderContainer width: control.width @@ -239,6 +261,35 @@ Item { QGroundControl.unitsConversion.appSettingsSpeedUnitsString : QGroundControl.unitsConversion.appSettingsVerticalDistanceUnitsString } + + QGCMouseArea { + anchors.fill: parent + onClicked: { + sliderValueTextField.text = _clampedSliderValue(_sliderValue) + sliderValueTextField.visible = true + sliderValueTextField.forceActiveFocus() + } + } + + QGCTextField { + id: sliderValueTextField + anchors.leftMargin: indicatorCanvas.pointerWidth + anchors.fill: parent + showUnits: true + unitsLabel: valueLabel.unitsString + visible: false + + onEditingFinished: { + visible = false + focus = false + setCurrentValue(_clampedSliderValue(parseFloat(text))) + } + + Connections { + target: control + on_sliderValueChanged: sliderValueTextField.visible = false + } + } } ColumnLayout {