2012-01-07 16:53:23 +00:00
|
|
|
#include "inputcolorgradation.h"
|
|
|
|
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QPushButton>
|
|
|
|
#include <QPainter>
|
|
|
|
#include <QColorDialog>
|
|
|
|
|
2012-01-08 10:31:01 +00:00
|
|
|
#include "tools.h"
|
|
|
|
|
|
|
|
#include "../lib_paysages/shared/functions.h"
|
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
class ColorGradationPreview:public QWidget
|
|
|
|
{
|
|
|
|
public:
|
2012-01-08 10:31:01 +00:00
|
|
|
ColorGradationPreview(QWidget* parent, ColorGradation* gradation):
|
|
|
|
QWidget(parent),
|
|
|
|
gradation(gradation)
|
2012-01-07 16:53:23 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void paintEvent(QPaintEvent* event)
|
|
|
|
{
|
2012-01-08 10:31:01 +00:00
|
|
|
QPainter painter(this);
|
|
|
|
int width = this->width();
|
|
|
|
int height = this->height();
|
|
|
|
|
|
|
|
for (int x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
painter.setPen(colorToQColor(colorGradationGet(gradation, (double)x / (double)width)));
|
|
|
|
painter.drawLine(x, 0, x, height - 1);
|
|
|
|
}
|
2012-01-07 16:53:23 +00:00
|
|
|
}
|
2012-01-08 10:31:01 +00:00
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
ColorGradation* gradation;
|
|
|
|
};
|
|
|
|
|
|
|
|
InputColorGradation::InputColorGradation(QWidget* form, QString label, ColorGradation* value):
|
|
|
|
BaseInput(form, label),
|
|
|
|
_value(value)
|
|
|
|
{
|
2012-01-08 10:31:01 +00:00
|
|
|
_preview = new ColorGradationPreview(form, value);
|
2012-01-07 16:53:23 +00:00
|
|
|
_preview->setMinimumSize(200, 20);
|
2012-01-08 10:31:01 +00:00
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
_control = new QPushButton("Edit", form);
|
|
|
|
_control->setMaximumWidth(150);
|
|
|
|
|
|
|
|
connect((QPushButton*)_control, SIGNAL(clicked()), this, SLOT(editGradation()));
|
|
|
|
}
|
|
|
|
|
2012-01-08 10:31:01 +00:00
|
|
|
void InputColorGradation::updatePreview()
|
|
|
|
{
|
|
|
|
_preview->update();
|
|
|
|
BaseInput::updatePreview();
|
|
|
|
}
|
|
|
|
|
2012-01-07 16:53:23 +00:00
|
|
|
void InputColorGradation::applyValue()
|
|
|
|
{
|
|
|
|
/*_value->r = ((ColorPreview*)_preview)->col.redF();
|
|
|
|
_value->g = ((ColorPreview*)_preview)->col.greenF();
|
|
|
|
_value->b = ((ColorPreview*)_preview)->col.blueF();
|
|
|
|
_value->a = 1.0;*/
|
|
|
|
BaseInput::applyValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputColorGradation::revert()
|
|
|
|
{
|
2012-01-08 10:31:01 +00:00
|
|
|
BaseInput::revert();
|
2012-01-07 16:53:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void InputColorGradation::editGradation()
|
|
|
|
{
|
|
|
|
/*QColor col = QColorDialog::getColor(((ColorPreview*)_preview)->col, _control);
|
|
|
|
if (col.isValid())
|
|
|
|
{
|
|
|
|
((ColorPreview*)_preview)->col = col;
|
|
|
|
applyValue();
|
|
|
|
}*/
|
|
|
|
}
|