r15771 by fschmid - Unified color testing code when importing vector graphics. Besides some code reduce it should also lowering the number of imported colors.

scribus-commit scribus-commit at lists.scribus.net
Fri Nov 5 16:33:39 CET 2010


Author: fschmid
Date: Fri Nov  5 15:33:39 2010
New Revision: 15771

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15771
Log:
Unified color testing code when importing vector graphics. Besides some code reduce it should also lowering the number of imported colors.

Modified:
    trunk/Scribus/scribus/plugins/import/ai/importai.cpp
    trunk/Scribus/scribus/plugins/import/cgm/importcgm.cpp
    trunk/Scribus/scribus/plugins/import/cvg/importcvg.cpp
    trunk/Scribus/scribus/plugins/import/drw/importdrw.cpp
    trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp
    trunk/Scribus/scribus/plugins/import/pct/importpct.cpp
    trunk/Scribus/scribus/plugins/import/ps/importps.cpp
    trunk/Scribus/scribus/plugins/import/svg/svgplugin.cpp
    trunk/Scribus/scribus/plugins/import/wmf/wmfimport.cpp
    trunk/Scribus/scribus/plugins/import/wpg/importwpg.cpp
    trunk/Scribus/scribus/plugins/import/xar/importxar.cpp
    trunk/Scribus/scribus/sccolor.cpp
    trunk/Scribus/scribus/sccolor.h
    trunk/Scribus/scribus/util_color.cpp

Modified: trunk/Scribus/scribus/plugins/import/ai/importai.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/ai/importai.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/ai/importai.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/ai/importai.cpp Fri Nov  5 15:33:39 2010
@@ -958,8 +958,8 @@
 					FarNam = QString::fromUtf8(farN.constData());
 					cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * yc), qRound(255 * k));
 					cc.setSpotColor(true);
-					if ((!CustColors.contains(FarNam)) && (!FarNam.isEmpty()))
-						CustColors.insert(FarNam, cc);
+					if (!FarNam.isEmpty())
+						CustColors.tryAddColor(FarNam, cc);
 					while (!ts.atEnd())
 					{
 						quint64 oldPos = ts.device()->pos();
@@ -989,8 +989,8 @@
 						FarNam = QString::fromUtf8(farN.constData());
 						cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * yc), qRound(255 * k));
 						cc.setSpotColor(true);
-						if ((!CustColors.contains(FarNam)) && (!FarNam.isEmpty()))
-							CustColors.insert(FarNam, cc);
+						if (!FarNam.isEmpty())
+							CustColors.tryAddColor(FarNam, cc);
 					}
 				}
 			}
@@ -1022,8 +1022,8 @@
 					}
 					FarNam = QString::fromUtf8(farN.constData());
 					cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * yc));
-					if ((!CustColors.contains(FarNam)) && (!FarNam.isEmpty()))
-						CustColors.insert(FarNam, cc);
+					if (!FarNam.isEmpty())
+						CustColors.tryAddColor(FarNam, cc);
 					while (!ts.atEnd())
 					{
 						quint64 oldPos = ts.device()->pos();
@@ -1052,8 +1052,8 @@
 						}
 						FarNam = QString::fromUtf8(farN.constData());
 						cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * yc));
-						if ((!CustColors.contains(FarNam)) && (!FarNam.isEmpty()))
-							CustColors.insert(FarNam, cc);
+						if (!FarNam.isEmpty())
+							CustColors.tryAddColor(FarNam, cc);
 					}
 				}
 			}
@@ -1108,8 +1108,7 @@
 							}
 							cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * yc), qRound(255 * k));
 							cc.setSpotColor(true);
-							if (!CustColors.contains(FarNam))
-								CustColors.insert(FarNam, cc);
+							CustColors.tryAddColor(FarNam, cc);
 						}
 					}
 				}
@@ -1153,9 +1152,7 @@
 		return ret;
 	double c, m, y, k;
 	ScColor tmp;
-	ColorList::Iterator it;
 	ScTextStream Code(&data, QIODevice::ReadOnly);
-	bool found = false;
 	Code >> c;
 	Code >> m;
 	Code >> y;
@@ -1164,30 +1161,14 @@
 	int Mc = qRound(m * 255);
 	int Yc = qRound(y * 255);
 	int Kc = qRound(k * 255);
-	int hC, hM, hY, hK;
 	tmp.setColor(Cc, Mc, Yc, Kc);
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelCMYK)
-		{
-			it.value().getCMYK(&hC, &hM, &hY, &hK);
-			if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
-			{
-				ret = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		QString namPrefix = "FromAI";
-		m_Doc->PageColors.insert(namPrefix+tmp.name(), tmp);
-		importedColors.append(namPrefix+tmp.name());
-		ret = namPrefix+tmp.name();
-	}
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	QString namPrefix = "FromAI";
+	QString fNam = m_Doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	if (fNam == namPrefix+tmp.name())
+		importedColors.append(fNam);
+	ret = fNam;
 	return ret;
 }
 
@@ -1200,33 +1181,16 @@
 	ScColor tmp;
 	ColorList::Iterator it;
 	ScTextStream Code(&data, QIODevice::ReadOnly);
-	bool found = false;
 	Code >> k;
 	int Kc = 255 - qRound(k * 255);
-	int hC, hM, hY, hK;
 	tmp.setColor(0, 0, 0, Kc);
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelCMYK)
-		{
-			it.value().getCMYK(&hC, &hM, &hY, &hK);
-			if ((hC == 0) && (hM == 0) && (hY == 0) && (Kc == hK))
-			{
-				ret = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		QString namPrefix = "FromAI";
-		m_Doc->PageColors.insert(namPrefix+tmp.name(), tmp);
-		importedColors.append(namPrefix+tmp.name());
-		ret = namPrefix+tmp.name();
-	}
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	QString namPrefix = "FromAI";
+	QString fNam = m_Doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	if (fNam == namPrefix+tmp.name())
+		importedColors.append(fNam);
+	ret = fNam;
 	return ret;
 }
 
