22 void VuoInputEditorEdgeBlend::setupSpinBox(
VuoDoubleSpinBox* spin,
double min,
double max,
double step,
double value)
24 const int decimalPrecision = DBL_MAX_10_EXP + DBL_DIG;
25 spin->setDecimals(decimalPrecision);
28 spin->setSingleStep(
step);
29 spin->setValue(value);
32 void VuoInputEditorEdgeBlend::setupSlider(QSlider* slider,
double min,
double max,
double step,
double value)
35 slider->setOrientation(Qt::Horizontal);
36 slider->setFocusPolicy(Qt::NoFocus);
37 slider->setMinimum(0);
38 slider->setMaximum(slider->width());
39 slider->setSingleStep(fmax(1,
step*(slider->maximum()-slider->minimum())/(max-min)));
48 bool hasMin =
false, hasMax =
false;
54 if (json_object_object_get_ex(details,
"suggestedMin", &suggestedMinValue))
62 if (json_object_object_get_ex(details,
"suggestedMax", &suggestedMaxValue))
70 if (json_object_object_get_ex(details,
"suggestedStep", &suggestedStepValue))
74 return hasMin && hasMax;
87 bool hasMinMax =
getDetails(details, &suggestedMin, &suggestedMax, &suggestedStep);
89 bool tabCycleForward =
true;
95 if (json_object_object_get_ex(details,
"forwardTabTraversal", &forwardTabTraversal))
96 tabCycleForward = json_object_get_boolean(forwardTabTraversal);
99 QGridLayout* layout =
new QGridLayout;
104 layout->setContentsMargins(4, 6, 12, hasMinMax ? 6 : 4);
105 layout->setSpacing(8);
109 unsigned int row = 0;
114 setupSpinBox(spinBox_crop, suggestedMin.crop, suggestedMax.crop, suggestedStep.crop, currentValue.crop);
115 connect(spinBox_crop,
static_cast<void (QDoubleSpinBox::*)(
const QString &)
>(&QDoubleSpinBox::valueChanged),
this, &VuoInputEditorEdgeBlend::setCrop);
117 layout->addWidget(
new QLabel(
"Crop"), row, 0 );
118 layout->addWidget( spinBox_crop, row, 1 );
125 slider_crop =
new QSlider;
126 setupSlider(slider_crop, suggestedMin.crop, suggestedMax.crop, suggestedStep.crop, currentValue.crop);
127 crop_slider_range = slider_crop->maximum();
128 connect(slider_crop, &QSlider::valueChanged,
this, &VuoInputEditorEdgeBlend::setCropSlider);
130 layout->addWidget(slider_crop, row, 1);
144 setupSpinBox(spinBox_cutoff, suggestedMin.cutoff, suggestedMax.cutoff, suggestedStep.cutoff, currentValue.cutoff);
146 connect(spinBox_cutoff,
static_cast<void (QDoubleSpinBox::*)(
const QString &)
>(&QDoubleSpinBox::valueChanged),
this, &VuoInputEditorEdgeBlend::setCutoff);
147 layout->addWidget(
new QLabel(
"Cutoff"), row, 0 );
148 layout->addWidget( spinBox_cutoff, row, 1);
155 slider_cutoff =
new QSlider;
156 setupSlider(slider_cutoff, suggestedMin.cutoff, suggestedMax.cutoff, suggestedStep.cutoff, currentValue.cutoff);
157 cutoff_slider_range = slider_cutoff->maximum();
158 connect(slider_cutoff, &QSlider::valueChanged,
this, &VuoInputEditorEdgeBlend::setCutoffSlider);
160 layout->addWidget(slider_cutoff, row, 1);
166 slider_cutoff = NULL;
175 setupSpinBox(spinBox_gamma, suggestedMin.gamma, suggestedMax.gamma, suggestedStep.gamma, currentValue.gamma);
176 connect(spinBox_gamma,
static_cast<void (QDoubleSpinBox::*)(
const QString &)
>(&QDoubleSpinBox::valueChanged),
this, &VuoInputEditorEdgeBlend::setGamma);
178 layout->addWidget(
new QLabel(
"Gamma"), row, 0 );
179 layout->addWidget( spinBox_gamma, row, 1 );
186 slider_gamma =
new QSlider;
187 setupSlider(slider_gamma, suggestedMin.gamma, suggestedMax.gamma, suggestedStep.gamma, currentValue.gamma);
188 gamma_slider_range = slider_gamma->maximum();
189 connect(slider_gamma, &QSlider::valueChanged,
this, &VuoInputEditorEdgeBlend::setGammaSlider);
191 layout->addWidget(slider_gamma, row, 1);
200 dialog.setLayout(layout);
202 dialog.setMaximumWidth(32);
203 dialog.setMaximumHeight(32);
208 (tabCycleForward ? spinBox_crop : spinBox_gamma)->setFocus();
209 (tabCycleForward ? spinBox_crop : spinBox_gamma)->selectAll();
214 void VuoInputEditorEdgeBlend::setCutoffSlider(
int newSliderValue)
216 currentValue.cutoff =
VuoDoubleSpinBox::sliderToDouble(slider_cutoff->minimum(), slider_cutoff->maximum(), suggestedMin.cutoff, suggestedMax.cutoff, newSliderValue);
217 spinBox_cutoff->setValue(currentValue.cutoff);
218 spinBox_cutoff->setFocus();
219 spinBox_cutoff->selectAll();
223 void VuoInputEditorEdgeBlend::setGammaSlider(
int newSliderValue)
225 currentValue.gamma =
VuoDoubleSpinBox::sliderToDouble(slider_gamma->minimum(), slider_gamma->maximum(), suggestedMin.gamma, suggestedMax.gamma, newSliderValue);
226 spinBox_gamma->setValue(currentValue.gamma);
227 spinBox_gamma->setFocus();
228 spinBox_gamma->selectAll();
232 void VuoInputEditorEdgeBlend::setCropSlider(
int newSliderValue)
235 spinBox_crop->setValue(currentValue.crop);
236 spinBox_crop->setFocus();
237 spinBox_crop->selectAll();
241 void VuoInputEditorEdgeBlend::setCutoff(QString newLineEditText)
243 double newLineEditValue = QLocale().toDouble(newLineEditText);
245 if(slider_cutoff != NULL)
247 int newSliderValue =
VuoDoubleSpinBox::doubleToSlider(slider_cutoff->minimum(), slider_cutoff->maximum(), suggestedMin.cutoff, suggestedMax.cutoff, newLineEditValue);
248 disconnect(slider_cutoff, &QSlider::valueChanged,
this, &VuoInputEditorEdgeBlend::setCutoffSlider);
249 slider_cutoff->setValue(newSliderValue);
250 connect(slider_cutoff, &QSlider::valueChanged,
this, &VuoInputEditorEdgeBlend::setCutoffSlider);
253 currentValue.cutoff = newLineEditValue;
257 void VuoInputEditorEdgeBlend::setGamma(QString newLineEditText)
259 double newLineEditValue = QLocale().toDouble(newLineEditText);
261 if(slider_gamma != NULL)
263 int newSliderValue =
VuoDoubleSpinBox::doubleToSlider(slider_gamma->minimum(), slider_gamma->maximum(), suggestedMin.gamma, suggestedMax.gamma, newLineEditValue);
265 disconnect(slider_gamma, &QSlider::valueChanged,
this, &VuoInputEditorEdgeBlend::setGammaSlider);
266 slider_gamma->setValue(newSliderValue);
267 connect(slider_gamma, &QSlider::valueChanged,
this, &VuoInputEditorEdgeBlend::setGammaSlider);
270 currentValue.gamma = newLineEditValue;
274 void VuoInputEditorEdgeBlend::setCrop(QString newLineEditText)
276 double newLineEditValue = QLocale().toDouble(newLineEditText);
278 if(slider_crop != NULL)
280 int newSliderValue =
VuoDoubleSpinBox::doubleToSlider(slider_crop->minimum(), slider_crop->maximum(), suggestedMin.crop, suggestedMax.crop, newLineEditValue);
282 disconnect(slider_crop, &QSlider::valueChanged,
this, &VuoInputEditorEdgeBlend::setCropSlider);
283 slider_crop->setValue(newSliderValue);
284 connect(slider_crop, &QSlider::valueChanged,
this, &VuoInputEditorEdgeBlend::setCropSlider);
287 currentValue.crop = newLineEditValue;