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-01-05 18:39:17 +00:00
|
|
|
BaseInput(form, label),
|
|
|
|
value(value), min(min), max(max), small_step(small_step), large_step(large_step)
|
|
|
|
{
|
|
|
|
slider = new QSlider(form);
|
|
|
|
|
|
|
|
slider->setOrientation(Qt::Horizontal);
|
2012-04-05 20:09:39 +00:00
|
|
|
slider->setMinimumWidth(200);
|
2012-01-05 18:39:17 +00:00
|
|
|
slider->setMaximumWidth(400);
|
|
|
|
|
2012-01-08 10:31:01 +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-01-08 10:31:01 +00:00
|
|
|
slider->setTickInterval(round(large_step / small_step));
|
2012-01-05 18:39:17 +00:00
|
|
|
slider->setTickPosition(QSlider::TicksBelow);
|
|
|
|
|
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue()));
|
|
|
|
|
|
|
|
_preview = new QLabel(form);
|
2012-06-05 20:22:12 +00:00
|
|
|
((QLabel*)_preview)->setAlignment(Qt::AlignCenter);
|
2012-01-05 18:39:17 +00:00
|
|
|
_control = slider;
|
|
|
|
}
|
|
|
|
|
2012-01-08 10:31:01 +00:00
|
|
|
void InputDouble::updatePreview()
|
|
|
|
{
|
|
|
|
((QLabel*)_preview)->setText(QString::number(*value, 'g', 3));
|
|
|
|
|
|
|
|
BaseInput::updatePreview();
|
|
|
|
}
|
|
|
|
|
2012-01-05 18:39:17 +00:00
|
|
|
void InputDouble::applyValue()
|
|
|
|
{
|
2012-01-08 10:31:01 +00:00
|
|
|
int ivalue = slider->value();
|
|
|
|
if (ivalue == slider->maximum())
|
|
|
|
{
|
|
|
|
*value = max;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
*value = min + ((double)ivalue) * small_step;
|
2012-01-08 10:31:01 +00:00
|
|
|
}
|
|
|
|
if (fabs(*value) < 0.0000001)
|
|
|
|
{
|
|
|
|
*value = 0.0;
|
|
|
|
}
|
2012-01-05 19:41:10 +00:00
|
|
|
|
|
|
|
BaseInput::applyValue();
|
2012-01-05 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputDouble::revert()
|
|
|
|
{
|
2012-01-08 10:31:01 +00:00
|
|
|
slider->setValue(round((*value - min) / small_step));
|
|
|
|
|
|
|
|
BaseInput::revert();
|
2012-01-05 18:39:17 +00:00
|
|
|
}
|