r23905 by jghali - Make gradient related code more easily understandable

scribus-commit scribus-commit at lists.scribus.net
Fri Jun 26 00:59:52 UTC 2020


Author: jghali
Date: Fri Jun 26 00:59:52 2020
New Revision: 23905

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23905
Log:
Make gradient related code more easily understandable

Modified:
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/ui/cpalette.cpp

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23905&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp	(original)
+++ trunk/Scribus/scribus/scribusdoc.cpp	Fri Jun 26 00:59:52 2020
@@ -8134,7 +8134,7 @@
 		currItem->setGradientType(typ);
 		switch (currItem->gradientType())
 		{
-			case 0:
+			case Gradient_None:
 				if (currItem->fillColor() != CommonStrings::None)
 				{
 					if (!PageColors.contains(currItem->fillColor()))
@@ -8161,23 +8161,23 @@
 					}
 				}
 				break;
-			case 1:
+			case Gradient_LinearLegacy1:
 				currItem->setGradientStart(0.0, currItem->height() / 2.0);
 				currItem->setGradientEnd(currItem->width(), currItem->height() / 2.0);
 				break;
-			case 2:
+			case Gradient_LinearLegacy2:
 				currItem->setGradientStart(currItem->width() / 2.0, 0.0);
 				currItem->setGradientEnd(currItem->width() / 2.0, currItem->height());
 				break;
-			case 3:
+			case Gradient_LinearLegacy3:
 				currItem->setGradientStart(0.0, 0.0);
 				currItem->setGradientEnd(currItem->width(), currItem->height());
 				break;
-			case 4:
+			case Gradient_LinearLegacy4:
 				currItem->setGradientStart(0.0, currItem->height());
 				currItem->setGradientEnd(currItem->width(), 0.0);
 				break;
-			case 5:
+			case Gradient_RadialLegacy5:	
 				currItem->setGradientStart(currItem->width() / 2.0, currItem->height() / 2.0);
 				if (currItem->width() >= currItem->height())
 					currItem->setGradientEnd(currItem->width(), currItem->height() / 2.0);
@@ -8191,7 +8191,7 @@
 		}
 		if ((typ > 0) && (typ < 8))
 			currItem->updateGradientVectors();
-		if (currItem->gradientType() == 13)
+		if (currItem->gradientType() == Gradient_Conical)
 			currItem->createConicalMesh();
 		currItem->update();
 	}
@@ -11337,7 +11337,7 @@
 		PageItem *currItem;
 		currItem = itemSelection->itemAt(i);
 		currItem->setFillGradient(newGradient);
-		if (currItem->gradientType() == 13)
+		if (currItem->gradientType() == Gradient_Conical)
 			currItem->createConicalMesh();
 		currItem->update();
 	}

Modified: trunk/Scribus/scribus/ui/cpalette.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23905&path=/trunk/Scribus/scribus/ui/cpalette.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/cpalette.cpp	(original)
+++ trunk/Scribus/scribus/ui/cpalette.cpp	Fri Jun 26 00:59:52 2020
@@ -756,7 +756,7 @@
 	double t4 = color4Alpha->value() / 100.0;
 	UndoTransaction trans;
 	if (UndoManager::undoEnabled())
-		trans = undoManager->beginTransaction(Um::Selection,Um::IFill,Um::GradVal,"",Um::IFill);
+		trans = undoManager->beginTransaction(Um::Selection, Um::IFill, Um::GradVal, QString(), Um::IFill);
 	currentItem->set4ColorShade(static_cast<int>(color1Shade->value()), static_cast<int>(color2Shade->value()), static_cast<int>(color3Shade->value()), static_cast<int>(color4Shade->value()));
 	currentItem->set4ColorTransparency(t1, t2, t3, t4);
 	currentItem->set4ColorColors(color1, color2, color3, color4);
@@ -780,20 +780,20 @@
 		currentItem->setGradient(name);
 	}
 	if (gradientType->currentIndex() == 0)
