Added presets to FreeFormHelper + small fixes

This commit is contained in:
Michaël Lemaire 2013-08-21 23:22:13 +02:00
parent 171df529fa
commit c46afa4152
10 changed files with 93 additions and 105 deletions

View file

@ -7,6 +7,7 @@
#include <QSlider>
#include <QPushButton>
#include <QWidget>
#include <QInputDialog>
#include "mainwindow.h"
#include "dialogrender.h"
#include "dialogexplorer.h"
@ -24,6 +25,7 @@ FreeFormHelper::FreeFormHelper(QWidget* form_widget)
_button_apply = NULL;
_button_revert = NULL;
_button_presets = NULL;
}
FreeFormHelper::~FreeFormHelper()
@ -79,115 +81,86 @@ void FreeFormHelper::startManaging()
void FreeFormHelper::addPreview(BasePreview* preview, PreviewRenderer* renderer)
{
if (preview && preview->inherits("BasePreview"))
{
_previews.append(preview);
preview->setRenderer(renderer);
}
}
void FreeFormHelper::addPreview(QString widget_name, PreviewRenderer* renderer)
{
addPreview(_form_widget->findChild<BasePreview*>(widget_name), renderer);
_previews.append(preview);
preview->setRenderer(renderer);
}
void FreeFormHelper::addDoubleInputSlider(WidgetSliderDecimal* slider, double* value, double min, double max, double small_step, double large_step)
{
if (slider && slider->inherits("WidgetSliderDecimal"))
{
_inputs_decimal.append(slider);
_inputs_decimal.append(slider);
slider->setDecimalRange(min, max, small_step, large_step);
slider->setDecimalValue(*value);
slider->setDecimalRange(min, max, small_step, large_step);
slider->setDecimalValue(*value);
slider->setProperty("data_pointer", QVariant::fromValue<double*>(value));
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<WidgetSliderDecimal*>(widget_name), value, min, max, small_step, large_step);
connect(slider, SIGNAL(decimalValueChanged(double)), this, SLOT(processDecimalChange(double)));
}
void FreeFormHelper::setApplyButton(QPushButton* button)
{
if (button && button->inherits("QPushButton"))
{
_button_apply = button;
button->setEnabled(_data_changed);
_button_apply = button;
button->setEnabled(_data_changed);
connect(button, SIGNAL(clicked()), this, SLOT(processApplyClicked()));
}
}
void FreeFormHelper::setApplyButton(QString widget_name)
{
setApplyButton(_form_widget->findChild<QPushButton*>(widget_name));
connect(button, SIGNAL(clicked()), this, SLOT(processApplyClicked()));
}
void FreeFormHelper::setRevertButton(QPushButton* button)
{
if (button && button->inherits("QPushButton"))
{
_button_revert = button;
button->setEnabled(_data_changed);
_button_revert = button;
button->setEnabled(_data_changed);
connect(button, SIGNAL(clicked()), this, SLOT(processRevertClicked()));
}
}
void FreeFormHelper::setRevertButton(QString widget_name)
{
setRevertButton(_form_widget->findChild<QPushButton*>(widget_name));
connect(button, SIGNAL(clicked()), this, SLOT(processRevertClicked()));
}
void FreeFormHelper::setExploreButton(QPushButton* button)
{
if (button && button->inherits("QPushButton"))
{
_button_explore = button;
_button_explore = button;
button->setToolTip(tr("Explore the scenery in 3D, with current changes applied"));
button->setToolTip(tr("Explore the scenery in 3D, with current changes applied"));
connect(button, SIGNAL(clicked()), this, SLOT(processExploreClicked()));
}
}
void FreeFormHelper::setExploreButton(QString widget_name)
{
setExploreButton(_form_widget->findChild<QPushButton*>(widget_name));
connect(button, SIGNAL(clicked()), this, SLOT(processExploreClicked()));
}
void FreeFormHelper::setRenderButton(QPushButton* button)
{
if (button && button->inherits("QPushButton"))
{
_button_render = button;
_button_render = button;
button->setToolTip(tr("Quick render preview, with current changes applied"));
button->setToolTip(tr("Quick render preview, with current changes applied"));
connect(button, SIGNAL(clicked()), this, SLOT(processRenderClicked()));
}
}
void FreeFormHelper::setRenderButton(QString widget_name)
{
setRenderButton(_form_widget->findChild<QPushButton*>(widget_name));
connect(button, SIGNAL(clicked()), this, SLOT(processRenderClicked()));
}
void FreeFormHelper::setLabelText(QLabel* label, QString text)
{
if (label && label->inherits("QLabel"))
{
label->setText(text);
}
label->setText(text);
}
void FreeFormHelper::setLabelText(QString widget_name, QString text)
void FreeFormHelper::addPreset(const QString& name)
{
setLabelText(_form_widget->findChild<QLabel*>(widget_name), text);
_presets << name;
}
void FreeFormHelper::setPresetButton(QPushButton* button)
{
_button_presets = button;
connect(button, SIGNAL(clicked()), this, SLOT(processPresetClicked()));
}
void FreeFormHelper::processPresetClicked()
{
bool ok;
QString item = QInputDialog::getItem(_form_widget, tr("Choose a preset"), tr("Preset settings : "), _presets, 0, false, &ok);
if (ok && !item.isEmpty())
{
int preset = _presets.indexOf(item);
if (preset >= 0)
{
emit presetSelected(preset);
emit needLocalRefreshing();
}
}
}
void FreeFormHelper::openDialog(QDialog* dialog)

