r14197 by fschmid - Added the ability to stroke lines with gradients (currently on screen only, pdf and ps to follow).

scribus-commit scribus-commit at lists.scribus.net
Tue Oct 20 11:20:56 CEST 2009


Revision: 14197
Author: fschmid
Date: 2009-10-20T06:38:53.033491Z
Commit message: Added the ability to stroke lines with gradients (currently on screen only, pdf and ps to follow).

Changeset: 
M  /trunk/Scribus/scribus/ui/propertiespalette.cpp
M  /trunk/Scribus/scribus/scribusview.h
M  /trunk/Scribus/scribus/canvas.cpp
M  /trunk/Scribus/scribus/pageitem.cpp
M  /trunk/Scribus/scribus/pageitem_pathtext.cpp
M  /trunk/Scribus/scribus/ui/propertiespalette.h
M  /trunk/Scribus/scribus/ui/cpalette.cpp
M  /trunk/Scribus/scribus/scribusdoc.cpp
M  /trunk/Scribus/scribus/pageitem_line.cpp
M  /trunk/Scribus/scribus/canvasmode_editgradient.cpp
M  /trunk/Scribus/scribus/ui/cpalette.h
M  /trunk/Scribus/scribus/scribusdoc.h
M  /trunk/Scribus/scribus/scribusview.cpp
M  /trunk/Scribus/scribus/pageitem_polyline.cpp

Diffs:
Index: scribus/canvasmode_editgradient.cpp
===================================================================
--- scribus/canvasmode_editgradient.cpp	(revision 14196)
+++ scribus/canvasmode_editgradient.cpp	(revision 14197)
@@ -179,15 +179,31 @@
 		double dx = fabs(Mxp - newX) + 5.0 / m_canvas->scale();
 		double dy = fabs(Myp - newY) + 5.0 / m_canvas->scale();
 		FPoint np(Mxp - newX, Myp - newY, 0, 0, currItem->rotation(), 1, 1, true);
-		if (m_gradientPoint == useGradientStart)
+		if (m_view->editStrokeGradient)
 		{
-			currItem->GrStartX -= np.x(); // (Mxp - newX); // / m_canvas->scale();
-			currItem->GrStartY -= np.y(); // (Myp - newY); // / m_canvas->scale();
+			if (m_gradientPoint == useGradientStart)
+			{
+				currItem->GrStrokeStartX -= np.x(); // (Mxp - newX); // / m_canvas->scale();
+				currItem->GrStrokeStartY -= np.y(); // (Myp - newY); // / m_canvas->scale();
+			}
+			if (m_gradientPoint == useGradientEnd)
+			{
+				currItem->GrStrokeEndX -= np.x(); // (Mxp - newX); // / m_canvas->scale();
+				currItem->GrStrokeEndY -= np.y(); // (Myp - newY); // / m_canvas->scale();
+			}
 		}
-		if (m_gradientPoint == useGradientEnd)
+		else
 		{
-			currItem->GrEndX -= np.x(); // (Mxp - newX); // / m_canvas->scale();
-			currItem->GrEndY -= np.y(); // (Myp - newY); // / m_canvas->scale();
+			if (m_gradientPoint == useGradientStart)
+			{
+				currItem->GrStartX -= np.x(); // (Mxp - newX); // / m_canvas->scale();
+				currItem->GrStartY -= np.y(); // (Myp - newY); // / m_canvas->scale();
+			}
+			if (m_gradientPoint == useGradientEnd)
+			{
+				currItem->GrEndX -= np.x(); // (Mxp - newX); // / m_canvas->scale();
+				currItem->GrEndY -= np.y(); // (Myp - newY); // / m_canvas->scale();
+			}
 		}
 		Mxp = newX;
 		Myp = newY;
@@ -223,9 +239,18 @@
 	PageItem *currItem = m_doc->m_Selection->itemAt(0);
 	itemMatrix.translate(currItem->xPos(), currItem->yPos());
 	itemMatrix.rotate(currItem->rotation());
-	QPointF gradientStart(currItem->GrStartX, currItem->GrStartY);
+	QPointF gradientStart, gradientEnd;
+	if (m_view->editStrokeGradient)
+	{
+		gradientStart = QPointF(currItem->GrStrokeStartX, currItem->GrStrokeStartY);
+		gradientEnd = QPointF(currItem->GrStrokeEndX, currItem->GrStrokeEndY);
+	}
+	else
+	{
+		gradientStart = QPointF(currItem->GrStartX, currItem->GrStartY);
+		gradientEnd = QPointF(currItem->GrEndX, currItem->GrEndY);
+	}
 	gradientStart = itemMatrix.map(gradientStart);
-	QPointF gradientEnd(currItem->GrEndX, currItem->GrEndY);
 	gradientEnd = itemMatrix.map(gradientEnd);
 	if (m_canvas->hitsCanvasPoint(m->globalPos(), gradientStart))
 		m_gradientPoint = useGradientStart;
Index: scribus/pageitem_line.cpp
===================================================================
--- scribus/pageitem_line.cpp	(revision 14196)
+++ scribus/pageitem_line.cpp	(revision 14197)
@@ -62,13 +62,42 @@
 				{
 					p->setPattern(&m_Doc->docPatterns[patternStrokeVal], patternStrokeScaleX, patternStrokeScaleY, patternStrokeOffsetX, patternStrokeOffsetY, patternStrokeRotation);
 					p->setStrokeMode(ScPainter::Pattern);
-					p->drawLine(FPoint(0, 0), FPoint(Width, 0));
 				}
