r15534 by craig - Related to #2707, #2660: Allow sections/page numbers to have a user-defined width and leading character

scribus-commit scribus-commit at lists.scribus.net
Thu Oct 14 21:33:42 CEST 2010


Author: craig
Date: Thu Oct 14 19:33:42 2010
New Revision: 15534

URL: http://scribus.info/websvn/listing.php?repname=Scribus&sc=1&rev=15534
Log:
Related to #2707, #2660: Allow sections/page numbers to have a user-defined width and leading character

Modified:
    trunk/Scribus/scribus/pageitem.cpp
    trunk/Scribus/scribus/pageitem_textframe.cpp
    trunk/Scribus/scribus/pagestructs.h
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
    trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
    trunk/Scribus/scribus/scribusdoc.cpp
    trunk/Scribus/scribus/scribusdoc.h
    trunk/Scribus/scribus/ui/prefs_documentsections.cpp
    trunk/Scribus/scribus/ui/prefs_documentsectionsbase.ui

Modified: trunk/Scribus/scribus/pageitem.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15534&path=/trunk/Scribus/scribus/pageitem.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem.cpp (original)
+++ trunk/Scribus/scribus/pageitem.cpp Thu Oct 14 19:33:42 2010
@@ -2394,7 +2394,7 @@
 
 QString PageItem::ExpandToken(uint base)
 {
-	uint zae = 0;
+	//uint zae = 0;
 	QChar ch = itemText.text(base);
 	QString chstr = ch;
 	if (ch == SpecialChars::PAGENUMBER)
@@ -2404,9 +2404,11 @@
 			return "";
 		if ((!m_Doc->masterPageMode()) && (OwnPage != -1))
 		{
-			QString out("%1");
 			//CB Section numbering
-			chstr = out.arg(m_Doc->getSectionPageNumberForPageIndex(OwnPage), -(int)zae);
+			//chstr = out.arg(m_Doc->getSectionPageNumberForPageIndex(OwnPage), -(int)zae);
+			chstr = QString("%1").arg(m_Doc->getSectionPageNumberForPageIndex(OwnPage),
+							m_Doc->getSectionPageNumberWidthForPageIndex(OwnPage),
+							m_Doc->getSectionPageNumberFillCharForPageIndex(OwnPage));
 		}
 		else
 			return "#";
@@ -2415,11 +2417,10 @@
 	{
 		if (!m_Doc->masterPageMode())
 		{
-			QString out("%1");
 			int key = m_Doc->getSectionKeyForPageIndex(OwnPage);
 			if (key == -1)
 				return "%";
-			chstr = out.arg(getStringFromSequence(m_Doc->sections()[key].type, m_Doc->sections()[key].toindex - m_Doc->sections()[key].fromindex + 1));
+			chstr = QString("%1").arg(getStringFromSequence(m_Doc->sections()[key].type, m_Doc->sections()[key].toindex - m_Doc->sections()[key].fromindex + 1));
 		}
 		else
 			return "%";
@@ -2470,7 +2471,6 @@
 	{
 		layout.glyph = style.font().char2CMap(chars[0].unicode());
 	}
-	
 	double tracking = 0.0;
 	if ( (style.effects() & ScStyle_StartOfLine) == 0)
 		tracking = style.fontSize() * style.tracking() / 10000.0;

Modified: trunk/Scribus/scribus/pageitem_textframe.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15534&path=/trunk/Scribus/scribus/pageitem_textframe.cpp
==============================================================================
--- trunk/Scribus/scribus/pageitem_textframe.cpp (original)
+++ trunk/Scribus/scribus/pageitem_textframe.cpp Thu Oct 14 19:33:42 2010
@@ -1083,7 +1083,6 @@
 //				   .arg(a);
 
 			chstr = ExpandToken(a);
-//			qDebug() << QString("expanded token: '%1'").arg(chstr);
 			if (chstr.isEmpty())
 				chstr = SpecialChars::ZWNBSPACE;
 			if (style.lineSpacingMode() == ParagraphStyle::AutomaticLineSpacing)

Modified: trunk/Scribus/scribus/pagestructs.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15534&path=/trunk/Scribus/scribus/pagestructs.h
==============================================================================
--- trunk/Scribus/scribus/pagestructs.h (original)
+++ trunk/Scribus/scribus/pagestructs.h Thu Oct 14 19:33:42 2010
@@ -61,6 +61,8 @@
 	uint sectionstartindex; // Start of section, an index in the range of type, eg for type i,ii,iii, this would be 2 for "ii".
 	bool reversed; // Counting 10-1 ?
 	bool active; // Is the section active, ie, if the fromindex is 10, and theres 5 pages, this should be inactive.
+	QChar pageNumberFillChar; //Prefix to be placed before page number
+	int pageNumberWidth; //Minimum width of page number string
 };
 
 typedef QMap<uint, DocumentSection> DocumentSectionMap;

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15534&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format.cpp Thu Oct 14 19:33:42 2010
@@ -1607,7 +1607,15 @@
 				newSection.type=Type_None;
 			newSection.sectionstartindex = attrs.valueAsInt("Start");
 			newSection.reversed = attrs.valueAsBool("Reversed");
-			newSection.active   = attrs.valueAsBool("Active");
+			newSection.active = attrs.valueAsBool("Active");
+			if (attrs.hasAttribute("FillChar"))
+				newSection.pageNumberFillChar = attrs.valueAsString("FillChar").at(0);
+			else
+				newSection.pageNumberFillChar = QChar();
+			if (attrs.hasAttribute("FieldWidth"))
+				newSection.pageNumberWidth = attrs.valueAsInt("FieldWidth");
+			else
+				newSection.pageNumberWidth = 0;
 			doc->sections().insert(newSection.number, newSection);
 		}
 	}

