paysages : Automatic colors updating for custom sky.

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@373 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-07-04 09:50:06 +00:00 committed by ThunderK
parent bce5dfbd8f
commit b7e4be1030
8 changed files with 78 additions and 53 deletions

1
TODO
View file

@ -1,6 +1,5 @@
Technology Preview 2 : Technology Preview 2 :
- Finalize Preetham's model usage - Finalize Preetham's model usage
=> Update all fields when "auto from daytime" is selected
=> Apply model to atmosphere (aerial perspective) => Apply model to atmosphere (aerial perspective)
=> Find a proper model for night sky (maybe Shirley) => Find a proper model for night sky (maybe Shirley)
- InputInt doesn't honor small_step. - InputInt doesn't honor small_step.

View file

@ -176,7 +176,7 @@ void BaseForm::revertConfig()
} }
updatePreviews(); updatePreviews();
configChangeEvent(); //configChangeEvent();
button_apply->setEnabled(false); button_apply->setEnabled(false);
button_revert->setEnabled(false); button_revert->setEnabled(false);

View file

@ -144,5 +144,11 @@ void FormSky::applyConfig()
void FormSky::configChangeEvent() void FormSky::configChangeEvent()
{ {
skyValidateDefinition(&_definition); skyValidateDefinition(&_definition);
if (_definition.model == SKY_MODEL_CUSTOM && _definition.model_custom.auto_from_daytime)
{
BaseForm::revertConfig();
}
BaseForm::configChangeEvent(); BaseForm::configChangeEvent();
} }

View file

@ -4,50 +4,55 @@
#include "math.h" #include "math.h"
InputDouble::InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step): InputDouble::InputDouble(QWidget* form, QString label, double* value, double min, double max, double small_step, double large_step):
BaseInput(form, label), BaseInput(form, label)
value(value), min(min), max(max), small_step(small_step), large_step(large_step)
{ {
slider = new QSlider(form); _value = value;
_min = min;
_max = max;
_small_step = small_step;
_large_step = large_step;
slider->setOrientation(Qt::Horizontal); _slider = new QSlider(form);
slider->setMinimumWidth(200);
slider->setMaximumWidth(400);
slider->setMinimum(0); _slider->setOrientation(Qt::Horizontal);
slider->setMaximum(round((max - min) / small_step)); _slider->setMinimumWidth(200);
slider->setValue(round((*value - min) / small_step)); _slider->setMaximumWidth(400);
slider->setTickInterval(round(large_step / small_step)); _slider->setMinimum(0);
slider->setTickPosition(QSlider::TicksBelow); _slider->setMaximum(round((max - min) / small_step));
_slider->setValue(round((*value - min) / small_step));
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue())); _slider->setTickInterval(round(large_step / small_step));
_slider->setTickPosition(QSlider::TicksBelow);
connect(_slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue()));
_preview = new QLabel(form); _preview = new QLabel(form);
((QLabel*)_preview)->setAlignment(Qt::AlignCenter); ((QLabel*)_preview)->setAlignment(Qt::AlignCenter);
_control = slider; _control = _slider;
} }
void InputDouble::updatePreview() void InputDouble::updatePreview()
{ {
((QLabel*)_preview)->setText(QString::number(*value, 'g', 3)); ((QLabel*)_preview)->setText(QString::number(*_value, 'g', 3));
BaseInput::updatePreview(); BaseInput::updatePreview();
} }
void InputDouble::applyValue() void InputDouble::applyValue()
{ {
int ivalue = slider->value(); int ivalue = _slider->value();
if (ivalue == slider->maximum()) if (ivalue == _slider->maximum())
{ {
*value = max; *_value = _max;
} }
else else
{ {
*value = min + ((double)ivalue) * small_step; *_value = _min + ((double)ivalue) * _small_step;
} }
if (fabs(*value) < 0.0000001) if (fabs(*_value) < 0.0000001)
{ {
*value = 0.0; *_value = 0.0;
} }
BaseInput::applyValue(); BaseInput::applyValue();
@ -55,7 +60,11 @@ void InputDouble::applyValue()
void InputDouble::revert() void InputDouble::revert()
{ {
slider->setValue(round((*value - min) / small_step)); double value = round((*_value - _min) / _small_step);
if (value != _slider->value())
{
_slider->setValue(value);
}
BaseInput::revert(); BaseInput::revert();
} }

View file

@ -18,12 +18,12 @@ public slots:
virtual void revert(); virtual void revert();
private: private:
QSlider* slider; QSlider* _slider;
double* value; double* _value;
double min; double _min;
double max; double _max;
double small_step; double _small_step;
double large_step; double _large_step;
}; };
#endif // _PAYSAGES_QT_INPUTDOUBLE_H_ #endif

View file

@ -23,7 +23,10 @@ void InputEnum::applyValue()
void InputEnum::revert() void InputEnum::revert()
{ {
((QComboBox*)_control)->setCurrentIndex(*_value); if (*_value != ((QComboBox*)_control)->currentIndex())
{
((QComboBox*)_control)->setCurrentIndex(*_value);
}
BaseInput::revert(); BaseInput::revert();
} }

View file

@ -3,46 +3,54 @@
#include <QLabel> #include <QLabel>
InputInt::InputInt(QWidget* form, QString label, int* value, int min, int max, int small_step, int large_step): InputInt::InputInt(QWidget* form, QString label, int* value, int min, int max, int small_step, int large_step):
BaseInput(form, label), BaseInput(form, label)
value(value), min(min), max(max), small_step(small_step), large_step(large_step)
{ {
slider = new QSlider(form); _value = value;
_min = min;
_max = max;
_small_step = small_step;
_large_step = large_step;
slider->setOrientation(Qt::Horizontal); _slider = new QSlider(form);
slider->setMinimumWidth(150);
slider->setMaximumWidth(400);
slider->setMinimum(min); _slider->setOrientation(Qt::Horizontal);
slider->setMaximum(max); _slider->setMinimumWidth(150);
slider->setValue(*value); _slider->setMaximumWidth(400);
slider->setTickInterval(large_step); _slider->setMinimum(min);
slider->setTickPosition(QSlider::TicksBelow); _slider->setMaximum(max);
_slider->setValue(*value);
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue())); _slider->setTickInterval(large_step);
_slider->setTickPosition(QSlider::TicksBelow);
connect(_slider, SIGNAL(valueChanged(int)), this, SLOT(applyValue()));
_preview = new QLabel(form); _preview = new QLabel(form);
((QLabel*)_preview)->setAlignment(Qt::AlignCenter); ((QLabel*)_preview)->setAlignment(Qt::AlignCenter);
_control = slider; _control = _slider;
} }
void InputInt::updatePreview() void InputInt::updatePreview()
{ {
((QLabel*)_preview)->setText(QString("%1").arg(*value)); ((QLabel*)_preview)->setText(QString("%1").arg(*_value));
BaseInput::updatePreview(); BaseInput::updatePreview();
} }
void InputInt::applyValue() void InputInt::applyValue()
{ {
*value = (int)slider->value(); *_value = (int)_slider->value();
BaseInput::applyValue(); BaseInput::applyValue();
} }
void InputInt::revert() void InputInt::revert()
{ {
slider->setValue(*value); if (*_value != _slider->value())
{
_slider->setValue(*_value);
}
BaseInput::revert(); BaseInput::revert();
} }

View file

@ -18,12 +18,12 @@ public slots:
virtual void revert(); virtual void revert();
private: private:
QSlider* slider; QSlider* _slider;
int* value; int* _value;
int min; int _min;
int max; int _max;
int small_step; int _small_step;
int large_step; int _large_step;
}; };
#endif #endif