+				else if (GrTypeStroke > 0)
+				{
+					if ((!gradientStrokeVal.isEmpty()) && (!m_Doc->docGradients.contains(gradientStrokeVal)))
+						gradientStrokeVal = "";
+					if (!(gradientStrokeVal.isEmpty()) && (m_Doc->docGradients.contains(gradientStrokeVal)))
+						stroke_gradient = m_Doc->docGradients[gradientStrokeVal];
+					if (stroke_gradient.Stops() < 2) // fall back to solid stroking if there are not enough colorstops in the gradient.
+					{
+						if (lineColor() != CommonStrings::None)
+						{
+							p->setBrush(strokeQColor);
+							p->setStrokeMode(ScPainter::Solid);
+						}
+						else
+							p->setStrokeMode(ScPainter::None);
+					}
+					else
+					{
+						p->setStrokeMode(ScPainter::Gradient);
+						p->stroke_gradient = stroke_gradient;
+						QTransform grm;
+						grm.rotate(Rot);
+						FPointArray gra;
+						if (GrTypeStroke == 6)
+							p->setGradient(VGradient::linear, FPoint(GrStrokeStartX, GrStrokeStartY), FPoint(GrStrokeEndX, GrStrokeEndY));
+						else
+						{
+							gra.setPoints(2, GrStrokeStartX, GrStrokeStartY, GrStrokeEndX, GrStrokeEndY);
+							p->setGradient(VGradient::radial, gra.point(0), gra.point(1), gra.point(0));
+						}
+					}
+				}
 				else if (lineColor() != CommonStrings::None)
-				{
 					p->setStrokeMode(ScPainter::Solid);
-					p->drawLine(FPoint(0, 0), FPoint(Width, 0));
-				}
+				p->drawLine(FPoint(0, 0), FPoint(Width, 0));
 			}
 			else
 			{
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp	(revision 14196)
+++ scribus/scribusdoc.cpp	(revision 14197)
@@ -110,7 +110,7 @@
 	void changed(PageItem* it)
 	{
 		it->invalidateLayout();
-		doc->regionsChanged()->update(it->getBoundingRect());
+		doc->regionsChanged()->update(it->getVisualBoundingRect());
 		doc->changed();
 	}
 };
@@ -5629,6 +5629,51 @@
 	}
 }
 
+void ScribusDoc::itemSelection_SetItemGradStroke(int typ)
+{
+	uint selectedItemCount=m_Selection->count();
+	if (selectedItemCount != 0)
+	{
+		m_updateManager.setUpdatesDisabled();
+		PageItem *currItem;
+		for (uint a = 0; a < selectedItemCount; ++a)
+		{
+			currItem = m_Selection->itemAt(a);
+			currItem->GrTypeStroke = typ;
+			if (currItem->GrTypeStroke == 0)
+			{
+				if (currItem->lineColor() != CommonStrings::None)
+				{
+					if (!PageColors.contains(currItem->lineColor()))
+					{
+						switch(currItem->itemType())
+						{
+							case PageItem::TextFrame:
+							case PageItem::PathText:
+								currItem->setLineColor(itemToolPrefs.textLineColor);
+								break;
+							case PageItem::Line:
+							case PageItem::PolyLine:
+							case PageItem::Polygon:
+							case PageItem::ImageFrame:
+							case PageItem::LatexFrame:
+								currItem->setLineColor(itemToolPrefs.shapeLineColor);
+								break;
+							default:
+								break;
+						}
+					}
+				}
+			}
+			if ((typ > 0) && (typ < 8))
+				currItem->updateGradientVectors();
+			currItem->update();
+		}
+		m_updateManager.setUpdatesEnabled();
+		changed();
+	}
+}
+
 void ScribusDoc::itemSelection_SetItemGradFill(int typ)
 {
 	uint selectedItemCount=m_Selection->count();
Index: scribus/scribusview.h
===================================================================
--- scribus/scribusview.h	(revision 14196)
+++ scribus/scribusview.h	(revision 14197)
@@ -159,6 +159,7 @@
 	bool Magnify;
 	bool storedFramesShown;
 	bool storedShowControls;
+	bool editStrokeGradient;
 	int redrawMode;
 	int redrawCount;
 	PageItem *redrawItem;
Index: scribus/pageitem_polyline.cpp
===================================================================
--- scribus/pageitem_polyline.cpp	(revision 14196)
+++ scribus/pageitem_polyline.cpp	(revision 14197)
@@ -101,13 +101,42 @@
 				{
 					p->setPattern(&m_Doc->docPatterns[patternStrokeVal], patternStrokeScaleX, patternStrokeScaleY, patternStrokeOffsetX, patternStrokeOffsetY, patternStrokeRotation);
 					p->setStrokeMode(ScPainter::Pattern);
-					p->strokePath();
 				}
+				else if (GrTypeStroke > 0)
+				{
+					if ((!gradientStrokeVal.isEmpty()) && (!m_Doc->docGradients.contains(gradientStrokeVal)))
+						gradientStrokeVal = "";
+					if (!(gradientStrokeVal.isEmpty()) && (m_Doc->docGradients.contains(gradientStrokeVal)))
+						stroke_gradient = m_Doc->docGradients[gradientStrokeVal];
+					if (stroke_gradient.Stops() < 2) // fall back to solid stroking if there are not enough colorstops in the gradient.
+					{
+						if (lineColor() != CommonStrings::None)
+						{
+							p->setBrush(strokeQColor);
+							p->setStrokeMode(ScPainter::Solid);
+						}
+						else
+							p->setStrokeMode(ScPainter::None);
+					}
+					else
+					{
+						p->setStrokeMode(ScPainter::Gradient);
+						p->stroke_gradient = stroke_gradient;
+						QTransform grm;
+						grm.rotate(Rot);
+						FPointArray gra;
+						if (GrTypeStroke == 6)
+							p->setGradient(VGradient::linear, FPoint(GrStrokeStartX, GrStrokeStartY), FPoint(GrStrokeEndX, GrStrokeEndY));
+						else
+						{
+							gra.setPoints(2, GrStrokeStartX, GrStrokeStartY, GrStrokeEndX, GrStrokeEndY);
+							p->setGradient(VGradient::radial, gra.point(0), gra.point(1), gra.point(0));
+						}
+					}
+				}
 				else if (lineColor() != CommonStrings::None)
-				{
 					p->setStrokeMode(ScPainter::Solid);
-					p->strokePath();
-				}
+				p->strokePath();
 			}
 			else
 			{
Index: scribus/canvas.cpp
===================================================================
--- scribus/canvas.cpp	(revision 14196)
+++ scribus/canvas.cpp	(revision 14197)
@@ -1161,10 +1161,20 @@
 	psx->rotate(currItem->rotation());
 	psx->setPen(QPen(Qt::blue, 1.0 / m_viewMode.scale, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
 	psx->setBrush(Qt::NoBrush);
-	psx->drawLine(QPointF(currItem->GrStartX, currItem->GrStartY), QPointF(currItem->GrEndX, currItem->GrEndY));
-	psx->setPen(QPen(Qt::magenta, 8.0 / m_viewMode.scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
-	psx->drawPoint(QPointF(currItem->GrStartX, currItem->GrStartY));
-	psx->drawPoint(QPointF(currItem->GrEndX, currItem->GrEndY));
+	if (m_view->editStrokeGradient)
+	{
+		psx->drawLine(QPointF(currItem->GrStrokeStartX, currItem->GrStrokeStartY), QPointF(currItem->GrStrokeEndX, currItem->GrStrokeEndY));
+		psx->setPen(QPen(Qt::magenta, 8.0 / m_viewMode.scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
+		psx->drawPoint(QPointF(currItem->GrStrokeStartX, currItem->GrStrokeStartY));
+		psx->drawPoint(QPointF(currItem->GrStrokeEndX, currItem->GrStrokeEndY));
+	}
+	else
+	{
+		psx->drawLine(QPointF(currItem->GrStartX, currItem->GrStartY), QPointF(currItem->GrEndX, currItem->GrEndY));
+		psx->setPen(QPen(Qt::magenta, 8.0 / m_viewMode.scale, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
+		psx->drawPoint(QPointF(currItem->GrStartX, currItem->GrStartY));
+		psx->drawPoint(QPointF(currItem->GrEndX, currItem->GrEndY));
+	}
 }
 
 
Index: scribus/pageitem_pathtext.cpp
===================================================================
--- scribus/pageitem_pathtext.cpp	(revision 14196)
+++ scribus/pageitem_pathtext.cpp	(revision 14197)
@@ -108,13 +108,42 @@
 				{
 					p->setPattern(&m_Doc->docPatterns[patternStrokeVal], patternStrokeScaleX, patternStrokeScaleY, patternStrokeOffsetX, patternStrokeOffsetY, patternStrokeRotation);
 					p->setStrokeMode(ScPainter::Pattern);
-					p->strokePath();
 				}
+				else if (GrTypeStroke > 0)
+				{
+					if ((!gradientStrokeVal.isEmpty()) && (!m_Doc->docGradients.contains(gradientStrokeVal)))
+						gradientStrokeVal = "";
+					if (!(gradientStrokeVal.isEmpty()) && (m_Doc->docGradients.contains(gradientStrokeVal)))
+						stroke_gradient = m_Doc->docGradients[gradientStrokeVal];
+					if (stroke_gradient.Stops() < 2) // fall back to solid stroking if there are not enough colorstops in the gradient.
+					{
+						if (lineColor() != CommonStrings::None)
+						{
+							p->setBrush(strokeQColor);
+							p->setStrokeMode(ScPainter::Solid);
+						}
+						else
+							p->setStrokeMode(ScPainter::None);
+					}
+					else
+					{
+						p->setStrokeMode(ScPainter::Gradient);
+						p->stroke_gradient = stroke_gradient;
+						QTransform grm;
+						grm.rotate(Rot);
+						FPointArray gra;
+						if (GrTypeStroke == 6)
+							p->setGradient(VGradient::linear, FPoint(GrStrokeStartX, GrStrokeStartY), FPoint(GrStrokeEndX, GrStrokeEndY));
+						else
+						{
+							gra.setPoints(2, GrStrokeStartX, GrStrokeStartY, GrStrokeEndX, GrStrokeEndY);
+							p->setGradient(VGradient::radial, gra.point(0), gra.point(1), gra.point(0));
+						}
+					}
+				}
 				else if (lineColor() != CommonStrings::None)
-				{
 					p->setStrokeMode(ScPainter::Solid);
-					p->strokePath();
-				}
+				p->strokePath();
 			}
 			else
 			{
Index: scribus/pageitem.cpp
===================================================================
--- scribus/pageitem.cpp	(revision 14196)
+++ scribus/pageitem.cpp	(revision 14197)
@@ -1163,7 +1163,7 @@
 			else
 				p->setFillMode(ScPainter::None);
 		}
-		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()))
+		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()) || (GrTypeStroke > 0))
 		{
 			p->setPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin);
 			if (DashValues.count() != 0)
@@ -1227,7 +1227,7 @@
 			{
 				if (lineBlendmode() != 0)
 					p->beginLayer(1.0 - lineTransparency(), lineBlendmode());
-				if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()))
+				if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()) || (GrTypeStroke > 0))
 				{
 					p->setPen(strokeQColor, m_lineWidth, PLineArt, PLineEnd, PLineJoin);
 					if (DashValues.count() != 0)
@@ -1246,6 +1246,38 @@
 							p->setPattern(&m_Doc->docPatterns[patternStrokeVal], patternStrokeScaleX, patternStrokeScaleY, patternStrokeOffsetX, patternStrokeOffsetY, patternStrokeRotation);
 							p->setStrokeMode(ScPainter::Pattern);
 						}
+						else if (GrTypeStroke > 0)
+						{
+							if ((!gradientStrokeVal.isEmpty()) && (!m_Doc->docGradients.contains(gradientStrokeVal)))
+								gradientStrokeVal = "";
+							if (!(gradientStrokeVal.isEmpty()) && (m_Doc->docGradients.contains(gradientStrokeVal)))
+								stroke_gradient = m_Doc->docGradients[gradientStrokeVal];
+							if (stroke_gradient.Stops() < 2) // fall back to solid stroking if there are not enough colorstops in the gradient.
+							{
+								if (lineColor() != CommonStrings::None)
+								{
+									p->setBrush(strokeQColor);
+									p->setStrokeMode(ScPainter::Solid);
+								}
+								else
+									p->setStrokeMode(ScPainter::None);
+							}
+							else
+							{
+								p->setStrokeMode(ScPainter::Gradient);
+								p->stroke_gradient = stroke_gradient;
+								QTransform grm;
+								grm.rotate(Rot);
+								FPointArray gra;
+								if (GrTypeStroke == 6)
+									p->setGradient(VGradient::linear, FPoint(GrStrokeStartX, GrStrokeStartY), FPoint(GrStrokeEndX, GrStrokeEndY));
+								else
+								{
+									gra.setPoints(2, GrStrokeStartX, GrStrokeStartY, GrStrokeEndX, GrStrokeEndY);
+									p->setGradient(VGradient::radial, gra.point(0), gra.point(1), gra.point(0));
+								}
+							}
+						}
 						else if (lineColor() != CommonStrings::None)
 						{
 							p->setStrokeMode(ScPainter::Solid);
@@ -1254,52 +1286,9 @@
 								p->setDash(DashValues, DashOffset);
 						}
 						p->strokePath();
-/*
-			else if ((GrType > 0) && (GrType < 8))
-			{
-				if ((!gradientVal.isEmpty()) && (!m_Doc->docGradients.contains(gradientVal)))
-					gradientVal = "";
-				if (!(gradientVal.isEmpty()) && (m_Doc->docGradients.contains(gradientVal)))
-					fill_gradient = m_Doc->docGradients[gradientVal];
-				if (fill_gradient.Stops() < 2) // fall back to solid filling if there are not enough colorstops in the gradient.
-				{
-					if (fillColor() != CommonStrings::None)
-					{
-						p->setBrush(fillQColor);
-						p->setFillMode(ScPainter::Solid);
 					}
 					else
-						p->setFillMode(ScPainter::None);
-				}
-				else
-				{
-					p->setStrokeMode(ScPainter::Gradient);
-					p->stroke_gradient = fill_gradient;
-					QTransform grm;
-					grm.rotate(Rot);
-					FPointArray gra;
-					switch (GrType)
 					{
-						case 1:
-						case 2:
-						case 3:
-						case 4:
-						case 6:
-							p->setGradient(VGradient::linear, FPoint(GrStartX, GrStartY), FPoint(GrEndX, GrEndY));
-							break;
-						case 5:
-						case 7:
-							gra.setPoints(2, GrStartX, GrStartY, GrEndX, GrEndY);
-							p->setGradient(VGradient::radial, gra.point(0), gra.point(1), gra.point(0));
-							break;
-					}
-				}
-				p->strokePath();
-			}
-*/
-					}
-					else
-					{
 						p->setStrokeMode(ScPainter::Solid);
 						multiLine ml = m_Doc->MLineStyles[NamedLStyle];
 						QColor tmp;
@@ -3967,6 +3956,17 @@
 				cstops.at(cst)->name = *it;
 		}
 	}
+
+	cstops = stroke_gradient.colorStops();
+	for (uint cst = 0; cst < stroke_gradient.Stops(); ++cst)
+	{
+		it = newNames.colors().find(cstops.at(cst)->name);
+		if (it != newNames.colors().end())
+		{
+			if (*it != CommonStrings::None)
+				cstops.at(cst)->name = *it;
+		}
+	}
 	if (effectsInUse.count() != 0)
 	{
 		QString col1 = CommonStrings::None;
@@ -4147,6 +4147,14 @@
 			lists.collectColor(cstops.at(cst)->name);
 		}
 	}
+	else if (GrTypeStroke > 0)
+	{
+		QList<VColorStop*> cstops = stroke_gradient.colorStops();
+		for (uint cst = 0; cst < stroke_gradient.Stops(); ++cst)
+		{
+			lists.collectColor(cstops.at(cst)->name);
+		}
+	}
 	if (effectsInUse.count() != 0)
 	{
 		for (int a = 0; a < effectsInUse.count(); ++a)
@@ -4591,7 +4599,7 @@
 	double extraSpace = 0.0;
 	if (NamedLStyle.isEmpty())
 	{
-		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()))
+		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()) || (GrTypeStroke > 0))
 			extraSpace = m_lineWidth / 2.0;
 	}
 	else
@@ -4742,7 +4750,7 @@
 	double extraSpace = 0.0;
 	if (NamedLStyle.isEmpty())
 	{
-		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()))
+		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()) || (GrTypeStroke > 0))
 			extraSpace = m_lineWidth / 2.0;
 	}
 	else