@@ -1237,39 +1201,21 @@
 		return ret;
 	double r, g, b;
 	ScColor tmp;
-	ColorList::Iterator it;
 	ScTextStream Code(&data, QIODevice::ReadOnly);
-	bool found = false;
 	Code >> r;
 	Code >> g;
 	Code >> b;
 	int Rc = qRound(r * 255);
 	int Gc = qRound(g * 255);
 	int Bc = qRound(b * 255);
-	int hR, hG, hB;
 	tmp.setColorRGB(Rc, Gc, Bc);
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelRGB)
-		{
-			it.value().getRGB(&hR, &hG, &hB);
-			if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-			{
-				ret = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		QString namPrefix = "FromAI";
-		m_Doc->PageColors.insert(namPrefix+tmp.name(), tmp);
-		importedColors.append(namPrefix+tmp.name());
-		ret = namPrefix+tmp.name();
-	}
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	QString namPrefix = "FromAI";
+	QString fNam = m_Doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	if (fNam == namPrefix+tmp.name())
+		importedColors.append(fNam);
+	ret = fNam;
 	return ret;
 }
 
@@ -1280,9 +1226,7 @@
 		return ret;
 	double c, m, y, k, sh;
 	ScColor tmp;
-	ColorList::Iterator it;
 	ScTextStream Code(&data, QIODevice::ReadOnly);
-	bool found = false;
 	Code >> c;
 	Code >> m;
 	Code >> y;
@@ -1300,29 +1244,13 @@
 	int Mc = qRound(m * 255);
 	int Yc = qRound(y * 255);
 	int Kc = qRound(k * 255);
-	int hC, hM, hY, hK;
 	tmp.setColor(Cc, Mc, Yc, Kc);
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelCMYK)
-		{
-			it.value().getCMYK(&hC, &hM, &hY, &hK);
-			if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
-			{
-				ret = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		tmp.setSpotColor(true);
-		tmp.setRegistrationColor(false);
-		m_Doc->PageColors.insert(FarNam, tmp);
+	tmp.setSpotColor(true);
+	tmp.setRegistrationColor(false);
+	QString fNam = m_Doc->PageColors.tryAddColor(FarNam, tmp);
+	if (fNam == FarNam)
 		importedColors.append(FarNam);
-		ret = FarNam;
-	}
+	ret = fNam;
 	return ret;
 }
 
@@ -1333,9 +1261,7 @@
 		return ret;
 	double c, m, y, k, sh, r, g, b;
 	ScColor tmp;
-	ColorList::Iterator it;
 	ScTextStream Code(&data, QIODevice::ReadOnly);
-	bool found = false;
 	if (type == "1")
 	{
 		Code >> r;
@@ -1344,21 +1270,7 @@
 		int Rc = qRound(r * 255);
 		int Gc = qRound(g * 255);
 		int Bc = qRound(b * 255);
-		int hR, hG, hB;
 		tmp.setColorRGB(Rc, Gc, Bc);
-		for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-		{
-			if (it.value().getColorModel() == colorModelRGB)
-			{
-				it.value().getRGB(&hR, &hG, &hB);
-				if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-				{
-					ret = it.key();
-					found = true;
-					break;
-				}
-			}
-		}
 	}
 	else
 	{
@@ -1370,21 +1282,7 @@
 		int Mc = qRound(m * 255);
 		int Yc = qRound(y * 255);
 		int Kc = qRound(k * 255);
-		int hC, hM, hY, hK;
 		tmp.setColor(Cc, Mc, Yc, Kc);
-		for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-		{
-			if (it.value().getColorModel() == colorModelCMYK)
-			{
-				it.value().getCMYK(&hC, &hM, &hY, &hK);
-				if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
-				{
-					ret = it.key();
-					found = true;
-					break;
-				}
-			}
-		}
 	}
 	QString tmpS = data;
 	int an = data.indexOf("(");
@@ -1395,15 +1293,13 @@
 	ScTextStream Val(&FarSha, QIODevice::ReadOnly);
 	Val >> sh;
 	shade = (1.0 - sh) * 100.0;
-	if (!found)
-	{
-		if (type == "0")
-			tmp.setSpotColor(true);
-		tmp.setRegistrationColor(false);
-		m_Doc->PageColors.insert(FarNam, tmp);
+	if (type == "0")
+		tmp.setSpotColor(true);
+	tmp.setRegistrationColor(false);
+	QString fNam = m_Doc->PageColors.tryAddColor(FarNam, tmp);
+	if (fNam == FarNam)
 		importedColors.append(FarNam);
-		ret = FarNam;
-	}
+	ret = fNam;
 	return ret;
 }
 

Modified: trunk/Scribus/scribus/plugins/import/cgm/importcgm.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/cgm/importcgm.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/cgm/importcgm.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/cgm/importcgm.cpp Fri Nov  5 15:33:39 2010
@@ -2566,61 +2566,9 @@
 
 QString CgmPlug::handleColor(ScColor &color, QString proposedName)
 {
-	QString tmpName = CommonStrings::None;
-	int hR, hG, hB, hK;
-	int pR, pG, pB, pC, pM, pY, pK;
-	bool found = false;
-	ColorList::Iterator it;
-	if (color.getColorModel() == colorModelRGB)
-		color.getRGB(&pR, &pG, &pB);
-	else
-		color.getCMYK(&pC, &pM, &pY, &pK);
-	if ((!proposedName.isEmpty()) && ((proposedName == "White") || (proposedName == "Black") || (m_Doc->PageColors.contains(proposedName))))
-		tmpName = proposedName;
-	else
-	{
-		if (color.getColorModel() == colorModelRGB)
-		{
-			for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-			{
-				if (it.value().getColorModel() == colorModelRGB)
-				{
-					it.value().getRGB(&hR, &hG, &hB);
-					if ((pR == hR) && (pG == hG) && (pB == hB))
-					{
-						tmpName = it.key();
-						found = true;
-						break;
-					}
-				}
-			}
-			if (!found)
-			{
-				m_Doc->PageColors.insert(proposedName, color);
-				importedColors.append(proposedName);
-				tmpName = proposedName;
-			}
-		}
-		else
-		{
-			for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-			{
-				it.value().getCMYK(&hR, &hG, &hB, &hK);
-				if ((pC == hR) && (pM == hG) && (pY == hB) && (pK == hK))
-				{
-					tmpName = it.key();
-					found = true;
-					break;
-				}
-			}
-			if (!found)
-			{
-				m_Doc->PageColors.insert(proposedName, color);
-				importedColors.append(proposedName);
-				tmpName = proposedName;
-			}
-		}
-	}
+	QString tmpName = m_Doc->PageColors.tryAddColor(proposedName, color);
+	if (tmpName == proposedName)
+		importedColors.append(tmpName);
 	return tmpName;
 }
 

