r15674 by fschmid - Final fixes for the PaintManager.

scribus-commit scribus-commit at lists.scribus.net
Thu Oct 28 22:42:03 CEST 2010


Author: fschmid
Date: Thu Oct 28 20:42:03 2010
New Revision: 15674

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15674
Log:
Final fixes for the PaintManager.

Modified:
    trunk/Scribus/scribus/colorsetmanager.cpp
    trunk/Scribus/scribus/prefsmanager.cpp
    trunk/Scribus/scribus/ui/paintmanager.cpp
    trunk/Scribus/scribus/ui/paintmanager.h

Modified: trunk/Scribus/scribus/colorsetmanager.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15674&path=/trunk/Scribus/scribus/colorsetmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/colorsetmanager.cpp (original)
+++ trunk/Scribus/scribus/colorsetmanager.cpp Thu Oct 28 20:42:03 2010
@@ -115,11 +115,11 @@
 	locations << ScPaths::instance().getDirsFromEnvVar("XDG_DATA_HOME", "scribus/swatches/");
 	for ( QStringList::Iterator it = locations.begin(); it != locations.end(); ++it )
 	{
-		QFile paletteDir(*it);
+		QFileInfo paletteDir(*it);
 		if (paletteDir.exists())
 		{
 			paletteLocations << (*it);
-			paletteLocationLocks.insert((*it), false);
+			paletteLocationLocks.insert((*it), !paletteDir.isWritable());
 		}
 	}
 	QStringList xdgSysLocations=ScPaths::instance().getDirsFromEnvVar("XDG_DATA_DIRS", "scribus/swatches/");

Modified: trunk/Scribus/scribus/prefsmanager.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15674&path=/trunk/Scribus/scribus/prefsmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/prefsmanager.cpp (original)
+++ trunk/Scribus/scribus/prefsmanager.cpp Thu Oct 28 20:42:03 2010
@@ -1606,39 +1606,6 @@
 		rde.appendChild(hyelm2);
 	}
 	elem.appendChild(rde);
-/*
-	ColorList::Iterator itc;
-	for (itc = appPrefs.colorPrefs.DColors.begin(); itc != appPrefs.colorPrefs.DColors.end(); ++itc)
-	{
-		QDomElement co=docu.createElement("Color");
-		co.setAttribute("Name",itc.key());
-		if (itc.value().getColorModel() == colorModelRGB)
-			co.setAttribute("RGB", itc.value().nameRGB());
-		else
-			co.setAttribute("CMYK", itc.value().nameCMYK());
-		co.setAttribute("Spot", static_cast<int>(itc.value().isSpotColor()));
-		co.setAttribute("Register", static_cast<int>(itc.value().isRegistrationColor()));
-		elem.appendChild(co);
-	}
-	QMap<QString, VGradient>::Iterator itGrad;
-	for (itGrad = appPrefs.defaultGradients.begin(); itGrad != appPrefs.defaultGradients.end(); ++itGrad)
-	{
-		QDomElement grad = docu.createElement("Gradient");
-		grad.setAttribute("Name",itGrad.key());
-		VGradient gra = itGrad.value();
-		QList<VColorStop*> cstops = gra.colorStops();
-		for (uint cst = 0; cst < gra.Stops(); ++cst)
-		{
-			QDomElement stop = docu.createElement("CStop");
-			stop.setAttribute("Name", cstops.at(cst)->name);
-			stop.setAttribute("RampPoint", ScCLocale::toQStringC(cstops.at(cst)->rampPoint));
-			stop.setAttribute("Opacity", ScCLocale::toQStringC(cstops.at(cst)->opacity));
-			stop.setAttribute("Shade", cstops.at(cst)->shade);
-			grad.appendChild(stop);
-		}
-		elem.appendChild(grad);
-	}
-*/
 	for (int rd=0; rd<appPrefs.uiPrefs.RecentDocs.count(); ++rd)
 	{
 		QDomElement rde=docu.createElement("Recent");
@@ -2335,55 +2302,13 @@
 				face.subset(static_cast<bool>(dc.attribute("Subset", "0").toInt()));
 			}
 		}
