r23322 by jghali - Simplify CanvasMode's drawOutline() by noticing its scalex and scaley arguments are always 1.0

scribus-commit scribus-commit at lists.scribus.net
Mon Nov 4 09:01:03 UTC 2019


Author: jghali
Date: Mon Nov  4 09:01:03 2019
New Revision: 23322

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23322
Log:
Simplify CanvasMode's drawOutline() by noticing its scalex and scaley arguments are always 1.0

Modified:
    trunk/Scribus/scribus/canvasmode.cpp
    trunk/Scribus/scribus/canvasmode.h
    trunk/Scribus/scribus/canvasmode_normal.cpp

Modified: trunk/Scribus/scribus/canvasmode.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23322&path=/trunk/Scribus/scribus/canvasmode.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode.cpp	(original)
+++ trunk/Scribus/scribus/canvasmode.cpp	Mon Nov  4 09:01:03 2019
@@ -471,7 +471,7 @@
 }
 
 
-void CanvasMode::drawOutline(QPainter* p, double scalex, double scaley, double deltax, double deltay)
+void CanvasMode::drawOutline(QPainter* p, double deltax, double deltay)
 {
 	p->save();
 	p->scale(m_canvas->scale(), m_canvas->scale());
@@ -481,153 +481,105 @@
 	{
 		PageItem *currItem = m_doc->m_Selection->itemAt(0);
 				
-		if ((scalex != 1.0) || (scaley != 1.0)) // changing size of page item
+//		QRectF br(currItem->getVisualBoundingRect());
+#ifdef GESTURE_FRAME_PREVIEW
+		QImage *pixItem(0);
+		if (m_pixmapCache.contains(currItem))
 		{
-			p->setBrush(m_brush["outline"]);
-			p->setPen(m_pen["outline"]);
-
-			QTransform itemTrans = currItem->getTransform();
-			QPointF itPos = itemTrans.map(QPointF(0, 0));
-			double gRot = getRotationDFromMatrix(itemTrans);
-			double m_scaleX, m_scaleY;
-			double addTransX = 0.0;
-			getScaleFromMatrix(itemTrans, m_scaleX, m_scaleY);
-			p->translate(itPos);
-			if (itemTrans.m11() < 0)
+			if (m_pixmapCache.value(currItem)->isReady())
+				pixItem = m_pixmapCache.value(currItem)->getImage();
+		}
+		else
+		{
+			m_pixmapCache[currItem] = new PageItemPreview(currItem);
+		}
+
+		if (pixItem)
+		{
+			p->save();
+			p->translate(br.x(),br.y());
+			p->translate(deltax, deltay);
+			p->drawImage(br.toRect(), *pixItem, pixItem->rect());
+			p->restore();
+		}
+#endif // GESTURE_FRAME_PREVIEW
+		{
+			QTransform itemTrans = currItem->getTransform(deltax, deltay);
+			double visualWidth = currItem->visualWidth();
+			double visualHeight = currItem->visualHeight();
+			double visualLineWidth = currItem->visualLineWidth();
+			double matRot = getRotationDFromMatrix(itemTrans);
+
+			if (currItem->isGroup())
 			{
-				gRot -= 180.0;
-		//		p->translate(-currItem->visualWidth(), 0);
-		//		addTransX = -currItem->visualWidth() * (scalex * m_scaleX);
-		//		m_scaleX *= -1;
-			}
-			p->translate(deltax, deltay);
-			if (currItem->imageFlippedH())
-			{
-				p->translate(currItem->width(), 0);
-				p->scale(-1.0, 1.0);
-			}
-			if (currItem->imageFlippedV())
-			{
-				p->translate(0, currItem->height());
-				p->scale(1.0, -1.0);
-			}
-			if (gRot != 0)
-			{
-				p->setRenderHint(QPainter::Antialiasing);
-				p->rotate(-gRot);
-			}
-			p->scale(scalex * m_scaleX, scaley * m_scaleY);
-			p->translate(addTransX, 0);
-			p->drawPath(currItem->PoLine.toQPainterPath(false));
-		//	currItem->DrawPolyL(p, currItem->Clip);
-		}
-		else // moving page item
-		{
-//			QRectF br(currItem->getVisualBoundingRect());
-#ifdef GESTURE_FRAME_PREVIEW
-			QImage *pixItem(0);
-			if (m_pixmapCache.contains(currItem))
-			{
-				if (m_pixmapCache.value(currItem)->isReady())
-					pixItem = m_pixmapCache.value(currItem)->getImage();
+				p->save();
+				p->setBrush(m_brush["outline"]);
+				p->setPen(m_pen["outline"]);
+				p->setWorldTransform(itemTrans, true);
+				if (matRot != 0)
+					p->setRenderHint(QPainter::Antialiasing);
+				p->drawRect(QRectF(0.0, 0.0, visualWidth, visualHeight));
+				p->setClipping(true);
+				p->setClipRect(QRectF(0.0, 0.0, visualWidth, visualHeight));
+				PageItem_Group* gItem = currItem->asGroupFrame();
+				int itemCountG = gItem->groupItemList.count();
+				if (itemCountG < m_canvas->moveWithFullOutlinesThreshold)
+				{
+					if (gItem->imageFlippedH())
+					{
+						p->translate(gItem->width(), 0);
+						p->scale(-1, 1);
+					}
+					if (gItem->imageFlippedV())
+					{
+						p->translate(0, gItem->height());
+						p->scale(1, -1);
+					}
+					p->scale(gItem->width() / gItem->groupWidth, gItem->height() / gItem->groupHeight);
+					for (int cg = 0; cg < itemCountG; cg++)
+					{
+						p->save();
+						currItem = gItem->groupItemList.at(cg);
+						p->translate(currItem->gXpos, currItem->gYpos);
+						if (currItem->rotation() != 0)
+						{
+							p->setRenderHint(QPainter::Antialiasing);
+							p->rotate(currItem->rotation());
+						}
+						p->drawPath(currItem->PoLine.toQPainterPath(false));
+						p->restore();
+					}
+				}
+				else
+				{
+					currItem->DrawPolyL(p, currItem->Clip);
+				}
+				p->restore();
 			}
 			else
 			{
-				m_pixmapCache[currItem] = new PageItemPreview(currItem);
-			}
-
-			if (pixItem)
-			{
 				p->save();
-				p->translate(br.x(),br.y());
-				p->translate(deltax, deltay);
-				p->drawImage(br.toRect(), *pixItem, pixItem->rect());
+				p->setBrush(m_brush["outline"]);
+				p->setPen(m_pen["outline"]);
+				p->setWorldTransform(itemTrans, true);
+				if (matRot != 0)
+					p->setRenderHint(QPainter::Antialiasing);
+				if (currItem->isLine())
+					p->drawRect(QRectF(0.0, -visualLineWidth / 2.0, currItem->visualWidth(), currItem->visualHeight()));
+				else
+					p->drawRect(QRectF(-visualLineWidth / 2.0, -visualLineWidth / 2.0, currItem->visualWidth(), currItem->visualHeight()));
+				p->restore();
+
+				p->save();
+				p->setBrush(m_brush["outline"]);
+				p->setPen(m_pen["outline"]);
+				p->setWorldTransform(itemTrans, true);
+				if (matRot != 0)
+					p->setRenderHint(QPainter::Antialiasing);
+				p->drawPath(currItem->PoLine.toQPainterPath(false));
 				p->restore();
 			}
-#endif // GESTURE_FRAME_PREVIEW
-			{
-				QTransform itemTrans = currItem->getTransform(deltax, deltay);
-				double visualWidth = currItem->visualWidth();
-				double visualHeight = currItem->visualHeight();
-				double visualLineWidth = currItem->visualLineWidth();
-				double matRot = getRotationDFromMatrix(itemTrans);
-				double matScaleX, matScaleY;
-				getScaleFromMatrix(itemTrans, matScaleX, matScaleY);
-
-				if (currItem->isGroup())
-				{
-					p->save();
-					p->setBrush(m_brush["outline"]);
-					p->setPen(m_pen["outline"]);
-					p->setWorldTransform(itemTrans, true);
-					if (matRot != 0)
-						p->setRenderHint(QPainter::Antialiasing);
-					p->scale(scalex, scaley);
-					p->drawRect(QRectF(0.0, 0.0, visualWidth, visualHeight));
-					p->setClipping(true);
-					p->setClipRect(QRectF(0.0, 0.0, visualWidth, visualHeight));
-					PageItem_Group* gItem = currItem->asGroupFrame();
-					int itemCountG = gItem->groupItemList.count();
-					if (itemCountG < m_canvas->moveWithFullOutlinesThreshold)
-					{
-						if (gItem->imageFlippedH())
-						{
-							p->translate(gItem->width(), 0);
-							p->scale(-1, 1);
-						}
-						if (gItem->imageFlippedV())
-						{
-							p->translate(0, gItem->height());
-							p->scale(1, -1);
-						}
-						p->scale(gItem->width() / gItem->groupWidth, gItem->height() / gItem->groupHeight);
-						for (int cg = 0; cg < itemCountG; cg++)
-						{
-							p->save();
-							currItem = gItem->groupItemList.at(cg);
-							p->translate(currItem->gXpos, currItem->gYpos);
-							if (currItem->rotation() != 0)
-							{
-								p->setRenderHint(QPainter::Antialiasing);
-								p->rotate(currItem->rotation());
-							}
-							p->drawPath(currItem->PoLine.toQPainterPath(false));
-							p->restore();
-						}
-					}
-					else
-					{
-						currItem->DrawPolyL(p, currItem->Clip);
-					}
-					p->restore();
-				}
-				else
-				{
-					p->save();
-					p->setBrush(m_brush["outline"]);
-					p->setPen(m_pen["outline"]);
-					p->setWorldTransform(itemTrans, true);
-					if (matRot != 0)
-						p->setRenderHint(QPainter::Antialiasing);
-					p->scale(scalex /** matScaleX*/, scaley /** matScaleY*/);
-					if (currItem->isLine())
-						p->drawRect(QRectF(0.0, -visualLineWidth / 2.0, currItem->visualWidth(), currItem->visualHeight()));
-					else
-						p->drawRect(QRectF(-visualLineWidth / 2.0, -visualLineWidth / 2.0, currItem->visualWidth(), currItem->visualHeight()));
-					p->restore();
-
-					p->save();
-					p->setBrush(m_brush["outline"]);
-					p->setPen(m_pen["outline"]);
-					p->setWorldTransform(itemTrans, true);
-					if (matRot != 0)
-						p->setRenderHint(QPainter::Antialiasing);
-					p->scale(scalex /** matScaleX*/, scaley /** matScaleY*/);
-					p->drawPath(currItem->PoLine.toQPainterPath(false));
-					p->restore();
-				}
-			}
-		}	
+		}
 	}
 	else if (m_doc->m_Selection->count() > 1)
 	{
@@ -646,92 +598,76 @@
 				if (currItem->Parent && !currItem->Parent->groupItemList.contains(currItem))
 					continue;
 				p->save();
-				if (docSelectionCount < m_canvas->moveWithFullOutlinesThreshold /*&& currItem->rotation() == 0*/)
-				{
-					if ((scalex != 1.0) || (scaley != 1.0))
-					{
+				if (docSelectionCount < m_canvas->moveWithFullOutlinesThreshold)
+				{
+//					QRectF br(currItem->getVisualBoundingRect());
+#ifdef GESTURE_FRAME_PREVIEW
+					QImage *pixItem(0);
+					if (m_pixmapCache.contains(currItem))
+					{
+						if (m_pixmapCache.value(currItem)->isReady())
+							pixItem = m_pixmapCache.value(currItem)->getImage();
+					}
+					else
+					{
+						m_pixmapCache[currItem] = new PageItemPreview(currItem);
+					}
+			
+
+					if (pixItem)
+					{
+						p->save();
+//							p->translate(br.x() /*- x*/, br.y() /*- y*/);
+						p->drawImage(br.toRect(), *pixItem, pixItem->rect());
+						p->restore();
+					}
+#endif  // GESTURE_FRAME_PREVIEW
+					{
+						QTransform itemTrans = currItem->getTransform(deltax, deltay);
+						double visualWidth = currItem->visualWidth();
+						double visualHeight = currItem->visualHeight();
+						double visualLineWidth = currItem->visualLineWidth();
+						double matRot = getRotationDFromMatrix(itemTrans);
+
+						p->save();
 						p->setBrush(m_brush["outline"]);
 						p->setPen(m_pen["outline"]);
-						p->translate(deltax, deltay);
-						p->translate(currItem->xPos() /*- x*/, currItem->yPos() /*- y*/);
-						p->scale(scalex, scaley);
-						if (currItem->rotation() != 0)
-						{
+						p->setWorldTransform(itemTrans, true);
+						if (matRot != 0)
 							p->setRenderHint(QPainter::Antialiasing);
-							p->rotate(currItem->rotation());
-						}
-						currItem->DrawPolyL(p, currItem->Clip);
-					}
-					else
-					{
-//						QRectF br(currItem->getVisualBoundingRect());
-#ifdef GESTURE_FRAME_PREVIEW
-						QImage *pixItem(0);
-						if (m_pixmapCache.contains(currItem))
-						{
-							if (m_pixmapCache.value(currItem)->isReady())
-								pixItem = m_pixmapCache.value(currItem)->getImage();
-						}
+						if (currItem->isLine())
+							p->drawRect(QRectF(0.0, -visualLineWidth / 2.0, currItem->visualWidth(), currItem->visualHeight()));
 						else
-						{
-							m_pixmapCache[currItem] = new PageItemPreview(currItem);
-						}
-			
-
-						if (pixItem)
-						{
-							p->save();
-//							p->translate(br.x() /*- x*/, br.y() /*- y*/);
-							p->drawImage(br.toRect(), *pixItem, pixItem->rect());
-							p->restore();
-						}
-#endif  // GESTURE_FRAME_PREVIEW
-						{
-							QTransform itemTrans = currItem->getTransform(deltax, deltay);
-							double visualWidth = currItem->visualWidth();
-							double visualHeight = currItem->visualHeight();
-							double visualLineWidth = currItem->visualLineWidth();
-							double matRot = getRotationDFromMatrix(itemTrans);
-							double matScaleX, matScaleY;
-							getScaleFromMatrix(itemTrans, matScaleX, matScaleY);
-
-							p->save();
-							p->setBrush(m_brush["outline"]);
-							p->setPen(m_pen["outline"]);
-							p->setWorldTransform(itemTrans, true);
-							if (matRot != 0)
-								p->setRenderHint(QPainter::Antialiasing);
-							p->scale(scalex /** matScaleX*/, scaley /** matScaleY*/);
-							if (currItem->isLine())
-								p->drawRect(QRectF(0.0, -visualLineWidth / 2.0, currItem->visualWidth(), currItem->visualHeight()));
-							else
-								p->drawRect(QRectF(-visualLineWidth / 2.0, -visualLineWidth / 2.0, currItem->visualWidth(), currItem->visualHeight()));
-							p->restore();
-
-							p->save();
-							p->setBrush(m_brush["outline"]);
-							p->setPen(m_pen["outline"]);
-							p->setWorldTransform(itemTrans, true);
-							if (matRot != 0)
-								p->setRenderHint(QPainter::Antialiasing);
-							p->scale(scalex /** matScaleX*/, scaley /** matScaleY*/);
-							p->drawPath(currItem->PoLine.toQPainterPath(false));
-							p->restore();
-						}
+							p->drawRect(QRectF(-visualLineWidth / 2.0, -visualLineWidth / 2.0, currItem->visualWidth(), currItem->visualHeight()));
+						p->restore();
+
+						p->save();
+						p->setBrush(m_brush["outline"]);
+						p->setPen(m_pen["outline"]);
+						p->setWorldTransform(itemTrans, true);
+						if (matRot != 0)
+							p->setRenderHint(QPainter::Antialiasing);
+						p->drawPath(currItem->PoLine.toQPainterPath(false));
+						p->restore();
 					}
 				}
 				else
 				{
+					QTransform itemTrans = currItem->getTransform(deltax, deltay);
+					double visualWidth = currItem->visualWidth();
+					double visualHeight = currItem->visualHeight();
+					double visualLineWidth = currItem->visualLineWidth();
+					double matRot = getRotationDFromMatrix(itemTrans);
+
 					p->setBrush(m_brush["outline"]);
 					p->setPen(m_pen["outline"]);
-					p->translate(deltax, deltay);
-					p->translate(x, y);
-					if (currItem->rotation() != 0)
-					{
+					p->setWorldTransform(itemTrans, true);
+					if (matRot != 0)
 						p->setRenderHint(QPainter::Antialiasing);
-						p->rotate(currItem->rotation());
-					}
-					p->drawRect(QRectF(0.0, 0.0, currItem->visualWidth(), currItem->visualHeight()));
+					if (currItem->isLine())
+						p->drawRect(QRectF(0.0, -visualLineWidth / 2.0, currItem->visualWidth(), currItem->visualHeight()));
+					else
+						p->drawRect(QRectF(-visualLineWidth / 2.0, -visualLineWidth / 2.0, currItem->visualWidth(), currItem->visualHeight()));
 				}
 				p->restore();
 			}
@@ -742,7 +678,6 @@
 			p->setPen(m_pen["outline"]);
 			p->translate(deltax, deltay);
 			p->translate(x, y);
-			p->scale(scalex, scaley);
 			p->drawRect(QRectF(0, 0, w, h));
 		}
 	}

