r14732 by jghali - #8813 : column / row guides are not correctly shown when reopening a document

scribus-commit scribus-commit at lists.scribus.net
Mon Feb 15 21:10:33 CET 2010


Revision: 14732
Author: jghali
Date: 2010-02-15T20:00:42.706459Z
Commit message: #8813 : column / row guides are not correctly shown when reopening a document

Changeset: 
M  /branches/Version135/Scribus/scribus/guidemanager.cpp
M  /branches/Version135/Scribus/scribus/guidemanager.h
M  /branches/Version135/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
M  /branches/Version135/Scribus/scribus/guidemanagercore.cpp
M  /branches/Version135/Scribus/scribus/guidemanagercore.h

Diffs:
Index: scribus/guidemanager.cpp
===================================================================
--- scribus/guidemanager.cpp	(revision 14731)
+++ scribus/guidemanager.cpp	(revision 14732)
@@ -550,92 +550,44 @@
 
 Guides GuideManager::getAutoVerticals()
 {
-	Guides retval;
-	double columnSize;
-	int value = verticalAutoCountSpin->value();
-	double offset = 0.0;
-	double newPageWidth = currentPage->width();
+GuideManagerCore guides;
 
-	if (value == 0)
-		return retval;
-	++value;
+	double gapValue = 0.0;
+	if (horizontalAutoGapCheck->isChecked())
+		gapValue = value2pts(horizontalAutoGapSpin->value(), docUnitIndex);
+	guides.setHorizontalAutoGap(gapValue);
+	guides.setHorizontalAutoCount(horizontalAutoCountSpin->value());
+	guides.setHorizontalAutoRefer(horizontalRefer());
 
-	if (verticalRefer() == 1)
-	{
-		newPageWidth = newPageWidth - currentPage->Margins.Left - currentPage->Margins.Right;
-		offset = currentPage->Margins.Left;
-	}
-	else if (verticalRefer() == 2)
-	{
-		if (qRound(currentPage->guides.gx) != 0)
-		{
-			offset = currentPage->guides.gx;
-			newPageWidth = currentPage->guides.gw;
-		}
-	}
+	gapValue = 0.0;
+	if (verticalAutoGapCheck->isChecked())
+		gapValue = value2pts(verticalAutoGapSpin->value(), docUnitIndex);
+	guides.setVerticalAutoGap(gapValue);
+	guides.setVerticalAutoCount(verticalAutoCountSpin->value());
+	guides.setVerticalAutoRefer(verticalRefer());
 
-	if (currentPage->guides.verticalAutoGap() > 0.0 && verticalAutoGapCheck->isChecked())
-		columnSize = (newPageWidth - (value - 1) * currentPage->guides.verticalAutoGap()) / value;
-	else
-		columnSize = newPageWidth / value;
-
-	for (int i = 1, gapCount = 0; i < value; ++i)
-	{
-		if (currentPage->guides.verticalAutoGap() > 0.0 && verticalAutoGapCheck->isChecked())
-		{
-			retval.append(offset + i * columnSize + gapCount * currentPage->guides.verticalAutoGap());
-			++gapCount;
-			retval.append(offset + i * columnSize + gapCount * currentPage->guides.verticalAutoGap());
-		}
-		else
-			retval.append(offset + columnSize * i);
-	}
-	return retval;
+	return guides.getAutoVerticals(currentPage);
 }
 
 Guides GuideManager::getAutoHorizontals()
 {
-	Guides retval;
-	double rowSize;
-	int value = horizontalAutoCountSpin->value();
-	double offset = 0.0;
-	double newPageHeight = currentPage->height();
+	GuideManagerCore guides;
 
-	if (value == 0)
-		return retval;
-	++value;
+	double gapValue = 0.0;
+	if (horizontalAutoGapCheck->isChecked())
+		gapValue = value2pts(horizontalAutoGapSpin->value(), docUnitIndex);
+	guides.setHorizontalAutoGap(gapValue);
+	guides.setHorizontalAutoCount(horizontalAutoCountSpin->value());
+	guides.setHorizontalAutoRefer(horizontalRefer());
 
-	if (horizontalRefer() == 1)
-	{
-		newPageHeight = newPageHeight - currentPage->Margins.Top - currentPage->Margins.Bottom;
-		offset = currentPage->Margins.Top;
-	}
-	else if (horizontalRefer() == 2)
-	{
-		if (qRound(currentPage->guides.gy) != 0.0)
-		{
-			offset = currentPage->guides.gy;
-			newPageHeight = currentPage->guides.gh;
-		}
-	}
+	gapValue = 0.0;
+	if (verticalAutoGapCheck->isChecked())
+		gapValue = value2pts(verticalAutoGapSpin->value(), docUnitIndex);
+	guides.setVerticalAutoGap(gapValue);
+	guides.setVerticalAutoCount(verticalAutoCountSpin->value());
+	guides.setVerticalAutoRefer(verticalRefer());
 
-	if (currentPage->guides.horizontalAutoGap() > 0.0 && horizontalAutoGapCheck->isChecked())
-		rowSize = (newPageHeight - (value - 1) * currentPage->guides.horizontalAutoGap()) / value;
-	else
-		rowSize = newPageHeight / value;
-
-	for (int i = 1, gapCount = 0; i < value; ++i)
-	{
-		if (currentPage->guides.horizontalAutoGap() > 0.0&& horizontalAutoGapCheck->isChecked())
-		{
-			retval.append(offset + i * rowSize + gapCount * currentPage->guides.horizontalAutoGap());
-			++gapCount;
-			retval.append(offset + i * rowSize + gapCount * currentPage->guides.horizontalAutoGap());
-		}
-		else
-			retval.append(offset + rowSize * i);
-	}
-	return retval;
+	return guides.getAutoHorizontals(currentPage);
 }
 
 void GuideManager::resetSelectionForPage()
