r21311 by jghali -

scribus-commit scribus-commit at lists.scribus.net
Sat May 14 11:57:25 UTC 2016


Author: jghali
Date: Sat May 14 11:57:25 2016
New Revision: 21311

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21311
Log:
#3725: wrong snapping when resizing objects off page

Modified:
    trunk/Scribus/scribus/canvasgesture_resize.cpp
    trunk/Scribus/scribus/canvasgesture_resize.h

Modified: trunk/Scribus/scribus/canvasgesture_resize.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21311&path=/trunk/Scribus/scribus/canvasgesture_resize.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasgesture_resize.cpp	(original)
+++ trunk/Scribus/scribus/canvasgesture_resize.cpp	Sat May 14 11:57:25 2016
@@ -550,14 +550,13 @@
 		|| m_handle == Canvas::SOUTHWEST || m_handle == Canvas::SOUTHEAST;
 	if (m_rotation == 0 || isCorner)
 	{
-		FPoint snappedPoint = m_doc->ApplyGridF(docPoint);
+		FPoint snappedPoint = applyGrid(docPoint);
+		snappedPoint = applyGuides(snappedPoint);
+
 		double x = snappedPoint.x(), y = snappedPoint.y();
-
-		m_doc->ApplyGuides(&x, &y);
-		m_doc->ApplyGuides(&x, &y,true);
-		if(x != snappedPoint.x() && m_handle != Canvas::NORTH && m_handle != Canvas::SOUTH)
+		if (x != snappedPoint.x() && m_handle != Canvas::NORTH && m_handle != Canvas::SOUTH)
 			xSnap = x;
-		if(y != snappedPoint.y() && m_handle != Canvas::EAST && m_handle != Canvas::WEST)
+		if (y != snappedPoint.y() && m_handle != Canvas::EAST && m_handle != Canvas::WEST)
 			ySnap = y;
 //		if (m_doc->ApplyGuides(&x, &y))
 //			qDebug() << "guides applied:" << snappedPoint.x() << snappedPoint.y() << "to" << x << y;
@@ -747,7 +746,243 @@
 	}
 }
 
