The expiration time for new job artifacts in CI/CD pipelines is now 30 days (GitLab default). Previously generated artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit 163acaae authored by Artur Grunau's avatar Artur Grunau
Browse files

Add a slider to FloatPropertyWidget

Each FloatPropertyWidget now gives the user two ways of modifying its
underlying property's value: the slider can be used for quick changes,
the spin box — for precise adjustments.
parent 5fbb429e
......@@ -29,21 +29,35 @@
#include "floatpropertywidget.h"
#include <cmath>
namespace campvis {
FloatPropertyWidget::FloatPropertyWidget(FloatProperty* property, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, parent)
, _slider(0)
, _spinBox(0)
{
const float& maxValue = property->getMaxValue();
const float& minValue = property->getMinValue();
const float& value = property->getValue();
const float stepValue = 0.01f;
_slider = new QSlider(Qt::Horizontal);
setSliderProperties(value, stepValue, minValue, maxValue);
_spinBox = new QDoubleSpinBox(this);
_spinBox->setMinimum(property->getMinValue());
_spinBox->setMaximum(property->getMaxValue());
_spinBox->setMinimum(minValue);
_spinBox->setMaximum(maxValue);
_spinBox->setDecimals(3);
_spinBox->setSingleStep(0.01);
_spinBox->setValue(property->getValue());
_spinBox->setSingleStep(stepValue);
_spinBox->setValue(value);
_spinBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
addWidget(_slider);
addWidget(_spinBox);
connect(_spinBox, SIGNAL(valueChanged(double)), this, SLOT(onValueChanged(double)));
connect(_spinBox, SIGNAL(valueChanged(double)), this, SLOT(onSpinBoxValueChanged(double)));
connect(_slider, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
property->s_minMaxChanged.connect(this, &FloatPropertyWidget::onPropertyMinMaxChanged);
}
......@@ -56,20 +70,50 @@ namespace campvis {
_spinBox->blockSignals(true);
_spinBox->setValue(prop->getValue());
_spinBox->blockSignals(false);
setSliderValue(prop->getValue(), 0.01f, prop->getMinValue());
}
void FloatPropertyWidget::onValueChanged(double value) {
void FloatPropertyWidget::onSpinBoxValueChanged(double value) {
++_ignorePropertyUpdates;
FloatProperty* prop = static_cast<FloatProperty*>(_property);
prop->setValue(value);
setSliderValue(value, 0.01f, prop->getMinValue());
--_ignorePropertyUpdates;
}
void FloatPropertyWidget::onSliderValueChanged(int value) {
FloatProperty* prop = static_cast<FloatProperty*>(_property);
++_ignorePropertyUpdates;
const float newPropValue = prop->getMinValue() + value * 0.01;
prop->setValue(newPropValue);
_spinBox->blockSignals(true);
_spinBox->setValue(newPropValue);
_spinBox->blockSignals(false);
--_ignorePropertyUpdates;
}
void FloatPropertyWidget::onPropertyMinMaxChanged(const AbstractProperty* property) {
if (_ignorePropertyUpdates == 0) {
FloatProperty* prop = static_cast<FloatProperty*>(_property);
_spinBox->setMinimum(prop->getMinValue());
_spinBox->setMaximum(prop->getMaxValue());
const float& maxValue = prop->getMaxValue();
const float& minValue = prop->getMinValue();
_spinBox->setMinimum(minValue);
_spinBox->setMaximum(maxValue);
setSliderProperties(prop->getValue(), 0.01f, minValue, maxValue);
}
}
}
\ No newline at end of file
void FloatPropertyWidget::setSliderValue(float value, float stepValue, float minValue) {
_slider->blockSignals(true);
_slider->setValue(std::ceil((value - minValue) / stepValue));
_slider->blockSignals(false);
}
void FloatPropertyWidget::setSliderProperties(float value, float stepValue, float minValue, float maxValue) {
// by default minimum and single step are 0 and 1, respectively, so we don't have to change them
_slider->setMaximum(std::ceil((maxValue - minValue) / stepValue));
setSliderValue(value, stepValue, minValue);
}
}
......@@ -34,6 +34,7 @@
#include "core/properties/numericproperty.h"
#include <QDoubleSpinBox>
#include <QSlider>
namespace campvis {
/**
......@@ -62,13 +63,41 @@ namespace campvis {
virtual void updateWidgetFromProperty();
private slots:
void onValueChanged(double value);
/// Slot getting called when the spin box's value changes
void onSpinBoxValueChanged(double value);
/// Slot getting called when the slider's value changes
void onSliderValueChanged(int value);
private:
/// Slot getting called when the property's min or max value has changed, so that the widget can be updated.
virtual void onPropertyMinMaxChanged(const AbstractProperty* property);
QDoubleSpinBox* _spinBox;
/**
* Calculate and set the slider's value.
*
* The slider's value will be based on the provided current, step, and minimum value of the property.
*
* \param value The property's current value
* \param stepValue The property's step value
* \param minValue The property's minimum value
*/
void setSliderValue(float value, float stepValue, float minValue);
/**
* Calculate and set the slider's properties.
*
* The slider's properties (current and maximum value) will be based on the provided current, step, minimum,
* and maximum value of the property.
*
* \param value The property's current value
* \param stepValue The property's step value
* \param minValue The property's minimum value
* \param maxValue The property's maximum value
*/
void setSliderProperties(float value, float stepValue, float minValue, float maxValue);
QSlider* _slider; ///< Slider allowing the user to quickly change the property's value
QDoubleSpinBox* _spinBox; ///< Spin box displaying the property's current value
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment