2012-07-13 12:23:58 +00:00
|
|
|
#include "dialogheightmap.h"
|
|
|
|
|
2012-07-15 14:42:50 +00:00
|
|
|
#include <QLabel>
|
2012-07-13 12:23:58 +00:00
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QPushButton>
|
2012-07-16 15:48:05 +00:00
|
|
|
#include <QComboBox>
|
2012-07-13 12:23:58 +00:00
|
|
|
#include <QSlider>
|
2012-07-13 21:24:19 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include "widgetheightmap.h"
|
2012-07-13 12:23:58 +00:00
|
|
|
|
|
|
|
/**************** Dialog form ****************/
|
|
|
|
DialogHeightMap::DialogHeightMap(QWidget* parent, HeightMap* heightmap) : DialogWithPreview(parent)
|
|
|
|
{
|
|
|
|
QWidget* mainarea;
|
|
|
|
QWidget* buttons;
|
|
|
|
QWidget* panel;
|
|
|
|
QWidget* viewer;
|
|
|
|
QGridLayout* viewer_layout;
|
|
|
|
|
2012-07-15 14:42:50 +00:00
|
|
|
QLabel* label;
|
2012-07-13 12:23:58 +00:00
|
|
|
QSlider* slider;
|
|
|
|
QPushButton* button;
|
2012-07-16 15:48:05 +00:00
|
|
|
QComboBox* combobox;
|
2012-07-13 12:23:58 +00:00
|
|
|
|
|
|
|
_value_original = heightmap;
|
|
|
|
_value_modified = heightmapCreate();
|
|
|
|
heightmapCopy(_value_original, &_value_modified);
|
|
|
|
setLayout(new QVBoxLayout());
|
|
|
|
|
|
|
|
// Dialog layout (main area + buttons)
|
|
|
|
mainarea = new QWidget(this);
|
|
|
|
mainarea->setLayout(new QHBoxLayout());
|
|
|
|
this->layout()->addWidget(mainarea);
|
|
|
|
|
|
|
|
buttons = new QWidget(this);
|
|
|
|
buttons->setLayout(new QHBoxLayout());
|
|
|
|
buttons->layout()->setAlignment(buttons, Qt::AlignBottom);
|
|
|
|
this->layout()->addWidget(buttons);
|
|
|
|
|
|
|
|
// Main area layout (viewer + panel)
|
|
|
|
viewer = new QWidget(mainarea);
|
|
|
|
viewer_layout = new QGridLayout();
|
|
|
|
viewer->setLayout(viewer_layout);
|
|
|
|
mainarea->layout()->addWidget(viewer);
|
|
|
|
|
|
|
|
panel = new QWidget(mainarea);
|
|
|
|
panel->setLayout(new QVBoxLayout());
|
|
|
|
mainarea->layout()->addWidget(panel);
|
2012-07-15 14:42:50 +00:00
|
|
|
mainarea->layout()->setAlignment(panel, Qt::AlignTop);
|
2012-07-13 12:23:58 +00:00
|
|
|
|
|
|
|
// Viewer layout (3d display + sliders)
|
|
|
|
_3dview = new WidgetHeightMap(viewer, &_value_modified);
|
|
|
|
viewer_layout->addWidget(_3dview, 0, 0);
|
|
|
|
slider = new QSlider(Qt::Horizontal, viewer);
|
2012-07-13 21:24:19 +00:00
|
|
|
slider->setRange(0, 1000);
|
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(angleHChanged(int)));
|
2012-07-13 12:23:58 +00:00
|
|
|
viewer_layout->addWidget(slider, 1, 0);
|
|
|
|
slider = new QSlider(Qt::Vertical, viewer);
|
2012-07-13 21:24:19 +00:00
|
|
|
slider->setRange(-300, 700);
|
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(angleVChanged(int)));
|
2012-07-13 12:23:58 +00:00
|
|
|
viewer_layout->addWidget(slider, 0, 1);
|
|
|
|
|
|
|
|
// Panel layout
|
2012-07-15 14:42:50 +00:00
|
|
|
button = new QPushButton(tr("Reset to terrain height"), panel);
|
2012-07-13 21:24:19 +00:00
|
|
|
connect(button, SIGNAL(clicked()), _3dview, SLOT(resetToTerrain()));
|
2012-07-13 12:23:58 +00:00
|
|
|
panel->layout()->addWidget(button);
|
2012-07-15 14:42:50 +00:00
|
|
|
|
2012-07-16 15:48:05 +00:00
|
|
|
combobox = new QComboBox(panel);
|
|
|
|
combobox->addItem(tr("Raise / lower"));
|
2012-07-26 11:55:19 +00:00
|
|
|
combobox->addItem(tr("Add noise / smooth"));
|
2012-07-16 15:48:05 +00:00
|
|
|
connect(combobox, SIGNAL(currentIndexChanged(int)), this, SLOT(brushModeChanged(int)));
|
|
|
|
panel->layout()->addWidget(combobox);
|
|
|
|
|
2012-07-15 14:42:50 +00:00
|
|
|
label = new QLabel(tr("Brush size"), panel);
|
|
|
|
panel->layout()->addWidget(label);
|
|
|
|
|
|
|
|
slider = new QSlider(Qt::Horizontal, panel);
|
2012-07-26 11:55:19 +00:00
|
|
|
slider->setRange(6, 300);
|
2012-07-15 14:42:50 +00:00
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(brushSizeChanged(int)));
|
|
|
|
panel->layout()->addWidget(slider);
|
2012-07-26 11:55:19 +00:00
|
|
|
slider->setValue(60);
|
2012-07-13 12:23:58 +00:00
|
|
|
|
2012-07-15 14:42:50 +00:00
|
|
|
label = new QLabel(tr("Brush smoothing"), panel);
|
|
|
|
panel->layout()->addWidget(label);
|
|
|
|
|
|
|
|
slider = new QSlider(Qt::Horizontal, panel);
|
|
|
|
slider->setRange(0, 1000);
|
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(brushSmoothingChanged(int)));
|
|
|
|
panel->layout()->addWidget(slider);
|
2012-07-16 20:34:01 +00:00
|
|
|
slider->setValue(600);
|
|
|
|
|
|
|
|
label = new QLabel(tr("Brush strength"), panel);
|
|
|
|
panel->layout()->addWidget(label);
|
|
|
|
|
|
|
|
slider = new QSlider(Qt::Horizontal, panel);
|
|
|
|
slider->setRange(0, 1000);
|
|
|
|
connect(slider, SIGNAL(valueChanged(int)), this, SLOT(brushStrengthChanged(int)));
|
|
|
|
panel->layout()->addWidget(slider);
|
2012-07-15 14:42:50 +00:00
|
|
|
slider->setValue(200);
|
|
|
|
|
2012-07-13 12:23:58 +00:00
|
|
|
// Buttons layout
|
|
|
|
button = new QPushButton(tr("Validate"), buttons);
|
|
|
|
buttons->layout()->addWidget(button);
|
|
|
|
QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept()));
|
|
|
|
|
|
|
|
button = new QPushButton(tr("Revert"), buttons);
|
|
|
|
buttons->layout()->addWidget(button);
|
|
|
|
QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert()));
|
|
|
|
|
|
|
|
button = new QPushButton(tr("Cancel"), buttons);
|
|
|
|
buttons->layout()->addWidget(button);
|
|
|
|
QObject::connect(button, SIGNAL(clicked()), this, SLOT(reject()));
|
|
|
|
|
|
|
|
setWindowTitle(tr("Paysages 3D - Height map painting"));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DialogHeightMap::editHeightMap(QWidget* parent, HeightMap* heightmap)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
DialogHeightMap* dialog = new DialogHeightMap(parent, heightmap);
|
|
|
|
result = dialog->exec();
|
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
|
|
|
|
return (result != 0) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogHeightMap::accept()
|
|
|
|
{
|
2012-07-16 20:34:01 +00:00
|
|
|
heightmapCopy(&_value_modified, _value_original);
|
2012-07-13 12:23:58 +00:00
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogHeightMap::revert()
|
|
|
|
{
|
2012-07-16 20:34:01 +00:00
|
|
|
heightmapCopy(_value_original, &_value_modified);
|
|
|
|
_3dview->revert();
|
2012-07-13 12:23:58 +00:00
|
|
|
}
|
2012-07-13 21:24:19 +00:00
|
|
|
|
|
|
|
void DialogHeightMap::angleHChanged(int value)
|
|
|
|
{
|
|
|
|
_3dview->setHorizontalViewAngle(M_PI * ((double)value) / 500.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogHeightMap::angleVChanged(int value)
|
|
|
|
{
|
|
|
|
_3dview->setVerticalViewAngle(M_PI_2 * ((double)value) / 1000.0);
|
|
|
|
}
|
2012-07-15 14:42:50 +00:00
|
|
|
|
2012-07-16 15:48:05 +00:00
|
|
|
void DialogHeightMap::brushModeChanged(int value)
|
|
|
|
{
|
|
|
|
_3dview->setBrushMode((HeightMapBrushMode)value);
|
|
|
|
}
|
|
|
|
|
2012-07-15 14:42:50 +00:00
|
|
|
void DialogHeightMap::brushSizeChanged(int value)
|
|
|
|
{
|
|
|
|
_3dview->setBrushSize((double)value / 10.0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogHeightMap::brushSmoothingChanged(int value)
|
|
|
|
{
|
|
|
|
_3dview->setBrushSmoothing((double)value / 1000.0);
|
|
|
|
}
|
2012-07-16 20:34:01 +00:00
|
|
|
|
|
|
|
void DialogHeightMap::brushStrengthChanged(int value)
|
|
|
|
{
|
|
|
|
_3dview->setBrushStrength((double)value / 2000.0);
|
|
|
|
}
|