View Issue Details

IDProjectCategoryView StatusLast Update
0010988ScribusGeneralpublic2019-12-08 21:24
Reporterale Assigned Toale  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version 
Target VersionFixed in Version1.5.6.svn 
Summary0010988: Snap to items should make the guides snap to items
DescriptionWhen snap to item is enabled, moving (and creating) guides should also snap to items.
Tagspatch
PatchYes

Relationships

duplicate of 0011718 confirmed Functional problems with rulers and guide lines 
has duplicate 0015227 closedjghali guides should snap to items when snap to items is enabled 

Activities

ale

2018-03-29 20:17

manager   ~0045121

i've started working on this... but i cannot promise that i find a solution...
i've somehow found where the relevant code is... but...

ale

2019-08-19 15:46

manager   ~0046488

back to this.

after having worked on snapping to bleeds, i thought i would have a better clue at how the snapping works.

indeed: now i have a simple patch for snapping the vertical guides to objects!

... the code is not that nice, but since i don't 100% what the parameters go, i'll just do it he "scribus way"...
... i still believe that ScribusDoc::getClosestElementBorder(x, y, &xout, &yout, &GxM, &GyM, this_page); & co need some refactoring and (if the refactoring is not good enough) some documentation.

ale

2019-08-19 16:46

manager   ~0046490

here it is!

i could not get it to visually snap while dragging... but it does snap.

if somebody has hints on how to get it to visually snap (and eventually to make the guide green while it snaps)...
... but we could first at least have the raw feature in there... or not?

guides-snap-to-item.diff (6,267 bytes)
diff --git a/scribus/canvasgesture_rulermove.cpp b/scribus/canvasgesture_rulermove.cpp
index fdcf13da8..1badc9b79 100644
--- a/scribus/canvasgesture_rulermove.cpp
+++ b/scribus/canvasgesture_rulermove.cpp
@@ -187,11 +187,13 @@ void RulerGesture::movePoint(QMouseEvent* m, bool mouseRelease)
 	const int page = m_doc->OnPage(mousePointDoc.x(), mousePointDoc.y());
 	QRect viewport(m_view->viewport()->mapToGlobal(QPoint(0,0)), QSize(m_view->visibleWidth(), m_view->visibleHeight()));
 	QPoint newMousePoint = m->globalPos() - (m_canvas->mapToParent(QPoint(0, 0)) + m_canvas->parentWidget()->mapToGlobal(QPoint(0, 0)));
