Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit f3c3b972 authored by Wolthera van Hövell's avatar Wolthera van Hövell 🛍

Add connector lines.

I think that's the last thing on my list...
parent ec532bfd
......@@ -62,6 +62,11 @@ KisWdgMultigridPattern::KisWdgMultigridPattern(QWidget* parent, const KoColorSpa
widget()->sldColorIntersect->setRange(-2.0, 2.0, 2);
widget()->sldColorIntersect->setPrefix(i18n("Intersect:"));
widget()->cmbConnectorType->addItem(i18n("No Connectors"));
widget()->cmbConnectorType->addItem(i18n("Acute Angles"));
widget()->cmbConnectorType->addItem(i18n("Obtuse Angles"));
widget()->cmbConnectorType->addItem(i18n("Cross Shape"));
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()));
......@@ -74,6 +79,10 @@ KisWdgMultigridPattern::KisWdgMultigridPattern(QWidget* parent, const KoColorSpa
connect(m_widget->spnLineWidth, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->bnLineColor, SIGNAL(changed(const KoColor&)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->spnConnectorWidth, SIGNAL(valueChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->bnConnectorColor, SIGNAL(changed(const KoColor&)), this, SIGNAL(sigConfigurationUpdated()));
connect(m_widget->cmbConnectorType, SIGNAL(currentIndexChanged(int)), this, SIGNAL(sigConfigurationUpdated()));
}
KisWdgMultigridPattern::~KisWdgMultigridPattern()
......@@ -109,6 +118,12 @@ void KisWdgMultigridPattern::setConfiguration(const KisPropertiesConfigurationSP
widget()->sldColorIndex->setValue(config->getFloat("colorIndex", 1.0));
widget()->sldColorRatio->setValue(config->getFloat("colorRatio", 0.0));
widget()->sldColorIntersect->setValue(config->getFloat("colorIntersect", 0.0));
c = config->getColor("connectorColor");
c.convertTo(m_cs);
widget()->bnConnectorColor->setColor(c);
widget()->cmbConnectorType->setCurrentIndex(config->getInt("connectorType", 1));
widget()->spnConnectorWidth->setValue(config->getInt("connectorWidth", 1));
}
KisPropertiesConfigurationSP KisWdgMultigridPattern::configuration() const
......@@ -139,6 +154,12 @@ KisPropertiesConfigurationSP KisWdgMultigridPattern::configuration() const
config->setProperty("colorIndex", widget()->sldColorIndex->value());
config->setProperty("colorIntersect", widget()->sldColorIntersect->value());
c.fromKoColor(widget()->bnConnectorColor->color());
v.setValue(c);
config->setProperty("connectorColor", v);
config->setProperty("connectorType", widget()->cmbConnectorType->currentIndex());
config->setProperty("connectorWidth", widget()->spnConnectorWidth->value());
return config;
}
......
......@@ -95,6 +95,10 @@ KisFilterConfigurationSP KisMultigridPatternGenerator::defaultConfiguration(KisR
config->setProperty("colorRatio", 1.0);
config->setProperty("colorIndex", 0.0);
config->setProperty("colorIntersect", 0.0);
config->setProperty("connectorColor", v);
config->setProperty("connectorType", Connector::None);
config->setProperty("connectorWidth", 1);
return config;
}
......@@ -221,6 +225,81 @@ void KisMultigridPatternGenerator::generate(KisProcessingInformation dstInfo,
gc.fillPainterPath(p, p.boundingRect().adjusted(-2, -2, 2, 2).toRect());
int connectorType = config->getInt("connectorType", Connector::None);
if (connectorType != Connector::None) {
gc.setBackgroundColor(config->getColor("connectorColor"));
qreal connectorWidth = qreal(config->getInt("connectorWidth", 1))*.5;
QPainterPath pConnect;
qreal lower = connectorWidth/scale;
if (connectorType == Connector::Cross) {
QPointF cl = QLineF(shape.at(0), shape.at(1)).pointAt(0.5-lower);
pConnect.moveTo(cl);
cl = QLineF(shape.at(0), shape.at(1)).pointAt(0.5+lower);
pConnect.lineTo(cl);
cl = QLineF(shape.at(2), shape.at(3)).pointAt(0.5-lower);
pConnect.lineTo(cl);
cl = QLineF(shape.at(2), shape.at(3)).pointAt(0.5+lower);
pConnect.lineTo(cl);
pConnect.closeSubpath();
cl = QLineF(shape.at(1), shape.at(2)).pointAt(0.5-lower);
pConnect.moveTo(cl);
cl = QLineF(shape.at(1), shape.at(2)).pointAt(0.5+lower);
pConnect.lineTo(cl);
cl = QLineF(shape.at(3), shape.at(0)).pointAt(0.5-lower);
pConnect.lineTo(cl);
cl = QLineF(shape.at(3), shape.at(0)).pointAt(0.5+lower);
pConnect.lineTo(cl);
pConnect.closeSubpath();
gc.fillPainterPath(pConnect);
} else {
for (int i=1; i<shape.size(); i++) {
QPainterPath pAngle;
QPointF curPoint = shape.at(i);
QLineF l1(curPoint, shape.at(i-1));
QPointF np;
if (i==4) {
np = shape.at(1);
} else {
np = shape.at(i+1);
}
QLineF l2(curPoint, np);
qreal angleDiff = abs(fmod(abs(l1.angle()-l2.angle())+180, 360)-180);
if (round(angleDiff) == 90) {
continue;
}
if (angleDiff > 90 && connectorType == Connector::Acute) {
continue;
}
if (angleDiff < 90 && connectorType == Connector::Obtuse) {
continue;
}
qreal length = (l1.length()*0.5)-connectorWidth;
QRectF sweep(curPoint-QPointF(length, length), curPoint+QPointF(length, length));
length = (l1.length()*0.5)+connectorWidth;
QRectF sweep2(curPoint-QPointF(length, length), curPoint+QPointF(length, length));
pAngle.moveTo(shape.at(i));
pAngle.addEllipse(sweep2);
pAngle.addEllipse(sweep);
pAngle = pAngle.intersected(p);
pAngle.closeSubpath();
pConnect.addPath(pAngle);
}
pConnect.closeSubpath();
}
pConnect.setFillRule(Qt::WindingFill);
gc.fillPainterPath(pConnect);
}
progress.step();
}
}
......
......@@ -58,6 +58,13 @@ class KisMultigridPatternGenerator : public KisGenerator
{
public:
enum Connector{
None,
Acute,
Obtuse,
Cross
};
KisMultigridPatternGenerator();
using KisGenerator::generate;
......
......@@ -7,12 +7,12 @@
<x>0</x>
<y>0</y>
<width>323</width>
<height>440</height>
<height>508</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QGroupBox" name="groupBox_2">
<widget class="QGroupBox" name="gbShapes">
<property name="title">
<string>Shapes</string>
</property>
......@@ -30,36 +30,83 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_3">
<widget class="QGroupBox" name="gbLines">
<property name="title">
<string>Lines</string>
</property>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spnLineWidth"/>
</item>
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Line Color: </string>
<string>Color: </string>
</property>
</widget>
</item>
<item row="0" column="1">
<item>
<widget class="KisColorButton" name="bnLineColor"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gbConnector">
<property name="title">
<string>Connector Lines</string>
</property>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Line Width:</string>
<string>Type:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spnLineWidth"/>
<item row="0" column="1">
<widget class="QComboBox" name="cmbConnectorType"/>
</item>
<item row="1" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spnConnectorWidth"/>
</item>
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>Color:</string>
</property>
</widget>
</item>
<item>
<widget class="KisColorButton" name="bnConnectorColor">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<widget class="QGroupBox" name="gbColors">
<property name="title">
<string>Colors</string>
</property>
......
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