r15047 by cbradney - Enable document sections and information in new doc setup dialog (which is still hidden in SVN)

scribus-commit scribus-commit at lists.scribus.net
Wed May 5 22:50:28 CEST 2010


Revision: 15047
Author: cbradney
Date: 2010-05-05T20:47:11.882623Z
Commit message: Enable document sections and information in new doc setup dialog (which is still hidden in SVN)

Changeset: 
M  /trunk/Scribus/scribus/ui/prefs_documentinformation.cpp
M  /trunk/Scribus/scribus/ui/prefs_documentsections.cpp
M  /trunk/Scribus/scribus/ui/prefs_documentsections.h

Diffs:
Index: scribus/ui/prefs_documentsections.h
===================================================================
--- scribus/ui/prefs_documentsections.h	(revision 15046)
+++ scribus/ui/prefs_documentsections.h	(revision 15047)
@@ -9,6 +9,7 @@
 #define PREFS_DOCUMENTSECTIONS_H
 
 #include "ui_prefs_documentsectionsbase.h"
+#include "pagestructs.h"
 #include "prefs_pane.h"
 #include "scribusapi.h"
 
@@ -26,6 +27,18 @@
 
 	public slots:
 		void languageChange();
+
+	protected:
+		DocumentSectionMap localSections;
+		uint m_maxpageindex;
+		QStringList styles;
+		ScribusDoc* m_doc;
+		virtual void updateTable();
+
+	protected slots:
+		virtual void tableItemChanged(int, int);
+		virtual void addEntry();
+		virtual void deleteEntry();
 };
 
 #endif // PREFS_DOCUMENTSECTIONS_H
Index: scribus/ui/prefs_documentsections.cpp
===================================================================
--- scribus/ui/prefs_documentsections.cpp	(revision 15046)
+++ scribus/ui/prefs_documentsections.cpp	(revision 15047)
@@ -5,15 +5,24 @@
 for which a new license (GPL+exception) is in place.
 */
 
+#include <QCheckBox>
+#include <QComboBox>
+#include <QMessageBox>
+
 #include "prefs_documentsections.h"
+#include "commonstrings.h"
 #include "prefsstructs.h"
 #include "scribusdoc.h"
 
 Prefs_DocumentSections::Prefs_DocumentSections(QWidget* parent, ScribusDoc* doc)
-	: Prefs_Pane(parent)
+	: Prefs_Pane(parent),
+	m_doc(doc)
 {
 	setupUi(this);
 	languageChange();
+	connect(sectionsTable, SIGNAL(cellChanged(int,int)), this, SLOT(tableItemChanged(int,int)));
+	connect(addButton, SIGNAL(clicked()), this, SLOT(addEntry()));
+	connect(deleteButton, SIGNAL(clicked()), this, SLOT(deleteEntry()));
 }
 
 Prefs_DocumentSections::~Prefs_DocumentSections()
@@ -26,11 +35,235 @@
 
 void Prefs_DocumentSections::restoreDefaults(struct ApplicationPrefs *prefsData)
 {
-//	autoSendCopiedToScrapCheckBox->setChecked(prefsData->scrapbookPrefs.doCopyToScrapbook);
+	localSections=prefsData->docSectionMap;
+	m_maxpageindex=m_doc->DocPages.count()-1;
+	styles.clear();
+	styles << tr("1, 2, 3, ...") << tr("i, ii, iii, ...") << tr("I, II, III, ...") << tr("a, b, c, ...") << tr("A, B, C, ...") << CommonStrings::tr_None;
+
+	updateTable();
 }
 
 void Prefs_DocumentSections::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
 {
-//	prefsData->scrapbookPrefs.doCopyToScrapbook=autoSendCopiedToScrapCheckBox->isChecked();
+	prefsData->docSectionMap=localSections;
 }
 
