r16961 by fschmid - Several improvements in the handling of groups.

scribus-commit scribus-commit at lists.scribus.net
Sat Nov 5 21:16:09 UTC 2011


Author: fschmid
Date: Sat Nov  5 21:16:08 2011
New Revision: 16961

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=16961
Log:
Several improvements in the handling of groups.

Modified:
    trunk/Scribus/scribus/canvasmode.cpp
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/pageitem.h
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusview.cpp
    trunk/Scribus/scribus/ui/cpalette.cpp

Modified: trunk/Scribus/scribus/canvasmode.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16961&path=/trunk/Scribus/scribus/canvasmode.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode.cpp (original)
+++ trunk/Scribus/scribus/canvasmode.cpp Sat Nov  5 21:16:08 2011
@@ -320,81 +320,81 @@
 		
 		// FIXME when more than 1 item is selected, first Rect is drew normally (<10ms here)
 		// but followings are damn long - pm 
-		for (uint a=0; a<docSelectionCount; ++a)
+		for (uint a = 0; a < docSelectionCount; ++a)
 		{
 			currItem = m_doc->m_Selection->itemAt(a);
-// 			qDebug()<<"It"<<currItem->xPos()<< currItem->yPos();
-			
 			psx->save();
 			psx->setPen(m_pen["selection"]);
 			psx->setBrush(m_brush["selection"]);
 			double lineAdjust(psx->pen().width()/m_canvas->scale());
 			double x, y, w, h;
-			w = currItem->visualWidth();
-			h = currItem->visualHeight();
-			if (currItem->rotation() != 0)
-			{
-				psx->setRenderHint(QPainter::Antialiasing);
-				psx->translate(currItem->xPos(), currItem->yPos());
-				psx->rotate(currItem->rotation());
-				x = currItem->asLine() ? 0 : (currItem->visualXPos() - currItem->xPos() - lineAdjust);
-				y = currItem->asLine() ? (h / -2.0) : (currItem->visualYPos() - currItem->yPos() - lineAdjust);
+			if (currItem->Parent != NULL)
+			{
+				QTransform t = currItem->getCombinedTransform();
+				psx->setTransform(t, true);
+				w = currItem->visualWidth();
+				h = currItem->visualHeight();
+			//	x = currItem->asLine() ? 0 : (currItem->visualXPos() - currItem->xPos() - lineAdjust);
+			//	y = currItem->asLine() ? (h / -2.0) : (currItem->visualYPos() - currItem->yPos() - lineAdjust);
+			//	w = currItem->width();
+			//	h = currItem->height();
+				x = -lineAdjust;
+				y = -lineAdjust;
+				psx->setPen(m_pen["selection-group-inside"]);
+				psx->setBrush(m_brush["selection-group-inside"]);
+				psx->drawRect(QRectF(x, y, w, h));
 			}
 			else
 			{
-				psx->translate(currItem->visualXPos(), currItem->visualYPos());
-				x = currItem->asLine() ? 0 : -lineAdjust;
-				y = currItem->asLine() ? 0 : -lineAdjust;
-			}
-			
-//			tt.start();
-			psx->drawRect(QRectF(x, y, w, h));
-//			tu << QString::number(tt.elapsed());
-			if(drawHandles && !currItem->locked())
-			{
-				psx->setBrush(m_brush["handle"]);
-				psx->setPen(m_pen["handle"]);
-				if(currItem->asLine())
+				if (currItem->rotation() != 0)
 				{
 					psx->setRenderHint(QPainter::Antialiasing);
-					psx->drawEllipse(QRectF(x+w-markWidth, y+h/2.0-markWidth, 2* markWidth,2* markWidth));
-// 					psx->setBrush(Qt::blue); // sometimes we forget which is what :)
-					psx->drawEllipse(QRectF(x-markWidth, y+h/2.0-markWidth, 2* markWidth, 2* markWidth));
+					psx->translate(currItem->xPos(), currItem->yPos());
+					psx->rotate(currItem->rotation());
+					x = currItem->asLine() ? 0 : (currItem->visualXPos() - currItem->xPos() - lineAdjust);
+					y = currItem->asLine() ? (h / -2.0) : (currItem->visualYPos() - currItem->yPos() - lineAdjust);
 				}
 				else
 				{
-					psx->drawRect(QRectF(x+w-markWidth, y+h-markWidth, markWidth, markWidth));
-					psx->drawRect(QRectF(x+w/2 - halfMarkWidth, y+h-markWidth, markWidth, markWidth));
-					psx->drawRect(QRectF(x+w/2 - halfMarkWidth, y, markWidth, markWidth));
-					psx->drawRect(QRectF(x+w-markWidth, y+h/2 - halfMarkWidth, markWidth, markWidth));
-					psx->drawRect(QRectF(x+w-markWidth, y, markWidth, markWidth));
-					psx->drawRect(QRectF(x, y, markWidth, markWidth));
-					psx->drawRect(QRectF(x, y+h/2 - halfMarkWidth, markWidth, markWidth));
-					psx->drawRect(QRectF(x, y+h-markWidth, markWidth, markWidth));
-				}
-			}
-			if (currItem->isWelded())
-			{
-				psx->setPen(QPen(Qt::yellow, 8.0 / m_canvas->scale(), Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
-				for (int i = 0 ; i <  currItem->weldList.count(); i++)
-				{
-					PageItem::weldingInfo wInf =  currItem->weldList.at(i);
-					psx->drawPoint(QPointF(wInf.weldPoint.x(), wInf.weldPoint.y()));
-				}
-				//draw marker for weld point
-			/*	psx->setBrush(m_brush["outline"]);
-				psx->setPen(m_pen["outline"]);
-				double weldX = x, weldY = y;
-				if (currItem->myWeldPoint == topCenter || currItem->myWeldPoint == centerCenter || currItem->myWeldPoint == bottomCenter)
-					weldX += w /2 - halfMarkWidth;
-				else if (currItem->myWeldPoint == topRight  || currItem->myWeldPoint == centerRight || currItem->myWeldPoint == bottomRight)
-					weldX += w - markWidth;
-
-				if (currItem->myWeldPoint == centerLeft  || currItem->myWeldPoint == centerCenter || currItem->myWeldPoint == centerRight)
-					weldY += h/2 - halfMarkWidth;
-				else if (currItem->myWeldPoint == bottomLeft  || currItem->myWeldPoint == bottomCenter || currItem->myWeldPoint == bottomRight)
-					weldY += h - markWidth;
-				psx->drawRect(QRectF(weldX, weldY, markWidth, markWidth));*/
+					psx->translate(currItem->visualXPos(), currItem->visualYPos());
+					x = currItem->asLine() ? 0 : -lineAdjust;
+					y = currItem->asLine() ? 0 : -lineAdjust;
+				}
+				w = currItem->visualWidth();
+				h = currItem->visualHeight();
+				psx->drawRect(QRectF(x, y, w, h));
+				if(drawHandles && !currItem->locked())
+				{
+					psx->setBrush(m_brush["handle"]);
+					psx->setPen(m_pen["handle"]);
+					if(currItem->asLine())
+					{
+						psx->setRenderHint(QPainter::Antialiasing);
+						psx->drawEllipse(QRectF(x+w-markWidth, y+h/2.0-markWidth, 2* markWidth,2* markWidth));
+	// 					psx->setBrush(Qt::blue); // sometimes we forget which is what :)
+						psx->drawEllipse(QRectF(x-markWidth, y+h/2.0-markWidth, 2* markWidth, 2* markWidth));
+					}
+					else
+					{
+						psx->drawRect(QRectF(x+w-markWidth, y+h-markWidth, markWidth, markWidth));
+						psx->drawRect(QRectF(x+w/2 - halfMarkWidth, y+h-markWidth, markWidth, markWidth));
+						psx->drawRect(QRectF(x+w/2 - halfMarkWidth, y, markWidth, markWidth));
+						psx->drawRect(QRectF(x+w-markWidth, y+h/2 - halfMarkWidth, markWidth, markWidth));
+						psx->drawRect(QRectF(x+w-markWidth, y, markWidth, markWidth));
+						psx->drawRect(QRectF(x, y, markWidth, markWidth));
+						psx->drawRect(QRectF(x, y+h/2 - halfMarkWidth, markWidth, markWidth));
+						psx->drawRect(QRectF(x, y+h-markWidth, markWidth, markWidth));
+					}
+				}
+				if (currItem->isWelded())
+				{
+					psx->setPen(QPen(Qt::yellow, 8.0 / m_canvas->scale(), Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
+					for (int i = 0 ; i <  currItem->weldList.count(); i++)
+					{
+						PageItem::weldingInfo wInf =  currItem->weldList.at(i);
+						psx->drawPoint(QPointF(wInf.weldPoint.x(), wInf.weldPoint.y()));
+					}
+				}
 			}
 			
 			psx->restore();

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16961&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Sat Nov  5 21:16:08 2011
@@ -179,7 +179,7 @@
 	OldB2(other.OldB2),
 	OldH2(other.OldH2),
 	Sizing(other.Sizing),
-	toPixmap(other.toPixmap),
+//	toPixmap(other.toPixmap),
 	LayerID(other.LayerID),
 	ScaleType(other.ScaleType),
 	AspectRatio(other.AspectRatio),
@@ -594,7 +594,7 @@
 	inPdfArticle = false;
 	isRaster = false;
 	Sizing = false;
-	toPixmap = false;
+//	toPixmap = false;
 	UseEmbedded = true;
 	IRender = Intent_Relative_Colorimetric;
 	EmProfile = "";
@@ -2055,8 +2055,6 @@
 
 QImage PageItem::DrawObj_toImage(double maxSize)
 {
-	QList<PageItem*> emG;
-	emG.clear();
 	double minx =  std::numeric_limits<double>::max();
 	double miny =  std::numeric_limits<double>::max();
 	double maxx = -std::numeric_limits<double>::max();
@@ -2067,13 +2065,55 @@
 	miny = qMin(miny, y1);
 	maxx = qMax(maxx, x2);
 	maxy = qMax(maxy, y2);
-	gXpos = xPos() - minx;
-	gYpos = yPos() - miny;
-	gWidth = maxx - minx;
-	gHeight = maxy - miny;
-	double sc = maxSize / qMax(gWidth, gHeight);
-	emG.append(this);
-	return DrawObj_toImage(emG, sc);
+	double igXpos = xPos() - minx;
+	double igYpos = yPos() - miny;
+	double igWidth = maxx - minx;
+	double igHeight = maxy - miny;
+	double sc = maxSize / qMax(igWidth, igHeight);
+	bool savedFlag = m_Doc->guidesPrefs().framesShown;
+	m_Doc->guidesPrefs().framesShown = false;
+	QImage retImg = QImage(qRound(igWidth * sc), qRound(igHeight * sc), QImage::Format_ARGB32_Premultiplied);
+	retImg.fill( qRgba(0, 0, 0, 0) );
+	ScPainter *painter = new ScPainter(&retImg, retImg.width(), retImg.height(), 1, 0);
+	painter->setZoomFactor(sc);
+	painter->save();
+	painter->translate(igXpos, igYpos);
+	isEmbedded = true;
+	invalid = true;
+	DrawObj(painter, QRectF());
+	isEmbedded = false;
+	painter->restore();
+	if (isTableItem)
+	{
+		painter->save();
+		painter->translate(igXpos, igYpos);
+		painter->rotate(rotation());
+		isEmbedded = true;
+		invalid = true;
+		if ((lineColor() != CommonStrings::None) && (lineWidth() != 0.0))
+		{
+			QColor tmp;
+			SetQColor(&tmp, lineColor(), lineShade());
+			if ((TopLine) || (RightLine) || (BottomLine) || (LeftLine))
+			{
+				painter->setPen(tmp, lineWidth(), PLineArt, Qt::SquareCap, PLineJoin);
+				if (TopLine)
+					painter->drawLine(FPoint(0.0, 0.0), FPoint(width(), 0.0));
+				if (RightLine)
+					painter->drawLine(FPoint(width(), 0.0), FPoint(width(), height()));
+				if (BottomLine)
+					painter->drawLine(FPoint(width(), height()), FPoint(0.0, height()));
+				if (LeftLine)
+					painter->drawLine(FPoint(0.0, height()), FPoint(0.0, 0.0));
+			}
+		}
+		isEmbedded = false;
+		painter->restore();
+	}
+	painter->end();
+	delete painter;
+	m_Doc->guidesPrefs().framesShown = savedFlag;
+	return retImg;
 }
 
 QImage PageItem::DrawObj_toImage(QList<PageItem*> &emG, double scaling)
@@ -5507,6 +5547,39 @@
 	return result;
 }
 
+QTransform PageItem::getCombinedTransform()
+{
+	QTransform result;
+	if (Parent != NULL)
+	{
+		QList<PageItem*> itList;
+		PageItem* ite = this;
+		while (ite->Parent != NULL)
+		{
+			itList.prepend(ite);
+			ite = ite->Parent;
+		}
+		result.translate(ite->xPos(), ite->yPos());
+		result.rotate(ite->rotation());
+		if (ite->isGroup())
+			result.scale(ite->width() / ite->groupWidth, ite->height() / ite->groupHeight);
+		for (int aa = 0; aa < itList.count(); aa++)
+		{
+			ite = itList.at(aa);
+			result.translate(ite->gXpos, ite->gYpos);
+			result.rotate(ite->rotation());
+			if (ite->isGroup())
+				result.scale(ite->width() / ite->groupWidth, ite->height() / ite->groupHeight);
+		}
+	}
+	else
+	{
+		result.translate(Xpos, Ypos);
+		result.rotate(Rot);
+	}
+	return result;
+}
+
 QRectF PageItem::getBoundingRect() const
 {
 	double x,y,x2,y2;
@@ -6515,7 +6588,9 @@
 	int y = qRound(floor(BoundingY - Oldm_lineWidth / 2.0 - 5) * viewScale);
 	int w = qRound(ceil(BoundingW + Oldm_lineWidth + 10) * viewScale);
 	int h = qRound(ceil(BoundingH + Oldm_lineWidth + 10) * viewScale);
-	QRect ret = QRect(x, y, w, h);
+	QRect ret = QRect(0, 0, w - x, h - y);
+	QTransform t = getCombinedTransform();
+	ret = t.mapRect(ret);
 	ret.translate(qRound(-m_Doc->minCanvasCoordinate.x() * viewScale), qRound(-m_Doc->minCanvasCoordinate.y() * viewScale));
 	return ret;
 }

Modified: trunk/Scribus/scribus/pageitem.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16961&path=/trunk/Scribus/scribus/pageitem.h
==============================================================================
--- trunk/Scribus/scribus/pageitem.h (original)
+++ trunk/Scribus/scribus/pageitem.h Sat Nov  5 21:16:08 2011
@@ -329,6 +329,7 @@
 	QTransform getGroupTransform() const;
 	void getTransform(QTransform& mat) const;
 	QTransform getTransform() const;
+	QTransform getCombinedTransform();
 	/**
 	 * @brief Check if a QPoint is within the items boundaries
 	 * No coordinates transformation is performed
@@ -557,7 +558,7 @@
 	double OldB2;
 	double OldH2;
 	bool Sizing;
-	bool toPixmap;
+//	bool toPixmap;
 	int  LayerID;
 	bool ScaleType;
 	bool AspectRatio;

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16961&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Sat Nov  5 21:16:08 2011
@@ -5510,13 +5510,23 @@
 bool ScribusDoc::itemNameExists(const QString checkItemName)
 {
 	bool found = false;
-	uint docItemCount=Items->count();
+	QList<PageItem*> allItems;
+	uint docItemCount = Items->count();
 	for (uint i = 0; i < docItemCount; ++i)
 	{
-		if (checkItemName == Items->at(i)->itemName())
-		{
-			found = true;
-			break;
+		PageItem *currItem = DocItems.at(i);
+		if (currItem->isGroup())
+			allItems = currItem->asGroupFrame()->getItemList();
+		else
+			allItems.append(currItem);
+		for (int ii = 0; ii < allItems.count(); ii++)
+		{
+			if (checkItemName == allItems.at(ii)->itemName())
+			{
+				found = true;
+				break;
+			}
+
 		}
 	}
 	return found;
@@ -13138,6 +13148,7 @@
 				rItem->setXYPos(ma.m11() * n.x() + ma.m21() * n.y() + ma.dx(), ma.m22() * n.y() + ma.m12() * n.x() + ma.dy());
 				rItem->rotateBy(currItem->rotation());
 				setRedrawBounding(rItem);
+				rItem->OwnPage = OnPage(rItem);
 			}
 			tempSelection.clear();
 			tempSelection.delaySignalsOff();

Modified: trunk/Scribus/scribus/scribusview.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16961&path=/trunk/Scribus/scribus/scribusview.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusview.cpp (original)
+++ trunk/Scribus/scribus/scribusview.cpp Sat Nov  5 21:16:08 2011
@@ -1721,7 +1721,8 @@
 		{
 			Doc->m_Selection->addItem(currItem);
 			currItem->isSingleSel = true;
-			updateContents(currItem->getRedrawBounding(m_canvas->scale()));
+			updateContents();
+//			updateContents(currItem->getRedrawBounding(m_canvas->scale()));
 		}
 		else
 		{
@@ -1743,7 +1744,8 @@
 			double x, y, w, h;
 			Doc->m_Selection->getGroupRect(&x, &y, &w, &h);
 			getGroupRectScreen(&x, &y, &w, &h);
-			updateContents(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10)));
+			updateContents();
+	//		updateContents(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10)));
 			//CB move in here as the emitAllToGUI will do it otherwise
 			emit ItemGeom();
 			emit HaveSel(currItem->itemType());

Modified: trunk/Scribus/scribus/ui/cpalette.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=16961&path=/trunk/Scribus/scribus/ui/cpalette.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/cpalette.cpp (original)
+++ trunk/Scribus/scribus/ui/cpalette.cpp Sat Nov  5 21:16:08 2011
@@ -344,25 +344,8 @@
 PageItem* Cpalette::currentItemFromSelection()
 {
 	PageItem *currentItem = NULL;
-
 	if (currentDoc)
-	{
-		if (currentDoc->m_Selection->count() > 1)
-		{
-			int lowestItem = 999999;
-			for (int a=0; a < currentDoc->m_Selection->count(); ++a)
-			{
-				currentItem = currentDoc->m_Selection->itemAt(a);
-				lowestItem = qMin(lowestItem, currentDoc->Items->indexOf(currentItem));
-			}
-			currentItem = currentDoc->Items->at(lowestItem);
-		}
-		else if (currentDoc->m_Selection->count() == 1)
-		{
-			currentItem = currentDoc->m_Selection->itemAt(0);
-		}
-	}
-
+		currentItem = currentDoc->m_Selection->itemAt(0);
 	return currentItem;
 }
 




More information about the scribus-commit mailing list