@@ -4760,7 +4768,7 @@
 	double extraSpace = 0.0;
 	if (NamedLStyle.isEmpty())
 	{
-		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()))
+		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()) || (GrTypeStroke > 0))
 			extraSpace = m_lineWidth / 2.0;
 	}
 	else
@@ -4778,7 +4786,7 @@
 	double extraSpace = 0.0;
 	if (NamedLStyle.isEmpty())
 	{
-		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()))
+		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()) || (GrTypeStroke > 0))
 			extraSpace = m_lineWidth;
 	}
 	else
@@ -4796,7 +4804,7 @@
 	double extraSpace = 0.0;
 	if (NamedLStyle.isEmpty())
 	{
-		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()))
+		if ((lineColor() != CommonStrings::None) || (!patternStrokeVal.isEmpty()) || (GrTypeStroke > 0))
 			extraSpace = m_lineWidth;
 	}
 	else
@@ -5144,6 +5152,40 @@
 				p->setPattern(&m_Doc->docPatterns[patternStrokeVal], patternStrokeScaleX, patternStrokeScaleY, patternStrokeOffsetX, patternStrokeOffsetY, patternStrokeRotation);
 				p->setFillMode(ScPainter::Pattern);
 			}
+			else if (GrTypeStroke > 0)
+			{
+				if ((!gradientStrokeVal.isEmpty()) && (!m_Doc->docGradients.contains(gradientStrokeVal)))
+					gradientStrokeVal = "";
+				if (!(gradientStrokeVal.isEmpty()) && (m_Doc->docGradients.contains(gradientStrokeVal)))
+					stroke_gradient = m_Doc->docGradients[gradientStrokeVal];
+				if (stroke_gradient.Stops() < 2) // fall back to solid stroking if there are not enough colorstops in the gradient.
+				{
+					if (lineColor() != CommonStrings::None)
+					{
+						p->setBrush(strokeQColor);
+						p->setBrushOpacity(1.0 - lineTransparency());
+						p->setLineWidth(0);
+						p->setFillMode(ScPainter::Solid);
+					}
+					else
+						p->setFillMode(ScPainter::None);
+				}
+				else
+				{
+					p->setFillMode(ScPainter::Gradient);
+					p->fill_gradient = stroke_gradient;
+					QTransform grm;
+					grm.rotate(Rot);
+					FPointArray gra;
+					if (GrTypeStroke == 6)
+						p->setGradient(VGradient::linear, FPoint(GrStrokeStartX, GrStrokeStartY), FPoint(GrStrokeEndX, GrStrokeEndY));
+					else
+					{
+						gra.setPoints(2, GrStrokeStartX, GrStrokeStartY, GrStrokeEndX, GrStrokeEndY);
+						p->setGradient(VGradient::radial, gra.point(0), gra.point(1), gra.point(0));
+					}
+				}
+			}
 			else if (lineColor() != CommonStrings::None)
 			{
 				p->setBrush(strokeQColor);
Index: scribus/scribusdoc.h
===================================================================
--- scribus/scribusdoc.h	(revision 14196)
+++ scribus/scribusdoc.h	(revision 14197)
@@ -1217,6 +1217,7 @@
 
 	void itemSelection_SetItemPen(QString farbe);
 	void itemSelection_SetItemPenShade(int sha);
+	void itemSelection_SetItemGradStroke(int typ);
 	void itemSelection_SetItemBrush(QString farbe);
 	void itemSelection_SetItemBrushShade(int sha);
 	void itemSelection_SetItemGradFill(int typ);
Index: scribus/scribusview.cpp
===================================================================
--- scribus/scribusview.cpp	(revision 14196)
+++ scribus/scribusview.cpp	(revision 14197)
@@ -1356,7 +1356,10 @@
 	QRect rect = currItem->getRedrawBounding(m_canvas->scale());
 	m_canvas->Transform(currItem, matrix);
 	FPointArray fpNew;
-	fpNew.setPoints(2, currItem->GrStartX, currItem->GrStartY, currItem->GrEndX, currItem->GrEndY);
+	if (editStrokeGradient)
+		fpNew.setPoints(2, currItem->GrStrokeStartX, currItem->GrStrokeStartY, currItem->GrStrokeEndX, currItem->GrStrokeEndY);
+	else
+		fpNew.setPoints(2, currItem->GrStartX, currItem->GrStartY, currItem->GrEndX, currItem->GrEndY);
 	fpNew.map(matrix);
 	if (dx < 8.0) dx = 8.0;
 	if (dy < 8.0) dy = 8.0;
Index: scribus/ui/cpalette.cpp
===================================================================
--- scribus/ui/cpalette.cpp	(revision 14196)
+++ scribus/ui/cpalette.cpp	(revision 14197)
@@ -323,9 +323,12 @@
 	connect(patternBoxStroke, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(selectPatternS(QListWidgetItem*)));
 	connect(tabWidgetStroke, SIGNAL(currentChanged(int)), this, SLOT(slotGradStroke(int)));
 	connect(editPatternPropsStroke, SIGNAL(clicked()), this, SLOT(changePatternPropsStroke()));
+	connect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradientStroke(const QString &)));
+	connect(gradientTypeStroke, SIGNAL(activated(int)), this, SLOT(slotGradTypeStroke(int)));
+	connect(gradEditButtonStroke, SIGNAL(clicked()), this, SLOT(editGradientVectorStroke()));
 	editFillColorSelector->setChecked(true);
 	editFillColorSelectorButton();
-	tabWidgetStroke->setTabEnabled(1, false);
+//	tabWidgetStroke->setTabEnabled(1, false);
 }
 
 void Cpalette::setCurrentItem(PageItem* item)