Index: scribus/guidemanagercore.cpp
===================================================================
--- scribus/guidemanagercore.cpp	(revision 14731)
+++ scribus/guidemanagercore.cpp	(revision 14732)
@@ -23,6 +23,7 @@
 GuideManagerCore::GuideManagerCore():
 	undoManager(UndoManager::instance()),
 	m_page(0),
+	gx(0), gy(0), gw(0), gh(0),
 	m_horizontalAutoGap(0.0),
 	m_verticalAutoGap(0.0),
 	m_horizontalAutoCount(0),
@@ -234,6 +235,106 @@
 	return -1.0; // just for compiler warning
 }
 
+Guides GuideManagerCore::getAutoHorizontals(Page* page)
+{
+	Guides guides;
+	double rowSize;
+	int value = m_horizontalAutoCount;
+	double offset = 0.0;
+	double newPageHeight = page->height();
+
+	if (page == NULL)
+		page = m_page;
+	if (page == NULL)
+		return guides;
+
+	if (m_horizontalAutoCount == 0)
+		return guides;
+	++value;
+
+	if (m_horizontalAutoRefer == 1)
+	{
+		newPageHeight = newPageHeight - page->Margins.Top - page->Margins.Bottom;
+		offset = page->Margins.Top;
+	}
+	else if (m_horizontalAutoRefer == 2)
+	{
+		if (qRound(page->guides.gy) != 0.0)
+		{
+			offset = page->guides.gy;
+			newPageHeight = page->guides.gh;
+		}
+	}
+
+	if (page->guides.horizontalAutoGap() > 0.0)
+		rowSize = (newPageHeight - (value - 1) * page->guides.horizontalAutoGap()) / value;
+	else
+		rowSize = newPageHeight / value;
+
+	for (int i = 1, gapCount = 0; i < value; ++i)
+	{
+		if (page->guides.horizontalAutoGap() > 0.0)
+		{
+			guides.append(offset + i * rowSize + gapCount * page->guides.horizontalAutoGap());
+			++gapCount;
+			guides.append(offset + i * rowSize + gapCount * page->guides.horizontalAutoGap());
+		}
+		else
+			guides.append(offset + rowSize * i);
+	}
+	return guides;
+}
+
+Guides GuideManagerCore::getAutoVerticals(Page* page)
+{
+	Guides guides;
+	double columnSize;
+	int value = m_verticalAutoCount;
+	double offset = 0.0;
+	double newPageWidth = page->width();
+
+	if (page == NULL)
+		page = m_page;
+	if (page == NULL)
+		return guides;
+
+	if (m_verticalAutoCount == 0)
+		return guides;
+	++value;
+
+	if (m_horizontalAutoRefer == 1)
+	{
+		newPageWidth = newPageWidth - page->Margins.Left - page->Margins.Right;
+		offset = page->Margins.Left;
+	}
+	else if (m_horizontalAutoRefer == 2)
+	{
+		if (qRound(page->guides.gx) != 0)
+		{
+			offset = page->guides.gx;
+			newPageWidth = page->guides.gw;
+		}
+	}
+
+	if (page->guides.verticalAutoGap() > 0.0)
+		columnSize = (newPageWidth - (value - 1) * page->guides.verticalAutoGap()) / value;
+	else
+		columnSize = newPageWidth / value;
+
+	for (int i = 1, gapCount = 0; i < value; ++i)
+	{
+		if (page->guides.verticalAutoGap() > 0.0)
+		{
+			guides.append(offset + i * columnSize + gapCount * page->guides.verticalAutoGap());
+			++gapCount;
+			guides.append(offset + i * columnSize + gapCount * page->guides.verticalAutoGap());
+		}
+		else
+			guides.append(offset + columnSize * i);
+	}
+	return guides;
+}
+
 void GuideManagerCore::clearHorizontals(GuideType type)
 {
 	switch (type)
Index: scribus/guidemanagercore.h
===================================================================
--- scribus/guidemanagercore.h	(revision 14731)
+++ scribus/guidemanagercore.h	(revision 14732)
@@ -56,6 +56,9 @@
 	double horizontal(uint ix, GuideType type);
 	double vertical(uint ix, GuideType type);
 
+	Guides getAutoHorizontals(Page* page = NULL);
+	Guides getAutoVerticals(Page* page = NULL);
+
 	void clearHorizontals(GuideType type);
 	void clearVerticals(GuideType type);
 
Index: scribus/plugins/fileloader/scribus134format/scribus134format.cpp
===================================================================
--- scribus/plugins/fileloader/scribus134format/scribus134format.cpp	(revision 14731)
+++ scribus/plugins/fileloader/scribus134format/scribus134format.cpp	(revision 14732)
@@ -967,6 +967,8 @@
 						pg.hasAttribute("NumHGuides"));
 				GuideManagerIO::readSelection(pg.attribute("AGSelection"), Apage);
 				
