void PropertyWidget_TextColor::showTextColors(QString p, QString b, double shp, double shb)
{
	if (!m_doc || !m_item || !m_ScMW || m_ScMW->scriptIsRunning())
		return;
	ColorList::Iterator it;
	int c = 0;
	fillShade->setValue(qRound(shb));
	strokeShade->setValue(qRound(shp));
	if ((b != CommonStrings::None) && (!b.isEmpty()))
	{
		c++;
		for (it = m_doc->PageColors.begin(); it != m_doc->PageColors.end(); ++it)
		{
			if (it.key() == b)
				break;
			c++;
		}
	}
	fillColor->setCurrentIndex(c);
	c = 0;
	if ((p != CommonStrings::None) && (!p.isEmpty()))
	{
		for (it = m_doc->PageColors.begin(); it != m_doc->PageColors.end(); ++it)
		{
			if (it.key() == p)
				break;
			c++;
		}
	}
	strokeColor->setCurrentIndex(c);
}
void ColorListBox::insertFancyPixmapItems(ColorList& list)
{
    ColorList::Iterator it;
    ScribusDoc* doc = list.document();
    for (it = list.begin(); it != list.end(); ++it)
    {
        if (it.key() == CommonStrings::None || it.key() == CommonStrings::tr_NoneColor)
            continue;
        addItem( new ColorPixmapItem(it.value(), doc, it.key()) );
    }
    if (itemDelegate())
        delete itemDelegate();
    setItemDelegate(new ColorFancyItemDelegate());
}
/**
 * Scripter.colors
 * Property
 * returns a color object
 */
QList<QVariant> ScripterImpl::colors()
{
	QList<QVariant> l;

	ColorList names = PrefsManager::instance()->colorSet();
	ColorList::Iterator it;
	for (it = names.begin(); it != names.end(); ++it)
	{
		ScColor *value = &(names[it.key()]);
		ColorAPI *color = new ColorAPI(value, it.key());
		l.append(qVariantFromValue((QObject *)(color)));
	}
	return l;
}
Example #4
0
/**
 * Scripter.activeDocument.colors
 * Property
 * Colors of activeDocument
 */
