2012-01-05 16:32:41 +00:00
|
|
|
#include "baseform.h"
|
2012-01-05 19:41:10 +00:00
|
|
|
|
2012-01-05 18:39:17 +00:00
|
|
|
#include "inputdouble.h"
|
2012-01-06 16:09:03 +00:00
|
|
|
#include "inputint.h"
|
2012-02-12 17:26:17 +00:00
|
|
|
#include "inputboolean.h"
|
2012-01-05 19:41:10 +00:00
|
|
|
#include "inputcolor.h"
|
2012-01-07 16:53:23 +00:00
|
|
|
#include "inputcolorgradation.h"
|
|
|
|
#include "inputnoise.h"
|
2012-05-29 13:32:23 +00:00
|
|
|
#include "inputcurve.h"
|
2012-06-02 09:46:24 +00:00
|
|
|
#include "inputmaterial.h"
|
2012-01-05 16:32:41 +00:00
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QLabel>
|
|
|
|
|
2012-02-05 11:31:16 +00:00
|
|
|
BaseForm::BaseForm(QWidget* parent, bool auto_apply, bool with_layers) : QWidget(parent)
|
2012-01-05 16:32:41 +00:00
|
|
|
{
|
2012-04-11 19:59:50 +00:00
|
|
|
QWidget* control;
|
|
|
|
QWidget* layers;
|
|
|
|
QLabel* label;
|
2012-01-05 16:32:41 +00:00
|
|
|
|
2012-01-27 23:01:21 +00:00
|
|
|
this->auto_apply = auto_apply;
|
2012-02-05 11:31:16 +00:00
|
|
|
this->with_layers = with_layers;
|
2012-01-27 23:01:21 +00:00
|
|
|
|
2012-04-11 19:59:50 +00:00
|
|
|
setLayout(new QHBoxLayout());
|
|
|
|
setObjectName("_base_form_");
|
2012-04-14 15:52:16 +00:00
|
|
|
|
2012-04-11 19:59:50 +00:00
|
|
|
control = new QWidget(this);
|
|
|
|
control->setLayout(new QVBoxLayout());
|
2012-04-14 15:52:16 +00:00
|
|
|
control->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
2012-04-11 19:59:50 +00:00
|
|
|
layout()->addWidget(control);
|
2012-02-05 11:31:16 +00:00
|
|
|
|
|
|
|
if (with_layers)
|
|
|
|
{
|
2012-04-11 19:59:50 +00:00
|
|
|
layers = new QWidget(this);
|
|
|
|
layers->setLayout(new QHBoxLayout());
|
|
|
|
layers->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
2012-02-05 11:31:16 +00:00
|
|
|
|
2012-04-11 19:59:50 +00:00
|
|
|
label = new QLabel(tr("Layers : "), layers);
|
|
|
|
label->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
layers->layout()->addWidget(label);
|
2012-02-05 11:31:16 +00:00
|
|
|
|
2012-04-11 19:59:50 +00:00
|
|
|
layer_list = new QComboBox(layers);
|
|
|
|
layers->layout()->addWidget(layer_list);
|
2012-02-05 11:31:16 +00:00
|
|
|
QObject::connect(layer_list, SIGNAL(currentIndexChanged(int)), this, SLOT(layerListChanged()));
|
|
|
|
|
2012-04-11 19:59:50 +00:00
|
|
|
layer_new = new QPushButton(tr("Add layer"), layers);
|
|
|
|
layers->layout()->addWidget(layer_new);
|
2012-02-05 11:31:16 +00:00
|
|
|
QObject::connect(layer_new, SIGNAL(clicked()), this, SLOT(layerAddClicked()));
|
|
|
|
|
2012-04-11 19:59:50 +00:00
|
|
|
layer_del = new QPushButton(tr("Delete layer"), layers);
|
|
|
|
layers->layout()->addWidget(layer_del);
|
2012-02-05 11:31:16 +00:00
|
|
|
QObject::connect(layer_del, SIGNAL(clicked()), this, SLOT(layerDelClicked()));
|
|
|
|
|
2012-04-11 19:59:50 +00:00
|
|
|
control->layout()->addWidget(layers);
|
|
|
|
control->layout()->setAlignment(buttons, Qt::AlignTop);
|
2012-02-05 11:31:16 +00:00
|
|
|
}
|
2012-01-05 16:32:41 +00:00
|
|
|
|
|
|
|
previews = new QWidget(this);
|
|
|
|
previews->setLayout(new QVBoxLayout());
|
2012-04-03 19:33:40 +00:00
|
|
|
previews->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2012-04-11 19:59:50 +00:00
|
|
|
layout()->addWidget(previews);
|
|
|
|
layout()->setAlignment(previews, Qt::AlignTop);
|
|
|
|
|
2012-01-05 16:32:41 +00:00
|
|
|
form = new QWidget(this);
|
2012-04-14 15:52:16 +00:00
|
|
|
form->setLayout(new QHBoxLayout());
|
2012-04-11 19:59:50 +00:00
|
|
|
control->layout()->addWidget(form);
|
2012-04-14 15:52:16 +00:00
|
|
|
control->layout()->setAlignment(form, Qt::AlignTop);
|
|
|
|
|
|
|
|
form_labels = new QWidget(form);
|
|
|
|
form_labels->setLayout(new QVBoxLayout());
|
|
|
|
form->layout()->addWidget(form_labels);
|
2012-01-05 16:32:41 +00:00
|
|
|
|
2012-04-14 15:52:16 +00:00
|
|
|
form_previews = new QWidget(form);
|
|
|
|
form_previews->setLayout(new QVBoxLayout());
|
|
|
|
form->layout()->addWidget(form_previews);
|
|
|
|
|
|
|
|
form_controls = new QWidget(form);
|
|
|
|
form_controls->setLayout(new QVBoxLayout());
|
|
|
|
form->layout()->addWidget(form_controls);
|
|
|
|
|
2012-01-05 16:32:41 +00:00
|
|
|
buttons = new QWidget(this);
|
2012-01-06 16:09:03 +00:00
|
|
|
buttons->setLayout(new QHBoxLayout());
|
2012-04-11 19:59:50 +00:00
|
|
|
control->layout()->addWidget(buttons);
|
|
|
|
control->layout()->setAlignment(buttons, Qt::AlignBottom);
|
2012-01-10 20:51:27 +00:00
|
|
|
|
2012-02-28 13:45:11 +00:00
|
|
|
button_apply = addButton(tr("Apply"));
|
2012-01-10 20:51:27 +00:00
|
|
|
button_apply->setEnabled(false);
|
|
|
|
connect(button_apply, SIGNAL(clicked()), this, SLOT(applyConfig()));
|
2012-02-28 13:45:11 +00:00
|
|
|
button_revert = addButton(tr("Revert"));
|
2012-01-10 20:51:27 +00:00
|
|
|
button_revert->setEnabled(false);
|
|
|
|
connect(button_revert, SIGNAL(clicked()), this, SLOT(revertConfig()));
|
2012-01-27 23:01:21 +00:00
|
|
|
|
|
|
|
if (auto_apply)
|
|
|
|
{
|
2012-06-02 09:46:24 +00:00
|
|
|
hideButtons();
|
2012-01-27 23:01:21 +00:00
|
|
|
}
|
2012-01-05 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
2012-06-02 09:46:24 +00:00
|
|
|
void BaseForm::hideButtons()
|
|
|
|
{
|
|
|
|
button_apply->hide();
|
|
|
|
button_revert->hide();
|
|
|
|
}
|
|
|
|
|
2012-01-25 22:32:06 +00:00
|
|
|
void BaseForm::configChangeEvent()
|
2012-01-05 16:32:41 +00:00
|
|
|
{
|
2012-01-27 23:01:21 +00:00
|
|
|
if (auto_apply)
|
|
|
|
{
|
|
|
|
applyConfig();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
button_apply->setEnabled(true);
|
|
|
|
button_revert->setEnabled(true);
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
QList<BasePreview*> list_previews = previews->findChildren<BasePreview*>("_form_preview_");
|
2012-01-05 16:32:41 +00:00
|
|
|
for (int i = 0; i < list_previews.size(); i++)
|
|
|
|
{
|
|
|
|
list_previews[i]->redraw();
|
|
|
|
}
|
2012-01-05 18:39:17 +00:00
|
|
|
}
|
2012-01-05 16:32:41 +00:00
|
|
|
|
2012-01-05 18:39:17 +00:00
|
|
|
void BaseForm::revertConfig()
|
|
|
|
{
|
2012-01-06 16:09:03 +00:00
|
|
|
QList<BaseInput*> inputs = form->findChildren<BaseInput*>("_form_input_");
|
|
|
|
for (int i = 0; i < inputs.size(); i++)
|
2012-01-05 16:32:41 +00:00
|
|
|
{
|
2012-01-06 16:09:03 +00:00
|
|
|
inputs[i]->revert();
|
2012-01-05 16:32:41 +00:00
|
|
|
}
|
2012-02-05 11:31:16 +00:00
|
|
|
|
|
|
|
if (with_layers)
|
|
|
|
{
|
|
|
|
if (layer_list->currentIndex() < 0 && layer_list->count() > 0)
|
|
|
|
{
|
|
|
|
layer_list->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
}
|
2012-01-05 18:39:17 +00:00
|
|
|
|
2012-01-25 22:32:06 +00:00
|
|
|
BaseForm::configChangeEvent();
|
2012-01-10 20:51:27 +00:00
|
|
|
|
|
|
|
button_apply->setEnabled(false);
|
|
|
|
button_revert->setEnabled(false);
|
2012-01-05 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
2012-01-06 16:09:03 +00:00
|
|
|
void BaseForm::applyConfig()
|
|
|
|
{
|
2012-01-27 23:01:21 +00:00
|
|
|
button_apply->setEnabled(false);
|
|
|
|
button_revert->setEnabled(false);
|
|
|
|
|
2012-01-26 22:30:20 +00:00
|
|
|
emit(configApplied());
|
2012-01-06 16:09:03 +00:00
|
|
|
}
|
|
|
|
|
2012-02-05 11:31:16 +00:00
|
|
|
void BaseForm::layerAddClicked()
|
|
|
|
{
|
|
|
|
layerAddedEvent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseForm::layerDelClicked()
|
|
|
|
{
|
|
|
|
layerDeletedEvent(layer_list->currentIndex());
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseForm::layerListChanged()
|
|
|
|
{
|
|
|
|
layerSelectedEvent(layer_list->currentIndex());
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
void BaseForm::addPreview(BasePreview* preview, QString label)
|
2012-01-05 16:32:41 +00:00
|
|
|
{
|
2012-04-03 19:33:40 +00:00
|
|
|
QLabel* label_widget;
|
|
|
|
|
|
|
|
label_widget = new QLabel(label, previews);
|
|
|
|
label_widget->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
|
|
|
|
|
|
previews->layout()->addWidget(label_widget);
|
2012-01-05 16:32:41 +00:00
|
|
|
previews->layout()->addWidget(preview);
|
2012-02-05 12:17:51 +00:00
|
|
|
|
2012-01-05 16:32:41 +00:00
|
|
|
preview->setObjectName("_form_preview_");
|
|
|
|
}
|
|
|
|
|
2012-01-06 16:09:03 +00:00
|
|
|
QPushButton* BaseForm::addButton(QString label)
|
|
|
|
{
|
|
|
|
QPushButton* button = new QPushButton(label);
|
|
|
|
buttons->layout()->addWidget(button);
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2012-01-05 18:39:17 +00:00
|
|
|
void BaseForm::addInput(BaseInput* input)
|
2012-01-05 16:32:41 +00:00
|
|
|
{
|
2012-04-14 15:52:16 +00:00
|
|
|
int row_height = 30;
|
|
|
|
|
|
|
|
form_labels->layout()->addWidget(input->label());
|
|
|
|
form_previews->layout()->addWidget(input->preview());
|
|
|
|
form_controls->layout()->addWidget(input->control());
|
|
|
|
|
|
|
|
input->label()->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed);
|
|
|
|
input->label()->setMinimumSize(150, row_height);
|
|
|
|
input->label()->setMaximumSize(250, row_height);
|
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
input->preview()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2012-04-14 15:52:16 +00:00
|
|
|
input->preview()->setMinimumSize(100, row_height);
|
|
|
|
input->preview()->setMaximumSize(250, row_height);
|
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
input->control()->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
2012-04-14 15:52:16 +00:00
|
|
|
input->control()->setMinimumSize(280, row_height);
|
|
|
|
input->control()->setMaximumSize(700, row_height);
|
2012-01-07 16:53:23 +00:00
|
|
|
|
2012-01-25 22:32:06 +00:00
|
|
|
connect(input, SIGNAL(valueChanged()), this, SLOT(configChangeEvent()));
|
2012-01-06 16:09:03 +00:00
|
|
|
|
|
|
|
input->setObjectName("_form_input_");
|
2012-01-08 10:31:01 +00:00
|
|
|
input->revert();
|
2012-01-06 16:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseForm::addInputInt(QString label, int* value, int min, int max, int small_step, int large_step)
|
|
|
|
{
|
|
|
|
addInput(new InputInt(form, label, value, min, max, small_step, large_step));
|
2012-01-05 18:39:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BaseForm::addInputDouble(QString label, double* value, double min, double max, double small_step, double large_step)
|
|
|
|
{
|
|
|
|
addInput(new InputDouble(form, label, value, min, max, small_step, large_step));
|
2012-01-05 16:32:41 +00:00
|
|
|
}
|
2012-01-05 19:41:10 +00:00
|
|
|
|
2012-02-12 17:26:17 +00:00
|
|
|
void BaseForm::addInputBoolean(QString label, int* value)
|
|
|
|
{
|
|
|
|
addInput(new InputBoolean(form, label, value));
|
|
|
|
}
|
|
|
|
|
2012-01-05 19:41:10 +00:00
|
|
|
void BaseForm::addInputColor(QString label, Color* value)
|
|
|
|
{
|
|
|
|
addInput(new InputColor(form, label, value));
|
|
|
|
}
|
2012-01-07 16:53:23 +00:00
|
|
|
|
|
|
|
void BaseForm::addInputColorGradation(QString label, ColorGradation* value)
|
|
|
|
{
|
|
|
|
addInput(new InputColorGradation(form, label, value));
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseForm::addInputNoise(QString label, NoiseGenerator* value)
|
|
|
|
{
|
|
|
|
addInput(new InputNoise(form, label, value));
|
|
|
|
}
|
2012-02-05 11:31:16 +00:00
|
|
|
|
2012-05-29 13:32:23 +00:00
|
|
|
void BaseForm::addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax)
|
|
|
|
{
|
|
|
|
addInput(new InputCurve(form, label, value, xmin, xmax, ymin, ymax));
|
|
|
|
}
|
|
|
|
|
2012-06-02 09:46:24 +00:00
|
|
|
void BaseForm::addInputMaterial(QString label, SurfaceMaterial* material)
|
|
|
|
{
|
|
|
|
addInput(new InputMaterial(form, label, material));
|
|
|
|
}
|
|
|
|
|
2012-02-05 11:31:16 +00:00
|
|
|
int BaseForm::currentLayer()
|
|
|
|
{
|
|
|
|
if (with_layers)
|
|
|
|
{
|
|
|
|
return layer_list->currentIndex();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseForm::setLayerCount(int layer_count)
|
|
|
|
{
|
|
|
|
int i, selected;
|
|
|
|
|
|
|
|
if (with_layers)
|
|
|
|
{
|
|
|
|
selected = layer_list->currentIndex();
|
|
|
|
layer_list->clear();
|
|
|
|
|
|
|
|
for (i = 0; i < layer_count; i++)
|
|
|
|
{
|
2012-02-28 13:45:11 +00:00
|
|
|
layer_list->addItem(QString(tr("Layer %1")).arg(i + 1));
|
2012-02-05 11:31:16 +00:00
|
|
|
}
|
2012-02-21 13:41:02 +00:00
|
|
|
if (selected >= 0)
|
|
|
|
{
|
|
|
|
if (selected > layer_count)
|
|
|
|
{
|
|
|
|
layer_list->setCurrentIndex(layer_count - 1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
layer_list->setCurrentIndex(selected);
|
|
|
|
}
|
|
|
|
}
|
2012-02-05 11:31:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseForm::layerAddedEvent()
|
|
|
|
{
|
|
|
|
setLayerCount(layer_list->count() + 1);
|
|
|
|
layer_list->setCurrentIndex(layer_list->count() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseForm::layerDeletedEvent(int layer)
|
|
|
|
{
|
|
|
|
layer_list->removeItem(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BaseForm::layerSelectedEvent(int layer)
|
|
|
|
{
|
|
|
|
QList<BaseInput*> inputs = form->findChildren<BaseInput*>("_form_input_");
|
|
|
|
for (int i = 0; i < inputs.size(); i++)
|
|
|
|
{
|
|
|
|
inputs[i]->revert();
|
|
|
|
}
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
QList<BasePreview*> list_previews = previews->findChildren<BasePreview*>("_form_preview_");
|
2012-02-05 11:31:16 +00:00
|
|
|
for (int i = 0; i < list_previews.size(); i++)
|
|
|
|
{
|
|
|
|
list_previews[i]->redraw();
|
|
|
|
}
|
|
|
|
}
|