Fix SpinBox. attempt 1

This commit is contained in:
vladest 2018-04-19 20:43:48 +02:00
parent 6f420ffae2
commit 663af09605
3 changed files with 12 additions and 2 deletions

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

View file

@ -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<int>(nodelist->getSocketLocalPort()); };
auto getter = [nodelist] { qWarning() << "vladest: port" << static_cast<int>(nodelist->getSocketLocalPort()); return static_cast<int>(nodelist->getSocketLocalPort()); };
auto setter = [nodelist](int preset) { nodelist->setSocketLocalPort(static_cast<quint16>(preset)); };
auto preference = new IntSpinnerPreference(NETWORKING, "Listening Port", getter, setter);
preference->setMin(MIN_PORT_NUMBER);

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