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 <QDialog>
#include <QVariant>
#include <cmath>
Q_DECLARE_METATYPE(double*)
FreeFormHelper::FreeFormHelper(QWidget* form_widget)
:QObject()
{
@ -42,21 +45,22 @@ void FreeFormHelper::addPreview(QString 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->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<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)
{
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)
@ -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<double*>();
if (pointer)
{
*pointer = value;
}
processDataChange();
}
}

View file

@ -3,6 +3,7 @@
#include <QSlider>
#include <QPushButton>
#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;

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/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 \

View file

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1073</width>
<height>662</height>
<width>1079</width>
<height>720</height>
</rect>
</property>
<property name="windowTitle">
@ -15,298 +15,294 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QWidget" name="verticalWidget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>15</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Infinite base shape</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_10">
<property name="spacing">
<number>20</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Infinite base shape</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QLabel" name="label_5">
<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;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>
</property>
<property name="scaledContents">
<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>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>Generate base noise</string>
<layout class="QFormLayout" name="formLayout_6">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<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>
<widget class="QWidget" name="widget_6" native="true">
<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">
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QWidget" name="formWidget" native="true">
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Relative water height</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" 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>
<widget class="QPushButton" name="button_goto_textures">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<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>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="button_goto_textures">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<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>
<widget class="QLabel" name="label_7">
<property name="text">
<string>{ textures info }</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_8" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QWidget" name="widget_8" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
@ -425,6 +421,11 @@
<header>basepreview.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>WidgetSliderDecimal</class>
<extends>QSlider</extends>
<header>common/widgetsliderdecimal.h</header>
</customwidget>
</customwidgets>
<resources>
<include location="../../../data/ui_pictures.qrc"/>