-/*
-		if (dc.tagName()=="Color")
-		{
-			if (dc.hasAttribute("CMYK"))
-				lf.setNamedColor(dc.attribute("CMYK"));
-			else
-				lf.fromQColor(QColor(dc.attribute("RGB")));
-			if (dc.hasAttribute("Spot"))
-				lf.setSpotColor(static_cast<bool>(dc.attribute("Spot").toInt()));
-			else
-				lf.setSpotColor(false);
-			if (dc.hasAttribute("Register"))
-				lf.setRegistrationColor(static_cast<bool>(dc.attribute("Register").toInt()));
-			else
-				lf.setRegistrationColor(false);
-			appPrefs.colorPrefs.DColors[dc.attribute("Name")] = lf;
-		}
-		if (dc.tagName() == "Gradient")
-		{
-			VGradient gra = VGradient(VGradient::linear);
-			gra.clearStops();
-			QDomNode grad = dc.firstChild();
-			while(!grad.isNull())
-			{
-				QDomElement stop = grad.toElement();
-				QString name = stop.attribute("Name");
-				double ramp  = ScCLocale::toDoubleC(stop.attribute("RampPoint"), 0.0);
-				int shade    = stop.attribute("Shade", "100").toInt();
-				double opa   = ScCLocale::toDoubleC(stop.attribute("Opacity"), 1.0);
-				QColor color;
-				if (name == CommonStrings::None)
-					color = QColor(255, 255, 255, 0);
-				else
-				{
-					const ScColor& col = appPrefs.colorPrefs.DColors[name];
-					color = ScColorEngine::getShadeColorProof(col, NULL, shade);
-				}
-				gra.addStop(color, ramp, 0.5, opa, name, shade);
-				grad = grad.nextSibling();
-			}
-			appPrefs.defaultGradients.insert(dc.attribute("Name"), gra);
-		}
-*/
 		if (dc.tagName()=="Substitute")
 		  appPrefs.fontPrefs.GFontSub[dc.attribute("Name")] = dc.attribute("Replace");
 		if (dc.tagName()=="ColorSet")
 			appPrefs.colorPrefs.CustomColorSets.append(dc.attribute("Name"));
 		if (dc.tagName()=="DefaultColorSet")
 		{
+			appPrefs.colorPrefs.DColors.clear();
 			QString pfadC = "";
 			appPrefs.colorPrefs.DColorSet = dc.attribute("Name");
 			if (appPrefs.colorPrefs.CustomColorSets.contains(appPrefs.colorPrefs.DColorSet))

Modified: trunk/Scribus/scribus/ui/paintmanager.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15674&path=/trunk/Scribus/scribus/ui/paintmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/paintmanager.cpp (original)
+++ trunk/Scribus/scribus/ui/paintmanager.cpp Thu Oct 28 20:42:03 2010
@@ -60,6 +60,7 @@
 	setupUi(this);
 	setModal(true);
 	paletteLocked = false;
+	modified = false;
 	sortRule = 0;
 	m_doc = doc;
 	m_colorList = doco;
@@ -131,10 +132,25 @@
 	connect(deleteButton, SIGNAL(clicked()), this, SLOT(removeColorItem()));
 	connect(deleteUnusedButton, SIGNAL(clicked()), this, SLOT(removeUnusedColorItem()));
 	connect(importButton, SIGNAL(clicked()), this, SLOT(importColorItems()));
-	connect(okButton, SIGNAL(clicked()), this, SLOT(accept()));
+	connect(okButton, SIGNAL(clicked()), this, SLOT(leaveDialog()));
 	connect(cancelButton, SIGNAL(clicked()), this, SLOT(reject()));
 	connect(SaveColSet, SIGNAL(clicked()), this, SLOT(saveDefaults()));
 	connect(LoadColSet, SIGNAL(activated(const QString &)), this, SLOT(loadDefaults(const QString&)));
+}
+
+void PaintManagerDialog::leaveDialog()
+{
+	if (!m_doc)
+	{
+		if (modified)
+		{
+			if (paletteLocked)
+				saveDefaults();
+			else
+				doSaveDefaults(LoadColSet->text(), true);
+		}
+	}
+	accept();
 }
 
 QTreeWidgetItem* PaintManagerDialog::updateGradientList(QString addedName)
