diff --git a/src/editing/common/freeformhelper.cpp b/src/editing/common/freeformhelper.cpp index f722580..d603c29 100644 --- a/src/editing/common/freeformhelper.cpp +++ b/src/editing/common/freeformhelper.cpp @@ -1,8 +1,11 @@ #include "freeformhelper.h" #include +#include #include +Q_DECLARE_METATYPE(double*) + FreeFormHelper::FreeFormHelper(QWidget* form_widget) :QObject() { @@ -42,21 +45,22 @@ void FreeFormHelper::addPreview(QString widget_name) addPreview(_form_widget->findChild(widget_name)); } -void FreeFormHelper::addDoubleInputSlider(QSlider* slider, double* value, double min, double max, double small_step, double large_step) +void FreeFormHelper::addDoubleInputSlider(WidgetSliderDecimal* slider, double* value, double min, double max, double small_step, double large_step) { - if (slider && slider->inherits("QSlider")) + if (slider && slider->inherits("WidgetSliderDecimal")) { - slider->setMinimum(0); - slider->setMaximum(round((max - min) / small_step)); - slider->setValue(round((*value - min) / small_step)); + slider->setDecimalRange(min, max, small_step, large_step); + slider->setDecimalValue(*value); - slider->setTickInterval(round(large_step / small_step)); + slider->setProperty("data_pointer", QVariant::fromValue(value)); + + connect(slider, SIGNAL(decimalValueChanged(double)), this, SLOT(processDecimalChange(double))); } } void FreeFormHelper::addDoubleInputSlider(QString widget_name, double* value, double min, double max, double small_step, double large_step) { - addDoubleInputSlider(_form_widget->findChild(widget_name), value, min, max, small_step, large_step); + addDoubleInputSlider(_form_widget->findChild(widget_name), value, min, max, small_step, large_step); } void FreeFormHelper::setApplyButton(QPushButton* button) @@ -168,3 +172,21 @@ void FreeFormHelper::processApplyClicked() _button_revert->setEnabled(false); } } + +void FreeFormHelper::processDecimalChange(double value) +{ + QObject* signal_sender = sender(); + + if (signal_sender && signal_sender->inherits("WidgetSliderDecimal")) + { + WidgetSliderDecimal* slider = (WidgetSliderDecimal*)signal_sender; + double* pointer = slider->property("data_pointer").value(); + + if (pointer) + { + *pointer = value; + } + + processDataChange(); + } +} diff --git a/src/editing/common/freeformhelper.h b/src/editing/common/freeformhelper.h index f5e9b84..24ea354 100644 --- a/src/editing/common/freeformhelper.h +++ b/src/editing/common/freeformhelper.h @@ -3,6 +3,7 @@ #include #include +#include "widgetsliderdecimal.h" #include "../basepreview.h" class FreeFormHelper:public QObject @@ -18,7 +19,7 @@ public: void addPreview(BasePreview* preview); void addPreview(QString widget_name); - void addDoubleInputSlider(QSlider* slider, double* value, double min=0.0, double max=1.0, double small_step=0.0, double large_step=0.0); + void addDoubleInputSlider(WidgetSliderDecimal* slider, double* value, double min=0.0, double max=1.0, double small_step=0.0, double large_step=0.0); void addDoubleInputSlider(QString widget_name, double* value, double min=0.0, double max=1.0, double small_step=0.0, double large_step=0.0); void setApplyButton(QPushButton* button); @@ -39,7 +40,6 @@ public: void openDialog(QDialog* dialog); signals: - void dataChanged(); void revertClicked(); void applyClicked(); @@ -52,6 +52,7 @@ public slots: void processDataChange(); void processRevertClicked(); void processApplyClicked(); + void processDecimalChange(double value); private: QWidget* _form_widget; diff --git a/src/editing/common/widgetsliderdecimal.cpp b/src/editing/common/widgetsliderdecimal.cpp new file mode 100644 index 0000000..84b8a68 --- /dev/null +++ b/src/editing/common/widgetsliderdecimal.cpp @@ -0,0 +1,67 @@ +#include "widgetsliderdecimal.h" + +#include + +WidgetSliderDecimal::WidgetSliderDecimal(QWidget *parent) : + QSlider(parent) +{ + _min = 0.0; + _max = 1.0; + _step = 0.01; + _value = 0.0; + + connect(this, SIGNAL(valueChanged(int)), this, SLOT(processIntValue(int))); +} + +void WidgetSliderDecimal::setDecimalRange(double min, double max, double precision, double tick_precision) +{ + double range = max - min; + if (range < 0.000001) + { + max = min + 0.000001; + range = max - min; + } + if (precision < 0.000001) + { + precision = range / 1000.0; + } + + _min = min; + _max = max; + _step = precision; + + setMinimum(0); + setMaximum(round(range / precision)); + + if (tick_precision < 0.000001) + { + tick_precision = 20.0 * range / precision; + } + setTickInterval(round(tick_precision / precision)); +} + +void WidgetSliderDecimal::setDecimalValue(double value) +{ + _value = value; + setValue(round((value - _min) / _step)); +} + +void WidgetSliderDecimal::processIntValue(int value) +{ + double result; + if (value == maximum()) + { + result = _max; + } + else + { + result = _min + ((double)value) * _step; + } + if (fabs(result) < 0.0000001) + { + result = 0.0; + } + _value = result; + + emit decimalValueChanged(result); +} diff --git a/src/editing/common/widgetsliderdecimal.h b/src/editing/common/widgetsliderdecimal.h new file mode 100644 index 0000000..9ee32d7 --- /dev/null +++ b/src/editing/common/widgetsliderdecimal.h @@ -0,0 +1,29 @@ +#ifndef WIDGETSLIDERDECIMAL_H +#define WIDGETSLIDERDECIMAL_H + +#include + +class WidgetSliderDecimal : public QSlider +{ + Q_OBJECT +public: + explicit WidgetSliderDecimal(QWidget *parent = 0); + + void setDecimalRange(double min, double max, double precision=0.0, double tick_interval=0.0); + void setDecimalValue(double value); + inline double decimalValue() {return _value;} + +signals: + void decimalValueChanged(double value); + +public slots: + void processIntValue(int value); + +private: + double _min; + double _max; + double _step; + double _value; +}; + +#endif // WIDGETSLIDERDECIMAL_H diff --git a/src/editing/paysages-qt.pro b/src/editing/paysages-qt.pro index 6bfb4a8..7acb11e 100644 --- a/src/editing/paysages-qt.pro +++ b/src/editing/paysages-qt.pro @@ -68,7 +68,8 @@ HEADERS += \ terrain/paintingbrush.h \ terrain/mainterrainform.h \ common/freeformhelper.h \ - terrain/previewterrainshape.h + terrain/previewterrainshape.h \ + common/widgetsliderdecimal.h SOURCES += \ widgetheightmap.cpp \ @@ -115,7 +116,8 @@ SOURCES += \ terrain/paintingbrush.cpp \ terrain/mainterrainform.cpp \ common/freeformhelper.cpp \ - terrain/previewterrainshape.cpp + terrain/previewterrainshape.cpp \ + common/widgetsliderdecimal.cpp FORMS += \ terrain/dialogterrainpainting.ui \ diff --git a/src/editing/terrain/mainterrainform.ui b/src/editing/terrain/mainterrainform.ui index b15d36a..10bba5b 100644 --- a/src/editing/terrain/mainterrainform.ui +++ b/src/editing/terrain/mainterrainform.ui @@ -6,8 +6,8 @@ 0 0 - 1073 - 662 + 1079 + 720 @@ -15,298 +15,294 @@ - - - - 15 - - - QLayout::SetDefaultConstraint - - - - - Infinite base shape - - - - - + + + 20 + + + + + Infinite base shape + + + + + + <html><head/><body><p><span style=" font-style:italic;">This is the base shape for your landscape, infinitely generated from a random mathematical function. You can then customize this raw shape by sculpting it, and adding displacement textures.</span></p></body></html> + + + false + + + true + + + + + + + + + Generate base noise + + + false + + + + + + + + 1 + 0 + + + + + 500 + 80 + + + + + + + + + + + + + Manual modifications + + + + + + + + + 0 + 0 + + + + Sculpt the terrain shape + + + + + + + + 0 + 0 + + + + { heightmap info } + + + + + + + + + + + + Global modifiers + + + + + + <html><head/><body><p><span style=" font-style:italic;">These modifiers change the base shape and manual modifications altogether.</span></p></body></html> + + + Qt::RichText + + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Scaling + + + + + + + + 400 + 16777215 + + + + Qt::Horizontal + + + + + + + Height + + + + + + + + 400 + 16777215 + + + + Qt::Horizontal + + + + + + + + + + + + Rendering control + + + + + + QFormLayout::AllNonFixedFieldsGrow + + + + + Shadow smoothing + + + + + + + + 400 + 16777215 + + + + Qt::Horizontal + + + + + + + + + + + + Links to other modules + + + + + + - - - Generate base noise + + + QFormLayout::AllNonFixedFieldsGrow - - false - - + + + + Relative water height + + + + + + + + 400 + 16777215 + + + + Qt::Horizontal + + + + - - - - 1 - 0 - - - - - 0 - 80 - - - - - 16777215 - 150 - - - - - - - - - - - - - - Manual modifications - - - - - - - - - - 0 - 0 - - - - Sculpt the terrain shape - - - - - - - - 0 - 0 - - - - { heightmap info } - - - - - - - - - - - - - Global modifiers - - - false - - - - - - <html><head/><body><p><span style=" font-style:italic;">These modifiers change the base shape and manual modifications altogether</span></p></body></html> - - - Qt::RichText - - - - - - - - - - Scaling - - - - - - - - 400 - 16777215 - - - - Qt::Horizontal - - - - - - - Height - - - - - - - - 400 - 16777215 - - - - Qt::Horizontal - - - - - - - - - - - - - Rendering control - - - - - - - - - Shadow smoothing - - - - - - - - 400 - 16777215 - - - - Qt::Horizontal - - - - - - - - - - - - - Links to other modules - - - - - - - + - - - - - - Relative water height - - - - - - - - 400 - 16777215 - - - - Qt::Horizontal - - - - + + + + 0 + 0 + + + + + 500 + 16777215 + + + + Go to textures to add small height displacements (rocks...) + - - - - - - 0 - 0 - - - - - 500 - 16777215 - - - - Go to textures to add small height displacements (rocks...) - - - - - - - { textures info } - - - - + + + { textures info } + + - - - - - - - 1 - 0 - - - - - 200 - 0 - - - - - - - - - - - + + + + + + + + 1 + 0 + + + + + 200 + 0 + + + + + + + + + + @@ -425,6 +421,11 @@
basepreview.h
1 + + WidgetSliderDecimal + QSlider +
common/widgetsliderdecimal.h
+