Modified: trunk/Scribus/scribus/plugins/import/cvg/importcvg.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/cvg/importcvg.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/cvg/importcvg.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/cvg/importcvg.cpp Fri Nov  5 15:33:39 2010
@@ -585,76 +585,36 @@
 void CvgPlug::parseColor(quint32 dataF, quint32 dataS, bool color, quint16 flag)
 {
 	ScColor tmp;
-	ColorList::Iterator it;
 	CurrColorFill = CommonStrings::None;
 	CurrFillShade = 100.0;
 	CurrColorStroke = CommonStrings::None;
 	CurrStrokeShade = 100.0;
 	QColor c;
-	int Rc, Gc, Bc, hR, hG, hB;
 	if (color)
 	{
-		bool found = false;
 		if ((flag == 0x0080) || (flag == 0x0200))
 		{
 			c.setRgb(dataF);
-			Rc = c.red();
-			Gc = c.green();
-			Bc = c.blue();
-			for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-			{
-				if (it.value().getColorModel() == colorModelRGB)
-				{
-					it.value().getRGB(&hR, &hG, &hB);
-					if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-					{
-						CurrColorFill = it.key();
-						found = true;
-						break;
-					}
-				}
-			}
-			if (!found)
-			{
-				tmp.fromQColor(c);
-				tmp.setSpotColor(false);
-				tmp.setRegistrationColor(false);
-				QString newColorName = "FromCVG"+c.name();
-				m_Doc->PageColors.insert(newColorName, tmp);
-				importedColors.append(newColorName);
-				CurrColorFill = newColorName;
-			}
+			tmp.fromQColor(c);
+			tmp.setSpotColor(false);
+			tmp.setRegistrationColor(false);
+			QString newColorName = "FromCVG"+c.name();
+			QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
+			if (fNam == newColorName)
+				importedColors.append(fNam);
+			CurrColorFill = fNam;
 		}
 		if ((flag == 0x0080) || (flag == 0x0100))
 		{
-			found = false;
 			c.setRgb(dataS);
-			Rc = c.red();
-			Gc = c.green();
-			Bc = c.blue();
-			for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-			{
-				if (it.value().getColorModel() == colorModelRGB)
-				{
-					it.value().getRGB(&hR, &hG, &hB);
-					if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-					{
-						CurrColorStroke = it.key();
-						found = true;
-						break;
-					}
-				}
-			}
-			if (!found)
-			{
-				tmp.fromQColor(c);
-				tmp.setSpotColor(false);
-				tmp.setRegistrationColor(false);
-				QString newColorName = "FromCVG"+c.name();
-				m_Doc->PageColors.insert(newColorName, tmp);
-				importedColors.append(newColorName);
-				CurrColorStroke = newColorName;
-			}
+			tmp.fromQColor(c);
+			tmp.setSpotColor(false);
+			tmp.setRegistrationColor(false);
+			QString newColorName = "FromCVG"+c.name();
+			QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
+			if (fNam == newColorName)
+				importedColors.append(fNam);
+			CurrColorStroke = fNam;
 		}
 	}
 	else

Modified: trunk/Scribus/scribus/plugins/import/drw/importdrw.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/drw/importdrw.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/drw/importdrw.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/drw/importdrw.cpp Fri Nov  5 15:33:39 2010
@@ -2045,61 +2045,9 @@
 
 QString DrwPlug::handleColor(ScColor &color, QString proposedName)
 {
-	QString tmpName = CommonStrings::None;
-	int hR, hG, hB, hK;
-	int pR, pG, pB, pC, pM, pY, pK;
-	bool found = false;
-	ColorList::Iterator it;
-	if (color.getColorModel() == colorModelRGB)
-		color.getRGB(&pR, &pG, &pB);
-	else
-		color.getCMYK(&pC, &pM, &pY, &pK);
-	if ((!proposedName.isEmpty()) && ((proposedName == "White") || (proposedName == "Black") || (m_Doc->PageColors.contains(proposedName))))
-		tmpName = proposedName;
-	else
-	{
-		if (color.getColorModel() == colorModelRGB)
-		{
-			for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-			{
-				if (it.value().getColorModel() == colorModelRGB)
-				{
-					it.value().getRGB(&hR, &hG, &hB);
-					if ((pR == hR) && (pG == hG) && (pB == hB))
-					{
-						tmpName = it.key();
-						found = true;
-						break;
-					}
-				}
-			}
-			if (!found)
-			{
-				m_Doc->PageColors.insert(proposedName, color);
-				importedColors.append(proposedName);
-				tmpName = proposedName;
-			}
-		}
-		else
-		{
-			for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-			{
-				it.value().getCMYK(&hR, &hG, &hB, &hK);
-				if ((pC == hR) && (pM == hG) && (pY == hB) && (pK == hK))
-				{
-					tmpName = it.key();
-					found = true;
-					break;
-				}
-			}
-			if (!found)
-			{
-				m_Doc->PageColors.insert(proposedName, color);
-				importedColors.append(proposedName);
-				tmpName = proposedName;
-			}
-		}
-	}
+	QString tmpName = m_Doc->PageColors.tryAddColor(proposedName, color);
+	if (tmpName == proposedName)
+		importedColors.append(tmpName);
 	return tmpName;
 }
 

Modified: trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/oodraw/oodrawimp.cpp Fri Nov  5 15:33:39 2010
@@ -1612,33 +1612,14 @@
 		else
 			c = parseColorN( rgbColor );
 	}