@@ -366,7 +369,10 @@
 	setActFarben(currentItem->lineColor(), currentItem->fillColor(), currentItem->lineShade(), currentItem->fillShade());
 	ChooseGrad(currentItem->GrType);
 	gradEdit->setGradient(currentItem->fill_gradient);
+	gradEditStroke->setGradient(currentItem->stroke_gradient);
 	disconnect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
+	disconnect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradientStroke(const QString &)));
+	disconnect(tabWidgetStroke, SIGNAL(currentChanged(int)), this, SLOT(slotGradStroke(int)));
 	if (!currentItem->gradient().isEmpty())
 	{
 		setCurrentComboItem(namedGradient, currentItem->gradient());
@@ -377,6 +383,16 @@
 		namedGradient->setCurrentIndex(0);
 		gradEdit->setGradientEditable(true);
 	}
+	if (!currentItem->strokeGradient().isEmpty())
+	{
+		setCurrentComboItem(namedGradientStroke, currentItem->strokeGradient());
+		gradEditStroke->setGradientEditable(false);
+	}
+	else
+	{
+		namedGradientStroke->setCurrentIndex(0);
+		gradEditStroke->setGradientEditable(true);
+	}
 	if (patternList->count() == 0)
 	{
 		tabWidgetStroke->setTabEnabled(2, false);
@@ -387,11 +403,15 @@
 		tabWidgetStroke->setTabEnabled(2, true);
 		tabWidget->setTabEnabled(2, true);
 	}
-	if (currentItem->strokePattern().isEmpty())
+	if (!currentItem->strokePattern().isEmpty())
+		tabWidgetStroke->setCurrentIndex(2);
+	else if (currentItem->GrTypeStroke > 0)
+		tabWidgetStroke->setCurrentIndex(1);
+	else
 		tabWidgetStroke->setCurrentIndex(0);
-	else
-		tabWidgetStroke->setCurrentIndex(2);
 	connect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
+	connect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradientStroke(const QString &)));
+	connect(tabWidgetStroke, SIGNAL(currentChanged(int)), this, SLOT(slotGradStroke(int)));
 }
 
 void Cpalette::updateCList()
@@ -551,6 +571,7 @@
 void Cpalette::updateGradientList()
 {
 	disconnect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
+	disconnect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradientStroke(const QString &)));
 	namedGradient->clear();
 	namedGradient->setIconSize(QSize(48, 12));
 	namedGradient->addItem( tr("Custom"));
@@ -580,6 +601,7 @@
 		namedGradientStroke->addItem(pm, it.key());
 	}
 	connect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
+	connect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradientStroke(const QString &)));
 }
 
 void Cpalette::SetGradients(QMap<QString, VGradient> *docGradients)
@@ -602,8 +624,32 @@
 		gradEdit->setGradientEditable(false);
 		currentItem->setGradient(name);
 	}
+	if (gradientType->currentIndex() == 0)
+		emit NewGradient(6);
+	else
+		emit NewGradient(7);
 }
 
+void Cpalette::setNamedGradientStroke(const QString &name)
+{
+	if (namedGradientStroke->currentIndex() == 0)
+	{
+		gradEditStroke->setGradient(currentItem->stroke_gradient);
+		currentItem->setStrokeGradient("");
+		gradEditStroke->setGradientEditable(true);
+	}
+	else
+	{
+		gradEditStroke->setGradient(gradientList->value(name));
+		gradEditStroke->setGradientEditable(false);
+		currentItem->setStrokeGradient(name);
+	}
+	if (gradientTypeStroke->currentIndex() == 0)
+		emit NewGradientS(6);
+	else
+		emit NewGradientS(7);
+}
+
 void Cpalette::updatePatternList()
 {
 	disconnect(patternBox, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(selectPattern(QListWidgetItem*)));
@@ -696,7 +742,7 @@
 {
 	if (number == 1)
 	{
-//		disconnect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
+		disconnect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradientStroke(const QString &)));
 		if (!currentItem->strokeGradient().isEmpty())
 		{
 			setCurrentComboItem(namedGradientStroke, currentItem->strokeGradient());
@@ -709,16 +755,24 @@
 			gradEditStroke->setGradient(currentItem->stroke_gradient);
 			gradEditStroke->setGradientEditable(true);
 		}
-//		if (gradientType->currentIndex() == 0)
-//			emit NewGradient(6);
-//		else
-//			currentItem->GrType = 7;
-//		connect(namedGradient, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradient(const QString &)));
+		emit NewPatternS("");
+		if (gradientTypeStroke->currentIndex() == 0)
+			emit NewGradientS(6);
+		else
+			emit NewGradientS(7);
+		connect(namedGradientStroke, SIGNAL(activated(const QString &)), this, SLOT(setNamedGradientStroke(const QString &)));
 	}
-//	else if (number == 2)
-//		emit NewGradient(8);
+	else if (number == 2)
+	{
+		emit NewGradient(0);
+		if (patternBoxStroke->currentItem())
+			emit NewPatternS(patternBoxStroke->currentItem()->text());
+	}
 	else
+	{
+		emit NewGradient(0);
 		emit NewPatternS("");
+	}
 }
 
 void Cpalette::ChooseGrad(int number)
@@ -788,6 +842,14 @@
 		emit NewGradient(7);
 }
 
+void Cpalette::slotGradTypeStroke(int type)
+{
+	if (type == 0)
+		emit NewGradientS(6);
+	else
+		emit NewGradientS(7);
+}
+
 void Cpalette::setActGradient(int typ)
 {
 	ChooseGrad(typ);
@@ -805,15 +867,35 @@
 	{
 		CGradDia->hide();
 	}
-	emit editGradient();
+	editStrokeGradient = false;
+	emit editGradient(editStrokeGradient);
 }
 
