paysages: Terrain tab redesign (WIP)

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@566 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2013-05-09 20:33:37 +00:00 committed by ThunderK
parent c9256e240c
commit 319d33e9f2
6 changed files with 417 additions and 295 deletions

View file

@ -1,8 +1,11 @@
#include "freeformhelper.h" #include "freeformhelper.h"
#include <QDialog> #include <QDialog>
#include <QVariant>
#include <cmath> #include <cmath>
Q_DECLARE_METATYPE(double*)
FreeFormHelper::FreeFormHelper(QWidget* form_widget) FreeFormHelper::FreeFormHelper(QWidget* form_widget)
:QObject() :QObject()
{ {
@ -42,21 +45,22 @@ void FreeFormHelper::addPreview(QString widget_name)
addPreview(_form_widget->findChild<BasePreview*>(widget_name)); addPreview(_form_widget->findChild<BasePreview*>(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->setDecimalRange(min, max, small_step, large_step);
slider->setMaximum(round((max - min) / small_step)); slider->setDecimalValue(*value);
slider->setValue(round((*value - min) / small_step));
slider->setTickInterval(round(large_step / small_step)); slider->setProperty("data_pointer", QVariant::fromValue<double*>(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) void FreeFormHelper::addDoubleInputSlider(QString widget_name, double* value, double min, double max, double small_step, double large_step)
{ {
addDoubleInputSlider(_form_widget->findChild<QSlider*>(widget_name), value, min, max, small_step, large_step); addDoubleInputSlider(_form_widget->findChild<WidgetSliderDecimal*>(widget_name), value, min, max, small_step, large_step);
} }
void FreeFormHelper::setApplyButton(QPushButton* button) void FreeFormHelper::setApplyButton(QPushButton* button)
@ -168,3 +172,21 @@ void FreeFormHelper::processApplyClicked()
_button_revert->setEnabled(false); _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<double*>();
if (pointer)
{
*pointer = value;
}
processDataChange();
}
}

View file

@ -3,6 +3,7 @@
#include <QSlider> #include <QSlider>
#include <QPushButton> #include <QPushButton>
#include "widgetsliderdecimal.h"
#include "../basepreview.h" #include "../basepreview.h"
class FreeFormHelper:public QObject class FreeFormHelper:public QObject
@ -18,7 +19,7 @@ public:
void addPreview(BasePreview* preview); void addPreview(BasePreview* preview);
void addPreview(QString widget_name); 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 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); void setApplyButton(QPushButton* button);
@ -39,7 +40,6 @@ public:
void openDialog(QDialog* dialog); void openDialog(QDialog* dialog);
signals: signals:
void dataChanged();
void revertClicked(); void revertClicked();
void applyClicked(); void applyClicked();
@ -52,6 +52,7 @@ public slots:
void processDataChange(); void processDataChange();
void processRevertClicked(); void processRevertClicked();
void processApplyClicked(); void processApplyClicked();
void processDecimalChange(double value);
private: private:
QWidget* _form_widget; QWidget* _form_widget;

View file

@ -0,0 +1,67 @@
#include "widgetsliderdecimal.h"
#include <cmath>
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);
}

View file

@ -0,0 +1,29 @@
#ifndef WIDGETSLIDERDECIMAL_H
#define WIDGETSLIDERDECIMAL_H
#include <QSlider>
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

View file

@ -68,7 +68,8 @@ HEADERS += \
terrain/paintingbrush.h \ terrain/paintingbrush.h \
terrain/mainterrainform.h \ terrain/mainterrainform.h \
common/freeformhelper.h \ common/freeformhelper.h \
terrain/previewterrainshape.h terrain/previewterrainshape.h \
common/widgetsliderdecimal.h
SOURCES += \ SOURCES += \
widgetheightmap.cpp \ widgetheightmap.cpp \
@ -115,7 +116,8 @@ SOURCES += \
terrain/paintingbrush.cpp \ terrain/paintingbrush.cpp \
terrain/mainterrainform.cpp \ terrain/mainterrainform.cpp \
common/freeformhelper.cpp \ common/freeformhelper.cpp \
terrain/previewterrainshape.cpp terrain/previewterrainshape.cpp \
common/widgetsliderdecimal.cpp
FORMS += \ FORMS += \
terrain/dialogterrainpainting.ui \ terrain/dialogterrainpainting.ui \