-	ColorList::Iterator it;
-	bool found = false;
-	int r, g, b;
-	QColor tmpR;
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelRGB)
-		{
-			it.value().getRGB(&r, &g, &b);
-			tmpR.setRgb(r, g, b);
-			if (c == tmpR)
-			{
-				ret = it.key();
-				found = true;
-			}
-		}
-	}
-	if (!found)
-	{
-		ScColor tmp;
-		tmp.fromQColor(c);
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		m_Doc->PageColors.insert("FromOODraw"+c.name(), tmp);
-		importedColors.append("FromOODraw"+c.name());
-		ret = "FromOODraw"+c.name();
-	}
+	ScColor tmp;
+	tmp.fromQColor(c);
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	QString fNam = m_Doc->PageColors.tryAddColor("FromOODraw"+c.name(), tmp);
+	if (fNam == "FromOODraw"+c.name())
+		importedColors.append(fNam);
+	ret = fNam;
 	return ret;
 }
 

Modified: trunk/Scribus/scribus/plugins/import/pct/importpct.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/pct/importpct.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pct/importpct.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/pct/importpct.cpp Fri Nov  5 15:33:39 2010
@@ -1106,7 +1106,6 @@
 	handleLineModeEnd();
 	QString tmpName = CommonStrings::None;
 	ScColor tmp;
-	ColorList::Iterator it;
 	quint16 Rc, Gc, Bc;
 	quint32 colVal;
 	ts >> colVal;
@@ -1163,30 +1162,15 @@
 	redC = qRound((Rc / 65535.0) * 255.0);
 	greenC = qRound((Gc / 65535.0) * 255.0);
 	blueC = qRound((Bc / 65535.0) * 255.0);
-	bool found = false;
 	QColor c = QColor(redC, greenC, blueC);
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelRGB)
-		{
-			it.value().getRGB(&hR, &hG, &hB);
-			if ((redC == hR) && (greenC == hG) && (blueC == hB))
-			{
-				tmpName = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		tmp.setColorRGB(redC, greenC, blueC);
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		tmpName = "FromPict"+c.name();
-		m_Doc->PageColors.insert(tmpName, tmp);
+	tmp.setColorRGB(redC, greenC, blueC);
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	tmpName = "FromPict"+c.name();
+	QString fNam = m_Doc->PageColors.tryAddColor(tmpName, tmp);
+	if (fNam == tmpName)
 		importedColors.append(tmpName);
-	}
+	tmpName = fNam;
 	if (back)
 	{
 		CurrColorFill = tmpName;
@@ -1211,30 +1195,15 @@
 	redC = qRound((Rc / 65535.0) * 255.0);
 	greenC = qRound((Gc / 65535.0) * 255.0);
 	blueC = qRound((Bc / 65535.0) * 255.0);
-	bool found = false;
 	QColor c = QColor(redC, greenC, blueC);
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelRGB)
-		{
-			it.value().getRGB(&hR, &hG, &hB);
-			if ((redC == hR) && (greenC == hG) && (blueC == hB))
-			{
-				tmpName = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		tmp.setColorRGB(redC, greenC, blueC);
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		tmpName = "FromPict"+c.name();
-		m_Doc->PageColors.insert(tmpName, tmp);
+	tmp.setColorRGB(redC, greenC, blueC);
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	tmpName = "FromPict"+c.name();
+	QString fNam = m_Doc->PageColors.tryAddColor(tmpName, tmp);
+	if (fNam == tmpName)
 		importedColors.append(tmpName);
-	}
+	tmpName = fNam;
 	if (back)
 	{
 		CurrColorFill = tmpName;

Modified: trunk/Scribus/scribus/plugins/import/ps/importps.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/ps/importps.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/ps/importps.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/ps/importps.cpp Fri Nov  5 15:33:39 2010
@@ -1024,9 +1024,7 @@
 		return ret;
 	double c, m, y, k, r, g, b;
 	ScColor tmp;
-	ColorList::Iterator it;
 	ScTextStream Code(&vals, QIODevice::ReadOnly);
-	bool found = false;
 	if (model == colorModelRGB)
 	{
 		Code >> r;
@@ -1040,21 +1038,7 @@
 		int Rc = qRound(r * 255);
 		int Gc = qRound(g * 255);
 		int Bc = qRound(b * 255);
-		int hR, hG, hB;
 		tmp.setColorRGB(Rc, Gc, Bc);
-		for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-		{
-			if (it.value().getColorModel() == colorModelRGB)
-			{
-				it.value().getRGB(&hR, &hG, &hB);
-				if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-				{
-					ret = it.key();
-					found = true;
-					break;
-				}
-			}
-		}
 	}
 	else
 	{
@@ -1063,40 +1047,18 @@
 		Code >> y;
 		Code >> k;
 		Code >> Opacity;
-/*		int Cc = static_cast<int>(c * 255 + 0.5);
-		int Mc = static_cast<int>(m * 255 + 0.5);
-		int Yc = static_cast<int>(y * 255 + 0.5);
-		int Kc = static_cast<int>(k * 255 + 0.5); */
 		int Cc = qRound(c * 255);
 		int Mc = qRound(m * 255);
 		int Yc = qRound(y * 255);
 		int Kc = qRound(k * 255);
-		int hC, hM, hY, hK;
 		tmp.setColor(Cc, Mc, Yc, Kc);
-		for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-		{
-			if (it.value().getColorModel() == colorModelCMYK)
-			{
-				it.value().getCMYK(&hC, &hM, &hY, &hK);
-				if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
-				{
-					ret = it.key();
-					found = true;
-					break;
-				}
-			}
-		}
-	}
-	if (!found)
-	{
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		QString namPrefix = "FromEPS";
-		if (!eps)
-			namPrefix = "FromPS";
-		m_Doc->PageColors.insert(namPrefix+tmp.name(), tmp);
-//		importedColors.append(namPrefix+tmp.name());
-		ret = namPrefix+tmp.name();
-	}
+	}
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	QString namPrefix = "FromEPS";
+	if (!eps)
+		namPrefix = "FromPS";
+	QString fNam = m_Doc->PageColors.tryAddColor(namPrefix+tmp.name(), tmp);
+	ret = fNam;
 	return ret;
 }

Modified: trunk/Scribus/scribus/plugins/import/svg/svgplugin.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/svg/svgplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/svg/svgplugin.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/svg/svgplugin.cpp Fri Nov  5 15:33:39 2010
@@ -2231,35 +2231,15 @@
 		else
 			c = parseColorN( rgbColor );
 	}
