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

Use IntAdjusterWidget in int and vector<int> property widgets

Previously, widgets for int and vector<int> properties used only spin
boxes to display and let users modify the values of their associated
property.

Now that we have IntAdjusterWidget, IntPropertyWidget and all
IVecPropertyWidgets have been updated to use it to make it possible to
change the values of their components with not only a spin box, but also
a slider.
parent 4dbd1800
......@@ -37,7 +37,7 @@
namespace campvis {
IntPropertyWidget::IntPropertyWidget(IntProperty* property, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, false, parent)
, _spinBox(0)
, _adjuster(0)
, _timer(0)
{
_timer = new QTimer(this);
......@@ -47,11 +47,11 @@ namespace campvis {
QGridLayout* layout = new QGridLayout(widget);
widget->setLayout(layout);
_spinBox = new QSpinBox(widget);
_spinBox->setMinimum(property->getMinValue());
_spinBox->setMaximum(property->getMaxValue());
_spinBox->setValue(property->getValue());
layout->addWidget(_spinBox, 0, 0, 1, 2);
_adjuster = new IntAdjusterWidget;
_adjuster->setMinimum(property->getMinValue());
_adjuster->setMaximum(property->getMaxValue());
_adjuster->setValue(property->getValue());
layout->addWidget(_adjuster, 0, 0, 1, 2);
_cbEnableTimer = new QCheckBox("Enable Timer", widget);
layout->addWidget(_cbEnableTimer, 1, 0);
......@@ -65,7 +65,7 @@ namespace campvis {
addWidget(widget);
connect(_timer, SIGNAL(timeout()), this, SLOT(onTimer()));
connect(_spinBox, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
connect(_adjuster, SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
connect(_cbEnableTimer, SIGNAL(stateChanged(int)), this, SLOT(onEnableTimerChanged(int)));
connect(_sbInterval, SIGNAL(valueChanged(int)), this, SLOT(onIntervalValueChanged(int)));
property->s_minMaxChanged.connect(this, &IntPropertyWidget::onPropertyMinMaxChanged);
......@@ -77,9 +77,9 @@ namespace campvis {
void IntPropertyWidget::updateWidgetFromProperty() {
IntProperty* prop = static_cast<IntProperty*>(_property);
_spinBox->blockSignals(true);
_spinBox->setValue(prop->getValue());
_spinBox->blockSignals(false);
_adjuster->blockSignals(true);
_adjuster->setValue(prop->getValue());
_adjuster->blockSignals(false);
}
void IntPropertyWidget::onValueChanged(int value) {
......@@ -92,8 +92,8 @@ namespace campvis {
void IntPropertyWidget::onPropertyMinMaxChanged(const AbstractProperty* property) {
if (_ignorePropertyUpdates == 0) {
IntProperty* prop = static_cast<IntProperty*>(_property);
_spinBox->setMinimum(prop->getMinValue());
_spinBox->setMaximum(prop->getMaxValue());
_adjuster->setMinimum(prop->getMinValue());
_adjuster->setMaximum(prop->getMaxValue());
}
}
......
......@@ -30,11 +30,10 @@
#ifndef INTPROPERTYWIDGET_H__
#define INTPROPERTYWIDGET_H__
#include "application/gui/adjusterwidgets/intadjusterwidget.h"
#include "application/gui/properties/abstractpropertywidget.h"
#include "core/properties/numericproperty.h"
#include <QSpinBox>
class QCheckBox;
class QTimer;
......@@ -74,7 +73,7 @@ namespace campvis {
/// 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);
QSpinBox* _spinBox;
IntAdjusterWidget* _adjuster;
QTimer* _timer;
QCheckBox* _cbEnableTimer;
......@@ -143,21 +142,21 @@ namespace campvis {
/// 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);
QSpinBox* _spinBox[size];
IntAdjusterWidget* _adjusters[size];
};
// ================================================================================================
template<size_t SIZE>
campvis::IVecPropertyWidget<SIZE>::IVecPropertyWidget(PropertyType* property, QWidget* parent /*= 0*/)
: AbstractPropertyWidget(property, false, parent)
: AbstractPropertyWidget(property, true, parent)
{
for (size_t i = 0; i < size; ++i) {
_spinBox[i] = new QSpinBox(this);
_spinBox[i]->setMinimum(property->getMinValue()[i]);
_spinBox[i]->setMaximum(property->getMaxValue()[i]);
_spinBox[i]->setValue(property->getValue()[i]);
addWidget(_spinBox[i]);
_adjusters[i] = new IntAdjusterWidget;
_adjusters[i]->setMinimum(property->getMinValue()[i]);
_adjusters[i]->setMaximum(property->getMaxValue()[i]);
_adjusters[i]->setValue(property->getValue()[i]);
addWidget(_adjusters[i]);
}
property->s_minMaxChanged.connect(this, &IVecPropertyWidget::onPropertyMinMaxChanged);
......@@ -173,9 +172,9 @@ namespace campvis {
void campvis::IVecPropertyWidget<SIZE>::updateWidgetFromProperty() {
PropertyType* prop = static_cast<PropertyType*>(_property);
for (size_t i = 0; i < size; ++i) {
_spinBox[i]->blockSignals(true);
_spinBox[i]->setValue(prop->getValue()[i]);
_spinBox[i]->blockSignals(false);
_adjusters[i]->blockSignals(true);
_adjusters[i]->setValue(prop->getValue()[i]);
_adjusters[i]->blockSignals(false);
}
}
......@@ -185,7 +184,7 @@ namespace campvis {
PropertyType* prop = static_cast<PropertyType*>(_property);
typename IVecPropertyWidgetTraits<SIZE>::BaseType newValue;
for (size_t i = 0; i < size; ++i)
newValue[i] = _spinBox[i]->value();
newValue[i] = _adjusters[i]->value();
prop->setValue(newValue);
--_ignorePropertyUpdates;
}
......@@ -195,8 +194,8 @@ namespace campvis {
if (_ignorePropertyUpdates == 0) {
PropertyType* prop = static_cast<PropertyType*>(_property);
for (size_t i = 0; i < size; ++i) {
_spinBox[i]->setMinimum(prop->getMinValue()[i]);
_spinBox[i]->setMaximum(prop->getMaxValue()[i]);
_adjusters[i]->setMinimum(prop->getMinValue()[i]);
_adjusters[i]->setMaximum(prop->getMaxValue()[i]);
}
}
}
......@@ -210,7 +209,7 @@ namespace campvis {
: IVecPropertyWidget<2>(property, parent)
{
for (size_t i = 0; i < size; ++i) {
connect(_spinBox[i], SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
connect(_adjusters[i], SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
}
}
......@@ -227,7 +226,7 @@ namespace campvis {
: IVecPropertyWidget<3>(property, parent)
{
for (size_t i = 0; i < size; ++i) {
connect(_spinBox[i], SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
connect(_adjusters[i], SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
}
}
......@@ -244,7 +243,7 @@ namespace campvis {
: IVecPropertyWidget<4>(property, parent)
{
for (size_t i = 0; i < size; ++i) {
connect(_spinBox[i], SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
connect(_adjusters[i], SIGNAL(valueChanged(int)), this, SLOT(onValueChanged(int)));
}
}
......
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