47 #include <QHBoxLayout> 49 #include <QPushButton> 50 #include <QDoubleSpinBox> 52 #include "numWidget.hh" 75 QHBoxLayout *hL =
new QHBoxLayout;
77 if (_hints.contains (
"precision"))
79 double v = _hints[
"precision"].toDouble (&ok);
86 while (precision_ * sliderMul_ != floor(precision_ * sliderMul_) && numDecimals_ <= 10)
92 if (_typeName ==
"Float")
94 else if (_typeName ==
"Integer")
96 else if (precision_ !=
int(precision_))
100 if (_hints.contains (
"min") && _hints.contains (
"max"))
102 double min = _hints[
"min"].toDouble (&ok);
108 double max = _hints[
"max"].toDouble (&ok);
115 max = min + precision_;
120 slider_ =
new QSlider;
121 slider_->setRange (min, max);
122 slider_->setSingleStep (precision_ * sliderMul_);
123 slider_->setOrientation (Qt::Horizontal);
125 connect (slider_, SIGNAL (valueChanged(
int)),
this, SLOT (sliderValueChanged(
int)));
127 hL->addWidget(slider_);
134 spin_ =
new QDoubleSpinBox;
136 if (_hints.contains (
"min") && _hints.contains (
"max"))
138 double min = _hints[
"min"].toDouble (&ok);
144 double max = _hints[
"max"].toDouble (&ok);
151 max = min + precision_;
153 spin_->setRange (min, max);
156 spin_->setRange (-1000000, 1000000);
158 spin_->setSingleStep (precision_);
159 spin_->setDecimals (numDecimals_);
160 connect (spin_, SIGNAL (valueChanged(
double)),
this, SLOT (spinValueChanged(
double)));
163 if (_hints.contains (
"default"))
164 default_ = _hints[
"default"].toFloat (&ok);
167 default_ = (spin_->minimum () + spin_->maximum ()) / 2;
169 spin_->setValue (default_);
171 hL->addWidget (spin_);
177 NumWidget::~ NumWidget()
186 return QString::number (spin_->value ());
194 spin_->setValue (_from.toDouble());
200 void VSI::NumWidget::sliderValueChanged(
int _value)
202 double v = _value / sliderMul_;
204 if (v != spin_->value ())
211 void VSI::NumWidget::spinValueChanged(
double _value)
213 double v = _value * sliderMul_;
215 if (slider_ && v != slider_->value ())
216 slider_->setValue (v);
224 spin_->setValue (default_);