@@ -357,6 +373,7 @@
 					dataTree->setCurrentItem(lg, 0, QItemSelectionModel::ClearAndSelect);
 				}
 				itemSelected(dataTree->currentItem());
+				modified = true;
 			}
 			delete dia;
 		}
@@ -375,6 +392,7 @@
 					dataTree->setCurrentItem(lg, 0, QItemSelectionModel::ClearAndSelect);
 				}
 				itemSelected(dataTree->currentItem());
+				modified = true;
 			}
 			delete dia;
 		}
@@ -414,6 +432,7 @@
 					dataTree->setCurrentItem(lg, 0, QItemSelectionModel::ClearAndSelect);
 				}
 				itemSelected(dataTree->currentItem());
+				modified = true;
 			}
 			delete dia;
 		}
@@ -440,6 +459,7 @@
 					dataTree->setCurrentItem(lg, 0, QItemSelectionModel::ClearAndSelect);
 				}
 				itemSelected(dataTree->currentItem());
+				modified = true;
 			}
 			delete dia;
 		}
@@ -481,6 +501,7 @@
 					dataTree->setCurrentItem(lg, 0, QItemSelectionModel::ClearAndSelect);
 				}
 				itemSelected(dataTree->currentItem());
+				modified = true;
 			}
 			delete dia;
 		}
@@ -509,6 +530,7 @@
 					dataTree->setCurrentItem(lg, 0, QItemSelectionModel::ClearAndSelect);
 				}
 				itemSelected(dataTree->currentItem());
+				modified = true;
 			}
 			delete dia;
 		}
@@ -589,6 +611,7 @@
 					m_colorList.remove(dColor);
 					updateGradientColors(replacementColor, dColor);
 				}
+				modified = true;
 			}
 			delete dia;
 		}
@@ -599,6 +622,7 @@
 				replaceColorMap.insert(colors[a], "Black");
 				m_colorList.remove(colors[a]);
 			}
+			modified = true;
 		}
 		updateGradientList();
 		updateColorList();
@@ -630,6 +654,7 @@
 				}
 				updateGradientList();
 				itemSelected(0);
+				modified = true;
 			}
 			else if ((it->parent() == colorItems) || (it == colorItems))
 			{
@@ -688,6 +713,7 @@
 				updateGradientList();
 				updateColorList();
 				itemSelected(0);
+				modified = true;
 			}
 		}
 	}
@@ -735,6 +761,7 @@
 			updateGradientList();
 			updateColorList();
 			itemSelected(0);
+			modified = true;
 		}
 	}
 }
@@ -774,6 +801,7 @@
 				updateGradientList();
 				updateColorList();
 				itemSelected(0);
+				modified = true;
 			}
 		}
 		else if ((it->parent() == colorItems) || (it == colorItems))
@@ -798,6 +826,7 @@
 			{
 				updateGradientList();
 				updateColorList();
+				modified = true;
 			}
 			itemSelected(0);
 		}
