Merge pull request #12943 from vladest/fix_spinbox

Fix SpinBox.
This commit is contained in:
John Conklin II 2018-04-23 13:02:01 -07:00 committed by GitHub
commit b3dbf7a025
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 65 additions and 53 deletions

View file

@ -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

View file

@ -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,8 +35,11 @@ SpinBox {
property real realTo: 100.0
property real realStepSize: 1.0
signal editingFinished()
implicitHeight: height
implicitWidth: width
editable: true
padding: 0
leftPadding: 0
@ -68,16 +72,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;
}
@ -88,12 +92,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

View file

@ -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();
}

View file

@ -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
}
}
}
}

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

@ -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
}

View file

@ -198,6 +198,7 @@ class IntPreference : public TypedPreference<int> {
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<int>::min() };
int _max { std::numeric_limits<int>::max() };
int _step { 1 };
int _decimals { 0 };
};
class StringPreference : public TypedPreference<QString> {