+	double x = mousePointDoc.x();
+	double y = mousePointDoc.y();
 	switch (m_mode)
 	{
 		case ORIGIN:
 			m_canvas->repaint();
-			m_canvas->displayCorrectedXYHUD(m->globalPos(), mousePointDoc.x(), mousePointDoc.y());
+			m_canvas->displayCorrectedXYHUD(m->globalPos(), x, y);
 			break;
 		case HORIZONTAL:
 			if (!m_ScMW->doc->guidesPrefs().guidesShown)
@@ -200,13 +202,21 @@ void RulerGesture::movePoint(QMouseEvent* m, bool mouseRelease)
 			m_canvas->update(0, newMousePoint.y()-2, m_canvas->width(), 4);
 			if ((page >= 0) && (viewport.contains(m->globalPos())))
 			{
+				if (m_doc->SnapElement) {
+					double xout = 0;
+					double yout = 0;
+					int GxM = -1, GyM = -1;
+					m_doc->getClosestElementBorder(x, y, &xout, &yout, &GxM, &GyM, m_doc->Pages->at(page));
+					if (GyM != -1)
+						y = yout+ m_doc->Pages->at(page)->yOffset();
+				}
 				if (!m_haveGuide)
 				{
 					qApp->changeOverrideCursor(QCursor(Qt::SplitVCursor));
 					if (mouseRelease)
 					{
-						m_doc->Pages->at(page)->guides.addHorizontal(mousePointDoc.y() - m_doc->Pages->at(page)->yOffset(), GuideManagerCore::Standard);
-						m_guide = mousePointDoc.y() - m_doc->Pages->at(page)->yOffset();
+						m_doc->Pages->at(page)->guides.addHorizontal(y - m_doc->Pages->at(page)->yOffset(), GuideManagerCore::Standard);
+						m_guide = y - m_doc->Pages->at(page)->yOffset();
 						m_page  = page;
 						m_haveGuide = true;
 						m_doc->changed();
@@ -215,11 +225,11 @@ void RulerGesture::movePoint(QMouseEvent* m, bool mouseRelease)
 				else if (mouseRelease)
 				{
 					if (page == m_page)
-						m_doc->Pages->at(page)->guides.moveHorizontal( m_guide, mousePointDoc.y() - m_doc->Pages->at(page)->yOffset(), GuideManagerCore::Standard);
+						m_doc->Pages->at(page)->guides.moveHorizontal( m_guide, y - m_doc->Pages->at(page)->yOffset(), GuideManagerCore::Standard);
 					else
 					{
 						m_doc->Pages->at(m_page)->guides.deleteHorizontal( m_guide, GuideManagerCore::Standard);
-						m_doc->Pages->at(page)->guides.addHorizontal(mousePointDoc.y() - m_doc->Pages->at(page)->yOffset(), GuideManagerCore::Standard);
+						m_doc->Pages->at(page)->guides.addHorizontal(y - m_doc->Pages->at(page)->yOffset(), GuideManagerCore::Standard);
 						m_page = page;
 					}
 					if (m_doc->currentPage() != m_doc->Pages->at(m_page))
@@ -232,7 +242,7 @@ void RulerGesture::movePoint(QMouseEvent* m, bool mouseRelease)
 					if (cursor && (cursor->shape() != Qt::SplitVCursor))
 						qApp->changeOverrideCursor(QCursor(Qt::SplitVCursor));
 				}
-				m_currentGuide = mousePointDoc.y() - m_doc->Pages->at(page)->yOffset();
+				m_currentGuide = y - m_doc->Pages->at(page)->yOffset();
 			}
 			else
 			{ 
@@ -247,7 +257,7 @@ void RulerGesture::movePoint(QMouseEvent* m, bool mouseRelease)
 					}
 				}
 			}
-			m_canvas->displayCorrectedSingleHUD(m->globalPos(), mousePointDoc.y(), false);
+			m_canvas->displayCorrectedSingleHUD(m->globalPos(), y, false);
 			break;
 		case VERTICAL:
 			if (!m_ScMW->doc->guidesPrefs().guidesShown)
@@ -256,13 +266,21 @@ void RulerGesture::movePoint(QMouseEvent* m, bool mouseRelease)
 			m_canvas->update(newMousePoint.x()-2, 0, 4, m_canvas->height());
 			if ((page >= 0) && viewport.contains(m->globalPos()))
 			{
+				if (m_doc->SnapElement) {
+					double xout = 0;
+					double yout = 0;
+					int GxM = -1, GyM = -1;
+					m_doc->getClosestElementBorder(x, y, &xout, &yout, &GxM, &GyM, m_doc->Pages->at(page));
+					if (GxM != -1)
+						x = xout+ m_doc->Pages->at(page)->xOffset();
+				}
 				if (!m_haveGuide)
 				{
 					qApp->changeOverrideCursor(QCursor(Qt::SplitHCursor));
 					if (mouseRelease)
 					{
-						m_doc->Pages->at(page)->guides.addVertical(mousePointDoc.x() - m_doc->Pages->at(page)->xOffset(), GuideManagerCore::Standard);
-						m_guide = mousePointDoc.x() - m_doc->Pages->at(page)->xOffset();
+						m_doc->Pages->at(page)->guides.addVertical(x - m_doc->Pages->at(page)->xOffset(), GuideManagerCore::Standard);
+						m_guide = x - m_doc->Pages->at(page)->xOffset();
 						m_page  = page;
 						m_haveGuide = true;
 						m_doc->changed();
@@ -271,11 +289,11 @@ void RulerGesture::movePoint(QMouseEvent* m, bool mouseRelease)
 				else if (mouseRelease)
 				{
 					if (page == m_page)
-						m_doc->Pages->at(page)->guides.moveVertical( m_guide, mousePointDoc.x() - m_doc->Pages->at(page)->xOffset(), GuideManagerCore::Standard);
+						m_doc->Pages->at(page)->guides.moveVertical( m_guide, x - m_doc->Pages->at(page)->xOffset(), GuideManagerCore::Standard);
 					else
 					{
 						m_doc->Pages->at(m_page)->guides.deleteVertical( m_guide, GuideManagerCore::Standard);
-						m_doc->Pages->at(page)->guides.addVertical(mousePointDoc.x() - m_doc->Pages->at(page)->xOffset(), GuideManagerCore::Standard);
+						m_doc->Pages->at(page)->guides.addVertical(x - m_doc->Pages->at(page)->xOffset(), GuideManagerCore::Standard);
 						m_page = page;
 					}
 					if (m_doc->currentPage() != m_doc->Pages->at(m_page))
@@ -288,7 +306,7 @@ void RulerGesture::movePoint(QMouseEvent* m, bool mouseRelease)
 					if (cursor && (cursor->shape() != Qt::SplitHCursor))
 						qApp->changeOverrideCursor(QCursor(Qt::SplitHCursor));
 				}
-				m_currentGuide = mousePointDoc.x() - m_doc->Pages->at(page)->xOffset();
+				m_currentGuide = x - m_doc->Pages->at(page)->xOffset();
 			}
 			else
 			{ 
@@ -303,7 +321,7 @@ void RulerGesture::movePoint(QMouseEvent* m, bool mouseRelease)
 					}
 				}
 			}
-			m_canvas->displayCorrectedSingleHUD(m->globalPos(), mousePointDoc.x(), true);
+			m_canvas->displayCorrectedSingleHUD(m->globalPos(), x, true);
 			break;
 	}
 	m_xy = newMousePoint;
