Commit a092fb59 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🐛

Implement a gradient edit for the shape colors.

parent d5494d3f
......@@ -21,6 +21,8 @@
#include "kis_wdg_multigrid_pattern.h"
#include <QLayout>
#include <QDomDocument>
#include <QDomElement>
#include <KoColor.h>
#include <filter/kis_filter_configuration.h>
......@@ -35,6 +37,13 @@ KisWdgMultigridPattern::KisWdgMultigridPattern(QWidget* parent, const KoColorSpa
m_widget->setupUi(this);
m_cs = cs;
QLinearGradient grad;
grad.setColorAt(0, Qt::green);
grad.setColorAt(1.0, Qt::blue);
m_gradient = KoStopGradient::fromQGradient(&grad);
widget()->wdgGradient->setGradient(m_gradient);
widget()->wdgGradient->setCompactMode(true);
widget()->sldDivisions->setRange(0, 100);
widget()->sldDivisions->setPrefix(i18n("Divisions:"));
......@@ -53,8 +62,6 @@ KisWdgMultigridPattern::KisWdgMultigridPattern(QWidget* parent, const KoColorSpa
widget()->sldColorIntersect->setRange(-2.0, 2.0, 2);
widget()->sldColorIntersect->setPrefix(i18n("Intersect:"));
connect(m_widget->bnColor1, SIGNAL(changed(const KoColor&)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->bnColor2, SIGNAL(changed(const KoColor&)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldDivisions, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldDimensions, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldOffset, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated()));
......@@ -63,6 +70,8 @@ KisWdgMultigridPattern::KisWdgMultigridPattern(QWidget* parent, const KoColorSpa
connect(m_widget->sldColorRatio, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldColorIntersect, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->wdgGradient, SIGNAL(sigGradientChanged()), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->spnLineWidth, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->bnLineColor, SIGNAL(changed(const KoColor&)), this, SIGNAL(sigConfigurationUpdated()));
}
......@@ -75,16 +84,18 @@ KisWdgMultigridPattern::~KisWdgMultigridPattern()
void KisWdgMultigridPattern::setConfiguration(const KisPropertiesConfigurationSP config)
{
QVariant value;
KoColor c =config->getColor("color1");
c.convertTo(m_cs);
widget()->bnColor1->setColor(c);
c = config->getColor("color2");
c.convertTo(m_cs);
widget()->bnColor2->setColor(c);
c = config->getColor("lineColor");
if (config->hasProperty("gradientXML")) {
QDomDocument doc;
doc.setContent(config->getString("gradientXML", ""));
KoStopGradient gradient = KoStopGradient::fromXML(doc.firstChildElement());
if (gradient.stops().size() > 0) {
m_gradient->setStops(gradient.stops());
}
widget()->wdgGradient->setGradient(m_gradient);
}
KoColor c = config->getColor("lineColor");
c.convertTo(m_cs);
widget()->bnLineColor->setColor(c);
......@@ -103,16 +114,17 @@ void KisWdgMultigridPattern::setConfiguration(const KisPropertiesConfigurationSP
KisPropertiesConfigurationSP KisWdgMultigridPattern::configuration() const
{
KisFilterConfigurationSP config = new KisFilterConfiguration("multigrid", 1, KisGlobalResourcesInterface::instance());
KoColor c;
c.fromKoColor(widget()->bnColor1->color());
QVariant v;
v.setValue(c);
config->setProperty("color1", v);
c.fromKoColor(widget()->bnColor2->color());
v.setValue(c);
config->setProperty("color2", v);
if (m_gradient) {
QDomDocument doc;
QDomElement elt = doc.createElement("gradient");
m_gradient->toXML(doc, elt);
doc.appendChild(elt);
config->setProperty("gradientXML", doc.toString());
}
QVariant v;
KoColor c;
c.fromKoColor(widget()->bnLineColor->color());
v.setValue(c);
config->setProperty("lineColor", v);
......
......@@ -24,6 +24,7 @@
#include <kis_config_widget.h>
#include <KoColorSpace.h>
#include <KoColorSpaceRegistry.h>
#include <KoStopGradient.h>
class Ui_WdgMultigridPatternOptions;
......@@ -42,6 +43,7 @@ public:
private:
Ui_WdgMultigridPatternOptions* m_widget;
const KoColorSpace *m_cs;
KoStopGradientSP m_gradient;
};
#endif
......
......@@ -25,6 +25,7 @@
#include <QVector>
#include <QMap>
#include <QtMath>
#include <QDomDocument>
#include <kis_debug.h>
......@@ -70,15 +71,20 @@ KisFilterConfigurationSP KisMultigridPatternGenerator::defaultConfiguration(KisR
{
KisFilterConfigurationSP config = factoryConfiguration(resourcesInterface);
QLinearGradient gradient;
gradient.setColorAt(0, Qt::green);
gradient.setColorAt(1.0, Qt::blue);
KoStopGradientSP grad = KoStopGradient::fromQGradient(&gradient);
if (grad) {
QDomDocument doc;
QDomElement elt = doc.createElement("gradient");
grad->toXML(doc, elt);
doc.appendChild(elt);
config->setProperty("gradientXML", doc.toString());
}
QVariant v;
KoColor c;
c.fromQColor(QColor(Qt::green));
v.setValue(c);
config->setProperty("color1", v);
c.fromQColor(QColor(Qt::blue));
v.setValue(c);
config->setProperty("color2", v);
c.fromQColor(QColor(Qt::black));
v.setValue(c);
config->setProperty("lineColor", v);
config->setProperty("divisions", 5);
......@@ -108,19 +114,20 @@ void KisMultigridPatternGenerator::generate(KisProcessingInformation dstInfo,
Q_ASSERT(!dst.isNull());
Q_ASSERT(config);
KoColor c1;
KoColor c2;
if (config) {
c1 = config->getColor("color1");
c1.setOpacity(1.0);
c2 = config->getColor("color2");
c2.setOpacity(1.0);
KoStopGradient grad;
auto gradientStops = grad.stops();
gradientStops.append(KoGradientStop(0, c1));
gradientStops.append(KoGradientStop(1, c2));
grad.setStops(gradientStops);
QLinearGradient gradient;
gradient.setColorAt(0, Qt::green);
gradient.setColorAt(1.0, Qt::blue);
KoStopGradientSP grad = KoStopGradient::fromQGradient(&gradient);
if (config->hasProperty("gradientXML")) {
QDomDocument doc;
doc.setContent(config->getString("gradientXML", ""));
KoStopGradient gradient = KoStopGradient::fromXML(doc.firstChildElement());
if (gradient.stops().size() > 0) {
grad->setStops(gradient.stops());
}
}
int divisions = config->getInt("divisions", 1);
int dimensions = config->getInt("dimensions", 5);
......@@ -155,7 +162,7 @@ void KisMultigridPatternGenerator::generate(KisProcessingInformation dstInfo,
QTransform tf;
tf.translate(bounds.center().x(), bounds.center().y());
tf.scale(scale, scale);
KoColor c = c1;
KoColor c = grad->stops()[0].color;
for (int i= 0; i < rhombs.size(); i++){
KisMultiGridRhomb rhomb = rhombs.at(i);
QPolygonF shape = tf.map(rhomb.shape);
......@@ -209,7 +216,7 @@ void KisMultigridPatternGenerator::generate(KisProcessingInformation dstInfo,
gradientPos *= 1-((1-indexRatio)*abs(colorIndex));
}
grad.colorAt(c, gradientPos);
grad->colorAt(c, gradientPos);
gc.setBackgroundColor(c);
gc.fillPainterPath(p, p.boundingRect().adjusted(-2, -2, 2, 2).toRect());
......
......@@ -64,38 +64,16 @@
<string>Colors</string>
</property>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="lblColor">
<property name="text">
<string>&amp;Color 1:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>bnColor1</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KisColorButton" name="bnColor1"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblColor2">
<property name="text">
<string>&amp;Color 2:</string>
<string>Color Factors:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>bnColor1</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="KisColorButton" name="bnColor2"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="KisDoubleSliderSpinBox" name="sldColorRatio" native="true"/>
</item>
......@@ -105,12 +83,21 @@
<item row="4" column="0" colspan="2">
<widget class="KisDoubleSliderSpinBox" name="sldColorIndex" native="true"/>
</item>
<item row="0" column="0">
<widget class="KisStopGradientEditor" name="wdgGradient" native="true"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KisStopGradientEditor</class>
<extends>QWidget</extends>
<header>kis_stopgradient_editor.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KisDoubleSliderSpinBox</class>
<extends>QWidget</extends>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment