r14662 by fschmid - CVG Importer: added preview function for the fileselector.

scribus-commit scribus-commit at lists.scribus.net
Mon Feb 8 22:00:42 CET 2010


Revision: 14662
Author: fschmid
Date: 2010-02-08T20:58:20.247197Z
Commit message: CVG Importer: added preview function for the fileselector.

Changeset: 
M  /trunk/Scribus/scribus/plugins/import/cvg/importcvgplugin.h
M  /trunk/Scribus/scribus/plugins/import/cvg/importcvg.h
M  /trunk/Scribus/scribus/plugins/import/xar/importxar.cpp
M  /trunk/Scribus/scribus/scribus.cpp
M  /trunk/Scribus/scribus/scribusdoc.cpp
M  /trunk/Scribus/scribus/plugins/import/cvg/importcvgplugin.cpp
M  /trunk/Scribus/scribus/plugins/import/cvg/importcvg.cpp

Diffs:
Index: scribus/scribusdoc.cpp
===================================================================
--- scribus/scribusdoc.cpp	(revision 14661)
+++ scribus/scribusdoc.cpp	(revision 14662)
@@ -519,6 +519,57 @@
 {
 	m_guardedObject.nullify();
 	CloseCMSProfiles();
+	ScCore->fileWatcher->stop();
+	ScCore->fileWatcher->removeFile(DocName);
+	for (int a = 0; a < DocItems.count(); ++a)
+	{
+		PageItem *currItem = DocItems.at(a);
+		if (currItem->PictureIsAvailable)
+			ScCore->fileWatcher->removeFile(currItem->Pfile);
+		if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty()))
+		{
+			QFileInfo fi(currItem->Pfile);
+			ScCore->fileWatcher->removeDir(fi.absolutePath());
+		}
+	}
+	for (int a = 0; a < MasterItems.count(); ++a)
+	{
+		PageItem *currItem = MasterItems.at(a);
+		if (currItem->PictureIsAvailable)
+			ScCore->fileWatcher->removeFile(currItem->Pfile);
+		if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty()))
+		{
+			QFileInfo fi(currItem->Pfile);
+			ScCore->fileWatcher->removeDir(fi.absolutePath());
+		}
+	}
+	for (int a = 0; a < FrameItems.count(); ++a)
+	{
+		PageItem *currItem = FrameItems.at(a);
+		if (currItem->PictureIsAvailable)
+			ScCore->fileWatcher->removeFile(currItem->Pfile);
+		if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty()))
+		{
+			QFileInfo fi(currItem->Pfile);
+			ScCore->fileWatcher->removeDir(fi.absolutePath());
+		}
+	}
+	QStringList patterns = docPatterns.keys();
+	for (int c = 0; c < patterns.count(); ++c)
+	{
+		ScPattern pa = docPatterns[patterns[c]];
+		for (int o = 0; o < pa.items.count(); o++)
+		{
+			PageItem *currItem = pa.items.at(o);
+			if (currItem->PictureIsAvailable)
+				ScCore->fileWatcher->removeFile(currItem->Pfile);
+			if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty()))
+			{
+				QFileInfo fi(currItem->Pfile);
+				ScCore->fileWatcher->removeDir(fi.absolutePath());
+			}
+		}
+	}
 	while (!DocItems.isEmpty())
 	{
 		delete DocItems.takeFirst();
@@ -548,6 +599,7 @@
 	if (docHyphenator)
 		delete docHyphenator;
 	delete m_serializer;
+	ScCore->fileWatcher->start();
 }
 
 
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp	(revision 14661)
+++ scribus/scribus.cpp	(revision 14662)
@@ -4363,61 +4363,11 @@
 	closeActiveWindowMasterPageEditor();
 	slotSelect();
 	doc->autoSaveTimer->stop();
-	ScCore->fileWatcher->stop();
 	disconnect(doc->autoSaveTimer, SIGNAL(timeout()), doc->WinHan, SLOT(slotAutoSave()));
 	disconnect(doc->WinHan, SIGNAL(AutoSaved()), this, SLOT(slotAutoSaved()));
 	disconnect(ScCore->fileWatcher, SIGNAL(fileChanged(QString )), doc, SLOT(updatePict(QString)));
 	disconnect(ScCore->fileWatcher, SIGNAL(fileDeleted(QString )), doc, SLOT(removePict(QString)));
 	disconnect(ScCore->fileWatcher, SIGNAL(dirChanged(QString )), doc, SLOT(updatePictDir(QString )));
-	for (int a = 0; a < doc->DocItems.count(); ++a)
-	{
-		PageItem *currItem = doc->DocItems.at(a);
-		if (currItem->PictureIsAvailable)
-			ScCore->fileWatcher->removeFile(currItem->Pfile);
-		if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty()))
-		{
-			QFileInfo fi(currItem->Pfile);
-			ScCore->fileWatcher->removeDir(fi.absolutePath());
-		}
-	}
-	for (int a = 0; a < doc->MasterItems.count(); ++a)
-	{
-		PageItem *currItem = doc->MasterItems.at(a);
-		if (currItem->PictureIsAvailable)
-			ScCore->fileWatcher->removeFile(currItem->Pfile);
-		if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty()))
-		{
-			QFileInfo fi(currItem->Pfile);
-			ScCore->fileWatcher->removeDir(fi.absolutePath());
-		}
-	}
-	for (int a = 0; a < doc->FrameItems.count(); ++a)
-	{
-		PageItem *currItem = doc->FrameItems.at(a);
-		if (currItem->PictureIsAvailable)
-			ScCore->fileWatcher->removeFile(currItem->Pfile);
-		if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty()))
-		{
-			QFileInfo fi(currItem->Pfile);
-			ScCore->fileWatcher->removeDir(fi.absolutePath());
-		}
-	}
-	QStringList patterns = doc->docPatterns.keys();
-	for (int c = 0; c < patterns.count(); ++c)
-	{
-		ScPattern pa = doc->docPatterns[patterns[c]];
-		for (int o = 0; o < pa.items.count(); o++)
-		{
-			PageItem *currItem = pa.items.at(o);
-			if (currItem->PictureIsAvailable)
-				ScCore->fileWatcher->removeFile(currItem->Pfile);
-			if ((currItem->asImageFrame()) && (!currItem->Pfile.isEmpty()))
-			{
-				QFileInfo fi(currItem->Pfile);
-				ScCore->fileWatcher->removeDir(fi.absolutePath());
-			}
-		}
-	}
 	if (ScCore->haveCMS())
 		doc->CloseCMSProfiles();
 	//<<Palettes
@@ -4574,7 +4524,6 @@
 		Q_ASSERT(plugin); // all the returned names should represent loaded plugins
 		plugin->unsetDoc();
 	}
-	QString fName(view->Doc->DocName);
 	view->close();
 // 	delete view;
 	//CB Yes, we are setting it to NULL without deleting it. ActWin(ScribusWin) owns the view
@@ -4587,7 +4536,6 @@
 	styleManager->setDoc(0);
 	layerPalette->ClearInhalt();
 	docCheckerPalette->buildErrorList(0);
-	ScCore->fileWatcher->removeFile(fName);
 	HaveDoc--;
 	delete doc;
 	doc = NULL;
@@ -4600,7 +4548,6 @@
 		else
 			QDir::setCurrent( QDir::homePath() );
 	}
-	ScCore->fileWatcher->start();
 	return true;
 }
 
Index: scribus/plugins/import/cvg/importcvgplugin.h
===================================================================
--- scribus/plugins/import/cvg/importcvgplugin.h	(revision 14661)
+++ scribus/plugins/import/cvg/importcvgplugin.h	(revision 14662)
@@ -33,6 +33,7 @@
 		virtual void languageChange();
 		virtual bool fileSupported(QIODevice* file, const QString & fileName=QString::null) const;
 		virtual bool loadFile(const QString & fileName, const FileFormat & fmt, int flags, int index = 0);
+		virtual QImage readThumbnail(const QString& fileName);
 		virtual void addToMainWindowMenu(ScribusMainWindow *) {};
 
 	public slots:
Index: scribus/plugins/import/cvg/importcvg.h
===================================================================
--- scribus/plugins/import/cvg/importcvg.h	(revision 14661)
+++ scribus/plugins/import/cvg/importcvg.h	(revision 14662)
@@ -52,6 +52,7 @@
 	\retval bool true if import was ok
 	 */
 	bool import(QString fn, const TransactionSettings& trSettings, int flags, bool showProgress = true);
+	QImage readThumbnail(QString fn);
 
 private:
 	void parseHeader(QString fName, double &b, double &h);
Index: scribus/plugins/import/cvg/importcvgplugin.cpp
===================================================================
--- scribus/plugins/import/cvg/importcvgplugin.cpp	(revision 14661)
+++ scribus/plugins/import/cvg/importcvgplugin.cpp	(revision 14662)
@@ -160,3 +160,23 @@
 	delete dia;
 	return true;
 }
+
+QImage ImportCvgPlugin::readThumbnail(const QString& fileName)
+{
+	bool wasUndo = false;
+	if( fileName.isEmpty() )
+		return QImage();
+	if (UndoManager::undoEnabled())
+	{
+		UndoManager::instance()->setUndoEnabled(false);
+		wasUndo = true;
+	}
+	m_Doc = ScCore->primaryMainWindow()->doc;
+	CvgPlug *dia = new CvgPlug(m_Doc, lfCreateThumbnail);
+	Q_CHECK_PTR(dia);
+	QImage ret = dia->readThumbnail(fileName);
+	if (wasUndo)
+		UndoManager::instance()->setUndoEnabled(true);
+	delete dia;
+	return ret;
+}
Index: scribus/plugins/import/cvg/importcvg.cpp
===================================================================
--- scribus/plugins/import/cvg/importcvg.cpp	(revision 14661)
+++ scribus/plugins/import/cvg/importcvg.cpp	(revision 14662)
@@ -52,9 +52,166 @@
 {
 	tmpSel=new Selection(this, false);
 	m_Doc=doc;
+	importerFlags = flags;
 	interactive = (flags & LoadSavePlugin::lfInteractive);
 }
 
+QImage CvgPlug::readThumbnail(QString fName)
+{
+	QFileInfo fi = QFileInfo(fName);
+	baseFile = QDir::cleanPath(QDir::toNativeSeparators(fi.absolutePath()+"/"));
+	bool haveDoc = false;
+	double b, h;
+	parseHeader(fName, b, h);
+	if (b == 0.0)
+		b = PrefsManager::instance()->appPrefs.docSetupPrefs.pageWidth;
+	if (h == 0.0)
+		h = PrefsManager::instance()->appPrefs.docSetupPrefs.pageHeight;
+	docWidth = b;
+	docHeight = h;
+	ScribusView* tempView;
+	progressDialog = NULL;
+	if (!m_Doc)
+	{
+		haveDoc = true;
+		m_Doc = new ScribusDoc();
+		m_Doc->setup(0, 1, 1, 1, 1, "Custom", "Custom");
+		m_Doc->setPage(docWidth, docHeight, 0, 0, 0, 0, 0, 0, false, false);
+		m_Doc->addPage(0);
+		tempView = new ScribusView(0, ScCore->primaryMainWindow(), m_Doc);
+		tempView->setScale(1);
+		m_Doc->setGUI(false, ScCore->primaryMainWindow(), tempView);
+	}
+	baseX = m_Doc->currentPage()->xOffset();
+	baseY = m_Doc->currentPage()->yOffset();
+	Elements.clear();
+	m_Doc->setLoading(true);
+	m_Doc->DoDrawing = false;
+	m_Doc->view()->updatesOn(false);
+	m_Doc->scMW()->ScriptRunning = true;
+	qApp->changeOverrideCursor(QCursor(Qt::WaitCursor));
+	QString CurDirP = QDir::currentPath();
+	QDir::setCurrent(fi.path());
+	int groupCount = m_Doc->GroupCounter;
+	int itemCount = m_Doc->TotalItems;
+	if (convert(fName))
+	{
+		tmpSel->clear();
+		QDir::setCurrent(CurDirP);
+		if (Elements.count() > 0)
+		{
+			bool isGroup = true;
+			int firstElem = -1;
+			if (Elements.at(0)->Groups.count() != 0)
+				firstElem = Elements.at(0)->Groups.top();
+			for (int bx = 0; bx < Elements.count(); ++bx)
+			{
+				PageItem* bxi = Elements.at(bx);
+				if (bxi->Groups.count() != 0)
+				{
+					if (bxi->Groups.top() != firstElem)
+						isGroup = false;
+				}
+				else
+					isGroup = false;
+			}
+			if (!isGroup)
+			{
+				double minx = 99999.9;
+				double miny = 99999.9;
+				double maxx = -99999.9;
+				double maxy = -99999.9;
+				uint lowestItem = 999999;
+				uint highestItem = 0;
+				for (int a = 0; a < Elements.count(); ++a)
+				{
+					Elements.at(a)->Groups.push(m_Doc->GroupCounter);
+					PageItem* currItem = Elements.at(a);
+					lowestItem = qMin(lowestItem, currItem->ItemNr);
+					highestItem = qMax(highestItem, currItem->ItemNr);
+					double x1, x2, y1, y2;
+					currItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
+					minx = qMin(minx, x1);
+					miny = qMin(miny, y1);
+					maxx = qMax(maxx, x2);
+					maxy = qMax(maxy, y2);
+				}
+				double gx = minx;
+				double gy = miny;
+				double gw = maxx - minx;
+				double gh = maxy - miny;
+				PageItem *high = m_Doc->Items->at(highestItem);
+				int z = m_Doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, m_Doc->itemToolPrefs.shapeFillColor, m_Doc->itemToolPrefs.shapeLineColor, true);
+				PageItem *neu = m_Doc->Items->takeAt(z);
+				m_Doc->Items->insert(lowestItem, neu);
+				neu->Groups.push(m_Doc->GroupCounter);
+				neu->setItemName( tr("Group%1").arg(neu->Groups.top()));
+				neu->AutoName = false;
+				neu->isGroupControl = true;
+				neu->groupsLastItem = high;
+				neu->setTextFlowMode(PageItem::TextFlowDisabled);
+				for (int a = 0; a < m_Doc->Items->count(); ++a)
+				{
+					m_Doc->Items->at(a)->ItemNr = a;
+				}
+				Elements.prepend(neu);
+				m_Doc->GroupCounter++;
+			}
+		}
+		m_Doc->DoDrawing = true;
+		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+		m_Doc->m_Selection->delaySignalsOn();
+		QImage tmpImage;
+		if (Elements.count() > 0)
+		{
+			for (int dre=0; dre<Elements.count(); ++dre)
+			{
+				tmpSel->addItem(Elements.at(dre), true);
+			}
+			tmpSel->setGroupRect();
+			double sc = 500.0 / qMax(tmpSel->width(), tmpSel->height());
+			m_Doc->scaleGroup(sc, sc, true, tmpSel);
+			tmpImage = Elements.at(0)->DrawObj_toImage();
+		}
+		m_Doc->itemSelection_DeleteItem(tmpSel);
+		m_Doc->view()->updatesOn(true);
+		m_Doc->scMW()->ScriptRunning = false;
+		m_Doc->setLoading(false);
+		if (importedColors.count() != 0)
+		{
+			for (int cd = 0; cd < importedColors.count(); cd++)
+			{
+				m_Doc->PageColors.remove(importedColors[cd]);
+			}
+		}
+		m_Doc->m_Selection->delaySignalsOff();
+		if (haveDoc)
+		{
+			delete tempView;
+			delete m_Doc;
+		}
+		m_Doc->GroupCounter = groupCount;
+		m_Doc->TotalItems = itemCount;
+		return tmpImage;
+	}
+	else
+	{
+		QDir::setCurrent(CurDirP);
+		m_Doc->DoDrawing = true;
+		m_Doc->scMW()->ScriptRunning = false;
+		m_Doc->view()->updatesOn(true);
+		qApp->changeOverrideCursor(QCursor(Qt::ArrowCursor));
+		if (haveDoc)
+		{
+			delete tempView;
+			delete m_Doc;
+		}
+	}
+	m_Doc->GroupCounter = groupCount;
+	m_Doc->TotalItems = itemCount;
+	return QImage();
+}
+
 bool CvgPlug::import(QString fNameIn, const TransactionSettings& trSettings, int flags, bool showProgress)
 {
 	QString fName = fNameIn;
@@ -314,7 +471,6 @@
 		b = pgY / 72.0;
 		h = pgY / 72.0 * scPg;
 		f.close();
-		qDebug() << "Y" << pgY << "W" << pgW << "H" << pgH << "Scale" << scPg;
 	}
 }
 
@@ -370,7 +526,8 @@
 				getObjects(ts, colorFlag, lenData - 26);
 			}
 			ts.device()->seek(currentFilePos + lenData - 6);
-			progressDialog->setProgress("GI", ts.device()->pos());
+			if (progressDialog)
+				progressDialog->setProgress("GI", ts.device()->pos());
 			qApp->processEvents();
 		}
 		if (Elements.count() == 0)
Index: scribus/plugins/import/xar/importxar.cpp
===================================================================
--- scribus/plugins/import/xar/importxar.cpp	(revision 14661)
+++ scribus/plugins/import/xar/importxar.cpp	(revision 14662)
@@ -62,6 +62,7 @@
 {
 	tmpSel=new Selection(this, false);
 	m_Doc=doc;
+	importerFlags = flags;
 	interactive = (flags & LoadSavePlugin::lfInteractive);
 }
 




More information about the scribus-commit mailing list