QList<QVariant> DocumentAPI::colors()
{
	QList<QVariant> l;

	ColorList names = ScCore->primaryMainWindow()->doc->PageColors;
	ColorList::Iterator it;
	for (it = names.begin(); it != names.end(); ++it)
	{
		ScColor *value = &(names[it.key()]);
		ColorAPI *color = new ColorAPI(value, it.key());
		l.append(qVariantFromValue((QObject *)(color)));
	}
	return l;
}
Example #5
0
void ColorCombo::initColorList(ColorList *colorList, ScribusDoc *doc, QString colorValue)
{
	clear();
	addItem(CommonStrings::tr_NoneColor, CommonStrings::None);
	if (colorValue == CommonStrings::None)
		setCurrentIndex(count()-1);
	ColorList::Iterator endOfColorList(colorList->end());
	for (ColorList::Iterator itc = colorList->begin(); itc != endOfColorList; ++itc)
	{
		insertFancyItem( itc.value(), doc, itc.key() );
		if (itc.key() == colorValue)
			setCurrentIndex(count()-1);
	}
}
void SMCStyleWidget::fillColorCombo(ColorList &colors)
{
	fillColor_->clear();
	strokeColor_->clear();

	fillColor_->addItem(CommonStrings::tr_NoneColor);
	strokeColor_->addItem(CommonStrings::tr_NoneColor);
	ColorList::Iterator itend=colors.end();
	ScribusDoc* doc = colors.document();
	for (ColorList::Iterator it = colors.begin(); it != itend; ++it)
	{
		fillColor_->insertFancyItem(it.value(), doc, it.key());
		strokeColor_->insertFancyItem(it.value(), doc, it.key());
	}
	fillColor_->view()->setMinimumWidth(fillColor_->view()->maximumViewportSize().width()+24);
	strokeColor_->view()->setMinimumWidth(strokeColor_->view()->maximumViewportSize().width()+24);
}
Example #7
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;
}
Example #8
0
QString gtAction::parseColor(const QString &s)
{
	QString ret = CommonStrings::None;
	if (s == CommonStrings::None)
		return ret; // don't want None to become Black or any color
	bool found = false;
	ColorList::Iterator it;
	for (it = textFrame->doc()->PageColors.begin(); it != textFrame->doc()->PageColors.end(); ++it)
	{
		if (it.key() == s)
		{
			ret = it.key();
			found = true;
		}
	}
	if (!found)
	{
		QColor c;
		if( s.startsWith( "rgb(" ) )
		{
			QString parse = s.trimmed();
			QStringList colors = parse.split(',', QString::SkipEmptyParts);
			QString r = colors[0].right( ( colors[0].length() - 4 ) );
			QString g = colors[1];
			QString b = colors[2].left( ( colors[2].length() - 1 ) );
			if( r.contains( "%" ) )
			{
				r.chop(1);
				r = QString::number( static_cast<int>( ( static_cast<double>( 255 * ScCLocale::toDoubleC(r) ) / 100.0 ) ) );
			}
			if( g.contains( "%" ) )
			{
				g.chop(1);
				g = QString::number( static_cast<int>( ( static_cast<double>( 255 * ScCLocale::toDoubleC(g) ) / 100.0 ) ) );
			}
			if( b.contains( "%" ) )
			{
				b.chop(1);
				b = QString::number( static_cast<int>( ( static_cast<double>( 255 * ScCLocale::toDoubleC(b) ) / 100.0 ) ) );
			}
			c = QColor(r.toInt(), g.toInt(), b.toInt());
		}
		else
		{
			QString rgbColor = s.trimmed();
			if( rgbColor.startsWith( "#" ) )
				c.setNamedColor( rgbColor );
			else
				c = parseColorN( rgbColor );
		}
		found = false;
		for (it = textFrame->doc()->PageColors.begin(); it != textFrame->doc()->PageColors.end(); ++it)
		{
			if (c == ScColorEngine::getRGBColor(it.value(), textFrame->doc()))
			{
				ret = it.key();
				found = true;
			}
		}
		if (!found)
		{
			ScColor tmp;
			tmp.fromQColor(c);
			textFrame->doc()->PageColors.insert("FromGetText"+c.name(), tmp);
			m_ScMW->propertiesPalette->updateColorList();
			ret = "FromGetText"+c.name();
		}
	}
	return ret;
}
Example #9
0
void Serializer::serializeObjects(const Selection& selection, SaxHandler& outputhandler)
{
	Xml_attr attr;
	UniqueID handler( & outputhandler );
	handler.beginDoc();
	handler.begin("SCRIBUSFRAGMENT", attr);
	ScribusDoc* doc = selection.itemAt(0)->doc();
	
	
	QMap<QString,int>::Iterator itf;
	for (itf = doc->UsedFonts.begin(); itf != doc->UsedFonts.end(); ++itf)
	{
		attr["name"] = itf.key();
		handler.beginEnd("font", attr);
	}
	
	ColorList usedColors;
	doc->getUsedColors(usedColors, false);
	ColorList::Iterator itc;
	for (itc = usedColors.begin(); itc != usedColors.end(); ++itc)
	{
		Xml_attr cattr;
		cattr["name"] = itc.key();
		if (doc->PageColors[itc.key()].getColorModel() == colorModelRGB)
			cattr["RGB"] = doc->PageColors[itc.key()].nameRGB();
		else
			cattr["CMYK"] = doc->PageColors[itc.key()].nameCMYK();
		cattr["Spot"] = toXMLString(doc->PageColors[itc.key()].isSpotColor());
		cattr["Register"] = toXMLString(doc->PageColors[itc.key()].isRegistrationColor());
		handler.beginEnd("color", cattr);
	}
	
	ResourceCollection lists;
	for (int i=0; i < doc->Items->count(); ++i)
		doc->Items->at(i)->getNamedResources(lists);
	
	QList<QString>::Iterator it;
	QList<QString> names = lists.styleNames();
	for (it = names.begin(); it != names.end(); ++it)
		doc->paragraphStyles().get(*it).saxx(handler);

	names = lists.charStyleNames();
	for (it = names.begin(); it != names.end(); ++it)
		doc->charStyles().get(*it).saxx(handler);
	
	names = lists.lineStyleNames();
	for (it = names.begin(); it != names.end(); ++it)
	{
		Xml_attr multiattr;
		multiattr["Name"] = *it;
		handler.begin("MultiLine", multiattr);		
		multiLine ml = doc->MLineStyles[*it];
		
		multiLine::Iterator itMU2;
		for (itMU2 = ml.begin(); itMU2 != ml.end(); ++itMU2)
		{
			Xml_attr lineattr;
			lineattr["Color"] = (*itMU2).Color;
			lineattr["Shade"] = toXMLString((*itMU2).Shade);
			lineattr["Dash"] = toXMLString((*itMU2).Dash);
			lineattr["LineEnd"] = toXMLString((*itMU2).LineEnd);
			lineattr["LineJoin"] = toXMLString((*itMU2).LineJoin);
			lineattr["Width"] = toXMLString((*itMU2).Width);
			handler.beginEnd("SubLine", lineattr);
		}
		handler.end("MultiLine");
	}

	/*	names = lists.patterns();
	for (it = names.begin(); it != names.end(); ++it)
		doc->patterns[*it].saxx(handler);
*/
/*
	QStringList patterns = doc->getUsedPatternsSelection((Selection*)&selection);
	for (int c = 0; c < patterns.count(); ++c)
	{
		ScPattern& pa = doc->docPatterns[patterns[c]];
		Xml_attr cattr;
		cattr["Name"] = patterns[c];
		cattr["scaleX"] = toXMLString(pa.scaleX);
		cattr["scaleY"] = toXMLString(pa.scaleY);
		cattr["width"] = toXMLString(pa.width);
		cattr["height"] = toXMLString(pa.height);
		cattr["xoffset"] = toXMLString(pa.xoffset);
		cattr["yoffset"] = toXMLString(pa.yoffset);
		handler.begin("Pattern", cattr);
		for (int o = 0; o < pa.items.count(); o++)
		{
			pa.items.at(o)->saxx(handler);
		}
		handler.end("Pattern");
	}
*/
	for (int i=0; i < doc->Items->count(); ++i)
	{
		int k = selection.findItem(doc->Items->at(i));
		if (k >=0)
			doc->Items->at(i)->saxx(handler);
	}

	handler.end("SCRIBUSFRAGMENT");
	handler.endDoc();
}
Example #10
0
bool EPSPlug::import(QString fName, const TransactionSettings &trSettings, int flags, bool showProgress)
{
#ifdef Q_OS_OSX
	#if QT_VERSION >= 0x050300
		showProgress = false;
	#endif
#endif

	bool success = false;
	interactive = (flags & LoadSavePlugin::lfInteractive);
	cancel = false;
	double x, y, b, h;
	bool ret = false;
	bool found = false;
	CustColors.clear();
	QFileInfo fi = QFileInfo(fName);
	QString ext = fi.suffix().toLower();
	if ( !ScCore->usingGUI() ) {
		interactive = false;
		showProgress = false;
	}
	if ( showProgress ) 
	{
		ScribusMainWindow* mw=(m_Doc==0) ? ScCore->primaryMainWindow() : m_Doc->scMW();
		progressDialog = new MultiProgressDialog( tr("Importing: %1").arg(fi.fileName()), CommonStrings::tr_Cancel, mw);
		QStringList barNames, barTexts;
		barNames << "GI";
		barTexts << tr("Analyzing PostScript:");
		QList<bool> barsNumeric;
		barsNumeric << false;
		progressDialog->addExtraProgressBars(barNames, barTexts, barsNumeric);
		progressDialog->setOverallTotalSteps(3);
		progressDialog->setOverallProgress(0);
		progressDialog->setProgress("GI", 0);
		progressDialog->show();
		connect(progressDialog, SIGNAL(canceled()), this, SLOT(cancelRequested()));
		qApp->processEvents();
	}
	else {
		progressDialog = NULL;
	}
	
/* Set default Page to size defined in Preferences */
	x = 0.0;
	y = 0.0;
	b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
	h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
	if (extensionIndicatesEPSorPS(ext))
	{
		QString tmp, BBox, tmp2, FarNam;
		ScColor cc;
		QFile f(fName);
		if (f.open(QIODevice::ReadOnly))
		{
/* Try to find Bounding Box */
			QDataStream ts(&f);
			while (!ts.atEnd())
			{
				tmp = readLinefromDataStream(ts);
				if (tmp.startsWith("%%BoundingBox:"))
				{
					found = true;
					BBox = tmp.remove("%%BoundingBox:");
				}
				if (!found)
				{
					if (tmp.startsWith("%%BoundingBox"))
					{
						found = true;
						BBox = tmp.remove("%%BoundingBox");
					}
				}
				if (tmp.startsWith("%%EndComments"))
					break; 
			}
			f.close();
			if (found)
			{
				QStringList bb = BBox.split(" ", QString::SkipEmptyParts);
				if (bb.count() == 4)
				{
					x = ScCLocale::toDoubleC(bb[0]);
					y = ScCLocale::toDoubleC(bb[1]);
					b = ScCLocale::toDoubleC(bb[2]);
					h = ScCLocale::toDoubleC(bb[3]);
				}
			}
		}
		importColorsFromFile(fName, CustColors);
	}
#ifdef HAVE_PODOFO
	else if (extensionIndicatesPDF(ext))
	{
		try
		{
			PoDoFo::PdfError::EnableDebug( false );
#if (PODOFO_VERSION == 0 && PODOFO_MINOR > 6)
		PoDoFo::PdfError::EnableLogging( false );
#endif
#if (PODOFO_VERSION == 0 && PODOFO_MINOR == 5 && PODOFO_REVISION == 99) || PODOFO_MINOR > 5
			PoDoFo::PdfMemDocument doc( fName.toLocal8Bit().data() );
#else
			PoDoFo::PdfDocument doc( fName.toLocal8Bit().data() );
#endif
			PoDoFo::PdfPage *curPage = doc.GetPage(0);
			if (curPage != NULL)
			{
				PoDoFo::PdfRect rect = curPage->GetMediaBox();
				b = rect.GetWidth() - rect.GetLeft();
				h = rect.GetHeight() - rect.GetBottom();
			}
		}
		catch(PoDoFo::PdfError& e)
		{
			qDebug("%s", "PoDoFo error while reading page size!");
			e.PrintErrorMsg();
		}
	}
#endif
	baseX = 0;
	baseY = 0;
	if (!interactive || (flags & LoadSavePlugin::lfInsertPage))
	{
		m_Doc->setPage(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false);
		m_Doc->addPage(0);
		m_Doc->view()->addPage(0, true);
		baseX = 0;
		baseY = 0;
	}
	else
	{
		if (!m_Doc || (flags & LoadSavePlugin::lfCreateDoc))
		{
			m_Doc=ScCore->primaryMainWindow()->doFileNew(b-x, h-y, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
			ScCore->primaryMainWindow()->HaveNewDoc();
			ret = true;
			baseX = 0;
			baseY = 0;
		}
	}
	if ((!ret) && (interactive))
	{
		baseX = m_Doc->currentPage()->xOffset();
		baseY = m_Doc->currentPage()->yOffset();
	}
	if ((ret) || (!interactive))
	{
		if (b-x > h-y)
			m_Doc->setPageOrientation(1);
		else
			m_Doc->setPageOrientation(0);
		m_Doc->setPageSize("Custom");
	}
	ColorList::Iterator it;
	for (it = CustColors.begin(); it != CustColors.end(); ++it)
	{
		if (!m_Doc->PageColors.contains(it.key()))
			m_Doc->PageColors.insert(it.key(), it.value());
	}
	boundingBoxRect.addRect(0, 0, b-x, h-y);
	Elements.clear();
	m_Doc->setLoading(true);
	m_Doc->DoDrawing = false;
	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
		m_Doc->view()->updatesOn(false);
	m_Doc->scMW()->setScriptRunning(true);
	qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
	QString CurDirP = QDir::currentPath();
	QDir::setCurrent(fi.path());
	if (convert(fName, x, y, b, h))
	{
// 		m_Doc->m_Selection->clear();
		tmpSel->clear();
		QDir::setCurrent(CurDirP);
//		if ((Elements.count() > 1) && (interactive))
		if (Elements.count() > 1)
			m_Doc->groupObjectsList(Elements);
		m_Doc->DoDrawing = true;
		m_Doc->scMW()->setScriptRunning(false);
		m_Doc->setLoading(false);
		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
		if ((Elements.count() > 0) && (!ret) && (interactive))
		{
			if (flags & LoadSavePlugin::lfScripted)
			{
				bool loadF = m_Doc->isLoading();
				m_Doc->setLoading(false);
				m_Doc->changed();
				m_Doc->setLoading(loadF);
				if (!(flags & LoadSavePlugin::lfLoadAsPattern))
				{
					m_Doc->m_Selection->delaySignalsOn();
					for (int dre=0; dre<Elements.count(); ++dre)
					{
						m_Doc->m_Selection->addItem(Elements.at(dre), true);
					}
					m_Doc->m_Selection->delaySignalsOff();
					m_Doc->m_Selection->setGroupRect();
					m_Doc->view()->updatesOn(true);
				}
			}
			else
			{
				m_Doc->DragP = true;
				m_Doc->DraggedElem = 0;
				m_Doc->DragElements.clear();
				m_Doc->m_Selection->delaySignalsOn();
				for (int dre=0; dre<Elements.count(); ++dre)
				{
					tmpSel->addItem(Elements.at(dre), true);
				}
				tmpSel->setGroupRect();
				ScriXmlDoc *ss = new ScriXmlDoc();
				ScElemMimeData* md = new ScElemMimeData();
				md->setScribusElem(ss->WriteElem(m_Doc, tmpSel));
				delete ss;
/*#ifndef Q_WS_MAC*/
// see #2196
				m_Doc->itemSelection_DeleteItem(tmpSel);
/*#else
				qDebug() << "psimport: leaving items on page";
#endif*/
				m_Doc->view()->updatesOn(true);
				m_Doc->m_Selection->delaySignalsOff();
				// We must copy the TransationSettings object as it is owned
				// by handleObjectImport method afterwards
				TransactionSettings* transacSettings = new TransactionSettings(trSettings);
				m_Doc->view()->handleObjectImport(md, transacSettings);
				m_Doc->DragP = false;
				m_Doc->DraggedElem = 0;
				m_Doc->DragElements.clear();
			}
		}
		else
		{
			m_Doc->changed();
			m_Doc->reformPages();
			if (!(flags & LoadSavePlugin::lfLoadAsPattern))
				m_Doc->view()->updatesOn(true);
		}
		success = true;
	}
	else
	{
		QDir::setCurrent(CurDirP);
		m_Doc->DoDrawing = true;
		m_Doc->scMW()->setScriptRunning(false);
		m_Doc->view()->updatesOn(true);
		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
	}
	if (interactive)
		m_Doc->setLoading(false);
	//CB If we have a gui we must refresh it if we have used the progressbar
	if (!(flags & LoadSavePlugin::lfLoadAsPattern))
	{
		if ((showProgress) && (!interactive))
			m_Doc->view()->DrawNew();
	}
	return success;
}
Example #11
0
bool importColorsFromFile(QString fileName, ColorList &EditColors, QHash<QString, VGradient> *dialogGradients, bool merge)
{
	if (fileName.isEmpty())
		return false;
	int oldCount = EditColors.count();

	QFileInfo fi = QFileInfo(fileName);
	QString ext = fi.suffix().toLower();
	if (extensionIndicatesEPSorPS(ext))
	{
		PaletteLoader_PS psPalLoader;
		psPalLoader.setupTargets(&EditColors, dialogGradients);
		return psPalLoader.importFile(fileName, merge);
	}
	else
	{
		QStringList allFormatsV = LoadSavePlugin::getExtensionsForColors();
		if (allFormatsV.contains(ext))
		{
			FileLoader fl(fileName);
			int testResult = fl.testFile();
			if (testResult != -1)
			{
				ColorList LColors;
				if (fl.readColors(LColors))
				{
					ColorList::Iterator it;
					for (it = LColors.begin(); it != LColors.end(); ++it)
					{
						EditColors.tryAddColor(it.key(), it.value());
					}
					return (EditColors.count() != oldCount);
				}
			}
		}
		if (ext == "acb")			// Adobe color book format
		{
			PaletteLoader_Adobe_acb adobePalLoader;
			if (adobePalLoader.isFileSupported(fileName))
			{
				adobePalLoader.setupTargets(&EditColors, dialogGradients);
				return adobePalLoader.importFile(fileName, merge);
			}

			PaletteLoader_Autocad_acb autocadPalLoder;
			if (autocadPalLoder.isFileSupported(fileName))
			{
				autocadPalLoder.setupTargets(&EditColors, dialogGradients);
				return autocadPalLoder.importFile(fileName, merge);
			}
			return false;
		}
		else if (ext == "aco")			// Adobe color swatch format
		{
			PaletteLoader_Adobe_aco adobePalLoader;
			if (adobePalLoader.isFileSupported(fileName))
			{
				adobePalLoader.setupTargets(&EditColors, dialogGradients);
				return adobePalLoader.importFile(fileName, merge);
			}
			return false;
		}
		else if (ext == "ase")			// Adobe swatch exchange format
		{
			PaletteLoader_Adobe_ase adobePalLoader;
			if (adobePalLoader.isFileSupported(fileName))
			{
				adobePalLoader.setupTargets(&EditColors, dialogGradients);
				return adobePalLoader.importFile(fileName, merge);
			}
			return false;
		}
		else if (ext == "cxf")			// Adobe swatch exchange format
		{
			PaletteLoader_CxF cxfLoader;
			if (cxfLoader.isFileSupported(fileName))
			{
				cxfLoader.setupTargets(&EditColors, dialogGradients);
				return cxfLoader.importFile(fileName, merge);
			}
			return false;
		}
		else if (ext == "skp")			// Sk1 palette
		{
			PaletteLoader_sK1 sk1PalLoader;
			if (sk1PalLoader.isFileSupported(fileName))
			{
				sk1PalLoader.setupTargets(&EditColors, dialogGradients);
				return sk1PalLoader.importFile(fileName, merge);
			}
			return false;
		}
		else if (ext == "sbz")
		{
			PaletteLoader_Swatchbook swatchbookLoader;
			if (swatchbookLoader.isFileSupported(fileName))
			{
				swatchbookLoader.setupTargets(&EditColors, dialogGradients);
				return swatchbookLoader.importFile(fileName, merge);
			}
			return false;
		}
		else							// try for OpenOffice, Viva and our own format
		{
			QFile fiC(fileName);
			if (fiC.open(QIODevice::ReadOnly))
			{
				QString ColorEn, Cname;
				int Rval, Gval, Bval, Kval;
				ScTextStream tsC(&fiC);
				ColorEn = tsC.readLine();
				bool cus = false;
				if (ColorEn.contains("OpenOffice"))
					cus = true;
				if ((ColorEn.startsWith("<?xml version=")) || (ColorEn.contains("VivaColors")))
				{
					QByteArray docBytes("");
					loadRawText(fileName, docBytes);
					QString docText("");
					docText = QString::fromUtf8(docBytes);
					QDomDocument docu("scridoc");
					docu.setContent(docText);
					ScColor lf = ScColor();
					QDomElement elem = docu.documentElement();
					QString dTag = "";
					dTag = elem.tagName();
					QString nameMask = "%1";
					nameMask = elem.attribute("mask", "%1");
					QDomNode PAGE = elem.firstChild();
					while (!PAGE.isNull())
					{
						QDomElement pg = PAGE.toElement();
						if (pg.tagName()=="COLOR" && pg.attribute("NAME")!=CommonStrings::None)
						{
							if (pg.hasAttribute("SPACE"))
							{
								QString space = pg.attribute("SPACE");
								if (space == "CMYK")
								{
									double c = pg.attribute("C", "0").toDouble() / 100.0;
									double m = pg.attribute("M", "0").toDouble() / 100.0;
									double y = pg.attribute("Y", "0").toDouble() / 100.0;
									double k = pg.attribute("K", "0").toDouble() / 100.0;
									lf.setCmykColorF(c, m, y, k);
								}
								else if (space == "RGB")
								{
									double r = pg.attribute("R", "0").toDouble() / 255.0;
									double g = pg.attribute("G", "0").toDouble() / 255.0;
									double b = pg.attribute("B", "0").toDouble() / 255.0;
									lf.setRgbColorF(r, g, b);
								}
								else if (space == "Lab")
								{
									double L = pg.attribute("L", "0").toDouble();
									double a = pg.attribute("A", "0").toDouble();
									double b = pg.attribute("B", "0").toDouble();
									lf.setLabColor(L, a, b);
								}
							}
							else if (pg.hasAttribute("CMYK"))
								lf.setNamedColor(pg.attribute("CMYK"));
							else if (pg.hasAttribute("RGB"))
								lf.fromQColor(QColor(pg.attribute("RGB")));
							else
							{
								double L = pg.attribute("L", "0").toDouble();
								double a = pg.attribute("A", "0").toDouble();
								double b = pg.attribute("B", "0").toDouble();
								lf.setLabColor(L, a, b);
							}
							if (pg.hasAttribute("Spot"))
								lf.setSpotColor(static_cast<bool>(pg.attribute("Spot").toInt()));
							else
								lf.setSpotColor(false);
							if (pg.hasAttribute("Register"))
								lf.setRegistrationColor(static_cast<bool>(pg.attribute("Register").toInt()));
							else
								lf.setRegistrationColor(false);
							EditColors.tryAddColor(pg.attribute("NAME"), lf);
						}
						else if (pg.tagName() == "Gradient")
						{
							if (dialogGradients != NULL)
							{
								VGradient gra = VGradient(VGradient::linear);
								gra.clearStops();
								QDomNode grad = pg.firstChild();
								while (!grad.isNull())
								{
									QDomElement stop = grad.toElement();
									QString name = stop.attribute("NAME");
									double ramp  = ScCLocale::toDoubleC(stop.attribute("RAMP"), 0.0);
									int shade    = stop.attribute("SHADE", "100").toInt();
									double opa   = ScCLocale::toDoubleC(stop.attribute("TRANS"), 1.0);
									QColor color;
									if (name == CommonStrings::None)
										color = QColor(255, 255, 255, 0);
									else
									{
										const ScColor& col = EditColors[name];
										color = ScColorEngine::getShadeColorProof(col, NULL, shade);
									}
									gra.addStop(color, ramp, 0.5, opa, name, shade);
									grad = grad.nextSibling();
								}
								if ((!dialogGradients->contains(pg.attribute("Name"))) || (merge))
									dialogGradients->insert(pg.attribute("Name"), gra);
								else
								{
									QString tmp;
									QString name = pg.attribute("Name");
									name += "("+tmp.setNum(dialogGradients->count())+")";
									dialogGradients->insert(name, gra);
								}
							}
						}
						else if (pg.tagName()=="draw:color" && pg.attribute("draw:name")!=CommonStrings::None)
						{
							if (pg.hasAttribute("draw:color"))
								lf.setNamedColor(pg.attribute("draw:color"));
							lf.setSpotColor(false);
							lf.setRegistrationColor(false);
							QString nam = pg.attribute("draw:name");
							if (!nam.isEmpty())
								EditColors.tryAddColor(nam, lf);
						}
						else if (dTag == "VivaColors")
						{
							int cVal = 0;
							int mVal = 0;
							int yVal = 0;
							int kVal = 0;
							QString nam = nameMask.arg(pg.attribute("name"));
							if (pg.attribute("type") == "cmyk")
							{
								QDomNode colNode = pg.firstChild();
								while (!colNode.isNull())
								{
									QDomElement colVal = colNode.toElement();
									if (colVal.tagName() == "cyan")
										cVal = colVal.text().toInt();
									if (colVal.tagName() == "magenta")
										mVal = colVal.text().toInt();
									if (colVal.tagName() == "yellow")
										yVal = colVal.text().toInt();
									if (colVal.tagName() == "key")
										kVal = colVal.text().toInt();
									colNode = colNode.nextSibling();
								}
								lf.setColorF(cVal / 100.0, mVal / 100.0, yVal / 100.0, kVal / 100.0);
								lf.setSpotColor(false);
								lf.setRegistrationColor(false);
								if (!nam.isEmpty())
									EditColors.tryAddColor(nam, lf);
							}
							else if (pg.attribute("type") == "rgb")
							{
								QDomNode colNode = pg.firstChild();
								while (!colNode.isNull())
								{
									QDomElement colVal = colNode.toElement();
									if (colVal.tagName() == "red")
										cVal = colVal.text().toInt();
									if (colVal.tagName() == "green")
										mVal = colVal.text().toInt();
									if (colVal.tagName() == "blue")
										yVal = colVal.text().toInt();
									colNode = colNode.nextSibling();
								}
								lf.setRgbColor(cVal, mVal, yVal);
								lf.setSpotColor(false);
								lf.setRegistrationColor(false);
								if (!nam.isEmpty())
									EditColors.tryAddColor(nam, lf);
							}
						}
						PAGE=PAGE.nextSibling();
					}
				}
				else
				{
					QString paletteName = "";
					QString dummy;
					if (ColorEn.startsWith("GIMP Palette"))
					{
						ColorEn = tsC.readLine();
						ScTextStream CoE(&ColorEn, QIODevice::ReadOnly);
						CoE >> dummy >> paletteName;
					}
					while (!tsC.atEnd())
					{
						ScColor tmp;
						ColorEn = tsC.readLine();
						if (ColorEn.length()>0 && ColorEn[0]==QChar('#'))
							continue;
						ScTextStream CoE(&ColorEn, QIODevice::ReadOnly);
						CoE >> Rval;
						CoE >> Gval;
						CoE >> Bval;
						if (cus)
						{
							CoE >> Kval;
							Cname = CoE.readAll().trimmed();
							tmp.setColor(Rval, Gval, Bval, Kval);
						}
						else
						{
							Cname = CoE.readAll().trimmed();
							tmp.setRgbColor(Rval, Gval, Bval);
						}
						if (Cname == "Untitled")
							Cname = "";
						if (Cname.length() == 0)
						{
							if (!cus)
								Cname = paletteName + QString("#%1%2%3").arg(Rval,2,16).arg(Gval,2,16).arg(Bval,2,16).toUpper();
							else
								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");
						}
						EditColors.tryAddColor(Cname, tmp);
					}
				}
				fiC.close();
			}
void CanvasMode_EyeDropper::mouseReleaseEvent(QMouseEvent *m)
{
	m_canvas->m_viewMode.m_MouseButtonPressed = false;
	m_canvas->resetRenderMode();
	m->accept();
//	m_view->stopDragTimer();

	releaseMouse();

	qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));

	QPixmap pm = QPixmap::grabWindow( QApplication::desktop()->winId(), m->globalPos().x(), m->globalPos().y(), 1, 1);
	QImage i = pm.toImage();
	QColor selectedColor=i.pixel(0, 0);

	bool found=false;
    ColorList::Iterator it;
	for (it = m_doc->PageColors.begin(); it != m_doc->PageColors.end(); ++it)
	{
		if (selectedColor== ScColorEngine::getRGBColor(it.value(), m_doc))
		{
			found=true;
			break;
		}
	}
	QString colorName=QString::null;
	if (found)
		colorName=it.key();
	else
	{
		bool ok;
		bool nameFound=false;
		QString questionString="<qt>"+ tr("The selected color does not exist in the document's color set. Please enter a name for this new color.")+"</qt>";
		do
		{
			colorName = QInputDialog::getText(m_ScMW, tr("Color Not Found"), questionString, QLineEdit::Normal, QString::null, &ok);
			if (ok)
			{
				if (m_doc->PageColors.contains(colorName))
					questionString="<qt>"+ tr("The name you have selected already exists. Please enter a different name for this new color.")+"</qt>";
				else
					nameFound=true;
			}
		} while (!nameFound && ok);
		if ( ok && !colorName.isEmpty() )
		{
			ScColor newColor(selectedColor.red(), selectedColor.green(), selectedColor.blue());
			m_doc->PageColors[colorName]=newColor;
			m_doc->changed();
			m_ScMW->updateColorLists();
		}
		else
			colorName=QString::null;
	}
	uint docSelectionCount=m_doc->m_Selection->count();
	if (!colorName.isNull() && docSelectionCount > 0)
	{
		for (uint i = 0; i < docSelectionCount; ++i)
		{
			PageItem *currItem=m_doc->m_Selection->itemAt(i);
			if (currItem!=NULL)
			{
				if ((m->modifiers() & Qt::ControlModifier) && (currItem->asTextFrame() || currItem->asPathText()))
					m_doc->itemSelection_SetFillColor(colorName); //Text colour
				else
				if (m->modifiers() & Qt::AltModifier) //Line colour
					m_doc->itemSelection_SetItemPen(colorName);
				else
					m_doc->itemSelection_SetItemBrush(colorName); //Fill colour
			}
		}
	}
	m_view->requestMode(modeNormal);
}