r21297 by jghali -
scribus-commit
scribus-commit at lists.scribus.net
Sat May 7 19:47:12 UTC 2016
Author: jghali
Date: Sat May 7 19:47:12 2016
New Revision: 21297
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21297
Log:
#12921: Snap to grid doesn't work if frame is partially outside page
Modified:
trunk/Scribus/scribus/canvasmode_normal.cpp
trunk/Scribus/scribus/scribusdoc.cpp
trunk/Scribus/scribus/scribusdoc.h
Modified: trunk/Scribus/scribus/canvasmode_normal.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21297&path=/trunk/Scribus/scribus/canvasmode_normal.cpp
==============================================================================
--- trunk/Scribus/scribus/canvasmode_normal.cpp (original)
+++ trunk/Scribus/scribus/canvasmode_normal.cpp Sat May 7 19:47:12 2016
@@ -612,16 +612,9 @@
gy += m_objectDeltaPos.y();
gxo = gx;
gyo = gy;
- FPoint npx = m_doc->ApplyGridF(FPoint(gx, gy));
- FPoint npw = m_doc->ApplyGridF(FPoint(gx+gw, gy+gh));
- if ((fabs(gx-npx.x())) > (fabs((gx+gw)-npw.x())))
- gx = npw.x() - gw;
- else
- gx = npx.x();
- if ((fabs(gy-npx.y())) > (fabs((gy+gh)-npw.y())))
- gy = npw.y() - gh;
- else
- gy = npx.y();
+ QRectF nr = m_doc->ApplyGridF(QRectF(gx, gy, gw, gh));
+ gx = nr.x();
+ gy = nr.y();
if ((fabs(gx - gxo) < (m_doc->guidesPrefs().guideRad) / m_canvas->scale()) && (fabs(gy - gyo) < (m_doc->guidesPrefs().guideRad) / m_canvas->scale()))
m_objectDeltaPos += FPoint(gx-gxo, gy-gyo);
}
@@ -698,16 +691,9 @@
gy += m_objectDeltaPos.y();
gxo = gx;
gyo = gy;
- FPoint npx = m_doc->ApplyGridF(FPoint(gx, gy));
- FPoint npw = m_doc->ApplyGridF(FPoint(gx+gw, gy+gh));
- if ((fabs(gx-npx.x())) > (fabs((gx+gw)-npw.x())))
- gx = npw.x() - gw;
- else
- gx = npx.x();
- if ((fabs(gy-npx.y())) > (fabs((gy+gh)-npw.y())))
- gy = npw.y() - gh;
- else
- gy = npx.y();
+ QRectF nr = m_doc->ApplyGridF(QRectF(gx, gy, gw, gh));
+ gx = nr.x();
+ gy = nr.y();
if ((fabs(gx - gxo) < (m_doc->guidesPrefs().guideRad) / m_canvas->scale()) && (fabs(gy - gyo) < (m_doc->guidesPrefs().guideRad) / m_canvas->scale()))
m_objectDeltaPos += FPoint(gx-gxo, gy-gyo);
}
@@ -1092,16 +1078,9 @@
double ny = gy;
if (!m_doc->ApplyGuides(&nx, &ny) && !m_doc->ApplyGuides(&nx, &ny,true))
{
- FPoint npx = m_doc->ApplyGridF(FPoint(gx, gy));
- FPoint npw = m_doc->ApplyGridF(FPoint(gx+gw, gy+gh));
- if ((fabs(gx-npx.x())) > (fabs((gx+gw)-npw.x())))
- nx = npw.x() - gw;
- else
- nx = npx.x();
- if ((fabs(gy-npx.y())) > (fabs((gy+gh)-npw.y())))
- ny = npw.y() - gh;
- else
- ny = npx.y();
+ QRectF nr = m_doc->ApplyGridF(QRectF(gx, gy, gw, gh));
+ nx = nr.x();
+ ny = nr.y();
}
m_doc->moveGroup(nx-gx, ny-gy);
m_doc->m_Selection->setGroupRect();
@@ -1127,16 +1106,9 @@
m_doc->m_Selection->getVisualGroupRect(&gx, &gy, &gw, &gh);
gxo = gx;
gyo = gy;
- FPoint npx = m_doc->ApplyGridF(FPoint(gx, gy));
- FPoint npw = m_doc->ApplyGridF(FPoint(gx+gw, gy+gh));
- if ((fabs(gx-npx.x())) > (fabs((gx+gw)-npw.x())))
- gx = npw.x() - gw;
- else
- gx = npx.x();
- if ((fabs(gy-npx.y())) > (fabs((gy+gh)-npw.y())))
- gy = npw.y() - gh;
- else
- gy = npx.y();
+ QRectF nr = m_doc->ApplyGridF(QRectF(gx, gy, gw, gh));
+ gx = nr.x();
+ gy = nr.y();
if ((fabs(gx - gxo) < (m_doc->guidesPrefs().guideRad) / m_canvas->scale()) && (fabs(gy - gyo) < (m_doc->guidesPrefs().guideRad) / m_canvas->scale()))
{
nx += (gx - gxo);
Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21297&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Sat May 7 19:47:12 2016
@@ -13361,6 +13361,74 @@
return np;
}
+QRectF ScribusDoc::ApplyGridF(const QRectF& in)
+{
+ QRectF nr(in);
+ if (!SnapGrid)
+ return nr;
+
+ bool onPage = false;
+ double dX = m_docPrefsData.guidesPrefs.minorGridSpacing;
+ double dY = m_docPrefsData.guidesPrefs.minorGridSpacing;
+ double newX = in.x(), newY = in.y();
+
+ FPoint fp1(in.x(), in.y());
+ FPoint fp2(in.x(), in.y() + in.height());
+ FPoint fp3(in.x() + in.width(), in.y());
+ FPoint fp4(in.x() + in.width(), in.y() + in.height());
+
+ int onp = OnPage(fp1.x(), fp1.y());
+ if (onp >= 0)
+ {
+ newX = qRound((fp1.x() - Pages->at(onp)->xOffset()) / m_docPrefsData.guidesPrefs.minorGridSpacing) * m_docPrefsData.guidesPrefs.minorGridSpacing + Pages->at(onp)->xOffset();
+ newY = qRound((fp1.y() - Pages->at(onp)->yOffset()) / m_docPrefsData.guidesPrefs.minorGridSpacing) * m_docPrefsData.guidesPrefs.minorGridSpacing + Pages->at(onp)->yOffset();
+ if (fabs(newX - fp1.x()) < fabs(dX))
+ dX = newX - fp1.x();
+ if (fabs(newY - fp1.y()) < fabs(dY))
+ dY = newY - fp1.y();
+ onPage = true;
+ }
+
+ onp = OnPage(fp2.x(), fp2.y());
+ if (onp >= 0)
+ {
+ newX = qRound((fp2.x() - Pages->at(onp)->xOffset()) / m_docPrefsData.guidesPrefs.minorGridSpacing) * m_docPrefsData.guidesPrefs.minorGridSpacing + Pages->at(onp)->xOffset();
+ newY = qRound((fp2.y() - Pages->at(onp)->yOffset()) / m_docPrefsData.guidesPrefs.minorGridSpacing) * m_docPrefsData.guidesPrefs.minorGridSpacing + Pages->at(onp)->yOffset();
+ if (fabs(newX - fp2.x()) < fabs(dX))
+ dX = newX - fp2.x();
+ if (fabs(newY - fp2.y()) < fabs(dY))
+ dY = newY - fp2.y();
+ onPage = true;
+ }
+
+ onp = OnPage(fp3.x(), fp3.y());
+ if (onp >= 0)
+ {
+ newX = qRound((fp3.x() - Pages->at(onp)->xOffset()) / m_docPrefsData.guidesPrefs.minorGridSpacing) * m_docPrefsData.guidesPrefs.minorGridSpacing + Pages->at(onp)->xOffset();
+ newY = qRound((fp3.y() - Pages->at(onp)->yOffset()) / m_docPrefsData.guidesPrefs.minorGridSpacing) * m_docPrefsData.guidesPrefs.minorGridSpacing + Pages->at(onp)->yOffset();
+ if (fabs(newX - fp3.x()) < fabs(dX))
+ dX = newX - fp3.x();
+ if (fabs(newY - fp3.y()) < fabs(dY))
+ dY = newY - fp3.y();
+ onPage = true;
+ }
+
+ onp = OnPage(fp4.x(), fp4.y());
+ if (onp >= 0)
+ {
+ newX = qRound((fp4.x() - Pages->at(onp)->xOffset()) / m_docPrefsData.guidesPrefs.minorGridSpacing) * m_docPrefsData.guidesPrefs.minorGridSpacing + Pages->at(onp)->xOffset();
+ newY = qRound((fp4.y() - Pages->at(onp)->yOffset()) / m_docPrefsData.guidesPrefs.minorGridSpacing) * m_docPrefsData.guidesPrefs.minorGridSpacing + Pages->at(onp)->yOffset();
+ if (fabs(newX - fp4.x()) < fabs(dX))
+ dX = newX - fp4.x();
+ if (fabs(newY - fp4.y()) < fabs(dY))
+ dY = newY - fp4.y();
+ onPage = true;
+ }
+
+ if (onPage)
+ nr.translate(dX, dY);
+ return nr;
+}
void ScribusDoc::itemSelection_MultipleDuplicate(ItemMultipleDuplicateData& mdData)
{
Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21297&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Sat May 7 19:47:12 2016
@@ -1143,6 +1143,8 @@
QPoint ApplyGrid(const QPoint& in);
/*! \brief Apply grid to an FPoint, from ScribusView */
FPoint ApplyGridF(const FPoint& in);
+ /*! \brief Apply grid to an QRectF, from ScribusView */
+ QRectF ApplyGridF(const QRectF& in);
/*! \brief Does this doc have any TOC setups and potentially a TOC to generate */
bool hasTOCSetup() { return !m_docPrefsData.tocPrefs.defaultToCSetups.empty(); }
//! \brief Get the closest guide to the given point
More information about the scribus-commit
mailing list