+void Cpalette::editGradientVectorStroke()
+{
+	if (gradEditButtonStroke->isChecked())
+	{
+		CGradDia->unitChange(currentDoc->unitIndex());
+		CGradDia->setValues(currentItem->GrStrokeStartX, currentItem->GrStrokeStartY, currentItem->GrStrokeEndX, currentItem->GrStrokeEndY);
+		CGradDia->show();
+	}
+	else
+	{
+		CGradDia->hide();
+	}
+	editStrokeGradient = true;
+	emit editGradient(editStrokeGradient);
+}
+
 void Cpalette::setActiveGradDia(bool active)
 {
 	if (!active)
 	{
-		gradEditButton->setChecked(false);
-		emit editGradient();
+		if (editStrokeGradient)
+			gradEditButtonStroke->setChecked(false);
+		else
+			gradEditButton->setChecked(false);
+		emit editGradient(editStrokeGradient);
 	}
 }
 
Index: scribus/ui/cpalette.h
===================================================================
--- scribus/ui/cpalette.h	(revision 14196)
+++ scribus/ui/cpalette.h	(revision 14197)
@@ -147,6 +147,7 @@
 	void SetPatterns(QMap<QString, ScPattern> *docPatterns);
 	void SetGradients(QMap<QString, VGradient> *docGradients);
 	void setNamedGradient(const QString &name);
+	void setNamedGradientStroke(const QString &name);
 	void selectPattern(QListWidgetItem *c);
 	void selectPatternS(QListWidgetItem *c);
 	void updatePatternList();
@@ -160,8 +161,10 @@
 	void ChooseGrad(int nr);
 	void slotGrad(int nr);
 	void slotGradType(int type);
+	void slotGradTypeStroke(int type);
 	void setActGradient(int typ);
 	void editGradientVector();
+	void editGradientVectorStroke();
 	void setActiveGradDia(bool active);
 	void setSpecialGradient(double x1, double y1, double x2, double y2);
 	void changePatternProps();
@@ -173,6 +176,7 @@
 	void NewPenShade(int);
 	void NewBrushShade(int);
 	void NewGradient(int);
+	void NewGradientS(int);
 	void NewPattern(QString);
 	void NewPatternProps(double, double, double, double, double);
 	void NewPatternS(QString);
@@ -184,7 +188,7 @@
 	void NewBlendS(int);
 	void NewOverprint(int);
 	void gradientChanged();
-	void editGradient();
+	void editGradient(bool);
 
 protected:
 	GradientVectorDialog* CGradDia;
@@ -205,6 +209,7 @@
 	double m_Pattern_offsetYS;
 	double m_Pattern_rotationS;
 	int currentUnit;
+	bool editStrokeGradient;
 };
 
 #endif
Index: scribus/ui/propertiespalette.h
===================================================================
--- scribus/ui/propertiespalette.h	(revision 14196)
+++ scribus/ui/propertiespalette.h	(revision 14197)
@@ -289,7 +289,7 @@
 	void MakeIrre(int f, int c, qreal *vals);
 	void NewTDist();
 	void NewSpGradient(double x1, double y1, double x2, double y2);
-	void toggleGradientEdit();
+	void toggleGradientEdit(bool);
 	void DoRevert();
 	void doClearCStyle();
 	void doClearPStyle();
Index: scribus/ui/propertiespalette.cpp
===================================================================
--- scribus/ui/propertiespalette.cpp	(revision 14196)
+++ scribus/ui/propertiespalette.cpp	(revision 14197)
@@ -1589,7 +1589,7 @@
 //	connect( colgapLabel, SIGNAL( clicked() ), this, SLOT( HandleGapSwitch() ) );
 	connect(colgapLabel, SIGNAL(activated(int)), this, SLOT(HandleGapSwitch()));
 	connect( Cpal, SIGNAL(NewSpecial(double, double, double, double )), this, SLOT(NewSpGradient(double, double, double, double )));
-	connect( Cpal, SIGNAL(editGradient()), this, SLOT(toggleGradientEdit()));
+	connect( Cpal, SIGNAL(editGradient(bool)), this, SLOT(toggleGradientEdit(bool)));
 	connect(startArrow, SIGNAL(activated(int)), this, SLOT(setStartArrow(int )));
 	connect(endArrow, SIGNAL(activated(int)), this, SLOT(setEndArrow(int )));
 // 	connect(lineSpacingPop, SIGNAL(triggered(QAction *)), this, SLOT(setLspMode(QAction *)));
@@ -1809,6 +1809,12 @@
 			LSize->setEnabled(setter);
 			LJoinStyle->setEnabled(setter);
 			LEndStyle->setEnabled(setter);
