From c9256e240c6c9b6ded9523f1f3fbf181b599524f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Thu, 9 May 2013 17:13:04 +0000 Subject: [PATCH] paysages: Terrain tab redesign (WIP) git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@565 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- src/editing/baseexplorerchunk.cpp | 6 +- src/editing/common/freeformhelper.cpp | 170 ++++++++++++++++++++ src/editing/common/freeformhelper.h | 69 ++++++++ src/editing/formterrain.cpp | 85 ---------- src/editing/formterrain.h | 30 ---- src/editing/mainwindow.cpp | 8 +- src/editing/paysages-qt.pro | 10 +- src/editing/terrain/mainterrainform.cpp | 64 ++++++++ src/editing/terrain/mainterrainform.h | 18 ++- src/editing/terrain/mainterrainform.ui | 167 +++++++++++-------- src/editing/terrain/previewterrainshape.cpp | 22 +++ src/editing/terrain/previewterrainshape.h | 21 +++ 12 files changed, 474 insertions(+), 196 deletions(-) create mode 100644 src/editing/common/freeformhelper.cpp create mode 100644 src/editing/common/freeformhelper.h delete mode 100644 src/editing/formterrain.cpp delete mode 100644 src/editing/formterrain.h create mode 100644 src/editing/terrain/previewterrainshape.cpp create mode 100644 src/editing/terrain/previewterrainshape.h diff --git a/src/editing/baseexplorerchunk.cpp b/src/editing/baseexplorerchunk.cpp index 9cf9b64..e8c78df 100644 --- a/src/editing/baseexplorerchunk.cpp +++ b/src/editing/baseexplorerchunk.cpp @@ -64,10 +64,10 @@ bool BaseExplorerChunk::maintain() _texture_changed = true; _lock_data.unlock(); - if (_texture_current_size < 4 && _texture_current_size < _texture_max_size) + /*if (_texture_current_size < 4 && _texture_current_size < _texture_max_size) { maintain(); - } + }*/ return true; } @@ -159,4 +159,4 @@ double BaseExplorerChunk::getDisplayedSizeHint(CameraDefinition*) Color BaseExplorerChunk::getTextureColor(double, double) { return COLOR_TRANSPARENT; -} \ No newline at end of file +} diff --git a/src/editing/common/freeformhelper.cpp b/src/editing/common/freeformhelper.cpp new file mode 100644 index 0000000..f722580 --- /dev/null +++ b/src/editing/common/freeformhelper.cpp @@ -0,0 +1,170 @@ +#include "freeformhelper.h" + +#include +#include + +FreeFormHelper::FreeFormHelper(QWidget* form_widget) + :QObject() +{ + _form_widget = form_widget; + _data_changed = false; + + _button_apply = NULL; + _button_revert = NULL; +} + +FreeFormHelper::~FreeFormHelper() +{ +} + +void FreeFormHelper::startManaging() +{ + connect(this, SIGNAL(needLocalRefreshing()), _form_widget, SLOT(refreshFromLocalData())); + connect(this, SIGNAL(needGlobalRefreshing()), _form_widget, SLOT(refreshFromFellowData())); + connect(this, SIGNAL(needReverting()), _form_widget, SLOT(updateLocalDataFromScenery())); + connect(this, SIGNAL(needCommitting()), _form_widget, SLOT(commitLocalDataToScenery())); + + emit needLocalRefreshing(); + emit needGlobalRefreshing(); + emit needReverting(); +} + +void FreeFormHelper::addPreview(BasePreview* preview) +{ + if (preview && preview->inherits("BasePreview")) + { + _previews.append(preview); + } +} + +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) +{ + if (slider && slider->inherits("QSlider")) + { + slider->setMinimum(0); + slider->setMaximum(round((max - min) / small_step)); + slider->setValue(round((*value - min) / small_step)); + + slider->setTickInterval(round(large_step / small_step)); + } +} + +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); +} + +void FreeFormHelper::setApplyButton(QPushButton* button) +{ + if (button && button->inherits("QPushButton")) + { + _button_apply = button; + button->setEnabled(_data_changed); + + connect(button, SIGNAL(clicked()), this, SLOT(processApplyClicked())); + } +} + +void FreeFormHelper::setApplyButton(QString widget_name) +{ + setApplyButton(_form_widget->findChild(widget_name)); +} + +void FreeFormHelper::setRevertButton(QPushButton* button) +{ + if (button && button->inherits("QPushButton")) + { + _button_revert = button; + button->setEnabled(_data_changed); + + connect(button, SIGNAL(clicked()), this, SLOT(processRevertClicked())); + } +} + +void FreeFormHelper::setRevertButton(QString widget_name) +{ + setRevertButton(_form_widget->findChild(widget_name)); +} + +void FreeFormHelper::setLabelText(QLabel* label, QString text) +{ + if (label && label->inherits("QLabel")) + { + label->setText(text); + } +} + +void FreeFormHelper::setLabelText(QString widget_name, QString text) +{ + setLabelText(_form_widget->findChild(widget_name), text); +} + +void FreeFormHelper::openDialog(QDialog* dialog) +{ + if (dialog->exec()) + { + processDataChange(); + } +} + +void FreeFormHelper::processDataChange() +{ + _data_changed = true; + if (_button_apply) + { + _button_apply->setEnabled(true); + } + if (_button_revert) + { + _button_revert->setEnabled(true); + } + + for (int i = 0; i < _previews.size(); i++) + { + _previews[i]->redraw(); + } + + emit needLocalRefreshing(); +} + +void FreeFormHelper::processRevertClicked() +{ + emit needReverting(); + + _data_changed = false; + if (_button_apply) + { + _button_apply->setEnabled(false); + } + if (_button_revert) + { + _button_revert->setEnabled(false); + } + + for (int i = 0; i < _previews.size(); i++) + { + _previews[i]->redraw(); + } + + emit needLocalRefreshing(); +} + +void FreeFormHelper::processApplyClicked() +{ + emit needCommitting(); + + _data_changed = false; + if (_button_apply) + { + _button_apply->setEnabled(false); + } + if (_button_revert) + { + _button_revert->setEnabled(false); + } +} diff --git a/src/editing/common/freeformhelper.h b/src/editing/common/freeformhelper.h new file mode 100644 index 0000000..f5e9b84 --- /dev/null +++ b/src/editing/common/freeformhelper.h @@ -0,0 +1,69 @@ +#ifndef FREEFORMHELPER_H +#define FREEFORMHELPER_H + +#include +#include +#include "../basepreview.h" + +class FreeFormHelper:public QObject +{ + Q_OBJECT + +public: + FreeFormHelper(QWidget* form_widget); + ~FreeFormHelper(); + + void startManaging(); + + 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(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 openDialog(QDialog* dialog); + +signals: + void dataChanged(); + void revertClicked(); + void applyClicked(); + + void needLocalRefreshing(); + void needGlobalRefreshing(); + void needReverting(); + void needCommitting(); + +public slots: + void processDataChange(); + void processRevertClicked(); + void processApplyClicked(); + +private: + QWidget* _form_widget; + + bool _data_changed; + + QVector _previews; + + QPushButton* _button_apply; + QPushButton* _button_revert; + QPushButton* _button_explore; + QPushButton* _button_render; +}; + +#endif // FREEFORMHELPER_H diff --git a/src/editing/formterrain.cpp b/src/editing/formterrain.cpp deleted file mode 100644 index b5a1967..0000000 --- a/src/editing/formterrain.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "formterrain.h" - -#include -#include -#include "tools.h" -#include "terrain/dialogterrainpainting.h" -#include "rendering/scenery.h" - -static TerrainDefinition* _definition; - -/**************** Previews ****************/ -class PreviewTerrainColor:public BasePreview -{ -public: - PreviewTerrainColor(QWidget* parent):BasePreview(parent) - { - _renderer = terrainCreatePreviewRenderer(); - - addOsd(QString("geolocation")); - - configScaling(20.0, 1000.0, 20.0, 50.0); - configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); - } -protected: - Color getColor(double x, double y) - { - return terrainGetPreviewColor(_renderer, x, y, scaling); - } - void updateData() - { - TerrainRendererClass.bind(_renderer, _definition); - } -private: - Renderer* _renderer; -}; - -/**************** Form ****************/ -FormTerrain::FormTerrain(QWidget *parent): - BaseForm(parent) -{ - _definition = (TerrainDefinition*)TerrainDefinitionClass.create(); - - QPushButton* button = addButton(tr("Paint")); - connect(button, SIGNAL(clicked()), this, SLOT(startPainting())); - - /*previewHeight = new PreviewTerrainHeight(this);*/ - previewColor = new PreviewTerrainColor(this); - /*addPreview(previewHeight, tr("Height preview (normalized)"));*/ - addPreview(previewColor, tr("Lighted preview (no texture)")); - - //addInputNoise(tr("Noise"), _definition.height_noise); - addInputDouble(tr("Scaling"), &_definition->scaling, 0.1, 3.0, 0.03, 0.3); - addInputDouble(tr("Height modifier"), &_definition->height, 0.0, 3.0, 0.01, 0.1); - addInputDouble(tr("Shadow smoothing"), &_definition->shadow_smoothing, 0.0, 0.3, 0.003, 0.03); - - revertConfig(); -} - -void FormTerrain::revertConfig() -{ - sceneryGetTerrain(_definition); - BaseForm::revertConfig(); -} - -void FormTerrain::applyConfig() -{ - scenerySetTerrain(_definition); - BaseForm::applyConfig(); -} - -void FormTerrain::configChangeEvent() -{ - TerrainDefinitionClass.validate(_definition); - BaseForm::configChangeEvent(); -} - -void FormTerrain::startPainting() -{ - DialogTerrainPainting* dialog = new DialogTerrainPainting(this, _definition); - if (dialog->exec()) - { - configChangeEvent(); - } - delete dialog; -} diff --git a/src/editing/formterrain.h b/src/editing/formterrain.h deleted file mode 100644 index a9b2c9c..0000000 --- a/src/editing/formterrain.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef _PAYSAGES_QT_FORMTERRAIN_H_ -#define _PAYSAGES_QT_FORMTERRAIN_H_ - -#include -#include "basepreview.h" -#include "baseform.h" - -class FormTerrain : public BaseForm -{ - Q_OBJECT - -public: - explicit FormTerrain(QWidget *parent = 0); - -public slots: - virtual void revertConfig(); - virtual void applyConfig(); - -protected slots: - virtual void configChangeEvent(); - -private slots: - void startPainting(); - -private: - /*BasePreview* previewHeight;*/ - BasePreview* previewColor; -}; - -#endif diff --git a/src/editing/mainwindow.cpp b/src/editing/mainwindow.cpp index 9b7f10a..b568c73 100644 --- a/src/editing/mainwindow.cpp +++ b/src/editing/mainwindow.cpp @@ -15,7 +15,6 @@ #include "basepreview.h" #include "formclouds.h" #include "formatmosphere.h" -#include "formterrain.h" #include "formtextures.h" #include "formwater.h" #include "formrender.h" @@ -89,11 +88,6 @@ QMainWindow(parent) tabs = new QTabWidget(this); tabs->setIconSize(QSize(32, 32)); - form = new FormTerrain(tabs); - tabs->addTab(form, QIcon(getDataPath("images/tab_terrain.png")), tr("Terrain")); - QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection); - _forms.append(form); - tabs->addTab(new MainTerrainForm(tabs), QIcon(getDataPath("images/tab_terrain.png")), tr("Landscape shape")); form = new FormTextures(tabs); @@ -242,7 +236,7 @@ void MainWindow::fileLoad() void MainWindow::showAboutDialog() { - QMessageBox::about(this, tr("Paysages 3D"), tr("A 3D landscape editing and rendering software.\n\nAuthors :\nProgramming - Michael Lemaire\n\nCredits :\nQt - http://qt.nokia.com/\nDevIL - http://openil.sourceforge.net/\nGLib - http://www.gtk.org/\n")); + QMessageBox::about(this, tr("Paysages 3D"), tr("A 3D landscape editing and rendering software.\n\nAuthors :\nProgramming - Michael Lemaire\n\nCredits :\nQt - http://qt-project.org/\nDevIL - http://openil.sourceforge.net/\nGLib - http://www.gtk.org/\n")); } void MainWindow::quickPreview() diff --git a/src/editing/paysages-qt.pro b/src/editing/paysages-qt.pro index c87076f..6bfb4a8 100644 --- a/src/editing/paysages-qt.pro +++ b/src/editing/paysages-qt.pro @@ -45,7 +45,6 @@ HEADERS += \ inputboolean.h \ formwater.h \ formtextures.h \ - formterrain.h \ formrender.h \ formmaterial.h \ formclouds.h \ @@ -67,7 +66,9 @@ HEADERS += \ terrain/dialogterrainpainting.h \ common/widgetglobalformbuttons.h \ terrain/paintingbrush.h \ - terrain/mainterrainform.h + terrain/mainterrainform.h \ + common/freeformhelper.h \ + terrain/previewterrainshape.h SOURCES += \ widgetheightmap.cpp \ @@ -91,7 +92,6 @@ SOURCES += \ inputboolean.cpp \ formwater.cpp \ formtextures.cpp \ - formterrain.cpp \ formrender.cpp \ formmaterial.cpp \ formclouds.cpp \ @@ -113,7 +113,9 @@ SOURCES += \ terrain/dialogterrainpainting.cpp \ common/widgetglobalformbuttons.cpp \ terrain/paintingbrush.cpp \ - terrain/mainterrainform.cpp + terrain/mainterrainform.cpp \ + common/freeformhelper.cpp \ + terrain/previewterrainshape.cpp FORMS += \ terrain/dialogterrainpainting.ui \ diff --git a/src/editing/terrain/mainterrainform.cpp b/src/editing/terrain/mainterrainform.cpp index f173d46..c91934f 100644 --- a/src/editing/terrain/mainterrainform.cpp +++ b/src/editing/terrain/mainterrainform.cpp @@ -1,14 +1,78 @@ #include "mainterrainform.h" #include "ui_mainterrainform.h" +#include "dialogterrainpainting.h" +#include "tools.h" +#include "rendering/scenery.h" + MainTerrainForm::MainTerrainForm(QWidget *parent) : QWidget(parent), ui(new Ui::MainTerrainForm) { + _terrain = (TerrainDefinition*)TerrainDefinitionClass.create(); + ui->setupUi(this); + + _form_helper = new FreeFormHelper(this); + + _form_helper->addPreview("preview_shape"); + + _form_helper->addDoubleInputSlider("input_scaling", &_terrain->scaling, 0.1, 3.0, 0.03, 0.3); + _form_helper->addDoubleInputSlider("input_height", &_terrain->height, 0.0, 3.0, 0.01, 0.1); + _form_helper->addDoubleInputSlider("input_shadow_smoothing", &_terrain->shadow_smoothing, 0.0, 0.3, 0.003, 0.03); + + _form_helper->setApplyButton("button_apply"); + _form_helper->setRevertButton("button_revert"); + + connect(findChild("button_dialog_painting"), SIGNAL(clicked()), this, SLOT(buttonPaintingPressed())); + connect(findChild("button_goto_textures"), SIGNAL(clicked()), this, SLOT(buttonTexturesPressed())); + + _form_helper->startManaging(); } MainTerrainForm::~MainTerrainForm() { + delete _form_helper; delete ui; + + TerrainDefinitionClass.destroy(_terrain); +} + +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))); + } + else + { + _form_helper->setLabelText("label_painting_info", tr("No manual scuplting done")); + } +} + +void MainTerrainForm::refreshFromFellowData() +{ + // TODO Refresh texture info +} + +void MainTerrainForm::updateLocalDataFromScenery() +{ + sceneryGetTerrain(_terrain); +} + +void MainTerrainForm::commitLocalDataToScenery() +{ + scenerySetTerrain(_terrain); +} + +void MainTerrainForm::buttonPaintingPressed() +{ + DialogTerrainPainting dialog(this, _terrain); + _form_helper->openDialog(&dialog); +} + +void MainTerrainForm::buttonTexturesPressed() +{ + // TODO Switch to textures tab } diff --git a/src/editing/terrain/mainterrainform.h b/src/editing/terrain/mainterrainform.h index b4d6e84..dcaa105 100644 --- a/src/editing/terrain/mainterrainform.h +++ b/src/editing/terrain/mainterrainform.h @@ -2,6 +2,8 @@ #define MAINTERRAINFORM_H #include +#include "common/freeformhelper.h" +#include "rendering/terrain/public.h" namespace Ui { class MainTerrainForm; @@ -14,9 +16,23 @@ class MainTerrainForm : public QWidget public: explicit MainTerrainForm(QWidget *parent = 0); ~MainTerrainForm(); - + + inline TerrainDefinition* getTerrainDefinition() {return _terrain;} + +public slots: + void refreshFromLocalData(); + void refreshFromFellowData(); + void updateLocalDataFromScenery(); + void commitLocalDataToScenery(); + + void buttonPaintingPressed(); + void buttonTexturesPressed(); + private: Ui::MainTerrainForm *ui; + FreeFormHelper* _form_helper; + + TerrainDefinition* _terrain; }; #endif // MAINTERRAINFORM_H diff --git a/src/editing/terrain/mainterrainform.ui b/src/editing/terrain/mainterrainform.ui index e106eed..b15d36a 100644 --- a/src/editing/terrain/mainterrainform.ui +++ b/src/editing/terrain/mainterrainform.ui @@ -68,8 +68,6 @@ - groupBox_1 - widget @@ -82,7 +80,7 @@ - + 0 @@ -95,7 +93,7 @@ - + 0 @@ -143,7 +141,7 @@ - + 400 @@ -163,7 +161,7 @@ - + 400 @@ -198,7 +196,7 @@ - + 400 @@ -223,49 +221,86 @@ - - - - - - Relative water height - - - - - - - - 400 - 16777215 - - - - Qt::Horizontal - - - - - - - - - - - 0 - 0 - - - - - 500 - 16777215 - - - - Go to textures to add small height displacements (rocks...) - - + + + + + + + + + + + Relative water height + + + + + + + + 400 + 16777215 + + + + Qt::Horizontal + + + + + + + + + + + + + 0 + 0 + + + + + 500 + 16777215 + + + + Go to textures to add small height displacements (rocks...) + + + + + + + { textures info } + + + + + + + + + + + + + 1 + 0 + + + + + 200 + 0 + + + + + @@ -289,7 +324,7 @@ - + 0 @@ -332,22 +367,22 @@ + + + + Qt::Vertical + + + + 20 + 40 + + + + - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -355,7 +390,7 @@ - + Revert modifications @@ -366,7 +401,7 @@ - + Apply modifications diff --git a/src/editing/terrain/previewterrainshape.cpp b/src/editing/terrain/previewterrainshape.cpp new file mode 100644 index 0000000..757559c --- /dev/null +++ b/src/editing/terrain/previewterrainshape.cpp @@ -0,0 +1,22 @@ +#include "previewterrainshape.h" + +PreviewTerrainShape::PreviewTerrainShape(QWidget *parent) : + BasePreview(parent) +{ + _renderer = terrainCreatePreviewRenderer(); + + addOsd(QString("geolocation")); + + configScaling(20.0, 1000.0, 20.0, 50.0); + configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0); +} + +Color PreviewTerrainShape::getColor(double x, double y) +{ + return terrainGetPreviewColor(_renderer, x, y, scaling); +} + +void PreviewTerrainShape::updateData() +{ + //TerrainRendererClass.bind(_renderer, _definition); +} diff --git a/src/editing/terrain/previewterrainshape.h b/src/editing/terrain/previewterrainshape.h new file mode 100644 index 0000000..4b9663c --- /dev/null +++ b/src/editing/terrain/previewterrainshape.h @@ -0,0 +1,21 @@ +#ifndef PREVIEWTERRAINSHAPE_H +#define PREVIEWTERRAINSHAPE_H + +#include "basepreview.h" +#include "rendering/renderer.h" + +class PreviewTerrainShape : public BasePreview +{ + Q_OBJECT +public: + explicit PreviewTerrainShape(QWidget *parent = 0); + +protected: + virtual Color getColor(double x, double y); + virtual void updateData(); + +private: + Renderer* _renderer; +}; + +#endif // PREVIEWTERRAINSHAPE_H