r17905 by fschmid - Fixed Bug #9633: "recalculate the group shape after having removed an item" by adding an "Adjust Group" command.

scribus-commit scribus-commit at lists.scribus.net
Sat Nov 24 22:28:02 UTC 2012


Author: fschmid
Date: Sat Nov 24 22:28:02 2012
New Revision: 17905

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17905
Log:
Fixed Bug #9633: "recalculate the group shape after having removed an item" by adding an "Adjust Group" command.

Modified:
    trunk/Scribus/scribus/actionmanager.cpp
    trunk/Scribus/scribus/fpointarray.cpp
    trunk/Scribus/scribus/fpointarray.h
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
    trunk/Scribus/scribus/scribus.cpp
    trunk/Scribus/scribus/scribus.h
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h
    trunk/Scribus/scribus/ui/contextmenu.cpp

Modified: trunk/Scribus/scribus/actionmanager.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17905&path=/trunk/Scribus/scribus/actionmanager.cpp
==============================================================================
--- trunk/Scribus/scribus/actionmanager.cpp (original)
+++ trunk/Scribus/scribus/actionmanager.cpp Sat Nov 24 22:28:02 2012
@@ -400,6 +400,8 @@
 	scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
 	name="itemUngroup";
 	scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
+	name="itemGroupAdjust";
+	scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
 	name="itemLock";
 	scrActions->insert(name, new ScrAction("", defaultKey(name), mainWindow));
 	name="itemLockSize";
@@ -524,6 +526,7 @@
 	connect( (*scrActions)["itemTransform"], SIGNAL(triggered()), mainWindow, SLOT(slotItemTransform()) );
 	connect( (*scrActions)["itemGroup"], SIGNAL(triggered()), mainWindow, SLOT(GroupObj()) );
 	connect( (*scrActions)["itemUngroup"], SIGNAL(triggered()), mainWindow, SLOT(UnGroupObj()) );
+	connect( (*scrActions)["itemGroupAdjust"], SIGNAL(triggered()), mainWindow, SLOT(AdjustGroupObj()) );
 	connect( (*scrActions)["itemPDFAnnotationProps"], SIGNAL(triggered()), mainWindow, SLOT(ModifyAnnot()) );
 	connect( (*scrActions)["itemPDFFieldProps"], SIGNAL(triggered()), mainWindow, SLOT(ModifyAnnot()) );
 	connect( (*scrActions)["itemSendToPattern"], SIGNAL(triggered()), mainWindow, SLOT(PutToPatterns()) );
@@ -1494,6 +1497,7 @@
 	(*scrActions)["itemDelete"]->setTexts( tr("&Delete"));
 	(*scrActions)["itemGroup"]->setTexts( tr("&Group"));
 	(*scrActions)["itemUngroup"]->setTexts( tr("&Ungroup"));
+	(*scrActions)["itemGroupAdjust"]->setTexts( tr("Adjust Group"));
 	(*scrActions)["itemLock"]->setTexts( tr("Is &Locked"));
 	(*scrActions)["itemLockSize"]->setTexts( tr("Si&ze is Locked"));
 	(*scrActions)["itemPrintingEnabled"]->setTexts( tr("&Printing Enabled"));
@@ -1993,6 +1997,7 @@
 		<< "itemDelete" 
 		<< "itemGroup" 
 		<< "itemUngroup"
+		<< "itemGroupAdjust"
 		<< "itemLock" 
 		<< "itemLockSize" 
 		<< "itemImageIsVisible" 

Modified: trunk/Scribus/scribus/fpointarray.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17905&path=/trunk/Scribus/scribus/fpointarray.cpp
==============================================================================
--- trunk/Scribus/scribus/fpointarray.cpp (original)
+++ trunk/Scribus/scribus/fpointarray.cpp Sat Nov 24 22:28:02 2012
@@ -566,7 +566,7 @@
 	return m_path;
 }
 
-void FPointArray::fromQPainterPath(QPainterPath &path)
+void FPointArray::fromQPainterPath(QPainterPath &path, bool close)
 {
 	resize(0);
 	svgInit();
@@ -591,6 +591,8 @@
 				break;
 		}
 	}
+	if (close)
+		svgClosePath();
 }
 
 FPointArray::~FPointArray()

Modified: trunk/Scribus/scribus/fpointarray.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17905&path=/trunk/Scribus/scribus/fpointarray.h
==============================================================================
--- trunk/Scribus/scribus/fpointarray.h (original)
+++ trunk/Scribus/scribus/fpointarray.h Sat Nov 24 22:28:02 2012
@@ -85,7 +85,7 @@
 	bool parseSVG(const QString& svgPath);
 	QString svgPath(bool closed = false) const;
 	QPainterPath toQPainterPath(bool closed);