-	ColorList::Iterator it;
-	bool found = false;
-	int r, g, b;
-	QColor tmpR;
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelRGB)
-		{
-			it.value().getRGB(&r, &g, &b);
-			tmpR.setRgb(r, g, b);
-			if (c == tmpR)
-			{
-				ret = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		ScColor tmp;
-		tmp.fromQColor(c);
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		QString newColorName = "FromSVG"+c.name();
-		m_Doc->PageColors.insert(newColorName, tmp);
+	ScColor tmp;
+	tmp.fromQColor(c);
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	QString newColorName = "FromSVG"+c.name();
+	QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
+	if (fNam == newColorName)
 		importedColors.append(newColorName);
-		ret = newColorName;
-	}
+	ret = fNam;
 	return ret;
 }
 
@@ -2267,7 +2247,7 @@
 {
 	QColor color, tmpR;
 	QString ret;
-	bool iccColorFound = false, found = false;
+	bool iccColorFound = false;
 	int iccColorIndex  = s.indexOf("icc-color");
 	if (iccColorIndex < 0)
 		return ret;
@@ -2311,34 +2291,15 @@
 	}
 	if (iccColorFound == false)
 		return ret;
-	int  c, m, y, k;
-	ColorList::Iterator it;
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		colorModel colorMod = it.value().getColorModel();
-		if (colorMod == colorModelCMYK)
-		{
-			it.value().getCMYK(&c, &m, &y, &k);
-			tmpR.setCmyk(c, m, y, k);
-			if (color == tmpR)
-			{
-				ret = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		ScColor tmp;
-		tmp.fromQColor(color);
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		QString newColorName = "FromSVG"+tmp.name();
-		m_Doc->PageColors.insert(newColorName, tmp);
+	ScColor tmp;
+	tmp.fromQColor(color);
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	QString newColorName = "FromSVG"+tmp.name();
+	QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
+	if (fNam == newColorName)
 		importedColors.append(newColorName);
-		ret = newColorName;
-	}
+	ret = fNam;
 	return ret;
 }
 

Modified: trunk/Scribus/scribus/plugins/import/wmf/wmfimport.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/wmf/wmfimport.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/wmf/wmfimport.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/wmf/wmfimport.cpp Fri Nov  5 15:33:39 2010
@@ -172,36 +172,15 @@
 
 QString WMFImport::importColor(const QColor& color)
 {
-	bool found = false;
-	int r, g, b;
-	QColor  tmpColor;
-	QString retColorName;
-	ColorList::Iterator it;
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelRGB)
-		{
-			it.value().getRGB(&r, &g, &b);
-			tmpColor.setRgb(r, g, b);
-			if (color == tmpColor)
-			{
-				retColorName = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		ScColor tmp;
-		tmp.fromQColor(color);
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		m_Doc->PageColors.insert("FromWMF"+color.name(), tmp);
-		importedColors.append("FromWMF"+color.name());
-		retColorName = "FromWMF"+color.name();
-	}
-	return retColorName;
+	ScColor tmp;
+	tmp.fromQColor(color);
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	QString pNam = "FromWMF"+color.name();
+	QString fNam = m_Doc->PageColors.tryAddColor(pNam, tmp);
+	if (fNam == pNam)
+		importedColors.append(pNam);
+	return fNam;
 }
 
 QColor WMFImport::colorFromParam( short* params )

Modified: trunk/Scribus/scribus/plugins/import/wpg/importwpg.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/wpg/importwpg.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/wpg/importwpg.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/wpg/importwpg.cpp Fri Nov  5 15:33:39 2010
@@ -115,34 +115,18 @@
 	ColorList::Iterator it;
 	CurrColorStroke = "Black";
 	CurrStrokeShade = 100.0;