-		emit NewGradient(6);
+		emit NewGradient(Gradient_Linear);
 	else if (gradientType->currentIndex() == 1)
-		emit NewGradient(7);
+		emit NewGradient(Gradient_Radial);
 	else if (gradientType->currentIndex() == 2)
-		emit NewGradient(13);
+		emit NewGradient(Gradient_Conical);
 	else if (gradientType->currentIndex() == 3)
 	{
 		setGradientColors();
-		emit NewGradient(9);
+		emit NewGradient(Gradient_4Colors);
 	}
 	else if (gradientType->currentIndex() == 4)
-		emit NewGradient(10);
+		emit NewGradient(Gradient_Diamond);
 	else if (gradientType->currentIndex() == 5)
-		emit NewGradient(11);
+		emit NewGradient(Gradient_Mesh);
 }
 
 void ColorPalette::setNamedGradientStroke(const QString &name)
@@ -811,9 +811,9 @@
 		currentItem->setStrokeGradient(name);
 	}
 	if (gradientTypeStroke->currentIndex() == 0)
-		emit NewGradientS(6);
-	else
-		emit NewGradientS(7);
+		emit NewGradientS(Gradient_Linear);
+	else
+		emit NewGradientS(Gradient_Radial);
 }
 
 void ColorPalette::updatePatternList()
@@ -949,20 +949,20 @@
 		}
 		emit NewPatternS("");
 		if (gradientTypeStroke->currentIndex() == 0)
-			emit NewGradientS(6);
+			emit NewGradientS(Gradient_Linear);
 		else
-			emit NewGradientS(7);
+			emit NewGradientS(Gradient_Radial);
 		namedGradientStroke->blockSignals(sigBlocked);
 	}
 	else if (number == 2)
 	{
-		emit NewGradientS(8);
+		emit NewGradientS(Gradient_Pattern);
 		if (patternBoxStroke->currentItem())
 			emit NewPatternS(patternBoxStroke->currentItem()->text());
 	}
 	else
 	{
-		emit NewGradientS(0);
+		emit NewGradientS(Gradient_None);
 		emit NewPatternS("");
 	}
 	strokeModeStack->setCurrentIndex(number);
@@ -1070,7 +1070,7 @@
 		if (patternList->count() == 0)
 		{
 			fillModeCombo->setCurrentIndex(0);
-			emit NewGradient(0);
+			emit NewGradient(Gradient_None);
 		}
 		else
 			fillModeCombo->setCurrentIndex(3);
@@ -1101,7 +1101,7 @@
 		if (patternList->count() == 0)
 		{
 			strokeModeCombo->setCurrentIndex(0);
-			emit NewGradient(0);
+			emit NewGradient(Gradient_None);
 		}
 		else
 			strokeModeCombo->setCurrentIndex(2);
@@ -1132,17 +1132,17 @@
 		if (gradientType->currentIndex() == 0)
 		{
 			stackedWidget_2->setCurrentIndex(0);
-			emit NewGradient(6);
+			emit NewGradient(Gradient_Linear);
 		}
 		else if (gradientType->currentIndex() == 1)
 		{
 			stackedWidget_2->setCurrentIndex(0);
-			emit NewGradient(7);
+			emit NewGradient(Gradient_Radial);
 		}
 		else if (gradientType->currentIndex() == 2)
 		{
 			stackedWidget_2->setCurrentIndex(0);
-			emit NewGradient(13);
+			emit NewGradient(Gradient_Conical);
 		}
 		else if (gradientType->currentIndex() == 3)
 		{
@@ -1171,12 +1171,12 @@
 			color2Shade->setValue(currentItem->GrCol2Shade);
 			color3Shade->setValue(currentItem->GrCol3Shade);
 			color4Shade->setValue(currentItem->GrCol4Shade);
-			emit NewGradient(9);
+			emit NewGradient(Gradient_4Colors);
 		}
 		else if (gradientType->currentIndex() == 4)
 		{
 			stackedWidget_2->setCurrentIndex(0);
-			emit NewGradient(10);
+			emit NewGradient(Gradient_Diamond);
 		}
 		else if (gradientType->currentIndex() == 5)
 		{
@@ -1188,12 +1188,12 @@
 				shadeMeshPoint->setValue(mp.shade);
 				transparencyMeshPoint->setValue(mp.transparency * 100);
 			}
