Commit edb7d691 authored by Artur Grunau's avatar Artur Grunau
Browse files

Derive DoubleAdjusterWidget from AbstractAdjusterWidget

DoubleAdjusterWidget used to inherit directly from QWidget. Rebasing it
on top of AbstractAdjusterWidget<double>, however, greatly simplified
its implementation and provided it with several additional API methods
for free.
parent 3a1f7c9f
......@@ -8,6 +8,7 @@ FILE(GLOB CampvisApplicationSources
*.cpp
gui/*.cpp
gui/properties/*.cpp
gui/adjusterwidgets/*.cpp
tools/*.cpp
)
......@@ -17,6 +18,7 @@ FILE(GLOB CampvisApplicationHeaders
glsl/*.vert
gui/*.h
gui/properties/*.h
gui/adjusterwidgets/*.h
tools/*.h
)
......@@ -37,7 +39,7 @@ SET(CampvisApplicationToBeMocced
gui/pipelinemdisubwindow.h
gui/visualizationpipelinewidget.h
gui/visualizationpipelinewrapper.h
gui/doubleadjusterwidget.h
gui/adjusterwidgets/doubleadjusterwidget.h
gui/properties/abstractpropertywidget.h
gui/properties/abstracttransferfunctioneditor.h
gui/properties/boolpropertywidget.h
......
......@@ -29,91 +29,47 @@
#include "doubleadjusterwidget.h"
#include <QHBoxLayout>
#include <cmath>
namespace campvis {
DoubleAdjusterWidget::DoubleAdjusterWidget(QWidget* parent /*= 0*/)
: QWidget(parent)
, _slider(0)
, _spinBox(0)
: AbstractAdjusterWidget<double>(parent)
{
_spinBox = new QDoubleSpinBox();
_spinBox->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred);
_slider = new QSlider(Qt::Horizontal);
setSliderProperties(_spinBox->value(), _spinBox->singleStep(), _spinBox->minimum(), _spinBox->maximum());
QHBoxLayout* layout = new QHBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(_slider);
layout->addWidget(_spinBox);
setLayout(layout);
setSliderProperties(_spinBox->singleStep(), _spinBox->minimum(), _spinBox->maximum());
connect(_spinBox, SIGNAL(valueChanged(double)), this, SLOT(onSpinBoxValueChanged(double)));
connect(_slider, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
}
double DoubleAdjusterWidget::value() const
{
return _spinBox->value();
}
void DoubleAdjusterWidget::setValue(double value)
{
_spinBox->setValue(value);
setSliderValue(value, _spinBox->singleStep(), _spinBox->minimum());
}
void DoubleAdjusterWidget::setMinimum(double minimum)
{
_spinBox->setMinimum(minimum);
setSliderProperties(_spinBox->value(), _spinBox->singleStep(), minimum, _spinBox->maximum());
}
void DoubleAdjusterWidget::setMaximum(double maximum)
{
_spinBox->setMaximum(maximum);
setSliderProperties(_spinBox->value(), _spinBox->singleStep(), _spinBox->minimum(), maximum);
}
void DoubleAdjusterWidget::setSingleStep(double value)
{
_spinBox->setSingleStep(value);
setSliderProperties(_spinBox->value(), value, _spinBox->minimum(), _spinBox->maximum());
setValueImpl(value);
}
void DoubleAdjusterWidget::setDecimals(int prec)
{
_spinBox->setDecimals(prec);
setSliderProperties(_spinBox->value(), _spinBox->singleStep(), _spinBox->minimum(), _spinBox->maximum());
setSliderProperties(_spinBox->singleStep(), _spinBox->minimum(), _spinBox->maximum());
}
void DoubleAdjusterWidget::onSpinBoxValueChanged(double value) {
onSpinBoxValueChangedImpl(value);
emit valueChanged(value);
setSliderValue(value, _spinBox->singleStep(), _spinBox->minimum());
}
void DoubleAdjusterWidget::onSliderValueChanged(int value) {
const double newValue = _spinBox->minimum() + value * _spinBox->singleStep();
_spinBox->blockSignals(true);
_spinBox->setValue(newValue);
_spinBox->blockSignals(false);
onSliderValueChangedImpl(newValue);
emit valueChanged(newValue);
}
void DoubleAdjusterWidget::setSliderValue(double value, double stepValue, double minValue) {
_slider->blockSignals(true);
_slider->setValue(std::ceil((value - minValue) / stepValue));
_slider->blockSignals(false);
void DoubleAdjusterWidget::setSliderValue(double value) {
AbstractAdjusterWidget<double>::setSliderValue(std::ceil((value - minimum()) / singleStep()));
}
void DoubleAdjusterWidget::setSliderProperties(double value, double stepValue, double minValue, double maxValue) {
void DoubleAdjusterWidget::setSliderProperties(double stepValue, double minValue, double 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);
AbstractAdjusterWidget<double>::setSliderProperties(1, 0, std::ceil((maxValue - minValue) / stepValue));
setSliderValue(value());
}
}
......@@ -30,8 +30,7 @@
#ifndef DOUBLEADJUSTERWIDGET_H__
#define DOUBLEADJUSTERWIDGET_H__
#include <QDoubleSpinBox>
#include <QSlider>
#include "abstractadjusterwidget.h"
namespace campvis {
/**
......@@ -40,92 +39,65 @@ namespace campvis {
* DoubleAdjusterWidget consists of a slider, which can be used to quickly change numeric values, and a spin box,
* which is better suited for precise adjustments.
*/
class DoubleAdjusterWidget : public QWidget {
class DoubleAdjusterWidget : public AbstractAdjusterWidget<double> {
Q_OBJECT
public:
/**
* Creates a new DoubleAdjusterWidget.
* \param parent Parent Qt widget
* \param parent parent Qt widget
*/
DoubleAdjusterWidget(QWidget* parent = 0);
/**
* Return the adjuster's current value.
*/
double value() const;
/**
* Change the adjuster's minimum value.
* \param minimum New minimum value for the adjuster
*/
void setMinimum(double minimum);
/**
* Change the adjuster's maximum value.
* \param maximum New maximum value for the adjuster
*/
void setMaximum(double maximum);
/**
* Change the adjuster's single step value.
* \param value New single step value for the adjuster
*/
void setSingleStep(double value);
/**
* Set how many decimals the adjuster will use for displaying and interpreting doubles.
* \param prec Number of decimals the adjuster will use
* \param prec number of decimals the adjuster will use
*/
void setDecimals(int prec);
public slots:
/**
* Change the adjuster's current value.
* \param value New value for the adjuster
* \param value new value for the adjuster
*/
void setValue(double value);
signals:
/**
* This signal is emitted whenever the adjuster's value is changed.
* \param value New value of the adjuster
* \param value new value of the adjuster
*/
void valueChanged(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);
private:
protected:
/**
* 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.
* The slider's value will be based on the provided current value of the adjuster, as well as its step and
* minimum value.
*
* \param value The property's current value
* \param stepValue The property's step value
* \param minValue The property's minimum value
* \param value the adjuster's new value
*/
void setSliderValue(double value, double stepValue, double minValue);
void setSliderValue(double value);
/**
* 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.
* The slider's properties will be based on the provided step, minimum, and maximum value of the adjuster.
*
* \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
* \param stepValue the adjuster's step value
* \param minValue the adjuster's minimum value
* \param maxValue the adjuster's maximum value
*/
void setSliderProperties(double value, double stepValue, double minValue, double maxValue);
void setSliderProperties(double stepValue, double minValue, double maxValue);
QSlider* _slider; ///< Slider allowing the user to quickly change the value
QDoubleSpinBox* _spinBox; ///< Spin box displaying the current 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);
};
......
......@@ -30,8 +30,8 @@
#ifndef FLOATPROPERTYWIDGET_H__
#define FLOATPROPERTYWIDGET_H__
#include "application/gui/adjusterwidgets/doubleadjusterwidget.h"
#include "application/gui/properties/abstractpropertywidget.h"
#include "application/gui/doubleadjusterwidget.h"
#include "core/properties/numericproperty.h"
namespace campvis {
......
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