Modified: trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15534&path=/trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp (original)
+++ trunk/Scribus/scribus/plugins/fileloader/scribus150format/scribus150format_save.cpp Thu Oct 14 19:33:42 2010
@@ -845,6 +845,8 @@
 		docu.writeAttribute("Start", (*it).sectionstartindex);
 		docu.writeAttribute("Reversed", (*it).reversed);
 		docu.writeAttribute("Active", (*it).active);
+		docu.writeAttribute("FillChar", (*it).pageNumberFillChar);
+		docu.writeAttribute("FieldWidth", (*it).pageNumberWidth);
 	}
 	docu.writeEndElement();
 }

Modified: trunk/Scribus/scribus/scribusdoc.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15534&path=/trunk/Scribus/scribus/scribusdoc.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.cpp (original)
+++ trunk/Scribus/scribus/scribusdoc.cpp Thu Oct 14 19:33:42 2010
@@ -3134,10 +3134,15 @@
 				//Our page number collection string
 				QString pageNumberText(QString::null);
 				if (chr == 30)
-				{
+				{//ch == SpecialChars::PAGENUMBER
 					//If not on a master page just get the page number for the page and the text
 					if (lc!=0)
-						pageNumberText=getSectionPageNumberForPageIndex(it->OwnPage);
+					{
+//						pageNumberText=getSectionPageNumberForPageIndex(it->OwnPage);
+						pageNumberText = QString("%1").arg(getSectionPageNumberForPageIndex(it->OwnPage),
+										getSectionPageNumberWidthForPageIndex(it->OwnPage),
+										getSectionPageNumberFillCharForPageIndex(it->OwnPage));
+					}
 					else
 					{
 						//Else, for a page number in a text frame on a master page we must scan
@@ -3150,7 +3155,10 @@
 						{
 							if (DocPages.at(a)->MPageNam == it->OnMasterPage)
 							{
-								newText=getSectionPageNumberForPageIndex(a);
+//								newText=getSectionPageNumberForPageIndex(a);
+								newText = QString("%1").arg(getSectionPageNumberForPageIndex(a),
+												getSectionPageNumberWidthForPageIndex(a),
+												getSectionPageNumberFillCharForPageIndex(a));
 								for (int nti=0;nti<newText.length();++nti)
 									if (pageNumberText.indexOf(newText[nti])==-1)
 										pageNumberText+=newText[nti];
@@ -3159,15 +3167,14 @@
 					}
 				}
 				else
-				{
+				{//ch == SpecialChars::PAGECOUNT
 					if (lc!=0)
 					{
-						QString out("%1");
 						int key = getSectionKeyForPageIndex(it->OwnPage);
 						if (key == -1)
 							pageNumberText = "";
 						else
-							pageNumberText = out.arg(getStringFromSequence(docPrefsData.docSectionMap[key].type, docPrefsData.docSectionMap[key].toindex - docPrefsData.docSectionMap[key].fromindex + 1));
+							pageNumberText = QString("%1").arg(getStringFromSequence(docPrefsData.docSectionMap[key].type, docPrefsData.docSectionMap[key].toindex - docPrefsData.docSectionMap[key].fromindex + 1));
 					}
 					else
 					{
@@ -3177,12 +3184,11 @@
 						{
 							if (DocPages.at(a)->MPageNam == it->OnMasterPage)
 							{
-								QString out("%1");
 								int key = getSectionKeyForPageIndex(a);
 								if (key == -1)
 									newText = "";
 								else
-									newText = out.arg(getStringFromSequence(docPrefsData.docSectionMap[key].type, docPrefsData.docSectionMap[key].toindex - docPrefsData.docSectionMap[key].fromindex + 1));
+									newText = QString("%1").arg(getStringFromSequence(docPrefsData.docSectionMap[key].type, docPrefsData.docSectionMap[key].toindex - docPrefsData.docSectionMap[key].fromindex + 1));
 								for (int nti=0;nti<newText.length();++nti)
 									if (pageNumberText.indexOf(newText[nti])==-1)
 										pageNumberText+=newText[nti];
@@ -5365,7 +5371,7 @@
 }
 
 
-void ScribusDoc::addSection(const int number, const QString& name, const uint fromindex, const uint toindex, const DocumentSectionType type, const uint sectionstartindex, const bool reversed, const bool active)
+void ScribusDoc::addSection(const int number, const QString& name, const uint fromindex, const uint toindex, const DocumentSectionType type, const uint sectionstartindex, const bool reversed, const bool active, const QChar fillChar, int fieldWidth)
 {
 	struct DocumentSection newSection;
 	uint docPageCount=DocPages.count();
@@ -5380,6 +5386,8 @@
 		newSection.sectionstartindex=1;
 		newSection.reversed=false;
 		newSection.active=true;
+		newSection.pageNumberFillChar=QChar();
+		newSection.pageNumberWidth=0;
 		docPrefsData.docSectionMap.insert(newSection.number, newSection);
 	}
 	else if (number!=-1)
@@ -5394,6 +5402,8 @@
 		newSection.sectionstartindex=sectionstartindex;
 		newSection.reversed=reversed;
 		newSection.active=active;
+		newSection.pageNumberFillChar=fillChar;
+		newSection.pageNumberWidth=fieldWidth;
 		docPrefsData.docSectionMap.insert(newSection.number, newSection);
 	}
 }
@@ -5457,15 +5467,41 @@
 	int key=getSectionKeyForPageIndex(pageIndex);
 	if (key==-1)
 		return retVal;
-
-	uint sectionIndexOffset=pageIndex-docPrefsData.docSectionMap[key].fromindex+docPrefsData.docSectionMap[key].sectionstartindex;
 	//If a section is inactive, theres no page numbers printed
 	if (docPrefsData.docSectionMap[key].active==false)
 		return "";
+	uint sectionIndexOffset=pageIndex-docPrefsData.docSectionMap[key].fromindex+docPrefsData.docSectionMap[key].sectionstartindex;
 	retVal=getStringFromSequence(docPrefsData.docSectionMap[key].type, sectionIndexOffset);
 	return retVal;
 }
 
+const QChar ScribusDoc::getSectionPageNumberFillCharForPageIndex(const uint pageIndex) const
+{
+	QChar retVal;
+	int key=getSectionKeyForPageIndex(pageIndex);
+	if (key==-1)
+		return retVal;
+
+	//If a section is inactive, theres no page numbers printed
+	if (docPrefsData.docSectionMap[key].active==false)
+		return retVal;
+	retVal=docPrefsData.docSectionMap[key].pageNumberFillChar;
+	return retVal;
+}
+
+int ScribusDoc::getSectionPageNumberWidthForPageIndex(const uint pageIndex) const
+{
+	int retVal=0;
+	int key=getSectionKeyForPageIndex(pageIndex);
+	if (key==-1)
+		return retVal;
+
+	//If a section is inactive, theres no page numbers printed
+	if (docPrefsData.docSectionMap[key].active==false)
+		return retVal;
+	retVal=docPrefsData.docSectionMap[key].pageNumberWidth;
+	return retVal;
+}
 
 void ScribusDoc::updateSectionPageNumbersToPages()
 {

Modified: trunk/Scribus/scribus/scribusdoc.h
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15534&path=/trunk/Scribus/scribus/scribusdoc.h
==============================================================================
--- trunk/Scribus/scribus/scribusdoc.h (original)
+++ trunk/Scribus/scribus/scribusdoc.h Thu Oct 14 19:33:42 2010
@@ -826,7 +826,7 @@
 	 * @brief Add a section to the document sections list
 	 * Set number to -1 to add in the default section if the map is empty
 	 */
-	void addSection(const int number=0, const QString& name=QString::null, const uint fromindex=0, const uint toindex=0, const  DocumentSectionType type=Type_1_2_3, const uint sectionstartindex=0, const bool reversed=false, const bool active=true);
+	void addSection(const int number=0, const QString& name=QString::null, const uint fromindex=0, const uint toindex=0, const  DocumentSectionType type=Type_1_2_3, const uint sectionstartindex=0, const bool reversed=false, const bool active=true, const QChar fillChar=QChar(), int fieldWidth=0);
 	/**
 	 * @brief Delete a section from the document sections list
 	 */
@@ -836,6 +836,16 @@
 	 * Returns QString::null on failure to find the pageIndex
 	 */
 	const QString getSectionPageNumberForPageIndex(const uint) const;
+	/**
+	 * @brief Gets the page number fill character to be printed based on the section it is in.
+	 * Returns QString::null on failure to find the pageIndex
+	 */
+	const QChar getSectionPageNumberFillCharForPageIndex(const uint) const;
+	/**
+	 * @brief Gets the page number fill character to be printed based on the section it is in.
+	 * Returns QString::null on failure to find the pageIndex
+	 */
+	int getSectionPageNumberWidthForPageIndex(const uint) const;
 	/**
 	 * @brief Gets the key of the sections map based on the section the page index is in.
 	 * Returns -1 on failure to find the pageIndex

Modified: trunk/Scribus/scribus/ui/prefs_documentsections.cpp
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15534&path=/trunk/Scribus/scribus/ui/prefs_documentsections.cpp
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_documentsections.cpp (original)
+++ trunk/Scribus/scribus/ui/prefs_documentsections.cpp Thu Oct 14 19:33:42 2010
@@ -57,35 +57,42 @@
 	{
 		uint i=0;
 		//Name
-		QTableWidgetItem *item1 = new QTableWidgetItem((*it).name);
-		sectionsTable->setItem(row, i++, item1);
+		QTableWidgetItem *item0 = new QTableWidgetItem((*it).name);
+		sectionsTable->setItem(row, i++, item0);
 		//Active
-		QCheckBox *item2 = new QCheckBox();
-		item2->setChecked((*it).active);
-		sectionsTable->setCellWidget(row, i++, item2);
+		QCheckBox *item1 = new QCheckBox();
+		item1->setChecked((*it).active);
+		sectionsTable->setCellWidget(row, i++, item1);
 		//FromIndex
-		QTableWidgetItem *item3 = new QTableWidgetItem(QString::number((*it).fromindex+1));
+		QTableWidgetItem *item2 = new QTableWidgetItem(QString::number((*it).fromindex+1));
+		sectionsTable->setItem(row, i++, item2);
+		//ToIndex
+		QTableWidgetItem *item3 = new QTableWidgetItem(QString::number((*it).toindex+1));
 		sectionsTable->setItem(row, i++, item3);
-		//ToIndex
-		QTableWidgetItem *item4 = new QTableWidgetItem(QString::number((*it).toindex+1));
-		sectionsTable->setItem(row, i++, item4);
 		//Style
-		QComboBox *item5 = new QComboBox();
-		item5->addItems(styles);
-		sectionsTable->setCellWidget(row, i++, item5);
+		QComboBox *item4 = new QComboBox();
+		item4->addItems(styles);
+		sectionsTable->setCellWidget(row, i++, item4);
 		if ((*it).type==Type_None)
-			item5->setCurrentIndex(styles.count()-1);
+			item4->setCurrentIndex(styles.count()-1);
 		else
-			item5->setCurrentIndex((*it).type);
+			item4->setCurrentIndex((*it).type);
 		//Start Page Number
-		QTableWidgetItem *item6 = new QTableWidgetItem(QString::number((*it).sectionstartindex));
-		sectionsTable->setItem(row, i++, item6);
+		QTableWidgetItem *item5 = new QTableWidgetItem(QString::number((*it).sectionstartindex));
+		sectionsTable->setItem(row, i++, item5);
 		//End Page Number
 		/*
 		QTableItem *item7 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, QString::number((*it).sectionstartindex + (*it).toindex - (*it).fromindex));
 		item7->setEnabled(false);
 		sectionsTable->setItem(row, i++, item7);
 		*/
+		//Field Width
+		QTableWidgetItem *item6 = new QTableWidgetItem(QString::number((*it).pageNumberWidth));
+		sectionsTable->setItem(row, i++, item6);
+		//Fill Char
+		QTableWidgetItem *item7 = new QTableWidgetItem(QString((*it).pageNumberFillChar));
+		sectionsTable->setItem(row, i++, item7);
+		//
 		QTableWidgetItem *t=sectionsTable->verticalHeaderItem(row);
 		if (t!=NULL)
 			t->setText(QString("%1").arg(row));
@@ -150,6 +157,18 @@
 		break;
 	case 5:
 		localSections[row].sectionstartindex=sectionsTable->item(row, col)->text().toUInt();
+		break;
+	case 6:
+		localSections[row].pageNumberWidth=sectionsTable->item(row, col)->text().toInt();
+		break;
+	case 7:
+		{
+			QString ch=sectionsTable->item(row, col)->text();
+			if (ch.length()>0)
+				localSections[row].pageNumberFillChar=sectionsTable->item(row, col)->text().at(0);
+			else
+				localSections[row].pageNumberFillChar=QChar();
+		}
 		break;
 	default:
 		break;

Modified: trunk/Scribus/scribus/ui/prefs_documentsectionsbase.ui
URL: http://scribus.info/websvn/diff.php?repname=Scribus&rev=15534&path=/trunk/Scribus/scribus/ui/prefs_documentsectionsbase.ui
==============================================================================
--- trunk/Scribus/scribus/ui/prefs_documentsectionsbase.ui (original)
+++ trunk/Scribus/scribus/ui/prefs_documentsectionsbase.ui Thu Oct 14 19:33:42 2010
@@ -73,6 +73,16 @@
        <string>Start</string>
       </property>
      </column>
+     <column>
+      <property name="text">
+       <string>Field Width</string>
+      </property>
+     </column>
+     <column>
+      <property name="text">
+       <string>Fill Character</string>
+      </property>
+     </column>
     </widget>
    </item>
    <item>




More information about the scribus-commit mailing list