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

Add line width, do some cleanup, making everything configurable.

The color options still need work...
parent 34af7558
......@@ -34,11 +34,37 @@ KisWdgMultigridPattern::KisWdgMultigridPattern(QWidget* parent, const KoColorSpa
m_widget = new Ui_WdgMultigridPatternOptions();
m_widget->setupUi(this);
m_cs = cs;
widget()->sldDivisions->setRange(0, 100);
widget()->sldDivisions->setPrefix(i18n("Divisions:"));
widget()->sldDimensions->setRange(3, 36);
widget()->sldDimensions->setPrefix(i18n("Dimensions:"));
widget()->sldOffset->setRange(0.01, 0.49, 2);
widget()->sldOffset->setPrefix(i18n("Offset:"));
widget()->sldColorRatio->setRange(0.0, 1.0, 2);
widget()->sldColorRatio->setPrefix(i18n("Ratio:"));
widget()->sldColorIndex->setRange(0.0, 1.0, 2);
widget()->sldColorIndex->setPrefix(i18n("Index:"));
widget()->sldColorIntersect->setRange(0.0, 1.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->spnDivisions, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->spnDimensions, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->spnOffset, SIGNAL(valueChanged(qreal)), 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()));
connect(m_widget->sldColorIndex, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldColorRatio, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->sldColorIntersect, SIGNAL(valueChanged(qreal)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->spnLineWidth, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->bnLineColor, SIGNAL(changed(const KoColor&)), this, SIGNAL(sigConfigurationUpdated()));
}
KisWdgMultigridPattern::~KisWdgMultigridPattern()
......@@ -58,10 +84,20 @@ void KisWdgMultigridPattern::setConfiguration(const KisPropertiesConfigurationSP
c.convertTo(m_cs);
widget()->bnColor2->setColor(c);
widget()->spnDivisions->setValue(config->getInt("divisions", 1));
c = config->getColor("lineColor");
c.convertTo(m_cs);
widget()->bnLineColor->setColor(c);
widget()->spnLineWidth->setValue(config->getInt("lineWidth", 1));
widget()->sldDivisions->setValue(config->getInt("divisions", 1));
widget()->spnDimensions->setValue(config->getInt("dimensions", 5));
widget()->spnOffset->setValue(config->getFloat("offset", 0.2));
widget()->sldDimensions->setValue(config->getInt("dimensions", 5));
widget()->sldOffset->setValue(config->getFloat("offset", 0.2));
widget()->sldColorIndex->setValue(config->getFloat("colorIndex", 1.0));
widget()->sldColorRatio->setValue(config->getFloat("colorRatio", 0.0));
widget()->sldColorIntersect->setValue(config->getFloat("colorIntersect", 0.0));
}
KisPropertiesConfigurationSP KisWdgMultigridPattern::configuration() const
......@@ -77,10 +113,19 @@ KisPropertiesConfigurationSP KisWdgMultigridPattern::configuration() const
v.setValue(c);
config->setProperty("color2", v);
config->setProperty("divisions", widget()->spnDivisions->value());
c.fromKoColor(widget()->bnLineColor->color());
v.setValue(c);
config->setProperty("lineColor", v);
config->setProperty("lineWidth", widget()->spnLineWidth->value());
config->setProperty("divisions", widget()->sldDivisions->value());
config->setProperty("dimensions", widget()->sldDimensions->value());
config->setProperty("offset", widget()->sldOffset->value());
config->setProperty("dimensions", widget()->spnDimensions->value());
config->setProperty("offset", widget()->spnOffset->value());
config->setProperty("colorRatio", widget()->sldColorRatio->value());
config->setProperty("colorIndex", widget()->sldColorIndex->value());
config->setProperty("colorIntersect", widget()->sldColorIntersect->value());
return config;
}
......
......@@ -78,9 +78,17 @@ KisFilterConfigurationSP KisMultigridPatternGenerator::defaultConfiguration(KisR
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", 1);
config->setProperty("lineWidth", 1);
config->setProperty("dimensions", 5);
config->setProperty("offset", .2);
config->setProperty("colorRatio", 1.0);
config->setProperty("colorIndex", 0.0);
config->setProperty("colorIntersect", 0.0);
return config;
}
......@@ -102,21 +110,35 @@ void KisMultigridPatternGenerator::generate(KisProcessingInformation dstInfo,
KoColor c1;
KoColor c2;
int divisions = 0;
if (config) {
c1 = config->getColor("color1");
c1.setOpacity(1.0);
c2 = config->getColor("color2");
c2.setOpacity(1.0);
divisions = config->getInt("divisions", 1);
KoStopGradient grad;
auto gradientStops = grad.stops();
gradientStops.append(KoGradientStop(0, c1));
gradientStops.append(KoGradientStop(1, c2));
grad.setStops(gradientStops);
int divisions = config->getInt("divisions", 1);
int dimensions = config->getInt("dimensions", 5);
qreal offset = config->getFloat("offset", .2);
QRectF bounds(QPoint(), size);
//QLineF l(bounds.topLeft(), bounds.bottomRight());
KoColor lineColor = config->getColor("lineColor");
lineColor.setOpacity(1.0);
int lineWidth = config->getInt("lineWidth", 1);
qreal colorRatio = config->getFloat("colorRatio", 1.0);
qreal colorIndex = config->getFloat("colorIndex", 0.0);
qreal colorIntersect = config->getFloat("colorIntersect", 0.0);
qreal diameter = QLineF(bounds.topLeft(), bounds.bottomRight()).length();
qreal scale = diameter/2/divisions;
int lineWidth = bounds.width()/2/divisions;
QList<KisMultiGridRhomb> rhombs = generateRhombs(dimensions, lineWidth, offset, bounds);
QList<KisMultiGridRhomb> rhombs = generateRhombs(dimensions, divisions, offset);
KisProgressUpdateHelper progress(progressUpdater, 100, rhombs.size());
......@@ -128,22 +150,35 @@ void KisMultigridPatternGenerator::generate(KisProcessingInformation dstInfo,
gc.setStrokeStyle(KisPainter::StrokeStyleBrush);
gc.setSelection(dstInfo.selection());
KoStopGradient grad;
auto gradientStops = grad.stops();
gradientStops.append(KoGradientStop(0, c1));
gradientStops.append(KoGradientStop(1, c2));
grad.setStops(gradientStops);
gc.fill(bounds.left(), bounds.top(), bounds.right(), bounds.bottom(), lineColor);
QTransform tf;
tf.translate(bounds.center().x(), bounds.center().y());
tf.scale(lineWidth/2, lineWidth/2);
tf.scale(scale, scale);
KoColor c = c1;
for (int i= 0; i < rhombs.size(); i++){
KisMultiGridRhomb rhomb = rhombs.at(i);
QPolygonF shape = tf.map(rhomb.shape);
if (shape.boundingRect().intersects(bounds)) {
QPointF center = shape.at(0)+shape.at(1)+shape.at(2)+shape.at(3);
center.setX(center.x()/4);
center.setY(center.y()/4);
QTransform lineWidthTransform;
qreal scaleForLineWidth = qMax(1-(qreal(lineWidth)/scale), 0.0);
lineWidthTransform.scale(scaleForLineWidth, scaleForLineWidth);
QPointF scaledCenter = lineWidthTransform.map(center);
lineWidthTransform.reset();
lineWidthTransform.translate(center.x()-scaledCenter.x(), center.y()-scaledCenter.y());
lineWidthTransform.scale(scaleForLineWidth, scaleForLineWidth);
shape = lineWidthTransform.map(shape);
if (shape.intersects(bounds) && shape.boundingRect().width()>0) {
QPainterPath p;
p.addPolygon(shape);
p.addPolygon(lineWidthTransform.map(shape));
qreal gradientPos = 1;
......@@ -158,14 +193,21 @@ void KisMultigridPatternGenerator::generate(KisProcessingInformation dstInfo,
qreal divisionRatio = 1-abs(qreal(rhomb.parallel1)/qreal(divisions));
divisionRatio *= 1-abs(qreal(rhomb.parallel2)/qreal(divisions));
gradientPos *= shapeRatio;
gradientPos *= intersectRatio;
gradientPos *= divisionRatio;
if (colorRatio!=0) {
gradientPos *= (shapeRatio*colorRatio);
}
if (colorIntersect!=0) {
gradientPos *= (intersectRatio*colorIntersect);
}
if (colorIndex!=0) {
gradientPos *= (divisionRatio*colorIndex);
}
grad.colorAt(c, gradientPos);
gc.setBackgroundColor(c);
gc.fillPainterPath(p, p.boundingRect().adjusted(-2, -2, 2, 2).toRect());
progress.step();
}
}
......@@ -174,15 +216,13 @@ void KisMultigridPatternGenerator::generate(KisProcessingInformation dstInfo,
}
}
QList<KisMultiGridRhomb> KisMultigridPatternGenerator::generateRhombs(int lines, int lineWidth, qreal offset, QRectF area) const
QList<KisMultiGridRhomb> KisMultigridPatternGenerator::generateRhombs(int lines, int divisions, qreal offset) const
{
QList<KisMultiGridRhomb> rhombs;
QList<QLineF> parallelLines;
QList<qreal> angles;
qreal radius = QLineF(area.topLeft(), area.topRight()).length();
int halfLines = radius/lineWidth;
int halfLines = divisions;
int totalLines = (halfLines*2) +1;
//setup our imaginary lines...
......
......@@ -76,7 +76,7 @@ public:
KisConfigWidget * createConfigurationWidget(QWidget* parent, const KisPaintDeviceSP dev, bool useForMasks) const override;
private:
QList<KisMultiGridRhomb> generateRhombs(int lines, int lineWidth, qreal offset, QRectF area) const;
QList<KisMultiGridRhomb> generateRhombs(int lines, int divisions, qreal offset) const;
QList<int> getIndicesFromPoint(QPointF point, QList<qreal> angles, qreal offset) const;
......
......@@ -6,12 +6,12 @@
<rect>
<x>0</x>
<y>0</y>
<width>282</width>
<height>227</height>
<width>323</width>
<height>440</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="4" rowspan="2">
<item row="0" column="1">
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
......@@ -27,40 +27,25 @@
</property>
</spacer>
</item>
<item row="0" column="0" rowspan="2" colspan="2">
<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>
<item row="0" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Shapes</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="KisSliderSpinBox" name="sldDimensions" native="true"/>
</item>
<item>
<widget class="KisSliderSpinBox" name="sldDivisions" native="true"/>
</item>
<item>
<widget class="KisDoubleSliderSpinBox" name="sldOffset" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="3" column="1">
<widget class="QLabel" name="lblDivisions">
<property name="text">
<string>Divisions:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLabel" name="lblColor2">
<property name="text">
<string>&amp;Color 2:</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="6" column="3">
<item row="3" column="0">
<spacer>
<property name="orientation">
<enum>Qt::Vertical</enum>
......@@ -76,53 +61,105 @@
</property>
</spacer>
</item>
<item row="5" column="3">
<widget class="QDoubleSpinBox" name="spnOffset">
<property name="minimum">
<double>0.010000000000000</double>
</property>
<property name="maximum">
<double>0.990000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="KisColorButton" name="bnColor2"/>
</item>
<item row="3" column="3">
<widget class="QSpinBox" name="spnDivisions"/>
</item>
<item row="0" column="3" rowspan="2">
<widget class="KisColorButton" name="bnColor1"/>
</item>
<item row="4" column="3">
<widget class="QSpinBox" name="spnDimensions"/>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Dimensions</string>
</property>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<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>
</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>
<item row="3" column="0" colspan="2">
<widget class="KisDoubleSliderSpinBox" name="sldColorIntersect" native="true"/>
</item>
<item row="4" column="0" colspan="2">
<widget class="KisDoubleSliderSpinBox" name="sldColorIndex" native="true"/>
</item>
</layout>
</widget>
</item>
<item row="5" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Offset</string>
</property>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Lines</string>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Line Color: </string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="KisColorButton" name="bnLineColor"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Line Width:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spnLineWidth"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KisDoubleSliderSpinBox</class>
<extends>QWidget</extends>
<header>kis_slider_spin_box.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KisColorButton</class>
<extends>QPushButton</extends>
<header>kis_color_button.h</header>
</customwidget>
<customwidget>
<class>KisSliderSpinBox</class>
<extends>QWidget</extends>
<header location="global">kis_slider_spin_box.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
......
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