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-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>
|
|
|
|
|
|
|
|
BaseForm::BaseForm(QWidget* parent) :
|
|
|
|
QWidget(parent)
|
|
|
|
{
|
|
|
|
QWidget* hwidget;
|
|
|
|
QVBoxLayout* vlayout;
|
|
|
|
QHBoxLayout* hlayout;
|
|
|
|
|
|
|
|
vlayout = new QVBoxLayout();
|
|
|
|
hlayout = new QHBoxLayout();
|
|
|
|
|
|
|
|
hwidget = new QWidget(this);
|
|
|
|
|
|
|
|
previews = new QWidget(this);
|
|
|
|
previews->setLayout(new QVBoxLayout());
|
|
|
|
|
|
|
|
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_");
|
|
|
|
|
|
|
|
button_apply = addButton("Apply");
|
|
|
|
button_apply->setEnabled(false);
|
|
|
|
connect(button_apply, SIGNAL(clicked()), this, SLOT(applyConfig()));
|
|
|
|
button_revert = addButton("Revert");
|
|
|
|
button_revert->setEnabled(false);
|
|
|
|
connect(button_revert, SIGNAL(clicked()), this, SLOT(revertConfig()));
|
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
|
|
|
{
|
|
|
|
QList<Preview*> list_previews = previews->findChildren<Preview*>("_form_preview_");
|
|
|
|
for (int i = 0; i < list_previews.size(); i++)
|
|
|
|
{
|
|
|
|
list_previews[i]->redraw();
|
|
|
|
}
|
2012-01-10 20:51:27 +00:00
|
|
|
|
|
|
|
button_apply->setEnabled(true);
|
|
|
|
button_revert->setEnabled(true);
|
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-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-23 23:45:33 +00:00
|
|
|
revertConfig();
|
2012-01-06 16:09:03 +00:00
|
|
|
}
|
|
|
|
|
2012-01-05 16:32:41 +00:00
|
|
|
void BaseForm::addPreview(Preview* preview, QString label)
|
|
|
|
{
|
|
|
|
previews->layout()->addWidget(new QLabel(label, previews));
|
|
|
|
previews->layout()->addWidget(preview);
|
2012-01-06 16:09:03 +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
|
|
|
{
|
|
|
|
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
|
|
|
|
|
|
|
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));
|
|
|
|
}
|