guides-snap-to-item.diff (6,267 bytes)

jghali

2019-08-23 11:48

administrator   ~0046525

I fixed the snap while dragging issue and committed. I fixed also an issue where guide snapping was not working on selected items.

PeterBenedek

2019-08-24 11:30

developer   ~0046532

Last edited: 2019-08-24 11:31

View 2 revisions

Scribus from this moment became really usable.
This is a big step.

PeterBenedek

2019-08-24 11:57

developer   ~0046534

Tested in Linux MInt 19.1; r23155

Guide snapping don't work (or it is malfunctioning) in rotated items.
Is the same as 0014208

Issue History

Date Modified Username Field Change
2012-08-01 15:06 ale New Issue
2012-08-01 15:06 ale Status new => assigned
2012-08-01 15:06 ale Assigned To => Chelen
2018-03-29 09:24 jghali Relationship added has duplicate 0015227
2018-03-29 09:24 jghali Project Contributor Builds => Scribus
2018-03-29 09:25 jghali Assigned To Chelen =>
2018-03-29 09:25 jghali Status assigned => new
2018-03-29 09:25 jghali Patch => No
2018-03-29 13:59 PeterBenedek Relationship added duplicate of 0011718
2018-03-29 20:17 ale Note Added: 0045121
2019-08-19 15:46 ale Note Added: 0046488
2019-08-19 16:46 ale File Added: guides-snap-to-item.diff
2019-08-19 16:46 ale Note Added: 0046490
2019-08-20 07:42 ale Summary Snap to items should make the guides snap to items => [PATCH] Snap to items should make the guides snap to items
2019-08-20 07:42 ale Patch No => Yes
2019-08-20 07:42 ale Tag Attached: patch
2019-08-23 11:42 jghali Summary [PATCH] Snap to items should make the guides snap to items => Snap to items should make the guides snap to items
2019-08-23 11:45 jghali Assigned To => ale
2019-08-23 11:45 jghali Status new => resolved
2019-08-23 11:45 jghali Resolution open => fixed
2019-08-23 11:45 jghali Fixed in Version => 1.5.6.svn
2019-08-23 11:48 jghali Note Added: 0046525
2019-08-24 11:30 PeterBenedek Note Added: 0046532
2019-08-24 11:31 PeterBenedek Note Edited: 0046532 View Revisions
2019-08-24 11:57 PeterBenedek Note Added: 0046534
2019-12-08 21:24 cbradney Status resolved => closed