Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GuidedValueSlier: Click on value to type into text field #12263

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions src/FlightDisplay/GuidedValueSlider.qml
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,34 @@ 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) {
var decimalPlaces = 0
if (_unitsSettings.verticalDistanceUnits.rawValue === UnitsSettings.VerticalDistanceUnitsMeters) {
decimalPlaces = 1
}
return value.toFixed(decimalPlaces)
return Math.min(Math.max(value , _sliderMinVal), _sliderMaxVal).toFixed(decimalPlaces)
}

function getOutputValue() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Loading