-
+FPoint ResizeGesture::applyGrid(const FPoint& docPoint)
+{
+	int pointPage;
+
+	if (!m_doc->SnapGrid)
+		return docPoint;
+	FPoint snappedPoint = docPoint;
+
+	switch (m_handle)
+	{
+		case Canvas::NORTHWEST:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+				snappedPoint = m_doc->ApplyGridF(docPoint);
+			else
+			{
+				FPoint tempPoint1 = m_doc->ApplyGridF(FPoint(docPoint.x(), m_bounds.bottom()));
+				FPoint tempPoint2 = m_doc->ApplyGridF(FPoint(m_bounds.right(), docPoint.y()));
+				snappedPoint.setXY(tempPoint1.x(), tempPoint2.y());
+			}
+			break;
+		case Canvas::NORTHEAST:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+				snappedPoint = m_doc->ApplyGridF(docPoint);
+			else
+			{
+				FPoint tempPoint1 = m_doc->ApplyGridF(FPoint(docPoint.x(), m_bounds.bottom()));
+				FPoint tempPoint2 = m_doc->ApplyGridF(FPoint(m_bounds.left(), docPoint.y()));
+				snappedPoint.setXY(tempPoint1.x(), tempPoint2.y());
+			}
+			break;
+		case Canvas::SOUTHWEST:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+				snappedPoint = m_doc->ApplyGridF(docPoint);
+			else
+			{
+				FPoint tempPoint1 = m_doc->ApplyGridF(FPoint(docPoint.x(), m_bounds.top()));
+				FPoint tempPoint2 = m_doc->ApplyGridF(FPoint(m_bounds.right(), docPoint.y()));
+				snappedPoint.setXY(tempPoint1.x(), tempPoint2.y());
+			}
+			break;
+		case Canvas::SOUTHEAST:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+				snappedPoint = m_doc->ApplyGridF(docPoint);
+			else
+			{
+				FPoint tempPoint1 = m_doc->ApplyGridF(FPoint(docPoint.x(), m_bounds.top()));
+				FPoint tempPoint2 = m_doc->ApplyGridF(FPoint(m_bounds.left(), docPoint.y()));
+				snappedPoint.setXY(tempPoint1.x(), tempPoint2.y());
+			}
+			break;
+		case Canvas::NORTH:
+		case Canvas::SOUTH:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+				snappedPoint = m_doc->ApplyGridF(docPoint);
+			else if (m_doc->OnPage(m_bounds.left(), docPoint.y()) >= 0)
+			{
+				FPoint tempPoint = m_doc->ApplyGridF(FPoint(m_bounds.left(), docPoint.y()));
+				snappedPoint.setY(tempPoint.y());
+			}
+			else if (m_doc->OnPage(m_bounds.right(), docPoint.y()) >= 0)
+			{
+				FPoint tempPoint = m_doc->ApplyGridF(FPoint(m_bounds.right(), docPoint.y()));
+				snappedPoint.setY(tempPoint.y());
+			}
+			break;
+		case Canvas::EAST:
+		case Canvas::WEST:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+				snappedPoint = m_doc->ApplyGridF(docPoint);
+			else if (m_doc->OnPage(docPoint.x(), m_bounds.top()) >= 0)
+			{
+				FPoint tempPoint = m_doc->ApplyGridF(FPoint(docPoint.x(), m_bounds.top()));
+				snappedPoint.setX(tempPoint.x());
+			}
+			else if (m_doc->OnPage(docPoint.x(), m_bounds.bottom()) >= 0)
+			{
+				FPoint tempPoint = m_doc->ApplyGridF(FPoint(docPoint.x(), m_bounds.bottom()));
+				snappedPoint.setX(tempPoint.x());
+			}
+			break;
+		default:
+			snappedPoint = m_doc->ApplyGridF(docPoint);
+			break;
+	}
+
+	/*double gx = snappedPoint.x(), gxo = docPoint.x();
+	double gy = snappedPoint.y(), gyo = docPoint.y();
+	if ((fabs(gx - gxo) > (m_doc->guidesPrefs().guideRad / m_canvas->scale())) || 
+		(fabs(gy - gyo) > (m_doc->guidesPrefs().guideRad / m_canvas->scale())))
+	{
+		snappedPoint = docPoint;
+	}*/
+	return snappedPoint;
+}
+
+FPoint ResizeGesture::applyGuides(const FPoint& docPoint)
+{
+	int pointPage;
+
+	if (!m_doc->SnapGuides)
+		return docPoint;
+	FPoint snappedPoint = docPoint;
+
+	switch (m_handle)
+	{
+		case Canvas::NORTHWEST:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+			{
+				m_doc->ApplyGuides(&snappedPoint);
+				m_doc->ApplyGuides(&snappedPoint, true);
+			}
+			else
+			{
+				FPoint tempPoint1(docPoint.x(), m_bounds.bottom());
+				m_doc->ApplyGuides(&tempPoint1);
+				m_doc->ApplyGuides(&tempPoint1, true);
+				FPoint tempPoint2(m_bounds.right(), docPoint.y());
+				m_doc->ApplyGuides(&tempPoint2);
+				m_doc->ApplyGuides(&tempPoint2, true);
+				snappedPoint.setXY(tempPoint1.x(), tempPoint2.y());
+			}
+			break;
+		case Canvas::NORTHEAST:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+			{
+				m_doc->ApplyGuides(&snappedPoint);
+				m_doc->ApplyGuides(&snappedPoint, true);
+			}
+			else
+			{
+				FPoint tempPoint1(docPoint.x(), m_bounds.bottom());
+				m_doc->ApplyGuides(&tempPoint1);
+				m_doc->ApplyGuides(&tempPoint1, true);
+				FPoint tempPoint2(m_bounds.left(), docPoint.y());
+				m_doc->ApplyGuides(&tempPoint2);
+				m_doc->ApplyGuides(&tempPoint2, true);
+				snappedPoint.setXY(tempPoint1.x(), tempPoint2.y());
+			}
+			break;
+		case Canvas::SOUTHWEST:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+			{
+				m_doc->ApplyGuides(&snappedPoint);
+				m_doc->ApplyGuides(&snappedPoint, true);
+			}
+			else
+			{
+				FPoint tempPoint1(docPoint.x(), m_bounds.top());
+				m_doc->ApplyGuides(&tempPoint1);
+				m_doc->ApplyGuides(&tempPoint1, true);
+				FPoint tempPoint2(m_bounds.right(), docPoint.y());
+				m_doc->ApplyGuides(&tempPoint2);
+				m_doc->ApplyGuides(&tempPoint2, true);
+				snappedPoint.setXY(tempPoint1.x(), tempPoint2.y());
+			}
+			break;
+		case Canvas::SOUTHEAST:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+			{
+				m_doc->ApplyGuides(&snappedPoint);
+				m_doc->ApplyGuides(&snappedPoint, true);
+			}
+			else
+			{
+				FPoint tempPoint1(docPoint.x(), m_bounds.top());
+				m_doc->ApplyGuides(&tempPoint1);
+				m_doc->ApplyGuides(&tempPoint1, true);
+				FPoint tempPoint2(m_bounds.left(), docPoint.y());
+				m_doc->ApplyGuides(&tempPoint2);
+				m_doc->ApplyGuides(&tempPoint2, true);
+				snappedPoint.setXY(tempPoint1.x(), tempPoint2.y());
+			}
+			break;
+		case Canvas::NORTH:
+		case Canvas::SOUTH:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+			{
+				m_doc->ApplyGuides(&snappedPoint);
+				m_doc->ApplyGuides(&snappedPoint, true);
+			}
+			else if (m_doc->OnPage(m_bounds.left(), docPoint.y()) >= 0)
+			{
+				FPoint tempPoint(m_bounds.left(), docPoint.y());
+				m_doc->ApplyGuides(&tempPoint);
+				m_doc->ApplyGuides(&tempPoint, true);
+				snappedPoint.setY(tempPoint.y());
+			}
+			else if (m_doc->OnPage(m_bounds.right(), docPoint.y()) >= 0)
+			{
+				FPoint tempPoint(m_bounds.right(), docPoint.y());
+				m_doc->ApplyGuides(&tempPoint);
+				m_doc->ApplyGuides(&tempPoint, true);
+				snappedPoint.setY(tempPoint.y());
+			}
+			break;
+		case Canvas::EAST:
+		case Canvas::WEST:
+			pointPage = m_doc->OnPage(docPoint.x(), docPoint.y());
+			if (pointPage >= 0)
+			{
+				m_doc->ApplyGuides(&snappedPoint);
+				m_doc->ApplyGuides(&snappedPoint, true);
+			}
+			else if (m_doc->OnPage(docPoint.x(), m_bounds.top()) >= 0)
+			{
+				FPoint tempPoint(docPoint.x(), m_bounds.top());
+				m_doc->ApplyGuides(&tempPoint);
+				m_doc->ApplyGuides(&tempPoint, true);
+				snappedPoint.setX(tempPoint.x());
+			}
+			else if (m_doc->OnPage(docPoint.x(), m_bounds.bottom()) >= 0)
+			{
+				FPoint tempPoint(docPoint.x(), m_bounds.bottom());
+				m_doc->ApplyGuides(&tempPoint);
+				m_doc->ApplyGuides(&tempPoint, true);
+				snappedPoint.setX(tempPoint.x());
+			}
+			break;
+		default:
+			m_doc->ApplyGuides(&snappedPoint);
+			m_doc->ApplyGuides(&snappedPoint, true);
+			break;
+	}
+
+	return snappedPoint;
+}
 
 void ResizeGesture::mousePressEvent(QMouseEvent *m)
 {

Modified: trunk/Scribus/scribus/canvasgesture_resize.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21311&path=/trunk/Scribus/scribus/canvasgesture_resize.h
==============================================================================
--- trunk/Scribus/scribus/canvasgesture_resize.h	(original)
+++ trunk/Scribus/scribus/canvasgesture_resize.h	Sat May 14 11:57:25 2016
@@ -73,6 +73,10 @@
 private:
 	void adjustBounds(QMouseEvent *m);
 	void doResize(bool scaleContent);
+
+	FPoint applyGrid(const FPoint& docPoint);
+	FPoint applyGuides(const FPoint& docPoint);
+
 	Canvas::FrameHandle m_handle;
 	double m_rotation;
 	double m_origRatio;




More information about the scribus-commit mailing list