-	int Rc, Gc, Bc, hR, hG, hB;
-	bool found = false;
+	int Rc, Gc, Bc;
 	Rc = pen.foreColor.red;
 	Gc = pen.foreColor.green;
 	Bc = pen.foreColor.blue;
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelRGB)
-		{
-			it.value().getRGB(&hR, &hG, &hB);
-			if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-			{
-				CurrColorStroke = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		tmp.setColorRGB(Rc, Gc, Bc);
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		QString newColorName = "FromWPG"+tmp.name();
-		m_Doc->PageColors.insert(newColorName, tmp);
+	tmp.setColorRGB(Rc, Gc, Bc);
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	QString newColorName = "FromWPG"+tmp.name();
+	QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
+	if (fNam == newColorName)
 		importedColors.append(newColorName);
-		CurrColorStroke = newColorName;
-	}
+	CurrColorStroke = fNam;
 	CurrStrokeTrans = pen.foreColor.alpha / 255.0;
 	if(!pen.solid)
 	{
@@ -191,36 +175,20 @@
 	ColorList::Iterator it;
 	CurrColorFill = "Black";
 	CurrFillShade = 100.0;
-	int Rc, Gc, Bc, hR, hG, hB;
+	int Rc, Gc, Bc;
 	if(brush.style == libwpg::WPGBrush::Solid)
 	{
-		bool found = false;
 		Rc = brush.foreColor.red;
 		Gc = brush.foreColor.green;
 		Bc = brush.foreColor.blue;
-		for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-		{
-			if (it.value().getColorModel() == colorModelRGB)
-			{
-				it.value().getRGB(&hR, &hG, &hB);
-				if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-				{
-					CurrColorFill = it.key();
-					found = true;
-					break;
-				}
-			}
-		}
-		if (!found)
-		{
-			tmp.setColorRGB(Rc, Gc, Bc);
-			tmp.setSpotColor(false);
-			tmp.setRegistrationColor(false);
-			QString newColorName = "FromWPG"+tmp.name();
-			m_Doc->PageColors.insert(newColorName, tmp);
+		tmp.setColorRGB(Rc, Gc, Bc);
+		tmp.setSpotColor(false);
+		tmp.setRegistrationColor(false);
+		QString newColorName = "FromWPG"+tmp.name();
+		QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
+		if (fNam == newColorName)
 			importedColors.append(newColorName);
-			CurrColorFill = newColorName;
-		}
+		CurrColorFill = fNam;
 		CurrFillTrans = brush.foreColor.alpha / 255.0;
 	}
 	else if (brush.style == libwpg::WPGBrush::Gradient)
@@ -232,33 +200,17 @@
 		for(unsigned c = 0; c < brush.gradient.count(); c++)
 		{
 			QString currStopColor = CommonStrings::None;
-			bool found = false;
 			Rc = brush.gradient.stopColor(c).red;
 			Gc = brush.gradient.stopColor(c).green;
 			Bc = brush.gradient.stopColor(c).blue;
-			for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-			{
-				if (it.value().getColorModel() == colorModelRGB)
-				{
-					it.value().getRGB(&hR, &hG, &hB);
-					if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-					{
-						currStopColor = it.key();
-						found = true;
-						break;
-					}
-				}
-			}
-			if (!found)
-			{
-				tmp.setColorRGB(Rc, Gc, Bc);
-				tmp.setSpotColor(false);
-				tmp.setRegistrationColor(false);
-				QString newColorName = "FromWPG"+tmp.name();
-				m_Doc->PageColors.insert(newColorName, tmp);
+			tmp.setColorRGB(Rc, Gc, Bc);
+			tmp.setSpotColor(false);
+			tmp.setRegistrationColor(false);
+			QString newColorName = "FromWPG"+tmp.name();
+			QString fNam = m_Doc->PageColors.tryAddColor(newColorName, tmp);
+			if (fNam == newColorName)
 				importedColors.append(newColorName);
-				currStopColor = newColorName;
-			}
+			currStopColor = fNam;
 			const ScColor& gradC = m_Doc->PageColors[currStopColor];
 			double pos = qBound(0.0, fabs(brush.gradient.stopOffset(c)), 1.0);
 			currentGradient.addStop( ScColorEngine::getRGBColor(gradC, m_Doc), pos, 0.5, 1.0, currStopColor, 100 );

Modified: trunk/Scribus/scribus/plugins/import/xar/importxar.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/plugins/import/xar/importxar.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/xar/importxar.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/xar/importxar.cpp Fri Nov  5 15:33:39 2010
@@ -3280,7 +3280,6 @@
 	quint16 charC = 0;
 	quint32 EntryIndex, component1, component2, component3, component4;
 	qint32 colorRef;
-	int hR, hG, hB;
 	ts >> Rc >> Gc >> Bc >> colorModel >> colorType;
 	ts >> EntryIndex;
 	ts >> colorRef;
@@ -3333,7 +3332,6 @@
 	double c4 = decodeColorComponent(component4);
 //	qDebug() << "Record" << recordCounter << "Complex Color" << XarName << colM << colT << colorRef;
 //	qDebug() << "\t\tComponents" << c1 << c2 << c3 << c4;
-	bool found = false;
 	if ((!XarName.isEmpty()) && ((XarName == "White") || (XarName == "Black") || (m_Doc->PageColors.contains(XarName))))
 		tmpName = XarName;
 	else
@@ -3347,81 +3345,22 @@
 				int Mc = qRound(c2 * 255);
 				int Yc = qRound(c3 * 255);
 				int Kc = qRound(c4 * 255);
-				int hC, hM, hY, hK;
 				tmp.setColor(Cc, Mc, Yc, Kc);
-				for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-				{
-					if (it.value().getColorModel() == colorModelCMYK)
-					{
-						it.value().getCMYK(&hC, &hM, &hY, &hK);
-						if ((Cc == hC) && (Mc == hM) && (Yc == hY) && (Kc == hK))
-						{
-							tmpName = it.key();
-							found = true;
-							break;
-						}
-					}
-				}
-				if (!found)
-				{
-					if (colorType == 1)
-						tmp.setSpotColor(true);
-					else
-						tmp.setSpotColor(false);
-					tmp.setRegistrationColor(false);
-					if (XarName.isEmpty())
-						tmpName = "FromXara"+c.name();
-					else
-						tmpName = XarName;
-					m_Doc->PageColors.insert(tmpName, tmp);
+				if (colorType == 1)
+					tmp.setSpotColor(true);
+				else
+					tmp.setSpotColor(false);
+				tmp.setRegistrationColor(false);
+				if (XarName.isEmpty())
+					tmpName = "FromXara"+c.name();
+				else
+					tmpName = XarName;
+				QString fNam = m_Doc->PageColors.tryAddColor(tmpName, tmp);
+				if (fNam == tmpName)
 					importedColors.append(tmpName);
-				}
+				tmpName = fNam;
 			}
 			else
-			{
-				for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-				{
-					if (it.value().getColorModel() == colorModelRGB)
-					{
-						it.value().getRGB(&hR, &hG, &hB);
-						if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-						{
-							tmpName = it.key();
-							found = true;
-							break;
-						}
-					}
-				}
-				if (!found)
-				{
-					tmp.setColorRGB(Rc, Gc, Bc);
-					tmp.setSpotColor(false);
-					tmp.setRegistrationColor(false);
-					if (XarName.isEmpty())
-						tmpName = "FromXara"+c.name();
-					else
-						tmpName = XarName;
-					m_Doc->PageColors.insert(tmpName, tmp);
-					importedColors.append(tmpName);
-				}
-			}
-		}
-		else
-		{
-			for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-			{
-				if (it.value().getColorModel() == colorModelRGB)
-				{
-					it.value().getRGB(&hR, &hG, &hB);
-					if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-					{
-						tmpName = it.key();
-						found = true;
-						break;
-					}
-				}
-			}
-			if (!found)
 			{
 				tmp.setColorRGB(Rc, Gc, Bc);
 				tmp.setSpotColor(false);
@@ -3430,9 +3369,25 @@
 					tmpName = "FromXara"+c.name();
 				else
 					tmpName = XarName;
-				m_Doc->PageColors.insert(tmpName, tmp);
+				QString fNam = m_Doc->PageColors.tryAddColor(tmpName, tmp);
+				if (fNam == tmpName)
+					importedColors.append(tmpName);
+				tmpName = fNam;
+			}
+		}
+		else
+		{
+			tmp.setColorRGB(Rc, Gc, Bc);
+			tmp.setSpotColor(false);
+			tmp.setRegistrationColor(false);
+			if (XarName.isEmpty())
+				tmpName = "FromXara"+c.name();
+			else
+				tmpName = XarName;
+			QString fNam = m_Doc->PageColors.tryAddColor(tmpName, tmp);
+			if (fNam == tmpName)
 				importedColors.append(tmpName);
-			}
+			tmpName = fNam;
 		}
 	}
 	XarColor color;