@@ -1136,7 +1165,6 @@
 
 void PaintManagerDialog::saveDefaults()
 {
-	QString Cpfad = QDir::convertSeparators(ScPaths::getApplicationDataDir());
 	QString Name = LoadColSet->text();
 	Query* dia = new Query(this, "Name", 1, 0, tr("&Name:"), tr("Choose a Name"));
 	if ((Name == "Scribus Basic") || (Name == "Scribus Small") || (Name == "X11 RGB-Set") || (Name == "OpenOffice.org-Set")
@@ -1145,67 +1173,72 @@
 	else
 		dia->setEditText(Name, false);
 	if (dia->exec())
-	{
-		QString Fname = dia->getEditText();
-		Fname.replace(" ", "_");
-		Fname  = Cpfad + Fname;
-		Fname += ".xml";
-		QFile fx(Fname);
-		if (fx.open(QIODevice::WriteOnly))
-		{
-			QDomDocument docu("scribus");
-			QString st="<SCRIBUSCOLORS></SCRIBUSCOLORS>";
-			docu.setContent(st);
-			QDomElement elem = docu.documentElement();
-			elem.setAttribute("Name", dia->getEditText());
-			ColorList::Iterator itc;
-			for (itc = m_colorList.begin(); itc != m_colorList.end(); ++itc)
-			{
-				QDomElement co = docu.createElement("COLOR");
-				co.setAttribute("NAME",itc.key());
-				if (m_colorList[itc.key()].getColorModel() == colorModelRGB)
-					co.setAttribute("RGB",m_colorList[itc.key()].nameRGB());
-				else
-					co.setAttribute("CMYK",m_colorList[itc.key()].nameCMYK());
-				co.setAttribute("Spot",static_cast<int>(m_colorList[itc.key()].isSpotColor()));
-				co.setAttribute("Register",static_cast<int>(m_colorList[itc.key()].isRegistrationColor()));
-				elem.appendChild(co);
-			}
-			QMap<QString, VGradient>::Iterator itGrad;
-			for (itGrad = dialogGradients.begin(); itGrad != dialogGradients.end(); ++itGrad)
-			{
-				QDomElement grad = docu.createElement("Gradient");
-				grad.setAttribute("Name",itGrad.key());
-				VGradient gra = itGrad.value();
-				QList<VColorStop*> cstops = gra.colorStops();
-				for (uint cst = 0; cst < gra.Stops(); ++cst)
-				{
-					QDomElement stop = docu.createElement("CSTOP");
-					stop.setAttribute("NAME", cstops.at(cst)->name);
-					stop.setAttribute("RAMP", ScCLocale::toQStringC(cstops.at(cst)->rampPoint));
-					stop.setAttribute("TRANS", ScCLocale::toQStringC(cstops.at(cst)->opacity));
-					stop.setAttribute("SHADE", cstops.at(cst)->shade);
-					grad.appendChild(stop);
-				}
-				elem.appendChild(grad);
-			}
-			static const char* xmlpi = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
-			QByteArray cs = docu.toString().toUtf8();
-			QDataStream s(&fx);
-			s.writeRawData(xmlpi, strlen(xmlpi));
-			s.writeRawData(cs, cs.length());
-			fx.close();
-			if (dia->getEditText() != Name)
-			{
-				QString nameC = dia->getEditText();
-				nameC.replace(" ", "_");
-				nameC += ".xml";
-				customColSet.append(nameC);
-				LoadColSet->addSubItem(dia->getEditText(), userSwatches);
-				disconnect(LoadColSet, SIGNAL(activated(const QString &)), this, SLOT(loadDefaults(const QString&)));
-				LoadColSet->setCurrentComboItem(dia->getEditText());
-				connect(LoadColSet, SIGNAL(activated(const QString &)), this, SLOT(loadDefaults(const QString&)));
-			}
+		doSaveDefaults(dia->getEditText(), (dia->getEditText() != Name));
+	delete dia;
+}
+
+void PaintManagerDialog::doSaveDefaults(QString name, bool changed)
+{
+	QString Cpfad = QDir::convertSeparators(ScPaths::getApplicationDataDir());
+	QString Fname = name;
+	Fname.replace(" ", "_");
+	Fname  = Cpfad + Fname;
+	Fname += ".xml";
+	QFile fx(Fname);
+	if (fx.open(QIODevice::WriteOnly))
+	{
+		QDomDocument docu("scribus");
+		QString st="<SCRIBUSCOLORS></SCRIBUSCOLORS>";
+		docu.setContent(st);
+		QDomElement elem = docu.documentElement();
+		elem.setAttribute("Name", name);
+		ColorList::Iterator itc;
+		for (itc = m_colorList.begin(); itc != m_colorList.end(); ++itc)
+		{
+			QDomElement co = docu.createElement("COLOR");
+			co.setAttribute("NAME",itc.key());
+			if (m_colorList[itc.key()].getColorModel() == colorModelRGB)
+				co.setAttribute("RGB",m_colorList[itc.key()].nameRGB());
+			else
+				co.setAttribute("CMYK",m_colorList[itc.key()].nameCMYK());
+			co.setAttribute("Spot",static_cast<int>(m_colorList[itc.key()].isSpotColor()));
+			co.setAttribute("Register",static_cast<int>(m_colorList[itc.key()].isRegistrationColor()));
+			elem.appendChild(co);
+		}
+		QMap<QString, VGradient>::Iterator itGrad;
+		for (itGrad = dialogGradients.begin(); itGrad != dialogGradients.end(); ++itGrad)
+		{
+			QDomElement grad = docu.createElement("Gradient");
+			grad.setAttribute("Name",itGrad.key());
+			VGradient gra = itGrad.value();
+			QList<VColorStop*> cstops = gra.colorStops();
+			for (uint cst = 0; cst < gra.Stops(); ++cst)
+			{
+				QDomElement stop = docu.createElement("CSTOP");
+				stop.setAttribute("NAME", cstops.at(cst)->name);
+				stop.setAttribute("RAMP", ScCLocale::toQStringC(cstops.at(cst)->rampPoint));
+				stop.setAttribute("TRANS", ScCLocale::toQStringC(cstops.at(cst)->opacity));
+				stop.setAttribute("SHADE", cstops.at(cst)->shade);
+				grad.appendChild(stop);
+			}
+			elem.appendChild(grad);
+		}
+		static const char* xmlpi = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
+		QByteArray cs = docu.toString().toUtf8();
+		QDataStream s(&fx);
+		s.writeRawData(xmlpi, strlen(xmlpi));
+		s.writeRawData(cs, cs.length());
+		fx.close();
+		if (changed)
+		{
+			QString nameC = name;
+			nameC.replace(" ", "_");
+			nameC += ".xml";
+			customColSet.append(nameC);
+			LoadColSet->addSubItem(name, userSwatches);
+			disconnect(LoadColSet, SIGNAL(activated(const QString &)), this, SLOT(loadDefaults(const QString&)));
+			LoadColSet->setCurrentComboItem(name);
+			connect(LoadColSet, SIGNAL(activated(const QString &)), this, SLOT(loadDefaults(const QString&)));
 		}
 	}
 }

Modified: trunk/Scribus/scribus/ui/paintmanager.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15674&path=/trunk/Scribus/scribus/ui/paintmanager.h
==============================================================================
--- trunk/Scribus/scribus/ui/paintmanager.h (original)
+++ trunk/Scribus/scribus/ui/paintmanager.h Thu Oct 28 20:42:03 2010
@@ -63,6 +63,7 @@
 		QStringList customColSet;
 		bool hasImportedColors;
 	private slots:
+		void leaveDialog();
 		void slotRightClick(QPoint p);
 		void selEditColor(QTreeWidgetItem *it);
 		void itemSelectionChanged();
@@ -83,8 +84,10 @@
 		void loadGimpFormat(QString fileName);
 		void addGimpColor(QString &colorName, double r, double g, double b);
 		void loadScribusFormat(QString fileName);
+		void doSaveDefaults(QString name, bool changed = false);
 		ColorSetManager csm;
 		bool paletteLocked;
+		bool modified;
 		int sortRule;
 		QTreeWidgetItem *colorItems;
 		QTreeWidgetItem *gradientItems;




More information about the scribus-commit mailing list