110 QLinearGradient gradient;
111 gradient.setColorAt(0, Qt::green);
112 gradient.setColorAt(1.0, Qt::blue);
114 if (config->hasProperty(
"gradientXML")) {
116 doc.setContent(config->getString(
"gradientXML",
""));
118 if (gradient.
stops().size() > 0) {
119 grad->setStops(gradient.
stops());
123 int divisions = config->getInt(
"divisions", 1);
124 int dimensions = config->getInt(
"dimensions", 5);
125 qreal offset = config->getFloat(
"offset", .2);
126 QRectF
bounds(QPoint(), size);
128 KoColor lineColor = config->getColor(
"lineColor");
130 int lineWidth = config->getInt(
"lineWidth", 1);
132 qreal colorRatio = config->getFloat(
"colorRatio", 1.0);
133 qreal colorIndex = config->getFloat(
"colorIndex", 0.0);
134 qreal colorIntersect = config->getFloat(
"colorIntersect", 0.0);
136 qreal diameter = QLineF(
bounds.topLeft(),
bounds.bottomRight()).length();
137 qreal scale = diameter/2/divisions;
155 tf.scale(scale, scale);
156 if (dimensions%2>0) {
157 tf.rotateRadians((
M_PI/dimensions)*0.5);
159 KoColor c = grad->stops()[0].color;
160 for (
int i= 0; i < rhombs.size(); i++){
162 QPolygonF shape = tf.map(rhomb.
shape);
164 QPointF center = shape.at(0)+shape.at(1)+shape.at(2)+shape.at(3);
165 center.setX(center.x()/4.0);
166 center.setY(center.y()/4.0);
168 QTransform lineWidthTransform;
170 qreal scaleForLineWidth = qMax(1-(qreal(lineWidth)/scale), 0.0);
171 lineWidthTransform.scale(scaleForLineWidth, scaleForLineWidth);
172 QPointF scaledCenter = lineWidthTransform.map(center);
173 lineWidthTransform.reset();
175 lineWidthTransform.translate(center.x()-scaledCenter.x(), center.y()-scaledCenter.y());
176 lineWidthTransform.scale(scaleForLineWidth, scaleForLineWidth);
178 shape = lineWidthTransform.map(shape);
179 if (shape.intersects(
bounds) && shape.boundingRect().width()>0) {
181 p.addPolygon(lineWidthTransform.map(shape));
183 qreal gradientPos = 1;
185 qreal w1 = QLineF (shape.at(0), shape.at(2)).length();
186 qreal w2 = QLineF (shape.at(1), shape.at(3)).length();
187 qreal shapeRatio = qMin(w1, w2)/qMax(w1, w2);
189 qreal intersectRatio = qreal(rhomb.
line1)/qreal(dimensions);
190 intersectRatio += qreal(rhomb.
line2)/qreal(dimensions);
191 intersectRatio *= 0.5;
193 qreal indexRatio = 1-abs(qreal(rhomb.
parallel1)/qreal(divisions/2.0));
194 indexRatio *= 1-abs(qreal(rhomb.
parallel2)/qreal(divisions/2.0));
197 gradientPos *= 1-(shapeRatio*colorRatio);
199 gradientPos *= 1-((1-shapeRatio)*abs(colorRatio));
201 if (colorIntersect>=0) {
202 gradientPos *= 1-(intersectRatio*colorIntersect);
204 gradientPos *= 1-((1-intersectRatio)*abs(colorIntersect));
207 gradientPos *= 1-(indexRatio*colorIndex);
209 gradientPos *= 1-((1-indexRatio)*abs(colorIndex));
212 grad->colorAt(c, gradientPos);
221 qreal connectorWidth = qreal(config->getInt(
"connectorWidth", 1))*.5;
222 QPainterPath pConnect;
223 qreal lower = connectorWidth/scale;
226 QPointF cl = QLineF(shape.at(0), shape.at(1)).pointAt(0.5-lower);
228 cl = QLineF(shape.at(0), shape.at(1)).pointAt(0.5+lower);
230 cl = QLineF(shape.at(2), shape.at(3)).pointAt(0.5-lower);
232 cl = QLineF(shape.at(2), shape.at(3)).pointAt(0.5+lower);
234 pConnect.closeSubpath();
236 cl = QLineF(shape.at(1), shape.at(2)).pointAt(0.5-lower);
238 cl = QLineF(shape.at(1), shape.at(2)).pointAt(0.5+lower);
240 cl = QLineF(shape.at(3), shape.at(0)).pointAt(0.5-lower);
242 cl = QLineF(shape.at(3), shape.at(0)).pointAt(0.5+lower);
244 pConnect.closeSubpath();
247 QPointF cW(connectorWidth, connectorWidth);
249 QRectF dot (shape.at(0)-cW, shape.at(0)+cW);
250 pConnect.addEllipse(dot);
251 dot = QRectF(shape.at(1)-cW, shape.at(1)+cW);
252 pConnect.addEllipse(dot);
253 dot = QRectF(shape.at(2)-cW, shape.at(2)+cW);
254 pConnect.addEllipse(dot);
255 dot = QRectF(shape.at(3)-cW, shape.at(3)+cW);
256 pConnect.addEllipse(dot);
257 pConnect = pConnect.intersected(
p);
261 QRectF dot (center-QPointF(connectorWidth, connectorWidth), center+QPointF(connectorWidth, connectorWidth));
262 pConnect.addEllipse(dot);
265 for (
int i=1; i<shape.size(); i++) {
267 QPointF curPoint = shape.at(i);
268 QLineF l1(curPoint, shape.at(i-1));
275 QLineF l2(curPoint, np);
276 qreal angleDiff = abs(fmod(abs(l1.angle()-l2.angle())+180, 360)-180);
278 if (round(angleDiff) == 90) {
288 qreal
length = (l1.length()*0.5)-connectorWidth;
290 length = (l1.length()*0.5)+connectorWidth;
293 pAngle.moveTo(shape.at(i));
294 pAngle.addEllipse(sweep2);
295 pAngle.addEllipse(sweep);
296 pAngle = pAngle.intersected(
p);
297 pAngle.closeSubpath();
298 pConnect.addPath(pAngle);
300 pConnect.closeSubpath();
303 pConnect.setFillRule(Qt::WindingFill);
322 int halfLines = divisions;
323 int totalLines = (halfLines*2) +1;
326 int dimensions = lines;
327 for (
int i = 0; i< dimensions; i++) {
328 qreal angle = 2*(
M_PI/lines)*i;
329 angles.append(angle);
333 for (
int i = 0; i <angles.size(); i++ ) {
334 qreal angle1 = angles.at(i);
335 QPointF
p1(totalLines*cos(angle1), -totalLines*sin(angle1));
339 for (
int parallel1 = 0; parallel1 < totalLines; parallel1++) {
340 int index1 = halfLines-parallel1;
342 QPointF offset1((index1+offset)*sin(angle1), (index1+offset)*cos(angle1));
344 l1.translate(offset1);
346 for (
int k = i+1; k <angles.size(); k++ ) {
347 qreal angle2 = angles.at(k);
348 QPointF
p3(totalLines*cos(angle2), -totalLines*sin(angle2));
352 for (
int parallel2 = 0; parallel2 < totalLines; parallel2++) {
353 int index2 = halfLines-parallel2;
355 QPointF offset2((index2+offset)*sin(angle2), (index2+offset)*cos(angle2));
357 l2.translate(offset2);
361 if (l1.intersects(l2, &intersect) == QLineF::BoundedIntersection) {
366 indices[i] = index1+1;
367 indices[k] = index2+1;
370 indices[k] = index2+1;
375 indices[i] = index1+1;
378 indices[i] = index1+1;
379 indices[k] = index2+1;
389 rhombs.append(rhomb);