@@ -3451,34 +3406,17 @@
 {
 	QString tmpName = CommonStrings::None;
 	ScColor tmp;
-	ColorList::Iterator it;
 	quint8 Rc, Gc, Bc;
-	int hR, hG, hB;
 	ts >> Rc >> Gc >> Bc;
-	bool found = false;
 	QColor c = QColor(Rc, Gc, Bc);
-	for (it = m_Doc->PageColors.begin(); it != m_Doc->PageColors.end(); ++it)
-	{
-		if (it.value().getColorModel() == colorModelRGB)
-		{
-			it.value().getRGB(&hR, &hG, &hB);
-			if ((Rc == hR) && (Gc == hG) && (Bc == hB))
-			{
-				tmpName = it.key();
-				found = true;
-				break;
-			}
-		}
-	}
-	if (!found)
-	{
-		tmp.setColorRGB(Rc, Gc, Bc);
-		tmp.setSpotColor(false);
-		tmp.setRegistrationColor(false);
-		tmpName = "FromXara"+c.name();
-		m_Doc->PageColors.insert(tmpName, tmp);
+	tmp.setColorRGB(Rc, Gc, Bc);
+	tmp.setSpotColor(false);
+	tmp.setRegistrationColor(false);
+	tmpName = "FromXara"+c.name();
+	QString fNam = m_Doc->PageColors.tryAddColor(tmpName, tmp);
+	if (fNam == tmpName)
 		importedColors.append(tmpName);
-	}
+	tmpName = fNam;
 	XarColor color;
 	color.colorType = 0;
 	color.colorModel = 2;

Modified: trunk/Scribus/scribus/sccolor.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/sccolor.cpp
==============================================================================
--- trunk/Scribus/scribus/sccolor.cpp (original)
+++ trunk/Scribus/scribus/sccolor.cpp Fri Nov  5 15:33:39 2010
@@ -381,3 +381,24 @@
 	if (addWhite)
 		insert("White", ScColor(0, 0, 0, 0));
 }
+
+QString ColorList::tryAddColor(QString name, ScColor col)
+{
+	if (contains(name))
+		return name;
+	bool found = false;
+	QString ret = name;
+	ColorList::Iterator it;
+	for (it = begin(); it != end(); ++it)
+	{
+		if (it.value() == col)
+		{
+			ret = it.key();
+			found = true;
+			break;
+		}
+	}
+	if (!found)
+		insert(name, col);
+	return ret;
+}

Modified: trunk/Scribus/scribus/sccolor.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/sccolor.h
==============================================================================
--- trunk/Scribus/scribus/sccolor.h (original)
+++ trunk/Scribus/scribus/sccolor.h Fri Nov  5 15:33:39 2010
@@ -166,6 +166,9 @@
 
 	/** \brief Ensure availability of black and white colors. */
 	void ensureBlackAndWhite(void);
+
+	/** \brief Try to add ScColor col to the list, if col already exists either by name or by value the existing color name is returned. */
+	QString tryAddColor(QString name, ScColor col);
 };
 
 #endif

Modified: trunk/Scribus/scribus/util_color.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15771&path=/trunk/Scribus/scribus/util_color.cpp
==============================================================================
--- trunk/Scribus/scribus/util_color.cpp (original)
+++ trunk/Scribus/scribus/util_color.cpp Fri Nov  5 15:33:39 2010
@@ -634,8 +634,8 @@
 							FarNam = FarNam.simplified();
 							cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * y), qRound(255 * k));
 							cc.setSpotColor(true);
-							if ((!EditColors.contains(FarNam)) && (!FarNam.isEmpty()))
-								EditColors.insert(FarNam, cc);
+							if (!FarNam.isEmpty())
+								EditColors.tryAddColor(FarNam, cc);
 							while (!ts.atEnd())
 							{
 								quint64 oldPos = ts.device()->pos();
@@ -655,8 +655,8 @@
 								FarNam = FarNam.simplified();
 								cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * y), qRound(255 * k));
 								cc.setSpotColor(true);
