10 setAttribute(Qt::WA_NoBackground);
15 void TransferBox::paintEvent(QPaintEvent *) {
16 static bool first =
true;
18 m_image = QImage(
sizeHint(), QImage::Format_RGB32);
20 points << QPointF(0,
sizeHint().height())
31 m_colors.append(QColor(0, 0, 0));
32 m_colors.append(QColor(0, 0, 0));
35 QPainter painter(
this);
36 painter.drawImage(0, 0, m_image);
38 painter.setPen(QColor(10, 10, 10));
40 QLinearGradient gradient(0, 0,
sizeHint().width(), 0);
41 for(
int i = 0; i < m_points.size(); i++) {
42 gradient.setColorAt((
double)m_points.at(i).x()/(double)
sizeHint().width(), m_colors.at(i));
44 painter.fillRect(rect(), gradient);
48 void TransferBox::mousePressEvent(QMouseEvent *event) {
54 for(
int i = 0; i < m_points.size(); i++) {
55 if(m_points.at(i).x() != points.at(i).x()) {
56 m_colors.insert(i, color);
62 m_colors.append(color);
70 for(
int i = 0; i < points.size(); i++) {
71 if(m_points.at(i).x() != points.at(i).x()) {
78 m_colors.remove(m_points.size()-2);
85 m_colors.remove(index);
86 m_colors.insert(index, color);
88 qDebug() << m_points.size() <<
" " << m_colors.size();
91 QVector<QVector4D> TransferBox::interpolate() {
92 QVector<QVector4D> out;
93 float stepSize = (float)width()/(
STEPS-1);
94 for(
float step = 0; step < width(); step += stepSize) {
96 for(index = 0; index < m_points.size()-1; index++) {
97 if(step < m_points.at(index+1).x()) {
101 int nextIndex = index+1;
102 float delta = m_points.at(nextIndex).x() - m_points.at(index).x();
103 float factor = (step - m_points.at(index).x()) / delta;
105 float deltaR = m_colors.at(nextIndex).red() - m_colors.at(index).red();
106 float deltaG = m_colors.at(nextIndex).green() - m_colors.at(index).green();
107 float deltaB = m_colors.at(nextIndex).blue() - m_colors.at(index).blue();
108 float deltaA = m_points.at(nextIndex).y() - m_points.at(index).y();
109 float interpolR = (m_colors.at(index).red() + (factor * deltaR))/255.0;
110 float interpolG = (m_colors.at(index).green() + (factor * deltaG))/255.0;
111 float interpolB = (m_colors.at(index).blue() + (factor * deltaB))/255.0;
112 float interpolA = (1.0 - (m_points.at(index).y() + (factor * deltaA))/
sizeHint().height());
113 vector.setX(interpolR);
114 vector.setY(interpolG);
115 vector.setZ(interpolB);
116 vector.setW(interpolA);
120 float step = width();
121 int index = m_points.size() - 2;
122 int nextIndex = m_points.size() - 1;
123 float delta = m_points.at(nextIndex).x() - m_points.at(index).x();
126 float deltaR = m_colors.at(nextIndex).red() - m_colors.at(index).red();
127 float deltaG = m_colors.at(nextIndex).green() - m_colors.at(index).green();
128 float deltaB = m_colors.at(nextIndex).blue() - m_colors.at(index).blue();
129 float deltaA = m_points.at(nextIndex).y() - m_points.at(index).y();
130 float interpolR = (m_colors.at(index).red() + (factor * deltaR))/255.0;
131 float interpolG = (m_colors.at(index).green() + (factor * deltaG))/255.0;
132 float interpolB = (m_colors.at(index).blue() + (factor * deltaB))/255.0;
133 float interpolA = (1.0 - (m_points.at(index).y() + (factor * deltaA))/
sizeHint().height());
134 vector.setX(interpolR);
135 vector.setY(interpolG);
136 vector.setZ(interpolB);
137 vector.setW(interpolA);
142 float* TransferBox::toFloatArray() {
143 float* value =
new float[
STEPS * 4];
144 QVector<QVector4D> vector = interpolate();
145 for (
int i=0; i < vector.count(); i++) {
146 QVector4D point = vector.at(i);
147 value[i * 4] = point.x();
148 value[i * 4 + 1] = point.y();
149 value[i * 4 + 2] = point.z();
150 value[i * 4 + 3] = pow(point.w(), 8);