Skip to content

Commit

Permalink
Click on value to type into text field
Browse files Browse the repository at this point in the history
  • Loading branch information
DonLakeFlyer committed Dec 30, 2024
1 parent 1284628 commit 399f6dc
Showing 1 changed file with 56 additions and 5 deletions.
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

0 comments on commit 399f6dc

Please sign in to comment.