Modified: trunk/Scribus/scribus/canvasmode.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23322&path=/trunk/Scribus/scribus/canvasmode.h
==============================================================================
--- trunk/Scribus/scribus/canvasmode.h	(original)
+++ trunk/Scribus/scribus/canvasmode.h	Mon Nov  4 09:01:03 2019
@@ -128,7 +128,7 @@
 	/** Draws an outline of selected items */
 	void drawSnapLine(QPainter* psx);
 	/** Draws an outline of selected items */
-	void drawOutline(QPainter* p, double scalex=1.0, double scaley=1.0, double deltax=0.0, double deltay=0.0);
+	void drawOutline(QPainter* p, double deltax=0.0, double deltay=0.0);
 #ifdef GESTURE_FRAME_PREVIEW
 	// I don’t know why the methods above have been implemented here and left non-virtual.
 	// I need to setup some companion members - pm

Modified: trunk/Scribus/scribus/canvasmode_normal.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23322&path=/trunk/Scribus/scribus/canvasmode_normal.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_normal.cpp	(original)
+++ trunk/Scribus/scribus/canvasmode_normal.cpp	Mon Nov  4 09:01:03 2019
@@ -100,7 +100,7 @@
 {
 //	qDebug() << "CanvasMode_Normal::drawControls";
 	if (m_canvas->m_viewMode.operItemMoving)
-		drawOutline(p, 1.0, 1.0, m_objectDeltaPos.x(), m_objectDeltaPos.y());
+		drawOutline(p, m_objectDeltaPos.x(), m_objectDeltaPos.y());
 	else
 		drawSelection(p, !m_doc->drawAsPreview);
 }




More information about the scribus-commit mailing list