-			emit NewGradient(11);
+			emit NewGradient(Gradient_Mesh);
 		}
 		else if (gradientType->currentIndex() == 6)
 		{
 			stackedWidget_2->setCurrentIndex(2);
-			emit NewGradient(12);
+			emit NewGradient(Gradient_PatchMesh);
 		}
 		gradEdit->blockSignals(sigBlocked1);
 		gradientType->blockSignals(sigBlocked2);
@@ -1213,12 +1213,12 @@
 		}
 		else
 			setCurrentComboItem(hatchBackground, CommonStrings::None);
-		emit NewGradient(14);
+		emit NewGradient(Gradient_Hatch);
 	}
 	else if (number == 3)
-		emit NewGradient(8);
-	else
-		emit NewGradient(0);
+		emit NewGradient(Gradient_Pattern);
+	else
+		emit NewGradient(Gradient_None);
 	fillModeStack->setCurrentIndex(number);
 }
 
@@ -1227,17 +1227,17 @@
 	if (type == 0)
 	{
 		stackedWidget_2->setCurrentIndex(0);
-		emit NewGradient(6);
+		emit NewGradient(Gradient_Linear);
 	}
 	else if (type == 1)
 	{
 		stackedWidget_2->setCurrentIndex(0);
-		emit NewGradient(7);
+		emit NewGradient(Gradient_Radial);
 	}
 	else if (type == 2)
 	{
 		stackedWidget_2->setCurrentIndex(0);
-		emit NewGradient(13);
+		emit NewGradient(Gradient_Conical);
 	}
 	else if (type == 3)
 	{
@@ -1266,12 +1266,12 @@
 		color2Shade->setValue(currentItem->GrCol2Shade);
 		color3Shade->setValue(currentItem->GrCol3Shade);
 		color4Shade->setValue(currentItem->GrCol4Shade);
-		emit NewGradient(9);
+		emit NewGradient(Gradient_4Colors);
 	}
 	else if (type == 4)
 	{
 		stackedWidget_2->setCurrentIndex(0);
-		emit NewGradient(10);
+		emit NewGradient(Gradient_Diamond);
 	}
 	else if (type == 5)
 	{
@@ -1283,21 +1283,21 @@
 			shadeMeshPoint->setValue(mp.shade);
 			transparencyMeshPoint->setValue(mp.transparency * 100);
 		}
-		emit NewGradient(11);
+		emit NewGradient(Gradient_Mesh);
 	}
 	else if (type == 6)
 	{
 		stackedWidget_2->setCurrentIndex(2);
-		emit NewGradient(12);
+		emit NewGradient(Gradient_PatchMesh);
 	}
 }
 
 void ColorPalette::slotGradTypeStroke(int type)
 {
 	if (type == 0)
-		emit NewGradientS(6);
-	else
-		emit NewGradientS(7);
+		emit NewGradientS(Gradient_Linear);
+	else
+		emit NewGradientS(Gradient_Radial);
 }
 
 void ColorPalette::editMeshPointColor()
@@ -1803,7 +1803,7 @@
 	m_Pattern_mirrorY = dia->FlipV->isChecked();
 	delete dia;
 	fillModeCombo->setCurrentIndex(3);
-	emit NewGradient(8);
+	emit NewGradient(Gradient_Pattern);
 }
 
 void ColorPalette::changePatternPropsStroke()




More information about the scribus-commit mailing list