-	void fromQPainterPath(QPainterPath &path);
+	void fromQPainterPath(QPainterPath &path, bool close = false);
 private:
 	SVGState * svgState;
 };

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17905&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Sat Nov 24 22:28:02 2012
@@ -2760,7 +2760,11 @@
 void PageItem::setGradient(const QString &newGradient)
 {
 	if (gradientVal != newGradient)
+	{
 		gradientVal = newGradient;
+		if (m_Doc->docGradients.contains(gradientVal))
+			fill_gradient = m_Doc->docGradients[gradientVal];
+	}
 }
 
 void PageItem::setMaskGradient(VGradient grad){

Modified: trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17905&path=/trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp (original)
+++ trunk/Scribus/scribus/plugins/import/pdf/importpdf.cpp Sat Nov 24 22:28:02 2012
@@ -266,8 +266,16 @@
 	{
 		tmpSele->clear();
 		QDir::setCurrent(CurDirP);
+		if ((Elements.count() == 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
+		{
+			PageItem *gr = Elements[0];
+			m_Doc->resizeGroupToContents(gr);
+		}
 		if ((Elements.count() > 1) && (!(importerFlags & LoadSavePlugin::lfCreateDoc)))
-			m_Doc->groupObjectsList(Elements);
+		{
+			PageItem *gr = m_Doc->groupObjectsList(Elements);
+			m_Doc->resizeGroupToContents(gr);
+		}
 		m_Doc->DoDrawing = true;
 		m_Doc->scMW()->setScriptRunning(false);
 		m_Doc->setLoading(false);

Modified: trunk/Scribus/scribus/scribus.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17905&path=/trunk/Scribus/scribus/scribus.cpp
==============================================================================
--- trunk/Scribus/scribus/scribus.cpp (original)
+++ trunk/Scribus/scribus/scribus.cpp Sat Nov 24 22:28:02 2012
@@ -826,6 +826,7 @@
 	scrMenuMgr->addMenuSeparator("Item");
 	scrMenuMgr->addMenuItem(scrActions["itemGroup"], "Item", false);
 	scrMenuMgr->addMenuItem(scrActions["itemUngroup"], "Item", false);
+	scrMenuMgr->addMenuItem(scrActions["itemGroupAdjust"], "Item", false);
 	scrMenuMgr->addMenuItem(scrActions["itemLock"], "Item", false);
 	scrMenuMgr->addMenuItem(scrActions["itemLockSize"], "Item", false);
 	scrMenuMgr->addMenuSeparator("Item");
@@ -3288,10 +3289,12 @@
 		if (currItem->isGroup())
 		{
 			scrActions["itemUngroup"]->setEnabled(doc->appMode != modeEdit);
+			scrActions["itemGroupAdjust"]->setEnabled(doc->appMode != modeEdit);
 		}
 		else
 		{
 			scrActions["itemUngroup"]->setEnabled(false);
+			scrActions["itemGroupAdjust"]->setEnabled(false);
 			scrActions["itemSplitPolygons"]->setEnabled( (currItem->asPolygon()) && (currItem->Segments.count() != 0) );
 		}
 		if (currItem->locked())
@@ -7825,6 +7828,7 @@
 		{
 			view->requestMode(modeEditClip);
 			scrActions["itemUngroup"]->setEnabled(false);
+			scrActions["itemGroupAdjust"]->setEnabled(false);
 		}
 	}
 	else if (ite->itemType() == PageItem::TextFrame)
@@ -9140,6 +9144,12 @@
 {
 	if (HaveDoc)
 		doc->itemSelection_UnGroupObjects();
+}
+
+void ScribusMainWindow::AdjustGroupObj()
+{
+	if (HaveDoc)
+		doc->itemSelection_resizeGroupToContents();
 }
 
 void ScribusMainWindow::restore(UndoState* state, bool isUndo)

Modified: trunk/Scribus/scribus/scribus.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17905&path=/trunk/Scribus/scribus/scribus.h
==============================================================================
--- trunk/Scribus/scribus/scribus.h (original)
+++ trunk/Scribus/scribus/scribus.h Sat Nov 24 22:28:02 2012
@@ -477,6 +477,7 @@
 	void Apply_MasterPage(QString pageName, int pageNumber, bool reb = true);
 	void GroupObj(bool showLockDia = true);
 	void UnGroupObj();
+	void AdjustGroupObj();
 	void StatusPic();
 	void ModifyAnnot();
 	void ToggleGuides();

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17905&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Sat Nov 24 22:28:02 2012
@@ -15137,6 +15137,77 @@
 	setRedrawBounding(item);
 }
 
+void ScribusDoc::resizeGroupToContents(PageItem* group)
+{
+	PageItem_Group* currItem = group->asGroupFrame();
+	QPainterPath input1 = currItem->PoLine.toQPainterPath(true);
+	input1.translate(currItem->xPos(), currItem->yPos());
+	if (currItem->fillEvenOdd())
+		input1.setFillRule(Qt::OddEvenFill);
+	else
+		input1.setFillRule(Qt::WindingFill);
+	double minx =  std::numeric_limits<double>::max();
+	double miny =  std::numeric_limits<double>::max();
+	double maxx = -std::numeric_limits<double>::max();
+	double maxy = -std::numeric_limits<double>::max();
+	int gcount = currItem->groupItemList.count();
+	for (int c = 0; c < gcount; c++)
+	{
+		PageItem* gItem = currItem->groupItemList.at(c);
+		gItem->setXYPos(currItem->xPos() + gItem->gXpos, currItem->yPos() + gItem->gYpos, true);
+		double x1, x2, y1, y2;
+		gItem->getVisualBoundingRect(&x1, &y1, &x2, &y2);
+		minx = qMin(minx, x1);
+		miny = qMin(miny, y1);
+		maxx = qMax(maxx, x2);
+		maxy = qMax(maxy, y2);
+	}
+	double oldW = currItem->width();
+	double oldH = currItem->height();
+	currItem->setXYPos(minx, miny, true);
+	currItem->setWidthHeight(maxx - minx, maxy - miny, true);
+	currItem->groupWidth = maxx - minx;
+	currItem->groupHeight = maxy - miny;
+	for (int c = 0; c < gcount; c++)
+	{
+		PageItem* gItem = currItem->groupItemList.at(c);
+		gItem->gXpos = gItem->xPos() - minx;
+		gItem->gYpos = gItem->yPos() - miny;
+		gItem->gWidth = maxx - minx;
+		gItem->gHeight = maxy - miny;
+	}
+	currItem->SetRectFrame();
+	if ((currItem->width() < oldW) || (currItem->height() < oldH))
+	{
+		QPainterPath input2 = currItem->PoLine.toQPainterPath(true);
+		input2.translate(currItem->xPos(), currItem->yPos());
+		if (currItem->fillEvenOdd())
+			input2.setFillRule(Qt::OddEvenFill);
+		else
+			input2.setFillRule(Qt::WindingFill);
+		QPainterPath result = input1.intersected(input2);
+		result.translate(-currItem->xPos(), -currItem->yPos());
+		currItem->PoLine.fromQPainterPath(result, true);
+	}
+	currItem->adjustXYPosition();
+}
+
+void ScribusDoc::itemSelection_resizeGroupToContents(Selection* customSelection)
+{
+	Selection* itemSelection = (customSelection!=0) ? customSelection : m_Selection;
+	if (itemSelection->count() != 0)
+	{
+		int docSelectionCount = itemSelection->count();
+		for (int a = 0; a < docSelectionCount; ++a)
+		{
+			PageItem *group = itemSelection->itemAt(a);
+			if (group->isGroup())
+				resizeGroupToContents(group);
+		}
+		regionsChanged()->update(QRectF());
+	}
+}
+
 void ScribusDoc::itemSelection_UniteItems(Selection* /*customSelection*/)
 {
 	PageItem *currItem;

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17905&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Sat Nov 24 22:28:02 2012
@@ -1030,6 +1030,8 @@
 	void itemSelection_UnGroupObjects(Selection* customSelection=0);
 	void addToGroup(PageItem* group, PageItem* item);
 	void removeFromGroup(PageItem* item);
+	void resizeGroupToContents(PageItem* group);
+	void itemSelection_resizeGroupToContents(Selection *customSelection=0);
 	void itemSelection_convertItemsTo(const PageItem::ItemType newType, Selection* restoredSelection=0, Selection* customSelection=0);
 
 	void itemSelection_ApplyParagraphStyle(const ParagraphStyle & newstyle, Selection* customSelection=0, bool rmDirectFormatting = false);

Modified: trunk/Scribus/scribus/ui/contextmenu.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17905&path=/trunk/Scribus/scribus/ui/contextmenu.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/contextmenu.cpp (original)
+++ trunk/Scribus/scribus/ui/contextmenu.cpp Sat Nov 24 22:28:02 2012
@@ -386,7 +386,10 @@
 	else
 	{
 		if (currItem->isGroup())
+		{
 			addAction(m_AP->scrActions["itemUngroup"]);
+			addAction(m_AP->scrActions["itemGroupAdjust"]);
+		}
 	}
 	//-->
 




More information about the scribus-commit mailing list