2012-02-20 21:17:13 +00:00
|
|
|
#include "dialogcolorgradation.h"
|
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
#include <QImage>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QColor>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QSlider>
|
|
|
|
#include <QScrollArea>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include "baseform.h"
|
2012-02-21 13:41:02 +00:00
|
|
|
#include "tools.h"
|
2012-02-20 21:17:13 +00:00
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
/**************** Preview ****************/
|
|
|
|
class PreviewColorGradation:public BasePreview
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PreviewColorGradation(QWidget* parent, ColorGradation* gradation): BasePreview(parent)
|
|
|
|
{
|
|
|
|
_gradation_original = gradation;
|
|
|
|
_gradation_preview = *gradation;
|
|
|
|
setMinimumSize(300, 30);
|
|
|
|
setMaximumSize(300, 30);
|
|
|
|
resize(300, 30);
|
|
|
|
// TODO No scrolling/scaling
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
_gradation_preview = *_gradation_original;
|
|
|
|
}
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
|
|
|
return colorToQColor(colorGradationGet(&_gradation_preview, x / 600 + 0.5));
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
ColorGradation* _gradation_original;
|
|
|
|
ColorGradation _gradation_preview;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************** Form ****************/
|
2012-02-20 21:17:13 +00:00
|
|
|
class FormColorGradation:public BaseForm
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
FormColorGradation(QWidget* parent, ColorGradation* gradation):BaseForm(parent, true, true)
|
|
|
|
{
|
2012-02-21 13:41:02 +00:00
|
|
|
QPushButton* button;
|
2012-02-20 21:17:13 +00:00
|
|
|
_gradation = gradation;
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
addPreview(new PreviewColorGradation(this, _gradation), "Preview");
|
|
|
|
|
2012-02-20 21:17:13 +00:00
|
|
|
addInputDouble("Position", &_layer.start, 0.0, 1.0, 0.01, 0.1);
|
|
|
|
addInputColor("Color", &_layer.col);
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
button = addButton("Validate");
|
|
|
|
QObject::connect(button, SIGNAL(clicked()), parent, SLOT(accept()));
|
|
|
|
|
|
|
|
button = addButton("Revert");
|
|
|
|
QObject::connect(button, SIGNAL(clicked()), parent, SLOT(revert()));
|
|
|
|
|
|
|
|
button = addButton("Cancel");
|
|
|
|
QObject::connect(button, SIGNAL(clicked()), parent, SLOT(reject()));
|
|
|
|
|
|
|
|
revertConfig();
|
2012-02-20 21:17:13 +00:00
|
|
|
}
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
void revertConfig()
|
2012-02-20 21:17:13 +00:00
|
|
|
{
|
2012-02-21 13:41:02 +00:00
|
|
|
setLayerCount(colorGradationGetPartCount(_gradation));
|
|
|
|
}
|
|
|
|
|
|
|
|
void configChangeEvent()
|
|
|
|
{
|
|
|
|
colorGradationSetPart(_gradation, currentLayer(), _layer);
|
|
|
|
|
|
|
|
BaseForm::configChangeEvent();
|
2012-02-20 21:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void layerAddedEvent()
|
|
|
|
{
|
2012-02-21 13:41:02 +00:00
|
|
|
if (colorGradationAddPart(_gradation) >= 0)
|
2012-02-20 21:17:13 +00:00
|
|
|
{
|
|
|
|
BaseForm::layerAddedEvent();
|
2012-02-21 13:41:02 +00:00
|
|
|
}
|
2012-02-20 21:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void layerDeletedEvent(int layer)
|
|
|
|
{
|
2012-02-21 13:41:02 +00:00
|
|
|
colorGradationDelPart(_gradation, layer);
|
2012-02-20 21:17:13 +00:00
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
BaseForm::layerDeletedEvent(layer);
|
2012-02-20 21:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void layerSelectedEvent(int layer)
|
|
|
|
{
|
2012-02-21 13:41:02 +00:00
|
|
|
_layer = colorGradationGetPart(_gradation, layer);
|
2012-02-20 21:17:13 +00:00
|
|
|
|
|
|
|
BaseForm::layerSelectedEvent(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
ColorGradation* _gradation;
|
|
|
|
ColorGradationPart _layer;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**************** Dialog ****************/
|
|
|
|
DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* gradation):
|
|
|
|
QDialog(parent)
|
|
|
|
{
|
|
|
|
QWidget* preview;
|
|
|
|
|
|
|
|
_base = gradation;
|
|
|
|
_current = colorGradationCreate();
|
2012-02-21 13:41:02 +00:00
|
|
|
_current = *_base;
|
2012-02-20 21:17:13 +00:00
|
|
|
|
|
|
|
setLayout(new QHBoxLayout());
|
|
|
|
|
|
|
|
preview = new QWidget(this);
|
|
|
|
layout()->addWidget(preview);
|
|
|
|
|
2012-02-21 13:41:02 +00:00
|
|
|
_form = new FormColorGradation(this, &_current);
|
|
|
|
layout()->addWidget(_form);
|
2012-02-20 21:17:13 +00:00
|
|
|
|
|
|
|
/*QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept()));
|
|
|
|
QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert()));
|
|
|
|
QObject::connect(button, SIGNAL(clicked()), this, SLOT(reject()));*/
|
|
|
|
|
|
|
|
setWindowTitle("Paysages 3D - Color gradation editor");
|
|
|
|
|
|
|
|
revert();
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogColorGradation::~DialogColorGradation()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool DialogColorGradation::getGradation(QWidget* parent, ColorGradation* gradation)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
DialogColorGradation* dialog = new DialogColorGradation(parent, gradation);
|
|
|
|
result = dialog->exec();
|
|
|
|
|
|
|
|
delete dialog;
|
|
|
|
|
|
|
|
return (result != 0) ? true : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogColorGradation::closeEvent(QCloseEvent* e)
|
|
|
|
{
|
|
|
|
reject();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogColorGradation::accept()
|
|
|
|
{
|
|
|
|
*_base = _current;
|
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogColorGradation::revert()
|
|
|
|
{
|
|
|
|
_current = *_base;
|
|
|
|
|
|
|
|
revertToCurrent();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogColorGradation::revertToCurrent()
|
|
|
|
{
|
2012-02-21 13:41:02 +00:00
|
|
|
_form->revertConfig();
|
2012-02-20 21:17:13 +00:00
|
|
|
}
|