View file

@ -1,6 +1,9 @@
#ifndef FREEFORMHELPER_H
#define FREEFORMHELPER_H
#include <QVector>
#include <QStringList>
#include "widgetsliderdecimal.h"
#include "../basepreview.h"
@ -18,25 +21,15 @@ public:
void startManaging();
void addPreview(BasePreview* preview, PreviewRenderer* renderer);
void addPreview(QString widget_name, PreviewRenderer* renderer);
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);
void setApplyButton(QString widget_name);
void setRevertButton(QPushButton* button);
void setRevertButton(QString widget_name);
void setExploreButton(QPushButton* button);
void setExploreButton(QString widget_name);
void setRenderButton(QPushButton* button);
void setRenderButton(QString widget_name);
void setLabelText(QLabel* label, QString text);
void setLabelText(QString widget_name, QString text);
void setPresetButton(QPushButton* button);
void addPreset(const QString& name);
void openDialog(QDialog* dialog);
void gotoMainTab(int position);
@ -45,6 +38,8 @@ signals:
void revertClicked();
void applyClicked();
void presetSelected(int position);
void needLocalRefreshing();
void needGlobalRefreshing();
void needReverting();
@ -59,6 +54,7 @@ public slots:
void processExploreClicked();
void processRenderClicked();
void processDecimalChange(double value);
void processPresetClicked();
protected:
bool eventFilter(QObject* object, QEvent* event);
@ -68,6 +64,9 @@ private:
bool _data_changed;
QPushButton* _button_presets;
QStringList _presets;
QVector<BasePreview*> _previews;
QVector<WidgetSliderDecimal*> _inputs_decimal;

View file

