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,13 +15,9 @@
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QWidget" name="verticalWidget" native="true">
<layout class="QVBoxLayout" name="verticalLayout">
<layout class="QVBoxLayout" name="verticalLayout_10">
<property name="spacing">
<number>15</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
<number>20</number>
</property>
<item>
<widget class="QGroupBox" name="groupBox_2">
@ -30,8 +26,20 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QWidget" name="widget" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<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">
@ -43,7 +51,7 @@
</widget>
</item>
<item>
<widget class="QWidget" name="widget_6" native="true">
<widget class="QWidget" name="widget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>1</horstretch>
@ -52,20 +60,13 @@
</property>
<property name="minimumSize">
<size>
<width>0</width>
<width>500</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>
@ -77,8 +78,7 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<widget class="QWidget" name="widget_5" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="button_dialog_painting">
<property name="sizePolicy">
@ -106,7 +106,6 @@
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
@ -116,14 +115,11 @@
<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>
<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>
@ -131,8 +127,10 @@
</widget>
</item>
<item>
<widget class="QWidget" name="widget_3" native="true">
<layout class="QFormLayout" name="formLayout_4">
<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">
@ -141,7 +139,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="input_scaling">
<widget class="WidgetSliderDecimal" name="input_scaling">
<property name="maximumSize">
<size>
<width>400</width>
@ -161,7 +159,7 @@
</widget>
</item>
<item row="1" column="1">
<widget class="QSlider" name="input_height">
<widget class="WidgetSliderDecimal" name="input_height">
<property name="maximumSize">
<size>
<width>400</width>
@ -174,7 +172,6 @@
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
@ -186,8 +183,10 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
<item>
<widget class="QWidget" name="widget_4" native="true">
<layout class="QFormLayout" name="formLayout_2">
<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">
@ -196,7 +195,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="input_shadow_smoothing">
<widget class="WidgetSliderDecimal" name="input_shadow_smoothing">
<property name="maximumSize">
<size>
<width>400</width>
@ -209,7 +208,6 @@
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
@ -223,11 +221,12 @@
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QWidget" name="widget_7" native="true">
<layout class="QVBoxLayout" name="verticalLayout_10">
<layout class="QVBoxLayout" name="verticalLayout_12">
<item>
<widget class="QWidget" name="formWidget" native="true">
<layout class="QFormLayout" name="formLayout_3">
<layout class="QFormLayout" name="formLayout_6">
<property name="fieldGrowthPolicy">
<enum>QFormLayout::AllNonFixedFieldsGrow</enum>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
@ -236,7 +235,7 @@
</widget>
</item>
<item row="0" column="1">
<widget class="QSlider" name="horizontalSlider_4">
<widget class="WidgetSliderDecimal" name="horizontalSlider_4">
<property name="maximumSize">
<size>
<width>400</width>
@ -249,7 +248,6 @@
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
@ -282,7 +280,6 @@
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QWidget" name="widget_8" native="true">
@ -306,7 +303,6 @@
</widget>
</item>
</layout>
</widget>
</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"/>