2012-01-05 18:39:17 +00:00
|
|
|
#include "inputdouble.h"
|
|
|
|
|
|
|
|
#include <QLabel>
|
2012-01-08 10:31:01 +00:00
|
|
|
#include "math.h"
|
2012-01-05 18:39:17 +00:00
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
InputDouble::InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step):
|
2012-07-04 09:50:06 +00:00
|
|
|
BaseInput(form, label)
|
2012-01-05 18:39:17 +00:00
|
|
|
{
|
2012-07-04 09:50:06 +00:00
|
|
|
_value = value;
|
|
|
|
_min = min;
|
|
|
|
_max = max;
|
|
|
|
_small_step = small_step;
|
|
|
|
_large_step = large_step;
|
|
|
|
|
|
|
|
_slider = new QSlider(form);
|
2012-01-05 18:39:17 +00:00
|
|
|
|
2012-07-04 09:50:06 +00:00
|
|
|
_slider->setOrientation(Qt::Horizontal);
|
|
|
|
_slider->setMinimumWidth(200);
|
|
|
|
_slider->setMaximumWidth(400);
|
2012-01-05 18:39:17 +00:00
|
|
|
|
2012-07-04 09:50:06 +00:00
|
|
|
_slider->setMinimum(0);
|
|
|
|
_slider->setMaximum(round((max - min) / small_step));
|
|
|
|
_slider->setValue(round((*value - min) / small_step));
|
2012-01-05 18:39:17 +00:00
|
|
|
|
2012-07-04 09:50:06 +00:00
|
|
|
_slider->setTickInterval(round(large_step / small_step));
|
|
|
|
_slider->setTickPosition(QSlider::TicksBelow);
|
2012-01-05 18:39:17 +00:00
|
|
|
|
2012-07-04 09:50:06 +00:00
|
|
|
connect(_slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue()));
|
2012-01-05 18:39:17 +00:00
|
|
|
|
|
|
|
_preview = new QLabel(form);
|
2012-06-05 20:22:12 +00:00
|
|
|
((QLabel*)_preview)->setAlignment(Qt::AlignCenter);
|
2012-07-04 09:50:06 +00:00
|
|
|
_control = _slider;
|
2012-01-05 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
2012-01-08 10:31:01 +00:00
|
|
|
void InputDouble::updatePreview()
|
|
|
|
{
|
2012-07-04 09:50:06 +00:00
|
|
|
((QLabel*)_preview)->setText(QString::number(*_value, 'g', 3));
|
2012-01-08 10:31:01 +00:00
|
|
|
|
|
|
|
BaseInput::updatePreview();
|
|
|
|
}
|
|
|
|
|
2012-11-24 14:19:43 +00:00
|
|
|
double InputDouble::getValue()
|
2012-01-05 18:39:17 +00:00
|
|
|
{
|
2012-11-24 14:19:43 +00:00
|
|
|
double result;
|
2012-07-04 09:50:06 +00:00
|
|
|
int ivalue = _slider->value();
|
|
|
|
if (ivalue == _slider->maximum())
|
2012-01-08 10:31:01 +00:00
|
|
|
{
|
2012-11-24 14:19:43 +00:00
|
|
|
result = _max;
|
2012-01-08 10:31:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-11-24 14:19:43 +00:00
|
|
|
result = _min + ((double)ivalue) * _small_step;
|
2012-01-08 10:31:01 +00:00
|
|
|
}
|
2012-07-04 09:50:06 +00:00
|
|
|
if (fabs(*_value) < 0.0000001)
|
2012-01-08 10:31:01 +00:00
|
|
|
{
|
2012-11-24 14:19:43 +00:00
|
|
|
result = 0.0;
|
2012-01-08 10:31:01 +00:00
|
|
|
}
|
2012-11-24 14:19:43 +00:00
|
|
|
return result;
|
|
|
|
}
|
2012-01-05 19:41:10 +00:00
|
|
|
|
2012-11-24 14:19:43 +00:00
|
|
|
void InputDouble::applyValue()
|
|
|
|
{
|
|
|
|
*_value = getValue();
|
2012-01-05 19:41:10 +00:00
|
|
|
BaseInput::applyValue();
|
2012-01-05 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputDouble::revert()
|
|
|
|
{
|
2012-07-04 09:50:06 +00:00
|
|
|
double value = round((*_value - _min) / _small_step);
|
|
|
|
if (value != _slider->value())
|
|
|
|
{
|
|
|
|
_slider->setValue(value);
|
|
|
|
}
|
2012-01-08 10:31:01 +00:00
|
|
|
|
|
|
|
BaseInput::revert();
|
2012-01-05 18:39:17 +00:00
|
|
|
}
|