paysages3d/gui_qt/previewcolorgradation.cpp

74 lines
2 KiB
C++
Raw Normal View History

#include "previewcolorgradation.h"
#include <QVBoxLayout>
#include <QImage>
#include <QLabel>
#include <QColor>
#include <QPainter>
#include <QSlider>
#include <QScrollArea>
#include <QPushButton>
#include "baseform.h"
#include "tools.h"
#include "widgetcurveeditor.h"
/**************** Preview ****************/
PreviewColorGradation::PreviewColorGradation(QWidget* parent, ColorGradation* gradation, EnumColorGradationBand band) : QWidget(parent)
{
this->gradation = gradation;
this->band = band;
}
void PreviewColorGradation::paintEvent(QPaintEvent* event)
{
Curve* curve;
QPainter painter(this);
int width = this->width();
int height = this->height();
curve = curveCreate();
switch (band)
{
case COLORGRADATIONBAND_RED:
colorGradationGetRedCurve(gradation, curve);
break;
case COLORGRADATIONBAND_GREEN:
colorGradationGetGreenCurve(gradation, curve);
break;
case COLORGRADATIONBAND_BLUE:
colorGradationGetBlueCurve(gradation, curve);
break;
default:
break;
}
for (int x = 0; x < width; x++)
{
switch (band)
{
case COLORGRADATIONBAND_RED:
painter.setPen(QColor::fromRgbF(curveGetValue(curve, (float)x / (float)width), 0.0, 0.0));
break;
case COLORGRADATIONBAND_GREEN:
painter.setPen(QColor::fromRgbF(0.0, curveGetValue(curve, (float)x / (float)width), 0.0));
break;
case COLORGRADATIONBAND_BLUE:
painter.setPen(QColor::fromRgbF(0.0, 0.0, curveGetValue(curve, (float)x / (float)width)));
break;
case COLORGRADATIONBAND_FINAL:
painter.setPen(colorToQColor(colorGradationGet(gradation, (float)x / (float)width)));
break;
}
painter.drawLine(x, 0, x, height - 1);
}
curveDelete(curve);
}
void PreviewColorGradation::mouseReleaseEvent(QMouseEvent* event)
{
emit clicked();
}