View file

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1073</width> <width>1079</width>
<height>662</height> <height>720</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -15,298 +15,294 @@
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QWidget" name="verticalWidget" native="true"> <layout class="QVBoxLayout" name="verticalLayout_10">
<layout class="QVBoxLayout" name="verticalLayout"> <property name="spacing">
<property name="spacing"> <number>20</number>
<number>15</number> </property>
</property> <item>
<property name="sizeConstraint"> <widget class="QGroupBox" name="groupBox_2">
<enum>QLayout::SetDefaultConstraint</enum> <property name="title">
</property> <string>Infinite base shape</string>
<item> </property>
<widget class="QGroupBox" name="groupBox_2"> <layout class="QVBoxLayout" name="verticalLayout_9">
<property name="title"> <item>
<string>Infinite base shape</string> <widget class="QLabel" name="label_5">
</property> <property name="text">
<layout class="QVBoxLayout" name="verticalLayout_9"> <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;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.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<item> </property>
<widget class="QWidget" name="widget" native="true"> <property name="scaledContents">
<layout class="QHBoxLayout" name="horizontalLayout_2"> <bool>false</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Generate base noise</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>500</width>
<height>80</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Manual modifications</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="button_dialog_painting">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Sculpt the terrain shape</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_painting_info">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>{ heightmap info }</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_1">
<property name="title">
<string>Global modifiers</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;These modifiers change the base shape and manual modifications altogether.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Scaling</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="WidgetSliderDecimal" name="input_scaling">
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="WidgetSliderDecimal" name="input_height">
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Rendering control</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<layout class="QFormLayout" name="formLayout_3">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Shadow smoothing</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="WidgetSliderDecimal" name="input_shadow_smoothing">
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>Links to other modules</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<layout class="QVBoxLayout" name="verticalLayout_12">
<item> <item>
<widget class="QPushButton" name="pushButton"> <layout class="QFormLayout" name="formLayout_6">
<property name="text"> <property name="fieldGrowthPolicy">
<string>Generate base noise</string> <enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property> </property>
<property name="flat"> <item row="0" column="0">
<bool>false</bool> <widget class="QLabel" name="label_4">
</property> <property name="text">
</widget> <string>Relative water height</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="WidgetSliderDecimal" name="horizontalSlider_4">
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item> </item>
<item> <item>
<widget class="QWidget" name="widget_6" native="true"> <layout class="QHBoxLayout" name="horizontalLayout_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>80</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>150</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Manual modifications</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QWidget" name="widget_5" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="button_dialog_painting">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Sculpt the terrain shape</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_painting_info">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>{ heightmap info }</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_1">
<property name="title">
<string>Global modifiers</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;These modifiers change the base shape and manual modifications altogether&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="textFormat">
<enum>Qt::RichText</enum>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_3" native="true">
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Scaling</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="input_scaling">
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="input_height">
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>Rendering control</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QWidget" name="widget_4" native="true">
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Shadow smoothing</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="input_shadow_smoothing">
<property name="maximumSize">
<size>
<width>400</width>
<height>16777215</height>
</size>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
<string>Links to other modules</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QWidget" name="widget_7" native="true">
<layout class="QVBoxLayout" name="verticalLayout_10">
<item> <item>
<widget class="QWidget" name="formWidget" native="true"> <widget class="QPushButton" name="button_goto_textures">
<layout class="QFormLayout" name="formLayout_3"> <property name="sizePolicy">
<item row="0" column="0"> <sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<widget class="QLabel" name="label_4"> <horstretch>0</horstretch>
<property name="text"> <verstretch>0</verstretch>
<string>Relative water height</string> </sizepolicy>
</property> </property>
</widget> <property name="maximumSize">
</item> <size>
<item row="0" column="1"> <width>500</width>
<widget class="QSlider" name="horizontalSlider_4"> <height>16777215</height>
<property name="maximumSize"> </size>
<size> </property>
<width>400</width> <property name="text">
<height>16777215</height> <string>Go to textures to add small height displacements (rocks...)</string>
</size> </property>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_5"> <widget class="QLabel" name="label_7">
<item> <property name="text">
<widget class="QPushButton" name="button_goto_textures"> <string>{ textures info }</string>
<property name="sizePolicy"> </property>
<sizepolicy hsizetype="Minimum" vsizetype="Fixed"> </widget>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>500</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Go to textures to add small height displacements (rocks...)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>{ textures info }</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </item>
</item> </layout>
<item> </item>
<widget class="QWidget" name="widget_8" native="true"> <item>
<property name="sizePolicy"> <widget class="QWidget" name="widget_8" native="true">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <property name="sizePolicy">
<horstretch>1</horstretch> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<verstretch>0</verstretch> <horstretch>1</horstretch>
</sizepolicy> <verstretch>0</verstretch>
</property> </sizepolicy>
<property name="minimumSize"> </property>
<size> <property name="minimumSize">
<width>200</width> <size>
<height>0</height> <width>200</width>
</size> <height>0</height>
</property> </size>
</widget> </property>
</item> </widget>
</layout> </item>
</item> </layout>
</layout> </item>
</widget> </layout>
</item> </widget>
</layout> </item>
</widget> </layout>
</item> </item>
<item> <item>
<widget class="Line" name="line"> <widget class="Line" name="line">
@ -425,6 +421,11 @@
<header>basepreview.h</header> <header>basepreview.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>WidgetSliderDecimal</class>
<extends>QSlider</extends>
<header>common/widgetsliderdecimal.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources> <resources>
<include location="../../../data/ui_pictures.qrc"/> <include location="../../../data/ui_pictures.qrc"/>