Fixed possible endless loop caused by round errors when passing float values between C++ and Javascript.

Increased granularity of the offset slider.
Textfield now accepts arbitrary values.
This commit is contained in:
2017-02-09 23:56:11 +01:00
parent 1aa1580a90
commit 9265829aff
2 changed files with 16 additions and 8 deletions
+15 -7
View File
@@ -45,7 +45,7 @@ MyStackViewPage {
Layout.preferredWidth: 40 Layout.preferredWidth: 40
text: "-" text: "-"
onClicked: { onClicked: {
accessibilityMoveYSlider.decrease() accessibilityMoveYSlider.value -= 0.05
} }
} }
@@ -53,7 +53,7 @@ MyStackViewPage {
id: accessibilityMoveYSlider id: accessibilityMoveYSlider
from: 0 from: 0
to: 1.5 to: 1.5
stepSize: 0.05 stepSize: 0.01
value: 0.0 value: 0.0
Layout.fillWidth: true Layout.fillWidth: true
onPositionChanged: { onPositionChanged: {
@@ -69,7 +69,7 @@ MyStackViewPage {
Layout.preferredWidth: 40 Layout.preferredWidth: 40
text: "+" text: "+"
onClicked: { onClicked: {
accessibilityMoveYSlider.increase() accessibilityMoveYSlider.value += 0.05
} }
} }
@@ -83,8 +83,12 @@ MyStackViewPage {
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
function onInputEvent(input) { function onInputEvent(input) {
var val = parseFloat(input) var val = parseFloat(input)
if (!isNaN(val) && val >= accessibilityMoveYSlider.from && val <= accessibilityMoveYSlider.to) { if (!isNaN(val)) {
accessibilityMoveYSlider.value = val.toFixed(2); if (val >= accessibilityMoveYSlider.from && val <= accessibilityMoveYSlider.to) {
accessibilityMoveYSlider.value = val.toFixed(2);
} else {
AccessibilityTabController.setHeightOffset(val.toFixed(2), false);
}
} }
text = AccessibilityTabController.heightOffset.toFixed(2) text = AccessibilityTabController.heightOffset.toFixed(2)
} }
@@ -146,8 +150,10 @@ MyStackViewPage {
Component.onCompleted: { Component.onCompleted: {
var heightOffsetFormatted = AccessibilityTabController.heightOffset.toFixed(2) var heightOffsetFormatted = AccessibilityTabController.heightOffset.toFixed(2)
if (heightOffsetFormatted >= accessibilityMoveYSlider.from && heightOffsetFormatted <= accessibilityMoveYSlider.to) {
accessibilityMoveYSlider.value = heightOffsetFormatted
}
accessibilityMoveYText.text = heightOffsetFormatted accessibilityMoveYText.text = heightOffsetFormatted
accessibilityMoveYSlider.value = heightOffsetFormatted
heightOffsetPttEnabledToggle.checked = AccessibilityTabController.pttEnabled heightOffsetPttEnabledToggle.checked = AccessibilityTabController.pttEnabled
heightOffsetPttLeftControllerToggle.checked = AccessibilityTabController.pttLeftControllerEnabled heightOffsetPttLeftControllerToggle.checked = AccessibilityTabController.pttLeftControllerEnabled
heightOffsetPttRightControllerToggle.checked = AccessibilityTabController.pttRightControllerEnabled heightOffsetPttRightControllerToggle.checked = AccessibilityTabController.pttRightControllerEnabled
@@ -157,8 +163,10 @@ MyStackViewPage {
target: AccessibilityTabController target: AccessibilityTabController
onHeightOffsetChanged: { onHeightOffsetChanged: {
var heightOffsetFormatted = AccessibilityTabController.heightOffset.toFixed(2) var heightOffsetFormatted = AccessibilityTabController.heightOffset.toFixed(2)
if (heightOffsetFormatted >= accessibilityMoveYSlider.from && heightOffsetFormatted <= accessibilityMoveYSlider.to) {
accessibilityMoveYSlider.value = heightOffsetFormatted
}
accessibilityMoveYText.text = heightOffsetFormatted accessibilityMoveYText.text = heightOffsetFormatted
accessibilityMoveYSlider.value = heightOffsetFormatted
} }
onPttEnabledChanged: { onPttEnabledChanged: {
heightOffsetPttEnabledToggle.checked = AccessibilityTabController.pttEnabled heightOffsetPttEnabledToggle.checked = AccessibilityTabController.pttEnabled
@@ -36,7 +36,7 @@ float AccessibilityTabController::heightOffset() const {
} }
void AccessibilityTabController::setHeightOffset(float value, bool notify) { void AccessibilityTabController::setHeightOffset(float value, bool notify) {
if (m_heightOffset != value) { if (std::abs(m_heightOffset - value) > 0.001) {
modHeightOffset(value - m_heightOffset, notify); modHeightOffset(value - m_heightOffset, notify);
} }
} }