+			disconnect(LineMode, SIGNAL(activated(int)), this, SLOT(NewLineMode()));
+			if (LMode)
+				LineMode->setCurrentIndex(1);
+			else
+				LineMode->setCurrentIndex(0);
+			connect(LineMode, SIGNAL(activated(int)), this, SLOT(NewLineMode()));
 		}
 		else if (t == idColorsItem)
 		{
@@ -1859,6 +1865,7 @@
 	disconnect(this->Cpal, SIGNAL(NewPenShade(int)), 0, 0);
 	disconnect(this->Cpal, SIGNAL(NewBrushShade(int)), 0, 0);
 	disconnect(this->Cpal, SIGNAL(NewGradient(int)), 0, 0);
+	disconnect(this->Cpal, SIGNAL(NewGradientS(int)), 0, 0);
 	disconnect(this->Cpal, SIGNAL(NewBlend(int)), 0, 0);
 	disconnect(this->Cpal, SIGNAL(NewBlendS(int)), 0, 0);
 	disconnect(this->Cpal, SIGNAL(NewPattern(QString)), 0, 0);
@@ -1938,6 +1945,7 @@
 	connect(this->Cpal, SIGNAL(NewPenShade(int)), doc, SLOT(itemSelection_SetItemPenShade(int)));
 	connect(this->Cpal, SIGNAL(NewBrushShade(int)), doc, SLOT(itemSelection_SetItemBrushShade(int)));
 	connect(this->Cpal, SIGNAL(NewGradient(int)), doc, SLOT(itemSelection_SetItemGradFill(int)));
+	connect(this->Cpal, SIGNAL(NewGradientS(int)), doc, SLOT(itemSelection_SetItemGradStroke(int)));
 	connect(this->Cpal, SIGNAL(NewPattern(QString)), doc, SLOT(itemSelection_SetItemPatternFill(QString)));
 	connect(this->Cpal, SIGNAL(NewPatternProps(double, double, double, double, double)), doc, SLOT(itemSelection_SetItemPatternProps(double, double, double, double, double)));
 	connect(this->Cpal, SIGNAL(NewOverprint(int)), this, SLOT(handleOverprint(int)));
@@ -2053,6 +2061,7 @@
 	disconnect(startArrow, SIGNAL(activated(int)), this, SLOT(setStartArrow(int )));
 	disconnect(endArrow, SIGNAL(activated(int)), this, SLOT(setEndArrow(int )));
 	disconnect(TabStack, SIGNAL(currentChanged(int)), this, SLOT(SelTab(int)));
+	disconnect(LineMode, SIGNAL(activated(int)), this, SLOT(NewLineMode()));
 
 
 	HaveItem = false;
@@ -2172,10 +2181,15 @@
 		dashEditor->setDashValues(CurItem->dashes(), qMax(CurItem->lineWidth(), 0.001), CurItem->dashOffset());
 		dashEditor->show();
 	}
+	if (LMode)
+		LineMode->setCurrentIndex(1);
+	else
+		LineMode->setCurrentIndex(0);
 	connect(StyledLine, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(SetSTline(QListWidgetItem*)));
 	connect(NameEdit, SIGNAL(Leaved()), this, SLOT(NewName()));
 	connect(startArrow, SIGNAL(activated(int)), this, SLOT(setStartArrow(int )));
 	connect(endArrow, SIGNAL(activated(int)), this, SLOT(setEndArrow(int )));
+	connect(LineMode, SIGNAL(activated(int)), this, SLOT(NewLineMode()));
 
 //CB replaces old emits from PageItem::emitAllToGUI()
 	disconnect(Xpos, SIGNAL(valueChanged(double)), this, SLOT(NewX()));
@@ -4575,28 +4589,52 @@
 		return;
 	if ((HaveDoc) && (HaveItem))
 	{
-		CurItem->GrStartX = x1 / m_unitRatio;
-		CurItem->GrStartY = y1 / m_unitRatio;
-		CurItem->GrEndX = x2 / m_unitRatio;
-		CurItem->GrEndY = y2 / m_unitRatio;
-		CurItem->update();
-		QRectF upRect(QPointF(CurItem->GrStartX, CurItem->GrStartY), QPointF(CurItem->GrEndX, CurItem->GrEndY));
+		QRectF upRect;
+		if (m_ScMW->view->editStrokeGradient)
+		{
+			CurItem->GrStrokeStartX = x1 / m_unitRatio;
+			CurItem->GrStrokeStartY = y1 / m_unitRatio;
+			CurItem->GrStrokeEndX = x2 / m_unitRatio;
+			CurItem->GrStrokeEndY = y2 / m_unitRatio;
+			CurItem->update();
+			upRect = QRectF(QPointF(CurItem->GrStrokeStartX, CurItem->GrStrokeStartY), QPointF(CurItem->GrStrokeEndX, CurItem->GrStrokeEndY));
+		}
+		else
+		{
+			CurItem->GrStartX = x1 / m_unitRatio;
+			CurItem->GrStartY = y1 / m_unitRatio;
+			CurItem->GrEndX = x2 / m_unitRatio;
+			CurItem->GrEndY = y2 / m_unitRatio;
+			CurItem->update();
+			upRect = QRectF(QPointF(CurItem->GrStartX, CurItem->GrStartY), QPointF(CurItem->GrEndX, CurItem->GrEndY));
+		}
 		upRect.translate(CurItem->xPos(), CurItem->yPos());
 		doc->regionsChanged()->update(upRect.adjusted(-10.0, -10.0, 10.0, 10.0));
 		emit DocChanged();
 	}
 }
 
-void PropertiesPalette::toggleGradientEdit()
+void PropertiesPalette::toggleGradientEdit(bool stroke)
 {
 	if (!m_ScMW || m_ScMW->ScriptRunning)
 		return;
 	if ((HaveDoc) && (HaveItem))
 	{
-		if (Cpal->gradEditButton->isChecked())
-			m_ScMW->view->requestMode(modeEditGradientVectors);
+		m_ScMW->view->editStrokeGradient = stroke;
+		if (stroke)
+		{
+			if (Cpal->gradEditButtonStroke->isChecked())
+				m_ScMW->view->requestMode(modeEditGradientVectors);
+			else
+				m_ScMW->view->requestMode(modeNormal);
+		}
 		else
-			m_ScMW->view->requestMode(modeNormal);
+		{
+			if (Cpal->gradEditButton->isChecked())
+				m_ScMW->view->requestMode(modeEditGradientVectors);
+			else
+				m_ScMW->view->requestMode(modeNormal);
+		}
 		m_ScMW->view->RefreshGradient(CurItem);
 	}
 }




More information about the scribus-commit mailing list