From 663af09605c57c7ebf7994879b1c3972c138d599 Mon Sep 17 00:00:00 2001 From: vladest Date: Thu, 19 Apr 2018 20:43:48 +0200 Subject: [PATCH 1/4] Fix SpinBox. attempt 1 --- interface/resources/qml/controls-uit/SpinBox.qml | 7 ++++++- interface/src/ui/PreferencesDialog.cpp | 2 +- libraries/shared/src/Preferences.h | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/interface/resources/qml/controls-uit/SpinBox.qml b/interface/resources/qml/controls-uit/SpinBox.qml index 83c30ce162..9af5ee1ae9 100644 --- a/interface/resources/qml/controls-uit/SpinBox.qml +++ b/interface/resources/qml/controls-uit/SpinBox.qml @@ -20,6 +20,7 @@ SpinBox { property int colorScheme: hifi.colorSchemes.light readonly property bool isLightColorScheme: colorScheme === hifi.colorSchemes.light property string label: "" + property string suffix: "" property string labelInside: "" property color colorLabelInside: hifi.colors.white property real controlHeight: height + (spinBoxLabel.visible ? spinBoxLabel.height + spinBoxLabel.anchors.bottomMargin : 0) @@ -34,6 +35,8 @@ SpinBox { property real realTo: 100.0 property real realStepSize: 1.0 + signal editingFinished() + implicitHeight: height implicitWidth: width @@ -88,12 +91,14 @@ SpinBox { : (spinBox.activeFocus ? hifi.colors.white : hifi.colors.lightGrayText) selectedTextColor: hifi.colors.black selectionColor: hifi.colors.primaryHighlight - text: spinBox.textFromValue(spinBox.value, spinBox.locale) + text: spinBox.textFromValue(spinBox.value, spinBox.locale) + suffix verticalAlignment: Qt.AlignVCenter leftPadding: spinBoxLabelInside.visible ? 30 : hifi.dimensions.textPadding //rightPadding: hifi.dimensions.spinnerSize width: spinBox.width - hifi.dimensions.spinnerSize + onEditingFinished: spinBox.editingFinished() } + up.indicator: Item { x: spinBox.width - implicitWidth - 5 y: 1 diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 4c233b986c..8067a27fb0 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -298,7 +298,7 @@ void setupPreferences() { { static const int MIN_PORT_NUMBER { 0 }; static const int MAX_PORT_NUMBER { 65535 }; - auto getter = [nodelist] { return static_cast(nodelist->getSocketLocalPort()); }; + auto getter = [nodelist] { qWarning() << "vladest: port" << static_cast(nodelist->getSocketLocalPort()); return static_cast(nodelist->getSocketLocalPort()); }; auto setter = [nodelist](int preset) { nodelist->setSocketLocalPort(static_cast(preset)); }; auto preference = new IntSpinnerPreference(NETWORKING, "Listening Port", getter, setter); preference->setMin(MIN_PORT_NUMBER); diff --git a/libraries/shared/src/Preferences.h b/libraries/shared/src/Preferences.h index a243a6d58d..76d61fe3f6 100644 --- a/libraries/shared/src/Preferences.h +++ b/libraries/shared/src/Preferences.h @@ -198,6 +198,7 @@ class IntPreference : public TypedPreference { Q_PROPERTY(float min READ getMin CONSTANT) Q_PROPERTY(float max READ getMax CONSTANT) Q_PROPERTY(float step READ getStep CONSTANT) + Q_PROPERTY(int decimals READ getDecimals CONSTANT) public: IntPreference(const QString& category, const QString& name, Getter getter, Setter setter) @@ -212,6 +213,9 @@ public: float getStep() const { return _step; } void setStep(float step) { _step = step; }; + int getDecimals() const { return _decimals; } + void setDecimals(int decimals) { _decimals = decimals; }; + signals: void valueChanged(); @@ -221,6 +225,7 @@ protected: int _min { std::numeric_limits::min() }; int _max { std::numeric_limits::max() }; int _step { 1 }; + int _decimals { 0 }; }; class StringPreference : public TypedPreference { From 0e28e41107bac8670c020c41d28dbe1a806b8412 Mon Sep 17 00:00:00 2001 From: vladest Date: Fri, 20 Apr 2018 19:15:29 +0200 Subject: [PATCH 2/4] Fix various issues with SpinBox-es and Sliders --- .../resources/qml/controls-uit/Slider.qml | 1 + .../resources/qml/controls-uit/SpinBox.qml | 8 ++-- .../dialogs/preferences/SpinBoxPreference.qml | 4 +- .../preferences/SpinnerSliderPreference.qml | 14 +++--- .../hifi/dialogs/attachments/Attachment.qml | 8 ++-- .../qml/hifi/dialogs/attachments/Vector3.qml | 22 ++++----- .../qml/hifi/tablet/OpenVrConfiguration.qml | 48 +++++++++---------- 7 files changed, 53 insertions(+), 52 deletions(-) diff --git a/interface/resources/qml/controls-uit/Slider.qml b/interface/resources/qml/controls-uit/Slider.qml index 3726d3f260..5ddd97f3f6 100644 --- a/interface/resources/qml/controls-uit/Slider.qml +++ b/interface/resources/qml/controls-uit/Slider.qml @@ -24,6 +24,7 @@ Slider { property alias minimumValue: slider.from property alias maximumValue: slider.to + property bool tickmarksEnabled: false height: hifi.fontSizes.textFieldInput + 14 // Match height of TextField control. y: sliderLabel.visible ? sliderLabel.height + sliderLabel.anchors.bottomMargin : 0 diff --git a/interface/resources/qml/controls-uit/SpinBox.qml b/interface/resources/qml/controls-uit/SpinBox.qml index 9af5ee1ae9..29f1de3dd7 100644 --- a/interface/resources/qml/controls-uit/SpinBox.qml +++ b/interface/resources/qml/controls-uit/SpinBox.qml @@ -71,16 +71,16 @@ SpinBox { } validator: DoubleValidator { - bottom: Math.min(spinBox.from, spinBox.to)*spinBox.factor - top: Math.max(spinBox.from, spinBox.to)*spinBox.factor + bottom: Math.min(spinBox.from, spinBox.to) + top: Math.max(spinBox.from, spinBox.to) } textFromValue: function(value, locale) { - return parseFloat(value*1.0/factor).toFixed(decimals); + return parseFloat(value/factor).toFixed(decimals); } valueFromText: function(text, locale) { - return Number.fromLocaleString(locale, text); + return Number.fromLocaleString(locale, text)*factor; } diff --git a/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml b/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml index e670cd37c4..89e1096a04 100644 --- a/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml +++ b/interface/resources/qml/dialogs/preferences/SpinBoxPreference.qml @@ -18,11 +18,11 @@ Preference { height: control.height + hifi.dimensions.controlInterlineHeight Component.onCompleted: { - spinner.value = preference.value; + spinner.realValue = preference.value; } function save() { - preference.value = spinner.value; + preference.value = spinner.realValue; preference.save(); } diff --git a/interface/resources/qml/dialogs/preferences/SpinnerSliderPreference.qml b/interface/resources/qml/dialogs/preferences/SpinnerSliderPreference.qml index 3cba67bc82..731acc7e5b 100644 --- a/interface/resources/qml/dialogs/preferences/SpinnerSliderPreference.qml +++ b/interface/resources/qml/dialogs/preferences/SpinnerSliderPreference.qml @@ -21,7 +21,7 @@ Preference { Component.onCompleted: { slider.value = preference.value; - spinner.value = preference.value; + spinner.realValue = preference.value; } function save() { @@ -60,7 +60,7 @@ Preference { maximumValue: MyAvatar.getDomainMaxScale() stepSize: preference.step onValueChanged: { - spinner.value = value + spinner.realValue = value } anchors { right: spinner.left @@ -73,12 +73,12 @@ Preference { SpinBox { id: spinner decimals: preference.decimals - value: preference.value + realValue: preference.value minimumValue: MyAvatar.getDomainMinScale() maximumValue: MyAvatar.getDomainMaxScale() width: 100 onValueChanged: { - slider.value = value; + slider.value = realValue; } anchors { right: button.left @@ -92,10 +92,10 @@ Preference { id: button onClicked: { if (spinner.maximumValue >= 1) { - spinner.value = 1 + spinner.realValue = 1 slider.value = 1 } else { - spinner.value = spinner.maximumValue + spinner.realValue = spinner.maximumValue slider.value = spinner.maximumValue } } @@ -108,4 +108,4 @@ Preference { colorScheme: hifi.colorSchemes.dark } } -} \ No newline at end of file +} diff --git a/interface/resources/qml/hifi/dialogs/attachments/Attachment.qml b/interface/resources/qml/hifi/dialogs/attachments/Attachment.qml index d93e077b5a..30e03bd02e 100644 --- a/interface/resources/qml/hifi/dialogs/attachments/Attachment.qml +++ b/interface/resources/qml/hifi/dialogs/attachments/Attachment.qml @@ -181,11 +181,11 @@ Item { minimumValue: 0.01 maximumValue: 10 realStepSize: 0.05; - value: attachment ? attachment.scale : 1.0 + realValue: attachment ? attachment.scale : 1.0 colorScheme: hifi.colorSchemes.dark - onValueChanged: { - if (completed && attachment && attachment.scale !== value) { - attachment.scale = value; + onRealValueChanged: { + if (completed && attachment && attachment.scale !== realValue) { + attachment.scale = realValue; updateAttachment(); } } diff --git a/interface/resources/qml/hifi/dialogs/attachments/Vector3.qml b/interface/resources/qml/hifi/dialogs/attachments/Vector3.qml index 228d71fe6f..311492858b 100644 --- a/interface/resources/qml/hifi/dialogs/attachments/Vector3.qml +++ b/interface/resources/qml/hifi/dialogs/attachments/Vector3.qml @@ -51,7 +51,7 @@ Item { id: xspinner width: root.spinboxWidth anchors { left: parent.left } - value: root.vector.x + realValue: root.vector.x labelInside: "X:" colorScheme: hifi.colorSchemes.dark colorLabelInside: hifi.colors.redHighlight @@ -72,17 +72,17 @@ Item { id: yspinner width: root.spinboxWidth anchors { horizontalCenter: parent.horizontalCenter } - value: root.vector.y + realValue: root.vector.y labelInside: "Y:" colorLabelInside: hifi.colors.greenHighlight colorScheme: hifi.colorSchemes.dark decimals: root.decimals - stepSize: root.stepSize + realStepSize: root.stepSize maximumValue: root.maximumValue minimumValue: root.minimumValue - onValueChanged: { - if (value !== vector.y) { - vector.y = value + onRealValueChanged: { + if (realValue !== vector.y) { + vector.y = realValue root.valueChanged(); } } @@ -93,17 +93,17 @@ Item { id: zspinner width: root.spinboxWidth anchors { right: parent.right; } - value: root.vector.z + realValue: root.vector.z labelInside: "Z:" colorLabelInside: hifi.colors.primaryHighlight colorScheme: hifi.colorSchemes.dark decimals: root.decimals - stepSize: root.stepSize + realStepSize: root.stepSize maximumValue: root.maximumValue minimumValue: root.minimumValue - onValueChanged: { - if (value !== vector.z) { - vector.z = value + onRealValueChanged: { + if (realValue !== vector.z) { + vector.z = realValue root.valueChanged(); } } diff --git a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml index bd3a95bca0..572d3a55f0 100644 --- a/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml +++ b/interface/resources/qml/hifi/tablet/OpenVrConfiguration.qml @@ -178,8 +178,8 @@ Rectangle { label: "Y Offset" suffix: " cm" minimumValue: -10 - stepSize: 1 - value: -5 + realStepSize: 1 + realValue: -5 colorScheme: hifi.colorSchemes.dark onEditingFinished: { @@ -193,10 +193,10 @@ Rectangle { width: 112 label: "Z Offset" minimumValue: -10 - stepSize: 1 + realStepSize: 1 decimals: 1 suffix: " cm" - value: -5 + realValue: -5 colorScheme: hifi.colorSchemes.dark onEditingFinished: { @@ -288,7 +288,7 @@ Rectangle { suffix: " cm" label: "Y Offset" minimumValue: -10 - stepSize: 1 + realStepSize: 1 colorScheme: hifi.colorSchemes.dark onEditingFinished: { @@ -303,7 +303,7 @@ Rectangle { label: "Z Offset" suffix: " cm" minimumValue: -10 - stepSize: 1 + realStepSize: 1 decimals: 1 colorScheme: hifi.colorSchemes.dark @@ -535,9 +535,9 @@ Rectangle { suffix: " cm" label: "Arm Circumference" minimumValue: 0 - stepSize: 1.0 + realStepSize: 1.0 colorScheme: hifi.colorSchemes.dark - value: 33.0 + realValue: 33.0 onEditingFinished: { sendConfigurationSettings(); @@ -550,10 +550,10 @@ Rectangle { label: "Shoulder Width" suffix: " cm" minimumValue: 0 - stepSize: 1.0 + realStepSize: 1.0 decimals: 1 colorScheme: hifi.colorSchemes.dark - value: 48 + realValue: 48 onEditingFinished: { sendConfigurationSettings(); @@ -659,13 +659,13 @@ Rectangle { InputConfiguration.uncalibratePlugin(pluginName); updateCalibrationButton(); } else { - calibrationTimer.interval = timeToCalibrate.value * 1000 - openVrConfiguration.countDown = timeToCalibrate.value; + calibrationTimer.interval = timeToCalibrate.realValue * 1000 + openVrConfiguration.countDown = timeToCalibrate.realValue; var calibratingScreen = screen.createObject(); stack.push(calibratingScreen); calibratingScreen.canceled.connect(cancelCalibration); calibratingScreen.restart.connect(restartCalibration); - calibratingScreen.start(calibrationTimer.interval, timeToCalibrate.value); + calibratingScreen.start(calibrationTimer.interval, timeToCalibrate.realValue); calibrationTimer.start(); } } @@ -728,12 +728,12 @@ Rectangle { anchors.leftMargin: leftMargin minimumValue: 5 - value: 5 + realValue: 5 colorScheme: hifi.colorSchemes.dark onEditingFinished: { - calibrationTimer.interval = value * 1000; - openVrConfiguration.countDown = value; + calibrationTimer.interval = realValue * 1000; + openVrConfiguration.countDown = realValue; numberAnimation.duration = calibrationTimer.interval; } } @@ -910,8 +910,8 @@ Rectangle { var desktopMode = settings["desktopMode"]; var hmdDesktopPosition = settings["hmdDesktopTracking"]; - armCircumference.value = settings.armCircumference; - shoulderWidth.value = settings.shoulderWidth; + armCircumference.realValue = settings.armCircumference; + shoulderWidth.realValue = settings.shoulderWidth; if (HmdHead) { headBox.checked = true; @@ -1075,22 +1075,22 @@ Rectangle { var headObject = { "override": overrideHead, - "Y": headYOffset.value, - "Z": headZOffset.value + "Y": headYOffset.realValue, + "Z": headZOffset.realValue } var handObject = { "override": overrideHandController, - "Y": handYOffset.value, - "Z": handZOffset.value + "Y": handYOffset.realValue, + "Z": handZOffset.realValue } var settingsObject = { "bodyConfiguration": trackerConfiguration, "headConfiguration": headObject, "handConfiguration": handObject, - "armCircumference": armCircumference.value, - "shoulderWidth": shoulderWidth.value, + "armCircumference": armCircumference.realValue, + "shoulderWidth": shoulderWidth.realValue, "desktopMode": viveInDesktop.checked, "hmdDesktopTracking": hmdInDesktop.checked } From 60115752ad3fc9be0c3ae9cb0ad6801baf1f3563 Mon Sep 17 00:00:00 2001 From: vladest Date: Sat, 21 Apr 2018 20:18:24 +0200 Subject: [PATCH 3/4] Fixed saving after editing --- interface/resources/qml/controls-uit/SpinBox.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/resources/qml/controls-uit/SpinBox.qml b/interface/resources/qml/controls-uit/SpinBox.qml index 29f1de3dd7..9d63122dbc 100644 --- a/interface/resources/qml/controls-uit/SpinBox.qml +++ b/interface/resources/qml/controls-uit/SpinBox.qml @@ -39,6 +39,7 @@ SpinBox { implicitHeight: height implicitWidth: width + editable: true padding: 0 leftPadding: 0 From cf070e6e92c7b954f92694306567f87ac4d51e76 Mon Sep 17 00:00:00 2001 From: vladest Date: Mon, 23 Apr 2018 18:56:16 +0200 Subject: [PATCH 4/4] Cleanup --- interface/src/ui/PreferencesDialog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/ui/PreferencesDialog.cpp b/interface/src/ui/PreferencesDialog.cpp index 8067a27fb0..4c233b986c 100644 --- a/interface/src/ui/PreferencesDialog.cpp +++ b/interface/src/ui/PreferencesDialog.cpp @@ -298,7 +298,7 @@ void setupPreferences() { { static const int MIN_PORT_NUMBER { 0 }; static const int MAX_PORT_NUMBER { 65535 }; - auto getter = [nodelist] { qWarning() << "vladest: port" << static_cast(nodelist->getSocketLocalPort()); return static_cast(nodelist->getSocketLocalPort()); }; + auto getter = [nodelist] { return static_cast(nodelist->getSocketLocalPort()); }; auto setter = [nodelist](int preset) { nodelist->setSocketLocalPort(static_cast(preset)); }; auto preference = new IntSpinnerPreference(NETWORKING, "Listening Port", getter, setter); preference->setMin(MIN_PORT_NUMBER);