r23704 by jghali - Simplify CreateMode::mouseMoveEvent() by returning early when possible

scribus-commit scribus-commit at lists.scribus.net
Tue May 5 22:16:42 UTC 2020


Author: jghali
Date: Tue May  5 22:16:41 2020
New Revision: 23704

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=23704
Log:
Simplify CreateMode::mouseMoveEvent() by returning early when possible

Modified:
    trunk/Scribus/scribus/canvasmode_create.cpp

Modified: trunk/Scribus/scribus/canvasmode_create.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=23704&path=/trunk/Scribus/scribus/canvasmode_create.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_create.cpp	(original)
+++ trunk/Scribus/scribus/canvasmode_create.cpp	Tue May  5 22:16:41 2020
@@ -250,82 +250,78 @@
 	{
 //		newX = mousePointDoc.x(); //m_view->translateToDoc(m->x(), m->y()).x());
 //		newY = mousePointDoc.y(); //m_view->translateToDoc(m->x(), m->y()).y());
-		
-		if (m_doc->DragP)
-			return;
+		return;
+	}
+	if ((!m_MouseButtonPressed) || !(m->buttons() & Qt::LeftButton))
+	{
+		m_canvas->displayCorrectedXYHUD(m->globalPos(), mousePointDoc.x(), mousePointDoc.y());
+		return;
+	}
+
+	newX = mousePointDoc.x();
+	newY = mousePointDoc.y();
+	if (createObjectMode == modeDrawLine)
+	{
+		if (m_doc->SnapGrid)
+		{
+			newX = qRound(newX / m_doc->guidesPrefs().minorGridSpacing) * m_doc->guidesPrefs().minorGridSpacing;
+			newY = qRound(newY / m_doc->guidesPrefs().minorGridSpacing) * m_doc->guidesPrefs().minorGridSpacing;
+		}
+		if (m->modifiers() & Qt::ControlModifier)
+		{
+			QRectF bounds(QPointF(createObjectPos.x(), createObjectPos.y()), QPointF(newX, newY));
+			double newRot = xy2Deg(bounds.width(), bounds.height());
+			if (newRot < 0.0)
+				newRot += 360;
+			newRot = constrainAngle(newRot, m_doc->opToolPrefs().constrain);
+			double len = qMax(0.01, distance(bounds.width(), bounds.height()));
+			bounds.setSize(len * QSizeF(cosd(newRot), sind(newRot)));
+			newX = bounds.right();
+			newY = bounds.bottom();
+		}
+	}
+	//CB: #8099: Readd snapping for drag creation of lines by commenting this else..
+	//else
+	//{
+		FPoint np2 = m_doc->ApplyGridF(FPoint(newX, newY));
+		double nx = np2.x();
+		double ny = np2.y();
+		m_doc->ApplyGuides(&nx, &ny);
+		m_doc->ApplyGuides(&nx, &ny,true);
+		if (nx != np2.x())
+			xSnap = nx;
+		if (ny != np2.y())
+			ySnap = ny;
+		// #8959 : suppress qRound here as this prevent drawing line with angle constrain
+		// precisely and does not allow to stick precisely to grid or guides
+		newX = /*qRound(*/nx/*)*/;
+		newY = /*qRound(*/ny/*)*/;
+	//}
+
+	canvasCurrCoord.setXY(newX, newY);
+	m_view->HaveSelRect = true;
+
+	double wSize = canvasCurrCoord.x() - createObjectPos.x();
+	double hSize = canvasCurrCoord.y() - createObjectPos.y();
+	QRectF createObjectRect(createObjectPos.x(), createObjectPos.y(), wSize, hSize);
+	createObjectRect = createObjectRect.normalized();
+	if (createObjectMode != modeDrawLine)
+	{
+		if (modifiers == Qt::ControlModifier)
+			hSize = wSize;
+		m_canvas->displaySizeHUD(m->globalPos(), wSize, hSize, false);
 	}
 	else
 	{
-		if ((m_MouseButtonPressed) && (m->buttons() & Qt::LeftButton))
-		{
-			newX = mousePointDoc.x();
-			newY = mousePointDoc.y();
-			if (createObjectMode == modeDrawLine)
-			{
-				if (m_doc->SnapGrid)
-				{
-					newX = qRound(newX / m_doc->guidesPrefs().minorGridSpacing) * m_doc->guidesPrefs().minorGridSpacing;
-					newY = qRound(newY / m_doc->guidesPrefs().minorGridSpacing) * m_doc->guidesPrefs().minorGridSpacing;
-				}
-				if (m->modifiers() & Qt::ControlModifier)
-				{
-					QRectF bounds(QPointF(createObjectPos.x(), createObjectPos.y()), QPointF(newX, newY));
-					double newRot = xy2Deg(bounds.width(), bounds.height());
-					if (newRot < 0.0)
-						newRot += 360;
-					newRot = constrainAngle(newRot, m_doc->opToolPrefs().constrain);
-					double len = qMax(0.01, distance(bounds.width(), bounds.height()));
-					bounds.setSize(len * QSizeF(cosd(newRot), sind(newRot)));
-					newX = bounds.right();
-					newY = bounds.bottom();
-				}
-			}
-			//CB: #8099: Readd snapping for drag creation of lines by commenting this else..
-			//else
-			//{
-				FPoint np2 = m_doc->ApplyGridF(FPoint(newX, newY));
-				double nx = np2.x();
-				double ny = np2.y();
-				m_doc->ApplyGuides(&nx, &ny);
-				m_doc->ApplyGuides(&nx, &ny,true);
-				if (nx != np2.x())
-					xSnap = nx;
-				if (ny != np2.y())
-					ySnap = ny;
-				// #8959 : suppress qRound here as this prevent drawing line with angle constrain
-				// precisely and does not allow to stick precisely to grid or guides
-				newX = /*qRound(*/nx/*)*/;
-				newY = /*qRound(*/ny/*)*/;
-			//}
-
-			canvasCurrCoord.setXY(newX, newY);
-			m_view->HaveSelRect = true;
-
-			double wSize = canvasCurrCoord.x() - createObjectPos.x();
-			double hSize = canvasCurrCoord.y() - createObjectPos.y();
-			QRectF createObjectRect(createObjectPos.x(), createObjectPos.y(), wSize, hSize);
-			createObjectRect = createObjectRect.normalized();
-			if (createObjectMode != modeDrawLine)
-			{
-				if (modifiers == Qt::ControlModifier)
-					hSize = wSize;
-				m_canvas->displaySizeHUD(m->globalPos(), wSize, hSize, false);
-			}
-			else
-			{
-				double angle = -xy2Deg(wSize, hSize);
-				if (angle < 0.0)
-					angle = angle + 360;
-				double trueLength = sqrt(pow(createObjectRect.width(), 2) + pow(createObjectRect.height(), 2));
-				m_canvas->displaySizeHUD(m->globalPos(), trueLength, angle, true);
-			}
-
-			// Necessary for drawControls to be called
-			m_canvas->repaint();
-		}
-		else
-			m_canvas->displayCorrectedXYHUD(m->globalPos(), mousePointDoc.x(), mousePointDoc.y());
-	}
+		double angle = -xy2Deg(wSize, hSize);
+		if (angle < 0.0)
+			angle = angle + 360;
+		double trueLength = sqrt(pow(createObjectRect.width(), 2) + pow(createObjectRect.height(), 2));
+		m_canvas->displaySizeHUD(m->globalPos(), trueLength, angle, true);
+	}
+
+	// Necessary for drawControls to be called
+	m_canvas->repaint();
 }
 
 void CreateMode::mousePressEvent(QMouseEvent *m)




More information about the scribus-commit mailing list