+				Apage->guides.addHorizontals(Apage->guides.getAutoHorizontals(Apage), GuideManagerCore::Auto);
+				Apage->guides.addVerticals(Apage->guides.getAutoVerticals(Apage), GuideManagerCore::Auto);
 			}
 			if ((pg.tagName()=="PAGEOBJECT") || (pg.tagName()=="MASTEROBJECT") || (pg.tagName()=="FRAMEOBJECT"))
 			{
@@ -2956,6 +2958,9 @@
 												GuideManagerCore::Standard,
 												pg.hasAttribute("NumHGuides"));
 				GuideManagerIO::readSelection(pg.attribute("AGSelection"), Apage);
+
+				Apage->guides.addHorizontals(Apage->guides.getAutoHorizontals(Apage), GuideManagerCore::Auto);
+				Apage->guides.addVerticals(Apage->guides.getAutoVerticals(Apage), GuideManagerCore::Auto);
 				
 			}
 			if ((pg.tagName()=="PAGEOBJECT") || (pg.tagName()=="MASTEROBJECT") || (pg.tagName()=="FRAMEOBJECT"))
Index: scribus/guidemanager.h
===================================================================
--- scribus/guidemanager.h	(revision 14731)
+++ scribus/guidemanager.h	(revision 14732)
@@ -99,6 +99,11 @@
 	\param page A reference to the page to store values. */
 	void storePageValues(Page * page);
 
+	/*! \brief Save needed (Auto) values into GuideManagerCore.
+	To be restored on the page return.
+	\param page A reference to the page to store values. */
+	void storePageValues(GuideManagerCore);
+
 	/*! \brief Overriden QDialog method to operate selection related widgets.
 	Auto guides tab. It disables the "selection" radio buttons when there
 	is no selection on current page. */




More information about the scribus-commit mailing list