-								if ((!EditColors.contains(FarNam)) && (!FarNam.isEmpty()))
-									EditColors.insert(FarNam, cc);
+								if (!FarNam.isEmpty())
+									EditColors.tryAddColor(FarNam, cc);
 							}
 						}
 					}
@@ -678,8 +678,8 @@
 							FarNam = FarNam.remove(FarNam.length()-1,1);
 							FarNam = FarNam.simplified();
 							cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * y));
-							if ((!EditColors.contains(FarNam)) && (!FarNam.isEmpty()))
-								EditColors.insert(FarNam, cc);
+							if (!FarNam.isEmpty())
+								EditColors.tryAddColor(FarNam, cc);
 							while (!ts.atEnd())
 							{
 								quint64 oldPos = ts.device()->pos();
@@ -698,8 +698,8 @@
 								FarNam = FarNam.remove(FarNam.length()-1,1);
 								FarNam = FarNam.simplified();
 								cc = ScColor(qRound(255 * c), qRound(255 * m), qRound(255 * y));
-								if ((!EditColors.contains(FarNam)) && (!FarNam.isEmpty()))
-									EditColors.insert(FarNam, cc);
+								if (!FarNam.isEmpty())
+									EditColors.tryAddColor(FarNam, cc);
 							}
 						}
 					}
@@ -727,8 +727,7 @@
 						ColorList::Iterator it;
 						for (it = LColors.begin(); it != LColors.end(); ++it)
 						{
-							if (!EditColors.contains(it.key()))
-								EditColors.insert(it.key(), it.value());
+							EditColors.tryAddColor(it.key(), it.value());
 						}
 					}
 				}
@@ -813,8 +812,7 @@
 								{
 									lf.setSpotColor(false);
 									lf.setRegistrationColor(false);
-									if (!EditColors.contains(name))
-										EditColors.insert(name, lf);
+									EditColors.tryAddColor(name, lf);
 								}
 							}
 						}
@@ -873,8 +871,7 @@
 											lf.setColorRGB(r, g, b);
 											lf.setSpotColor(false);
 											lf.setRegistrationColor(false);
-											if (!EditColors.contains(colorName))
-												EditColors.insert(colorName, lf);
+											EditColors.tryAddColor(colorName, lf);
 										}
 									}
 									colNode = colNode.nextSibling();
@@ -942,8 +939,7 @@
 									{
 										lf.setSpotColor(false);
 										lf.setRegistrationColor(false);
-										if (!EditColors.contains(name))
-											EditColors.insert(name, lf);
+										EditColors.tryAddColor(name, lf);
 									}
 								}
 							}
@@ -991,8 +987,7 @@
 									lf.setColor(qRound(255 * c), qRound(255 * m), qRound(255 * y), qRound(255 * k));
 									lf.setSpotColor(false);
 									lf.setRegistrationColor(false);
-									if (!EditColors.contains(Cname))
-										EditColors.insert(Cname, lf);
+									EditColors.tryAddColor(Cname, lf);
 								}
 							}
 							else
@@ -1007,8 +1002,7 @@
 									lf.setColorRGB(qRound(255 * r), qRound(255 * g), qRound(255 * b));
 									lf.setSpotColor(false);
 									lf.setRegistrationColor(false);
-									if (!EditColors.contains(Cname))
-										EditColors.insert(Cname, lf);
+									EditColors.tryAddColor(Cname, lf);
 								}
 							}
 						}
@@ -1061,8 +1055,7 @@
 									lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
 								else
 									lf.setRegistrationColor(false);
-								if (!EditColors.contains(pg.attribute("NAME")))
-									EditColors.insert(pg.attribute("NAME"), lf);
+								EditColors.tryAddColor(pg.attribute("NAME"), lf);
 							}
 							else if (pg.tagName() == "Gradient")
 							{
@@ -1107,8 +1100,8 @@
 								lf.setSpotColor(false);
 								lf.setRegistrationColor(false);
 								QString nam = pg.attribute("draw:name");
-								if ((!EditColors.contains(nam)) && (!nam.isEmpty()))
-									EditColors.insert(nam, lf);
+								if (!nam.isEmpty())
+									EditColors.tryAddColor(nam, lf);
 							}
 							else if (dTag == "VivaColors")
 							{
@@ -1136,8 +1129,8 @@
 									lf.setColor(qRound(2.55 * cVal), qRound(2.55 * mVal), qRound(2.55 * yVal), qRound(2.55 * kVal));
 									lf.setSpotColor(false);
 									lf.setRegistrationColor(false);
-									if ((!EditColors.contains(nam)) && (!nam.isEmpty()))
-										EditColors.insert(nam, lf);
+									if (!nam.isEmpty())
+										EditColors.tryAddColor(nam, lf);
 								}
 								else if (pg.attribute("type") == "rgb")
 								{
@@ -1156,8 +1149,8 @@
 									lf.setColorRGB(cVal, mVal, yVal);
 									lf.setSpotColor(false);
 									lf.setRegistrationColor(false);
-									if ((!EditColors.contains(nam)) && (!nam.isEmpty()))
-										EditColors.insert(nam, lf);
+									if (!nam.isEmpty())
+										EditColors.tryAddColor(nam, lf);
 								}
 							}
 							PAGE=PAGE.nextSibling();
@@ -1204,8 +1197,7 @@
 									Cname = paletteName + QString("#%1%2%3%4").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).arg(Kval,2,16).toUpper();
 								Cname.replace(" ","0");
 							}
-							if (!EditColors.contains(Cname))
-								EditColors.insert(Cname, tmp);
+							EditColors.tryAddColor(Cname, tmp);
 						}
 					}
 					fiC.close();




More information about the scribus-commit mailing list