2012-02-20 21:17:13 +00:00
|
|
|
#include "dialogcolorgradation.h"
|
|
|
|
|
|
|
|
#include <QVBoxLayout>
|
2012-03-29 20:19:50 +00:00
|
|
|
#include <QHBoxLayout>
|
2012-02-20 21:17:13 +00:00
|
|
|
#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-03-08 15:10:25 +00:00
|
|
|
#include "widgetcurveeditor.h"
|
2012-02-20 21:17:13 +00:00
|
|
|
|
|
|
|
/**************** Dialog ****************/
|
|
|
|
DialogColorGradation::DialogColorGradation(QWidget *parent, ColorGradation* gradation):
|
|
|
|
QDialog(parent)
|
|
|
|
{
|
2012-03-29 20:19:50 +00:00
|
|
|
QWidget* buttons;
|
|
|
|
|
2012-02-20 21:17:13 +00:00
|
|
|
_base = gradation;
|
|
|
|
_current = colorGradationCreate();
|
2012-03-08 15:10:25 +00:00
|
|
|
colorGradationCopy(_base, _current);
|
2012-02-20 21:17:13 +00:00
|
|
|
|
2012-03-18 19:51:06 +00:00
|
|
|
setLayout(new QVBoxLayout());
|
2012-02-20 21:17:13 +00:00
|
|
|
|
2012-03-08 15:10:25 +00:00
|
|
|
_curve_editor = new WidgetCurveEditor(this);
|
|
|
|
layout()->addWidget(_curve_editor);
|
2012-03-29 20:19:50 +00:00
|
|
|
connect(_curve_editor, SIGNAL(liveChanged()), this, SLOT(updateColors()));
|
2012-02-20 21:17:13 +00:00
|
|
|
|
2012-03-29 20:19:50 +00:00
|
|
|
_preview_red = new PreviewColorGradation(this, _current, COLORGRADATIONBAND_RED);
|
2012-03-18 19:51:06 +00:00
|
|
|
_preview_red->setMinimumHeight(50);
|
2012-03-18 21:00:50 +00:00
|
|
|
connect(_preview_red, SIGNAL(clicked()), this, SLOT(selectRed()));
|
2012-03-18 19:51:06 +00:00
|
|
|
layout()->addWidget(_preview_red);
|
|
|
|
|
2012-03-29 20:19:50 +00:00
|
|
|
_preview_green = new PreviewColorGradation(this, _current, COLORGRADATIONBAND_GREEN);
|
2012-03-18 19:51:06 +00:00
|
|
|
_preview_green->setMinimumHeight(50);
|
2012-03-18 21:00:50 +00:00
|
|
|
connect(_preview_green, SIGNAL(clicked()), this, SLOT(selectGreen()));
|
2012-03-18 19:51:06 +00:00
|
|
|
layout()->addWidget(_preview_green);
|
|
|
|
|
2012-03-29 20:19:50 +00:00
|
|
|
_preview_blue = new PreviewColorGradation(this, _current, COLORGRADATIONBAND_BLUE);
|
2012-03-18 19:51:06 +00:00
|
|
|
_preview_blue->setMinimumHeight(50);
|
2012-03-18 21:00:50 +00:00
|
|
|
connect(_preview_blue, SIGNAL(clicked()), this, SLOT(selectBlue()));
|
2012-03-18 19:51:06 +00:00
|
|
|
layout()->addWidget(_preview_blue);
|
|
|
|
|
2012-03-29 20:19:50 +00:00
|
|
|
_preview_final = new PreviewColorGradation(this, _current, COLORGRADATIONBAND_FINAL);
|
2012-03-18 19:51:06 +00:00
|
|
|
_preview_final->setMinimumHeight(50);
|
|
|
|
layout()->addWidget(_preview_final);
|
|
|
|
|
2012-03-29 20:19:50 +00:00
|
|
|
buttons = new QWidget(this);
|
|
|
|
layout()->addWidget(buttons);
|
|
|
|
buttons->setLayout(new QHBoxLayout());
|
2012-03-08 15:56:44 +00:00
|
|
|
|
2012-03-29 20:19:50 +00:00
|
|
|
_button_accept = new QPushButton(tr("Validate"), buttons);
|
|
|
|
buttons->layout()->addWidget(_button_accept);
|
|
|
|
QObject::connect(_button_accept, SIGNAL(clicked()), this, SLOT(accept()));
|
|
|
|
|
|
|
|
_button_revert = new QPushButton(tr("Revert"), buttons);
|
|
|
|
buttons->layout()->addWidget(_button_revert);
|
|
|
|
QObject::connect(_button_revert, SIGNAL(clicked()), this, SLOT(revert()));
|
|
|
|
|
|
|
|
_button_cancel = new QPushButton(tr("Cancel"), buttons);
|
|
|
|
buttons->layout()->addWidget(_button_cancel);
|
|
|
|
QObject::connect(_button_cancel, SIGNAL(clicked()), this, SLOT(reject()));
|
|
|
|
|
|
|
|
_curve = curveCreate();
|
2012-02-20 21:17:13 +00:00
|
|
|
|
2012-02-28 13:45:11 +00:00
|
|
|
setWindowTitle(tr("Paysages 3D - Color gradation editor"));
|
2012-02-20 21:17:13 +00:00
|
|
|
|
|
|
|
revert();
|
|
|
|
}
|
|
|
|
|
|
|
|
DialogColorGradation::~DialogColorGradation()
|
|
|
|
{
|
2012-03-08 15:10:25 +00:00
|
|
|
colorGradationDelete(_current);
|
2012-03-08 15:56:44 +00:00
|
|
|
curveDelete(_curve);
|
2012-02-20 21:17:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2012-03-08 15:10:25 +00:00
|
|
|
colorGradationCopy(_current, _base);
|
2012-02-20 21:17:13 +00:00
|
|
|
QDialog::accept();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogColorGradation::revert()
|
|
|
|
{
|
2012-03-29 20:19:50 +00:00
|
|
|
_selected = 0;
|
2012-03-08 15:10:25 +00:00
|
|
|
colorGradationCopy(_base, _current);
|
2012-02-20 21:17:13 +00:00
|
|
|
revertToCurrent();
|
|
|
|
}
|
|
|
|
|
2012-03-18 21:00:50 +00:00
|
|
|
void DialogColorGradation::selectRed()
|
2012-02-20 21:17:13 +00:00
|
|
|
{
|
2012-03-08 15:56:44 +00:00
|
|
|
colorGradationGetRedCurve(_current, _curve);
|
|
|
|
_curve_editor->setCurve(_curve);
|
2012-03-29 20:19:50 +00:00
|
|
|
_selected = 1;
|
2012-02-20 21:17:13 +00:00
|
|
|
}
|
2012-03-18 21:00:50 +00:00
|
|
|
|
|
|
|
void DialogColorGradation::selectGreen()
|
|
|
|
{
|
|
|
|
colorGradationGetGreenCurve(_current, _curve);
|
|
|
|
_curve_editor->setCurve(_curve);
|
2012-03-29 20:19:50 +00:00
|
|
|
_selected = 2;
|
2012-03-18 21:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogColorGradation::selectBlue()
|
|
|
|
{
|
|
|
|
colorGradationGetBlueCurve(_current, _curve);
|
|
|
|
_curve_editor->setCurve(_curve);
|
2012-03-29 20:19:50 +00:00
|
|
|
_selected = 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DialogColorGradation::updateColors()
|
|
|
|
{
|
|
|
|
Curve* curve;
|
|
|
|
|
|
|
|
curve = curveCreate();
|
|
|
|
_curve_editor->getCurve(curve);
|
|
|
|
|
|
|
|
switch (_selected)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
_preview_red->update();
|
|
|
|
_preview_green->update();
|
|
|
|
_preview_blue->update();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
colorGradationSetRedCurve(_current, curve);
|
|
|
|
_preview_red->update();
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
colorGradationSetGreenCurve(_current, curve);
|
|
|
|
_preview_green->update();
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
colorGradationSetBlueCurve(_current, curve);
|
|
|
|
_preview_blue->update();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
_preview_final->update();
|
|
|
|
|
|
|
|
curveDelete(curve);
|
2012-03-18 21:00:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DialogColorGradation::revertToCurrent()
|
|
|
|
{
|
2012-03-29 20:19:50 +00:00
|
|
|
updateColors();
|
2012-03-18 21:00:50 +00:00
|
|
|
selectRed();
|
|
|
|
}
|