64 lines
1.1 KiB
C++
64 lines
1.1 KiB
C++
#include "propslider.h"
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
PropSlider::PropSlider(QWidget *parent)
|
|
:QSlider(parent),
|
|
mapped_value(mapValue())
|
|
{
|
|
connect(this, SIGNAL(valueChanged(int)),
|
|
this, SLOT(setValue(int)));
|
|
}
|
|
|
|
|
|
int PropSlider::mapValue() const
|
|
{
|
|
return (value - min) * maximum() / (max - min);
|
|
}
|
|
|
|
|
|
double PropSlider::unmapValue() const
|
|
{
|
|
return (double) mapped_value * (max - min) / maximum() + min;
|
|
}
|
|
|
|
|
|
void PropSlider::setMinimum(double min)
|
|
{
|
|
this->min = min;
|
|
}
|
|
|
|
|
|
void PropSlider::setMaximum(double max)
|
|
{
|
|
this->max = max;
|
|
((QSlider *) this)->setMaximum((max-min) / step);
|
|
}
|
|
|
|
|
|
void PropSlider::setStep(double step)
|
|
{
|
|
this->step = step;
|
|
setMaximum(max);
|
|
}
|
|
|
|
|
|
void PropSlider::setValue(double value)
|
|
{
|
|
qDebug() << "PropSlider, setting from double" << value;
|
|
this->value = value;
|
|
((QSlider *) this)->setValue(mapValue());
|
|
}
|
|
|
|
|
|
void PropSlider::setValue(int mapped_value) {
|
|
qDebug() << "PropSlider, setting from int" << mapped_value;
|
|
if (mapValue() != mapped_value) {
|
|
qDebug() << "Mapped value changed, transmitting to GLArea";
|
|
this->mapped_value = mapped_value;
|
|
this->value = unmapValue();
|
|
emit valueChanged(this->value);
|
|
}
|
|
}
|