25 QLabel* label =
new QLabel(text);
26 label->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
33 VuoDoubleSpinBox* VuoInputEditorPoint2d::initSpinBox(coord whichCoord, QDialog& dialog,
double initialValue)
36 const int decimalPrecision = FLT_MAX_10_EXP + FLT_DIG;
37 spin->setDecimals(decimalPrecision);
38 spin->setFixedWidth(100);
41 spin->setSingleStep(suggestedStepForCoord[whichCoord]);
42 spin->setValue(initialValue);
49 QSlider* VuoInputEditorPoint2d::initSlider(coord whichCoord, QDialog& dialog,
double initialValue)
51 double min = suggestedMinForCoord[whichCoord];
52 double max = suggestedMaxForCoord[whichCoord];
53 double step = suggestedStepForCoord[whichCoord];
54 double range = max - min;
56 QSlider* slider =
new QSlider(&dialog);
57 slider->setOrientation(Qt::Horizontal);
58 slider->setFocusPolicy(Qt::NoFocus);
59 slider->setMinimum(0);
60 slider->setMaximum(slider->width());
61 slider->setSingleStep( fmax(1,
step * (slider->maximum() - slider->minimum()) / range ) );
74 const double max_dbl = std::numeric_limits<double>::max();
80 bool hasMinMax =
true;
81 bool tabCycleForward =
true;
87 if (json_object_object_get_ex(details,
"forwardTabTraversal", &forwardTabTraversal))
88 tabCycleForward = json_object_get_boolean(forwardTabTraversal);
92 if (json_object_object_get_ex(details,
"suggestedMin", &suggestedMinValue))
99 if (json_object_object_get_ex(details,
"suggestedMax", &suggestedMaxValue))
107 (suggestedMax.y - suggestedMin.y)/10.);
109 if (json_object_object_get_ex(details,
"suggestedStep", &suggestedStepValue))
113 suggestedMinForCoord[coord_x] = suggestedMin.x;
114 suggestedMinForCoord[coord_y] = suggestedMin.y;
115 suggestedMaxForCoord[coord_x] = suggestedMax.x;
116 suggestedMaxForCoord[coord_y] = suggestedMax.y;
117 suggestedStepForCoord[coord_x] = suggestedStep.x;
118 suggestedStepForCoord[coord_y] = suggestedStep.y;
120 spinboxForCoord[coord_x] = initSpinBox(coord_x, dialog, current.x);
121 spinboxForCoord[coord_y] = initSpinBox(coord_y, dialog, current.y);
122 connect(spinboxForCoord[coord_x],
static_cast<void (QDoubleSpinBox::*)(
const QString &)
>(&QDoubleSpinBox::valueChanged),
this, &VuoInputEditorPoint2d::onSpinboxUpdate);
123 connect(spinboxForCoord[coord_y],
static_cast<void (QDoubleSpinBox::*)(
const QString &)
>(&QDoubleSpinBox::valueChanged),
this, &VuoInputEditorPoint2d::onSpinboxUpdate);
127 sliderForCoord[coord_x] = initSlider(coord_x, dialog, current.x);
128 sliderForCoord[coord_y] = initSlider(coord_y, dialog, current.y);
129 connect(sliderForCoord[coord_x], &QSlider::valueChanged,
this, &VuoInputEditorPoint2d::onSliderUpdate);
130 connect(sliderForCoord[coord_y], &QSlider::valueChanged,
this, &VuoInputEditorPoint2d::onSliderUpdate);
134 QGridLayout* layout =
new QGridLayout;
135 dialog.setLayout(layout);
140 layout->setContentsMargins(4, 4, 16, 4);
141 layout->setSpacing(4);
145 layout->addWidget(
makeLabel(
"X"), row, 0, Qt::AlignHCenter);
146 layout->addWidget(spinboxForCoord[coord_x], row++, 1);
147 if(hasMinMax) layout->addWidget(sliderForCoord[coord_x], row++, 1);
149 layout->addWidget(
makeLabel(
"Y"), row, 0, Qt::AlignHCenter);
150 layout->addWidget(spinboxForCoord[coord_y], row++, 1);
151 if(hasMinMax) layout->addWidget(sliderForCoord[coord_y], row++, 1);
153 dialog.setMaximumWidth(1);
154 dialog.setMaximumHeight(1);
165 (tabCycleForward ? spinboxForCoord[coord_x] : spinboxForCoord[coord_y])->setFocus();
166 (tabCycleForward ? spinboxForCoord[coord_x] : spinboxForCoord[coord_y])->selectAll();
169 bool VuoInputEditorPoint2d::getCoordFromQObject(QObject* sender, VuoInputEditorPoint2d::coord* whichCoord)
171 if(sender == spinboxForCoord[coord_x] || sender == sliderForCoord[coord_x])
172 *whichCoord = coord_x;
173 else if(sender == spinboxForCoord[coord_y] || sender == sliderForCoord[coord_y])
174 *whichCoord = coord_y;
181 void VuoInputEditorPoint2d::setCoord(coord c,
double value)
185 else if(c == coord_y)
192 void VuoInputEditorPoint2d::onSliderUpdate(
int sliderValue)
196 if(!getCoordFromQObject(QObject::sender(), &whichCoord))
199 QSlider *targetSlider = sliderForCoord[whichCoord];
202 targetSlider->maximum(),
203 suggestedMinForCoord[whichCoord],
204 suggestedMaxForCoord[whichCoord],
206 setCoord(whichCoord, value);
209 disconnect(spinboxForCoord[whichCoord],
static_cast<void (QDoubleSpinBox::*)(
const QString &)
>(&QDoubleSpinBox::valueChanged),
this, &VuoInputEditorPoint2d::onSpinboxUpdate);
210 spinboxForCoord[whichCoord]->setValue( value );
211 connect(spinboxForCoord[whichCoord],
static_cast<void (QDoubleSpinBox::*)(
const QString &)
>(&QDoubleSpinBox::valueChanged),
this, &VuoInputEditorPoint2d::onSpinboxUpdate);
213 spinboxForCoord[whichCoord]->setFocus();
214 spinboxForCoord[whichCoord]->selectAll();
222 void VuoInputEditorPoint2d::onSpinboxUpdate(QString spinboxValue)
226 if(!getCoordFromQObject(QObject::sender(), &whichCoord))
229 double value = QLocale().toDouble(spinboxValue);
230 setCoord(whichCoord, value);
232 QSlider *targetSlider = sliderForCoord[whichCoord];
234 if(targetSlider != NULL)
236 int sliderValue =
VuoDoubleSpinBox::doubleToSlider(targetSlider->minimum(), targetSlider->maximum(), suggestedMinForCoord[whichCoord], suggestedMaxForCoord[whichCoord], value);
237 disconnect(targetSlider, &QSlider::valueChanged,
this, &VuoInputEditorPoint2d::onSliderUpdate);
238 targetSlider->setValue( sliderValue );
239 connect(targetSlider, &QSlider::valueChanged,
this, &VuoInputEditorPoint2d::onSliderUpdate);
256 void VuoInputEditorPoint2d::emitValueChanged()