r14785 by fschmid - Allow dropping of objects from the scrapbook onto an empty Scribus main window, now complete for .sce, .sml and .shape.

scribus-commit scribus-commit at lists.scribus.net
Sun Feb 21 00:50:38 CET 2010


Revision: 14785
Author: fschmid
Date: 2010-02-20T23:47:16.235114Z
Commit message: Allow dropping of objects from the scrapbook onto an empty Scribus main window, now complete for .sce, .sml and .shape.

Changeset: 
M  /trunk/Scribus/scribus/scribus.cpp

Diffs:
Index: scribus/scribus.cpp
===================================================================
--- scribus/scribus.cpp	(revision 14784)
+++ scribus/scribus.cpp	(revision 14785)
@@ -9265,7 +9265,7 @@
 		for( int i = 0; i < fileUrls.count(); ++i )
 		{
 			fileUrl = fileUrls[i].toLocalFile().toLower();
-			if ( fileUrl.endsWith(".sla") || fileUrl.endsWith(".sla.gz") )
+			if (fileUrl.endsWith(".sla") || fileUrl.endsWith(".sla.gz") || fileUrl.endsWith(".sml") || fileUrl.endsWith(".shape") || fileUrl.endsWith(".sce"))
 			{
 				accepted = true;
 				break;
@@ -9284,6 +9284,12 @@
 			}
 		}
 	}
+	else if (e->mimeData()->hasText())
+	{
+		QString text = e->mimeData()->text();
+		if ((text.startsWith("<SCRIBUSELEM")) || (text.startsWith("SCRIBUSELEMUTF8")))
+			accepted = true;
+	}
 	if (accepted)
 		e->accept();
 }
@@ -9308,6 +9314,45 @@
 					loadDoc( fi.absoluteFilePath() );
 				}
 			}
+			else if ((fileUrl.endsWith(".shape")) || (fileUrl.endsWith(".sml")) || (fileUrl.endsWith(".sce")))
+			{
+				QUrl url( fileUrls[i] );
+				QFileInfo fi(url.path());
+				if ( fi.exists() )
+				{
+					accepted = true;
+					QString data;
+					QByteArray cf;
+					loadRawText(url.toLocalFile(), cf);
+					if (fileUrl.endsWith(".sce"))
+						data = QString::fromUtf8(cf.data());
+					else
+					{
+						QString f = QString::fromUtf8(cf.data());
+						StencilReader *pre = new StencilReader();
+						if (fileUrl.endsWith(".shape"))
+							data = pre->createShape(f);
+						else if (fileUrl.endsWith(".sml"))
+							data = pre->createObjects(f);
+						delete pre;
+					}
+					double gx, gy, gw, gh;
+					ScriXmlDoc *ss = new ScriXmlDoc();
+					if(ss->ReadElemHeader(data, false, &gx, &gy, &gw, &gh))
+					{
+						doFileNew(gw, gh, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
+						HaveNewDoc();
+						doc->reformPages(true);
+						if (fileUrl.endsWith(".sce"))
+							slotElemRead(data, doc->currentPage()->xOffset(), doc->currentPage()->yOffset(), false, false, doc, view);
+						else
+							slotElemRead(data, doc->currentPage()->xOffset(), doc->currentPage()->yOffset(), false, true, doc, view);
+						slotDocCh(false);
+						doc->regionsChanged()->update(QRectF());
+						delete ss;
+					}
+				}
+			}
 			else
 			{
 				QUrl url( fileUrls[i] );
@@ -9326,6 +9371,28 @@
 			}
 		}
 	}
+	else
+	{
+		if (e->mimeData()->hasText())
+		{
+			QString text = e->mimeData()->text();
+			if ((text.startsWith("<SCRIBUSELEM")) || (text.startsWith("SCRIBUSELEMUTF8")))
+			{
+				double gx, gy, gw, gh;
+				ScriXmlDoc *ss = new ScriXmlDoc();
+				if(ss->ReadElemHeader(text, false, &gx, &gy, &gw, &gh))
+				{
+					doFileNew(gw, gh, 0, 0, 0, 0, 0, 0, false, false, 0, false, 0, 1, "Custom", true);
+					HaveNewDoc();
+					doc->reformPages(true);
+					slotElemRead(text, doc->currentPage()->xOffset(), doc->currentPage()->yOffset(), false, false, doc, view);
+					slotDocCh(false);
+					doc->regionsChanged()->update(QRectF());
+					delete ss;
+				}
+			}
+		}
+	}
 	if (accepted)
 		e->accept();
 }




More information about the scribus-commit mailing list