+
+void Prefs_DocumentSections::updateTable()
+{
+	sectionsTable->setRowCount(localSections.count());
+	int row=0;
+	for(DocumentSectionMap::Iterator it = localSections.begin(); it!= localSections.end(); ++it)
+	{
+		uint i=0;
+		//Name
+		QTableWidgetItem *item1 = new QTableWidgetItem((*it).name);
+		sectionsTable->setItem(row, i++, item1);
+		//Active
+		QCheckBox *item2 = new QCheckBox();
+		item2->setChecked((*it).active);
+		sectionsTable->setCellWidget(row, i++, item2);
+		//FromIndex
+		QTableWidgetItem *item3 = new QTableWidgetItem(QString::number((*it).fromindex+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);
+		if ((*it).type==Type_None)
+			item5->setCurrentIndex(styles.count()-1);
+		else
+			item5->setCurrentIndex((*it).type);
+		//Start Page Number
+		QTableWidgetItem *item6 = new QTableWidgetItem(QString::number((*it).sectionstartindex));
+		sectionsTable->setItem(row, i++, item6);
+		//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);
+		*/
+		QTableWidgetItem *t=sectionsTable->verticalHeaderItem(row);
+		if (t!=NULL)
+			t->setText(QString("%1").arg(row));
+		row++;
+	}
+	deleteButton->setEnabled(localSections.count()>1);
+}
+
+void Prefs_DocumentSections::tableItemChanged( int row, int col )
+{
+	bool outOfRange=false;
+	uint newDocPageSpec;
+
+	switch (col)
+	{
+	case 0:
+		localSections[row].name=sectionsTable->item(row, col)->text();
+		break;
+	case 1:
+		{
+			QCheckBox* qcti=dynamic_cast<QCheckBox*>(sectionsTable->cellWidget(row,col));
+			if (qcti!=NULL)
+				localSections[row].active=qcti->isChecked();
+		}
+		break;
+	case 2:
+	case 3:
+		// Validate to/from page specification before conversion to an index
+		//!!!	There is still a problem here if m_maxpageindex == MAX_UINT ;)
+		newDocPageSpec=sectionsTable->item(row, col)->text().toUInt();
+		if (newDocPageSpec==0)
+		{
+			newDocPageSpec=1;
+			outOfRange=true;
+		}
+		else
+		if (newDocPageSpec>m_maxpageindex+1)
+		{
+			newDocPageSpec=m_maxpageindex+1;
+			outOfRange=true;
+		}
+		// Now, since newDocPageSpec >= 1, convert to index
+		--newDocPageSpec;
+		if (col==2)
+			localSections[row].fromindex=newDocPageSpec;
+		else
+			localSections[row].toindex=newDocPageSpec;
+		break;
+	case 4:
+		{
+			QComboBox* qcti=dynamic_cast<QComboBox*>(sectionsTable->cellWidget(row,col));
+			if (qcti!=NULL)
+			{
+				int index=qcti->currentIndex();
+				if (index<styles.count()-1)
+					localSections[row].type=(DocumentSectionType)index;
+				else
+					if (index==styles.count()-1)
+					localSections[row].type=Type_None;
+			}
+		}
+		break;
+	case 5:
+		localSections[row].sectionstartindex=sectionsTable->item(row, col)->text().toUInt();
+		break;
+	default:
+		break;
+	}
+
+	if (outOfRange)
+	{
+		updateTable();
+		QMessageBox::warning(parentWidget(), tr("Page Number Out Of Bounds"),"<qt>"+ tr("The value you have entered is outside the range of page numbers in the current document (%1-%2).").arg(1).arg(m_maxpageindex+1)+"</qt>",QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
+	}
+}
+
+void Prefs_DocumentSections::addEntry()
+{
+	int currRow=sectionsTable->currentRow();
+	bool found=false;
+	DocumentSectionMap::Iterator it = localSections.begin();
+	int count=0;
+	for(; it!= localSections.end(); ++it)
+	{
+		if(count==currRow)
+		{
+			found=true;
+			break;
+		}
+		++count;
+	}
+	if (!found) //End of map, just append
+	{
+		struct DocumentSection blank;
+		uint count=localSections.count();
+		blank.number=count;
+		blank.name=QString::number(count);
+		blank.fromindex=m_maxpageindex+1;
+		blank.toindex=m_maxpageindex+1;
+		blank.type=Type_1_2_3;
+		blank.sectionstartindex=1;
+		blank.reversed=false;
+		blank.active=true;
+		localSections.insert(count, blank);
+	}
+	else
+	{
+		//Now, copy to a temp map
+		DocumentSectionMap tempSections(localSections);
+		localSections.clear();
+		//Copy the temp map entries over. When we find the number of the current row, also insert a new entry.
+		uint i=0;
+		for(DocumentSectionMap::Iterator it2 = tempSections.begin(); it2!= tempSections.end(); ++it2)
+		{
+			it2.value().number=i;
+			localSections.insert(i, it2.value());
+
+			if ((*it).number==i)
+			{
+				struct DocumentSection blank;
+				blank.number=++i;
+				blank.name=QString::number(i);
+				blank.fromindex=(*it).toindex+1+1;
+				blank.toindex=(*it).toindex+2+1;
+				blank.type=Type_1_2_3;
+				blank.sectionstartindex=1;
+				blank.reversed=false;
+				blank.active=true;
+				localSections.insert(i, blank);
+			}
+			++i;
+		}
+	}
+	updateTable();
+}
+
+void Prefs_DocumentSections::deleteEntry()
+{
+	int currRow=sectionsTable->currentRow();
+	if (currRow==0 && localSections.count()==1)
+		return;
+	bool found=false;
+	DocumentSectionMap::Iterator it = localSections.begin();
+	int count=0;
+	for(; it!= localSections.end(); ++it)
+	{
+		if(count==currRow)
+		{
+			found=true;
+			break;
+		}
+		++count;
+	}
+	if (found)
+	{
+		//If we arent at the start, copy the toindex of the current item
+		//to the toindex of the previous item
+		if (it!=localSections.begin())
+		{
+			DocumentSectionMap::Iterator it2(it);
+			(*--it2).toindex=(*it).toindex;
+		}
+		//Delete the currently selected entry
+		localSections.erase(it);
+		//Now, copy to a temp map and reinsert with consecutive keys again
+		DocumentSectionMap tempSections(localSections);
+		localSections.clear();
+		uint i=0;
+		it = tempSections.begin();
+		for(; it!= tempSections.end(); ++it)
+		{
+			it.value().number=i;
+			localSections.insert(i++, it.value());
+		}
+		int newCount=localSections.count();
+		//int preIndex=qMax(currentIndex-1, 0);
+		localSections[0].fromindex=0;
+		localSections[newCount-1].toindex=m_maxpageindex;
+		updateTable();
+	}
+}
Index: scribus/ui/prefs_documentinformation.cpp
===================================================================
--- scribus/ui/prefs_documentinformation.cpp	(revision 15046)
+++ scribus/ui/prefs_documentinformation.cpp	(revision 15047)
@@ -26,41 +26,41 @@
 
 void Prefs_DocumentInformation::restoreDefaults(struct ApplicationPrefs *prefsData)
 {
-//	titleLineEdit->setText(prefsData->docInfo.title());
-//	authorLineEdit->setText(prefsData->docInfo.author());
-//	subjectLineEdit->setText(prefsData->docInfo.subject());
-//	keywordsTextEdit->setText(prefsData->docInfo.keywords());
-//	descriptionTextEdit->setText(prefsData->docInfo.comments());
-//	publisherLineEdit->setText(prefsData->docInfo.publisher());
-//	contributorsTextEdit->setText(prefsData->docInfo.contrib());
-//	dateLineEdit->setText(prefsData->docInfo.date());
-//	typeLineEdit->setText(prefsData->docInfo.type());
-//	formatLineEdit->setText(prefsData->docInfo.format());
-//	identifierLineEdit->setText(prefsData->docInfo.ident());
-//	sourceLineEdit->setText(prefsData->docInfo.source());
-//	languageLineEdit->setText(prefsData->docInfo.langInfo());
-//	relationLineEdit->setText(prefsData->docInfo.relation());
-//	coverageLineEdit->setText(prefsData->docInfo.cover());
-//	rightsLineEdit->setText(prefsData->docInfo.rights());
+	titleLineEdit->setText(prefsData->docInfo.title());
+	authorLineEdit->setText(prefsData->docInfo.author());
+	subjectLineEdit->setText(prefsData->docInfo.subject());
+	keywordsTextEdit->setText(prefsData->docInfo.keywords());
+	descriptionTextEdit->setText(prefsData->docInfo.comments());
+	publisherLineEdit->setText(prefsData->docInfo.publisher());
+	contributorsTextEdit->setText(prefsData->docInfo.contrib());
+	dateLineEdit->setText(prefsData->docInfo.date());
+	typeLineEdit->setText(prefsData->docInfo.type());
+	formatLineEdit->setText(prefsData->docInfo.format());
+	identifierLineEdit->setText(prefsData->docInfo.ident());
+	sourceLineEdit->setText(prefsData->docInfo.source());
+	languageLineEdit->setText(prefsData->docInfo.langInfo());
+	relationLineEdit->setText(prefsData->docInfo.relation());
+	coverageLineEdit->setText(prefsData->docInfo.cover());
+	rightsLineEdit->setText(prefsData->docInfo.rights());
 }
 
 void Prefs_DocumentInformation::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
 {
-//	prefsData->docInfo.setTitle(titleLineEdit->text());
-//	prefsData->docInfo.setAuthor(authorLineEdit->text());
-//	prefsData->docInfo.setSubject(subjectLineEdit->text());
-//	prefsData->docInfo.setKeywords(keywordsTextEdit->toPlainText());
-//	prefsData->docInfo.setComments(descriptionTextEdit->toPlainText());
-//	prefsData->docInfo.setPublisher(publisherLineEdit->text());
-//	prefsData->docInfo.setContrib(contributorsTextEdit->toPlainText());
-//	prefsData->docInfo.setDate(dateLineEdit->text());
-//	prefsData->docInfo.setType(typeLineEdit->text());
-//	prefsData->docInfo.setFormat(formatLineEdit->text());
-//	prefsData->docInfo.setIdent(identifierLineEdit->text());
-//	prefsData->docInfo.setSource(sourceLineEdit->text());
-//	prefsData->docInfo.setLangInfo(languageLineEdit->text());
-//	prefsData->docInfo.setRelation(relationLineEdit->text());
-//	prefsData->docInfo.setCover(coverageLineEdit->text());
-//	prefsData->docInfo.setRights(rightsLineEdit->text());
+	prefsData->docInfo.setTitle(titleLineEdit->text());
+	prefsData->docInfo.setAuthor(authorLineEdit->text());
+	prefsData->docInfo.setSubject(subjectLineEdit->text());
+	prefsData->docInfo.setKeywords(keywordsTextEdit->toPlainText());
+	prefsData->docInfo.setComments(descriptionTextEdit->toPlainText());
+	prefsData->docInfo.setPublisher(publisherLineEdit->text());
+	prefsData->docInfo.setContrib(contributorsTextEdit->toPlainText());
+	prefsData->docInfo.setDate(dateLineEdit->text());
+	prefsData->docInfo.setType(typeLineEdit->text());
+	prefsData->docInfo.setFormat(formatLineEdit->text());
+	prefsData->docInfo.setIdent(identifierLineEdit->text());
+	prefsData->docInfo.setSource(sourceLineEdit->text());
+	prefsData->docInfo.setLangInfo(languageLineEdit->text());
+	prefsData->docInfo.setRelation(relationLineEdit->text());
+	prefsData->docInfo.setCover(coverageLineEdit->text());
+	prefsData->docInfo.setRights(rightsLineEdit->text());
 }
 




More information about the scribus-commit mailing list