53 #include <QHBoxLayout> 55 #include <QPushButton> 56 #include <QDoubleSpinBox> 58 #include "numWidget.hh" 81 QHBoxLayout *hL =
new QHBoxLayout;
83 if (_hints.contains (
"precision"))
85 double v = _hints[
"precision"].toDouble (&ok);
92 while (precision_ * sliderMul_ != floor(precision_ * sliderMul_) && numDecimals_ <= 10)
98 if (_typeName ==
"Float")
100 else if (_typeName ==
"Integer")
102 else if (precision_ !=
int(precision_))
106 if (_hints.contains (
"min") && _hints.contains (
"max"))
108 double min = _hints[
"min"].toDouble (&ok);
114 double max = _hints[
"max"].toDouble (&ok);
121 max = min + precision_;
126 slider_ =
new QSlider;
127 slider_->setRange (min, max);
128 slider_->setSingleStep (precision_ * sliderMul_);
129 slider_->setOrientation (Qt::Horizontal);
131 connect (slider_, SIGNAL (valueChanged(
int)),
this, SLOT (sliderValueChanged(
int)));
133 hL->addWidget(slider_);
140 spin_ =
new QDoubleSpinBox;
142 if (_hints.contains (
"min") && _hints.contains (
"max"))
144 double min = _hints[
"min"].toDouble (&ok);
150 double max = _hints[
"max"].toDouble (&ok);
157 max = min + precision_;
159 spin_->setRange (min, max);
162 spin_->setRange (-1000000, 1000000);
164 spin_->setSingleStep (precision_);
165 spin_->setDecimals (numDecimals_);
166 connect (spin_, SIGNAL (valueChanged(
double)),
this, SLOT (spinValueChanged(
double)));
169 if (_hints.contains (
"default"))
170 default_ = _hints[
"default"].toFloat (&ok);
173 default_ = (spin_->minimum () + spin_->maximum ()) / 2;
175 spin_->setValue (default_);
177 hL->addWidget (spin_);
192 return QString::number (spin_->value ());
200 spin_->setValue (_from.toDouble());
206 void VSI::NumWidget::sliderValueChanged(
int _value)
208 double v = _value / sliderMul_;
210 if (v != spin_->value ())
217 void VSI::NumWidget::spinValueChanged(
double _value)
219 double v = _value * sliderMul_;
221 if (slider_ && v != slider_->value ())
222 slider_->setValue (v);
230 spin_->setValue (default_);
void fromValue(QString _from)
Read value from string.
NumWidget(QMap< QString, QString > &_hints, QString _typeName, QWidget *_parent=NULL)
Constructor.
QString toValue()
Convert current value to string.
void toDefault()
Reset to default.