Commit 77653ee0 authored by Artur Grunau's avatar Artur Grunau
Browse files

FloatPropertyWidget: use DoubleAdjusterWidget

Previously, FloatPropertyWidget used standard spin boxes and sliders to
display and let users modify the value of its associated property.
Consequently, it had to synchronise the states of those widgets on its

Now that we have a separate widget that implements the two ways of
changing double values that FloatPropertyWidget provides, it makes sense
to simplify FloatPropertyWidget's code by making it use
DoubleAdjusterWidget internally.
parent 778445ea
......@@ -29,35 +29,24 @@
#include "floatpropertywidget.h"
#include <cmath>
namespace campvis {
FloatPropertyWidget::FloatPropertyWidget(FloatProperty* property, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, parent)
, _slider(0)
, _spinBox(0)
, _adjuster(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->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
_adjuster = new DoubleAdjusterWidget();
connect(_spinBox, SIGNAL(valueChanged(double)), this, SLOT(onSpinBoxValueChanged(double)));
connect(_slider, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
connect(_adjuster, SIGNAL(valueChanged(double)), this, SLOT(onAdjusterValueChanged(double)));
connect(this, SIGNAL(propertyValueChanged(double)), _adjuster, SLOT(setValue(double)));
property->s_minMaxChanged.connect(this, &FloatPropertyWidget::onPropertyMinMaxChanged);
......@@ -67,53 +56,23 @@ namespace campvis {
void FloatPropertyWidget::updateWidgetFromProperty() {
FloatProperty* prop = static_cast<FloatProperty*>(_property);
setSliderValue(prop->getValue(), 0.01f, prop->getMinValue());
emit propertyValueChanged(prop->getValue());
void FloatPropertyWidget::onSpinBoxValueChanged(double value) {
void FloatPropertyWidget::onAdjusterValueChanged(double value) {
FloatProperty* prop = static_cast<FloatProperty*>(_property);
setSliderValue(value, 0.01f, prop->getMinValue());
void FloatPropertyWidget::onSliderValueChanged(int value) {
FloatProperty* prop = static_cast<FloatProperty*>(_property);
const float newPropValue = prop->getMinValue() + value * 0.01;
void FloatPropertyWidget::onPropertyMinMaxChanged(const AbstractProperty* property) {
if (_ignorePropertyUpdates == 0) {
FloatProperty* prop = static_cast<FloatProperty*>(_property);
const float& maxValue = prop->getMaxValue();
const float& minValue = prop->getMinValue();
setSliderProperties(prop->getValue(), 0.01f, minValue, maxValue);
const FloatProperty* prop = static_cast<const FloatProperty*>(property);
void FloatPropertyWidget::setSliderValue(float value, float stepValue, float minValue) {
_slider->setValue(std::ceil((value - minValue) / stepValue));
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);
......@@ -31,17 +31,17 @@
#include "application/gui/properties/abstractpropertywidget.h"
#include "application/gui/doubleadjusterwidget.h"
#include "core/properties/numericproperty.h"
#include <QDoubleSpinBox>
#include <QSlider>
namespace campvis {
* Widget for a FloatProperty
class FloatPropertyWidget : public AbstractPropertyWidget {
......@@ -62,42 +62,19 @@ namespace campvis {
virtual void updateWidgetFromProperty();
/// Signal emitted when the property's value changes
void propertyValueChanged(double value);
private slots:
/// 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);
/// Slot getting called when the adjuster's value changes
void onAdjusterValueChanged(double value);
/// 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);
* 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
DoubleAdjusterWidget* _adjuster; ///< Widget allowing the user to change the property's value
Supports Markdown
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