@ -58,10 +58,10 @@ private:
RenderParams _params;
};
class RenderArea:public QWidget
class _RenderArea:public QWidget
{
public:
RenderArea(QWidget* parent):
_RenderArea(QWidget* parent):
QWidget(parent)
{
setMinimumSize(800, 600);
@ -91,7 +91,7 @@ DialogRender::DialogRender(QWidget *parent, Renderer* renderer):
_scroll = new QScrollArea(this);
_scroll->setAlignment(Qt::AlignCenter);
area = new RenderArea(_scroll);
area = new _RenderArea(_scroll);
_scroll->setWidget(area);
layout()->addWidget(_scroll);

View file

@ -27,7 +27,7 @@ public:
addOsd(QString("geolocation"));
addToggle("highlight", tr("Coverage highlight"), true);
configScaling(20.0, 1000.0, 20.0, 50.0);
configScaling(20.0, 1000.0, 20.0, 200.0);
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
protected:

View file

@ -2,6 +2,9 @@
<ui version="4.0">
<class>DialogMaterialEditor</class>
<widget class="QDialog" name="DialogMaterialEditor">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
@ -11,7 +14,10 @@
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
<string>Paysages 3D - Material editor</string>
</property>
<property name="modal">
<bool>true</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@ -38,9 +44,6 @@
<property name="text">
<string>This controls the way the surface diffuses its inner color in all directions, when a light source reaches it</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
@ -155,9 +158,6 @@
<property name="text">
<string>Amount and direction of light that is directly reflected from an incoming source (useful for shiny things)</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>

View file

@ -56,11 +56,11 @@ void MainTerrainForm::refreshFromLocalData()
qint64 memused = terrainGetMemoryStats(_terrain);
if (memused > 0)
{
_form_helper->setLabelText("label_painting_info", tr("Memory used by sculpted data: %1").arg(getHumanMemory(memused)));
_form_helper->setLabelText(ui->label_painting_info, tr("Memory used by sculpted data: %1").arg(getHumanMemory(memused)));
}
else
{
_form_helper->setLabelText("label_painting_info", tr("No manual scuplting done"));
_form_helper->setLabelText(ui->label_painting_info, tr("No manual scuplting done"));
}
ui->widget_base_noise_preview->setNoise(_terrain->_height_noise);

View file

@ -17,7 +17,7 @@ void PreviewTerrainShape::bindEvent(BasePreview* preview)
preview->addOsd(QString("geolocation"));
//preview->addToggle("highlight", tr("Coverage highlight"), true);
preview->configScaling(20.0, 1000.0, 20.0, 50.0);
preview->configScaling(20.0, 1000.0, 20.0, 200.0);
preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}

View file

@ -18,8 +18,8 @@ void WidgetTerrainBaseNoisePreview::setNoise(NoiseGenerator* noise)
void WidgetTerrainBaseNoisePreview::doDrawing(QPainter* painter)
{
painter->setBrush(Qt::SolidPattern);
painter->drawRect(rect());
painter->fillRect(rect(), QColor(20, 40, 80));
painter->setPen(QColor(220, 210, 180));
int height = this->height();
@ -37,7 +37,6 @@ void WidgetTerrainBaseNoisePreview::doDrawing(QPainter* painter)
{
value = noiseGet1DTotal(_noise, 100.0 * ((double)x) / factor);
painter->setPen(Qt::white);
painter->drawLine(x, height - 1 - (value - minvalue) * factor, x, height - 1);
}
}

View file

@ -33,6 +33,12 @@ MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui
preview_layer_coverage->setTextures(textures);
form_helper->addPreview(ui->preview_coverage, preview_layer_coverage);
form_helper->addPreset(tr("Rocks with grass"));
form_helper->addPreset(tr("Snow covered mountains"));
form_helper->addPreset(tr("Arid canyons"));
form_helper->setPresetButton(ui->button_preset);
connect(form_helper, SIGNAL(presetSelected(int)), this, SLOT(selectPreset(int)));
connect(layer_helper, SIGNAL(layersChanged()), form_helper, SLOT(processDataChange()));
}
@ -92,6 +98,11 @@ void MainTexturesForm::selectLayer(int layer)
}
}
void MainTexturesForm::selectPreset(int preset)
{
texturesAutoPreset(textures, (TexturesPreset)preset);
}
void MainTexturesForm::updateLocalDataFromScenery()
{
sceneryGetTextures(textures);

View file

@ -16,8 +16,14 @@ void texturesAutoPreset(TexturesDefinition* definition, TexturesPreset preset)
layersSetName(definition->layers, 1, "Grass");
}
else if (preset == TEXTURES_PRESET_ALPS)
{
/* TODO */
{
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_ROCK);
layersSetName(definition->layers, 0, "Ground");
layer = layersGetLayer(definition->layers, layersAddLayer(definition->layers, NULL));
texturesLayerAutoPreset(layer, TEXTURES_LAYER_PRESET_SNOW);
layersSetName(definition->layers, 1, "Snow");
}
else if (preset == TEXTURES_PRESET_CANYON)
{