From 663af09605c57c7ebf7994879b1c3972c138d599 Mon Sep 17 00:00:00 2001 From: vladest Date: Thu, 19 Apr 2018 20:43:48 +0200 Subject: [PATCH] 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 {