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-01-05 16:32:41 +00:00
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QHBoxLayout>
|
|
|
|
#include <QGridLayout>
|
|
|
|
#include <QLabel>
|
2012-02-05 11:31:16 +00:00
|
|
|
#include <qt4/QtGui/qboxlayout.h>
|
2012-01-05 16:32:41 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
QWidget* hwidget;
|
|
|
|
QVBoxLayout* vlayout;
|
|
|
|
QHBoxLayout* hlayout;
|
|
|
|
|
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-01-05 16:32:41 +00:00
|
|
|
vlayout = new QVBoxLayout();
|
|
|
|
hlayout = new QHBoxLayout();
|
2012-02-05 11:31:16 +00:00
|
|
|
|
|
|
|
if (with_layers)
|
|
|
|
{
|
|
|
|
hwidget = new QWidget(this);
|
|
|
|
hwidget->setLayout(new QHBoxLayout());
|
|
|
|
|
2012-02-28 13:45:11 +00:00
|
|
|
hwidget->layout()->addWidget(new QLabel(tr("Layers : "), hwidget));
|
2012-02-05 11:31:16 +00:00
|
|
|
|
|
|
|
layer_list = new QComboBox(hwidget);
|
|
|
|
hwidget->layout()->addWidget(layer_list);
|
|
|
|
QObject::connect(layer_list, SIGNAL(currentIndexChanged(int)), this, SLOT(layerListChanged()));
|
|
|
|
|
2012-02-28 13:45:11 +00:00
|
|
|
layer_new = new QPushButton(tr("Add layer"), hwidget);
|
2012-02-05 11:31:16 +00:00
|
|
|
hwidget->layout()->addWidget(layer_new);
|
|
|
|
QObject::connect(layer_new, SIGNAL(clicked()), this, SLOT(layerAddClicked()));
|
|
|
|
|
2012-02-28 13:45:11 +00:00
|
|
|
layer_del = new QPushButton(tr("Delete layer"), hwidget);
|
2012-02-05 11:31:16 +00:00
|
|
|
hwidget->layout()->addWidget(layer_del);
|
|
|
|
QObject::connect(layer_del, SIGNAL(clicked()), this, SLOT(layerDelClicked()));
|
|
|
|
|
|
|
|
vlayout->addWidget(hwidget);
|
|
|
|
}
|
2012-01-05 16:32:41 +00:00
|
|
|
|
|
|
|
hwidget = new QWidget(this);
|
|
|
|
|
|
|
|
previews = new QWidget(this);
|
|
|
|
previews->setLayout(new QVBoxLayout());
|
2012-04-03 19:33:40 +00:00
|
|
|
previews->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
2012-01-05 16:32:41 +00:00
|
|
|
|
|
|
|
form = new QWidget(this);
|
|
|
|
form->setLayout(new QGridLayout());
|
2012-01-07 16:53:23 +00:00
|
|
|
form->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
|
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-01-05 16:32:41 +00:00
|
|
|
|
|
|
|
hlayout->addWidget(previews);
|
|
|
|
hlayout->addWidget(form);
|
2012-01-07 16:53:23 +00:00
|
|
|
hlayout->setAlignment(form, Qt::AlignTop);
|
|
|
|
|
2012-01-05 16:32:41 +00:00
|
|
|
vlayout->addWidget(hwidget);
|
|
|
|
vlayout->addWidget(buttons);
|
|
|
|
|
|
|
|
hwidget->setLayout(hlayout);
|
|
|
|
this->setLayout(vlayout);
|
2012-01-10 20:51:27 +00:00
|
|
|
this->setObjectName("_base_form_");
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
button_apply->hide();
|
|
|
|
button_revert->hide();
|
|
|
|
}
|
2012-01-05 16:32:41 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
preview->start();
|
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
|
|
|
{
|
|
|
|
QGridLayout* layout = (QGridLayout*)form->layout();
|
|
|
|
int row = layout->rowCount();
|
|
|
|
|
2012-01-05 18:39:17 +00:00
|
|
|
layout->addWidget(input->label(), row, 0);
|
|
|
|
layout->addWidget(input->preview(), row, 1);
|
|
|
|
layout->addWidget(input->control(), row, 2);
|
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
input->label()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
input->preview()->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
|
|
input->control()->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
|
|
|
|
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
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|