28 suggestedMin = INT_MIN;
29 suggestedMax = INT_MAX;
34 bool hasMinMax = details != NULL, hasAutoValue = details != NULL;
41 if (json_object_object_get_ex(details,
"auto", &autoJsonValue))
48 if (json_object_object_get_ex(details,
"suggestedMin", &suggestedMinValue))
55 if (json_object_object_get_ex(details,
"suggestedMax", &suggestedMaxValue))
62 suggestedStep = fmax((suggestedMax - suggestedMin)/10, 1);
64 if (json_object_object_get_ex(details,
"suggestedStep", &suggestedStepValue))
69 if (json_object_object_get_ex(details,
"default", &defaultJsonValue))
76 spinbox->setSingleStep(suggestedStep);
77 spinbox->setValue(current);
78 spinbox->setEnabled(autoToggle == NULL || !autoToggle->isChecked());
80 connect(spinbox,
static_cast<void (QSpinBox::*)(
const QString &)
>(&QSpinBox::valueChanged),
this, &VuoInputEditorInteger::onSpinboxUpdate);
84 slider =
new QSlider(&dialog);
85 slider->setOrientation(Qt::Horizontal);
86 slider->setFocusPolicy(Qt::NoFocus);
87 slider->setMinimum(suggestedMin);
88 slider->setMaximum(suggestedMax);
89 slider->setSingleStep(suggestedStep);
90 slider->setValue(current);
91 slider->setEnabled(autoToggle == NULL || !autoToggle->isChecked());
93 connect(slider, &QSlider::valueChanged,
this, &VuoInputEditorInteger::onSliderUpdate);
97 QGridLayout* layout =
new QGridLayout;
98 dialog.setLayout(layout);
103 layout->setContentsMargins(4, 4, 12, 4);
104 layout->setSpacing(4);
105 if(hasAutoValue) layout->setHorizontalSpacing(8);
111 autoToggle =
new QCheckBox(
"Auto");
112 connect(autoToggle, &QCheckBox::stateChanged,
this, &VuoInputEditorInteger::setAutoToggled);
113 bool currentIsAuto = (current == autoValue);
114 autoToggle->setChecked(currentIsAuto);
116 previous = defaultValue;
118 layout->addWidget(autoToggle, row++, 0);
119 autoToggle->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
122 layout->addWidget(spinbox, row++, 0);
128 QHBoxLayout* sliderLayout =
new QHBoxLayout();
129 sliderLayout->setContentsMargins(-2, 0, 2, 0);
130 sliderLayout->addWidget(slider);
131 layout->addLayout(sliderLayout, row++, 0);
134 dialog.setMaximumWidth(1);
135 dialog.setMaximumHeight(1);
147 void VuoInputEditorInteger::setAutoToggled(
int state)
149 if(state == Qt::Unchecked)
151 spinbox->setSpecialValueText(
"");
152 spinbox->setMinimum(suggestedMin);
153 spinbox->setMaximum(suggestedMax);
160 spinbox->setSpecialValueText(
" Auto ");
161 spinbox->setMinimum(autoValue);
162 spinbox->setMaximum(autoValue);
165 spinbox->setValue(current);
166 spinbox->setEnabled(!autoToggle->isChecked());
167 if(slider) slider->setEnabled(!autoToggle->isChecked());
173 void VuoInputEditorInteger::onSliderUpdate(
int sliderValue)
175 current = sliderValue;
178 disconnect(spinbox,
static_cast<void (QSpinBox::*)(
const QString &)
>(&QSpinBox::valueChanged),
this, &VuoInputEditorInteger::onSpinboxUpdate);
179 spinbox->setValue( current );
180 connect(spinbox,
static_cast<void (QSpinBox::*)(
const QString &)
>(&QSpinBox::valueChanged),
this, &VuoInputEditorInteger::onSpinboxUpdate);
183 spinbox->selectAll();
191 void VuoInputEditorInteger::onSpinboxUpdate(QString spinboxValue)
193 current = QLocale().toInt(spinboxValue);
197 disconnect(slider, &QSlider::valueChanged,
this, &VuoInputEditorInteger::onSliderUpdate);
198 slider->setValue( current );
199 connect(slider, &QSlider::valueChanged,
this, &VuoInputEditorInteger::onSliderUpdate);