Index: Scribus/scribus/tocindexprefs.h =================================================================== --- Scribus/scribus/tocindexprefs.h (wersja 15812) +++ Scribus/scribus/tocindexprefs.h (kopia robocza) @@ -56,9 +56,19 @@ virtual void itemFrameSelected( const QString & frameName ); virtual void itemPageNumberPlacedSelected( const QString & pageLocation ); virtual void itemParagraphStyleSelected( const QString & itemStyle ); + + virtual void PScomboBoxSelected1text(const QString&); + virtual void PScomboBoxSelected1toc(const QString&); + virtual void PScomboBoxSelected2text(const QString&); + virtual void PScomboBoxSelected2toc(const QString&); + virtual void PScomboBoxSelected3text(const QString&); + virtual void PScomboBoxSelected3toc(const QString&); + virtual void setToCName( const QString & newName ); virtual void nonPrintingFramesSelected( bool showNonPrinting ); + virtual void usePSsearching( bool searchPS ); + protected: int numSelected; QString strPNNotShown; Index: Scribus/scribus/tocindexprefs.ui =================================================================== --- Scribus/scribus/tocindexprefs.ui (wersja 15812) +++ Scribus/scribus/tocindexprefs.ui (kopia robocza) @@ -1,83 +1,76 @@ - + + TOCIndexPrefs - - + + 0 0 - 444 - 234 + 492 + 559 - + Table of Contents and Indexes - - + + 6 - + 0 - - - - - 0 - 0 - 436 - 202 - - - + + + Table Of Contents - - + + 6 - + 0 - - + + 6 - + 0 - + - + - - + + 6 - + 0 - - + + &Add - + Alt+A - - + + &Delete - + Alt+D @@ -87,117 +80,239 @@ - - + + 6 - + 0 - - + + 0 - + 6 - - - - The frame the table of contents will be placed into + + + + Item Attribute Name: + + false + - - - - Page Number Placement: + + + + The Item Attribute that will be set on frames used as a basis for creation of the entries - - false - - - - - Item Attribute Name: + + + + Destination Frame: - + false - - - - The Item Attribute that will be set on frames used as a basis for creation of the entries + + + + The frame the table of contents will be placed into - - - + + + + Page Number Placement: + + + false + + + + + + Place page numbers of the entries at the beginning or the end of the line, or not at all - - - - Include frames that are set to not print as well + + + + TOC Paragraph Style: - - List Non-Printing Entries + + false - - - + + + The paragraph style used for the entry lines - - - - Paragraph Style: + + + + Include frames that are set to not print as well - - false + + List Non-Printing Entries - - - - Destination Frame: + + + + + + + + Paragraph Style based TOC - - false - + + + + 0 + 20 + 267 + 239 + + + + + + + Turning ON seraching text for selected paragraph styles + + + Use Paragraph Style based TOC + + + + + + + Level1 + + + + + + + Search Paragraph Style + + + + + + + The paragraph style name for searching in text + + + + + + + TOC Paragraph Style + + + + + + + The paragraph style used for the entry lines + + + + + + + Level2 + + + + + + + Search Paragraph Style + + + + + + + TOC Paragraph Style + + + + + + + Level3 + + + + + + + Search Paragraph Style + + + + + + + TOC Paragraph Style + + + + + + + The paragraph style name for searching in text + + + + + + + The paragraph style used for the entry lines + + + + + + + The paragraph style name for searching in text + + + + + + + The paragraph style used for the entry lines + + + + + - - - - Qt::Vertical - - - QSizePolicy::Expanding - - - - 16 - 36 - - - - @@ -206,7 +321,7 @@ - + tabTOCIndexWidget tocListBox Index: Scribus/scribus/text/storytext.cpp =================================================================== --- Scribus/scribus/text/storytext.cpp (wersja 15812) +++ Scribus/scribus/text/storytext.cpp (kopia robocza) @@ -850,13 +850,13 @@ } -int StoryText::nrOfParagraph(uint index) const +uint StoryText::nrOfParagraph(int pos) const { int result = 0; StoryText* that = const_cast(this); bool lastWasPARSEP = true; - index = qMin(index, (uint) that->length()); - for (uint i=0; i < index; ++i) { + pos = qMin(pos, that->length()); + for (int i=0; i < pos; ++i) { lastWasPARSEP = that->d->at(i)->ch == SpecialChars::PARSEP; if (lastWasPARSEP) ++result; Index: Scribus/scribus/text/storytext.h =================================================================== --- Scribus/scribus/text/storytext.h (wersja 15812) +++ Scribus/scribus/text/storytext.h (kopia robocza) @@ -146,7 +146,7 @@ uint nrOfParagraphs() const; int startOfParagraph(uint index) const; int endOfParagraph(uint index) const; - int nrOfParagraph(uint index) const; + uint nrOfParagraph(int pos) const; uint nrOfRuns() const; int startOfRun(uint index) const; Index: Scribus/scribus/tocindexprefs.cpp =================================================================== --- Scribus/scribus/tocindexprefs.cpp (wersja 15812) +++ Scribus/scribus/tocindexprefs.cpp (kopia robocza) @@ -44,6 +44,10 @@ * \brief Constructs a TOCIndexPrefs as a child of 'parent', with the * name 'name' and widget flags set to 'f'. */ + +#define con_LEVEL_CB_SLOT( post ) connect(PScomboBox##post , SIGNAL( activated(const QString&) ), this, SLOT( PScomboBoxSelected##post(const QString&) ) ) +#define dis_LEVEL_CB_SLOT( post) disconnect(PScomboBox##post , SIGNAL( activated(const QString&) ), this, SLOT( PScomboBoxSelected##post(const QString&) ) ) + TOCIndexPrefs::TOCIndexPrefs( QWidget* parent, const char* name, Qt::WFlags fl ) : QWidget( parent, fl ) { @@ -54,7 +58,13 @@ itemAttrComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" )); itemNumberPlacementComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" )); itemParagraphStyleComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" )); - resize( QSize(444, 234).expandedTo(minimumSizeHint()) ); + PScomboBox1text->setMaximumWidth(fontMetrics().width( "This is a very long Name" )); + PScomboBox1toc->setMaximumWidth(fontMetrics().width( "This is a very long Name" )); + PScomboBox2text->setMaximumWidth(fontMetrics().width( "This is a very long Name" )); + PScomboBox2toc->setMaximumWidth(fontMetrics().width( "This is a very long Name" )); + PScomboBox3text->setMaximumWidth(fontMetrics().width( "This is a very long Name" )); + PScomboBox3toc->setMaximumWidth(fontMetrics().width( "This is a very long Name" )); + resize( QSize(444, 450).expandedTo(minimumSizeHint()) ); // signals and slots connections connect( tocListBox, SIGNAL( currentRowChanged(int) ), this, SLOT( selectToC(int) ) ); @@ -63,9 +73,17 @@ connect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) ); connect( itemDestFrameComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemFrameSelected(const QString&) ) ); connect( itemParagraphStyleComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemParagraphStyleSelected(const QString&) ) ); + con_LEVEL_CB_SLOT(1text); + con_LEVEL_CB_SLOT(1toc); + con_LEVEL_CB_SLOT(2text); + con_LEVEL_CB_SLOT(2toc); + con_LEVEL_CB_SLOT(3text); + con_LEVEL_CB_SLOT(3toc); + connect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) ); connect( tocNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( setToCName(const QString&) ) ); connect( itemListNonPrintingCheckBox, SIGNAL( toggled(bool) ), this, SLOT( nonPrintingFramesSelected(bool) ) ); + connect( itemParStyleBasedCheckBox, SIGNAL( toggled(bool) ), this, SLOT( usePSsearching(bool) ) ); init(); } @@ -200,9 +218,19 @@ disconnect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) ); disconnect( itemDestFrameComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemFrameSelected(const QString&) ) ); disconnect( itemParagraphStyleComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemParagraphStyleSelected(const QString&) ) ); + + dis_LEVEL_CB_SLOT(1text); + dis_LEVEL_CB_SLOT(1toc); + dis_LEVEL_CB_SLOT(2text); + dis_LEVEL_CB_SLOT(2toc); + dis_LEVEL_CB_SLOT(3text); + dis_LEVEL_CB_SLOT(3toc); + disconnect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) ); disconnect( tocNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( setToCName(const QString&) ) ); disconnect( itemListNonPrintingCheckBox, SIGNAL( toggled(bool) ), this, SLOT( nonPrintingFramesSelected(bool) ) ); + disconnect( itemParStyleBasedCheckBox, SIGNAL( toggled(bool) ), this, SLOT( usePSsearching(bool) ) ); + if (localToCSetupVector[numSelected].itemAttrName==strNone) setCurrentComboItem(itemAttrComboBox, trStrNone); else @@ -230,8 +258,23 @@ else setCurrentComboItem(itemParagraphStyleComboBox, localToCSetupVector[numSelected].textStyle); } + +#define setPScbox( post ) \ + if (!paragraphStyleList.contains(localToCSetupVector[numSelected].SearchStyle##post) || localToCSetupVector[numSelected].SearchStyle##post==strNone) \ + setCurrentComboItem(PScomboBox##post, trStrNone); \ + else \ + setCurrentComboItem(PScomboBox##post, localToCSetupVector[numSelected].textStyle); + + setPScbox(1text) + setPScbox(1toc) + setPScbox(2text) + setPScbox(2toc) + setPScbox(3text) + setPScbox(3toc) + } - + itemParStyleBasedCheckBox->setChecked(localToCSetupVector[numSelected].usePSsearching); + if (tocListBox->currentItem()) tocNameLineEdit->setText(tocListBox->currentItem()->text()); @@ -239,9 +282,18 @@ connect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) ); connect( itemDestFrameComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemFrameSelected(const QString&) ) ); connect( itemParagraphStyleComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemParagraphStyleSelected(const QString&) ) ); + + con_LEVEL_CB_SLOT(1text); + con_LEVEL_CB_SLOT(1toc); + con_LEVEL_CB_SLOT(2text); + con_LEVEL_CB_SLOT(2toc); + con_LEVEL_CB_SLOT(3text); + con_LEVEL_CB_SLOT(3toc); + connect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) ); connect( tocNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( setToCName(const QString&) ) ); connect( itemListNonPrintingCheckBox, SIGNAL( toggled(bool) ), this, SLOT( nonPrintingFramesSelected(bool) ) ); + connect( itemParStyleBasedCheckBox, SIGNAL( toggled(bool) ), this, SLOT( usePSsearching(bool) ) ); } @@ -296,6 +348,18 @@ } itemParagraphStyleComboBox->clear(); itemParagraphStyleComboBox->addItems(paragraphStyleList); + PScomboBox1text->clear(); + PScomboBox1text->addItems(paragraphStyleList); + PScomboBox1toc->clear(); + PScomboBox1toc->addItems(paragraphStyleList); + PScomboBox2text->clear(); + PScomboBox2text->addItems(paragraphStyleList); + PScomboBox2toc->clear(); + PScomboBox2toc->addItems(paragraphStyleList); + PScomboBox3text->clear(); + PScomboBox3text->addItems(paragraphStyleList); + PScomboBox3toc->clear(); + PScomboBox3toc->addItems(paragraphStyleList); } @@ -414,6 +478,36 @@ } } +//void TOCIndexPrefs::levelParagraphStyleSelected( const QString& itemStyle, const ushort Level, bool searchPS ) +#define LEVEL_CB_SLOT_DEF( post ) void TOCIndexPrefs::PScomboBoxSelected##post(const QString& itemStyle) \ +{ \ + int numberSelected=tocListBox->currentRow(); \ + if (numberSelected>=0) \ + { \ + int i=0; \ + ToCSetupVector::Iterator it=localToCSetupVector.begin(); \ + while (it!= localToCSetupVector.end() && icurrentRow(); + if (numberSelected>=0) + { + int i=0; + ToCSetupVector::Iterator it=localToCSetupVector.begin(); + while (it!= localToCSetupVector.end() && i ToCSetupVector; Index: Scribus/scribus/tocgenerator.cpp =================================================================== --- Scribus/scribus/tocgenerator.cpp (wersja 15812) +++ Scribus/scribus/tocgenerator.cpp (kopia robocza) @@ -22,15 +22,20 @@ #include #include +#include #include "scribusdoc.h" #include "pagestructs.h" #include "pageitem.h" +#include "pageitem_textframe.h" #include "gtparagraphstyle.h" #include "gtframestyle.h" #include "gtwriter.h" #include "page.h" +#include "scmessagebox.h" +#include "scribuscore.h" + TOCGenerator::TOCGenerator(QObject *parent, ScribusDoc *doc) : QObject(parent) { currDoc=doc; @@ -65,6 +70,10 @@ } return targetFrame; } +struct TOCItem { + QString Text; + QString TocPs; +}; void TOCGenerator::generateDefault() { @@ -74,18 +83,44 @@ for(ToCSetupVector::Iterator tocSetupIt = currDoc->docToCSetups.begin() ; tocSetupIt != currDoc->docToCSetups.end(); ++tocSetupIt ) { PageItem* tocFrame=findTargetFrame((*tocSetupIt).frameName); - if (tocFrame!=NULL) + if (tocFrame != NULL) { PageItem *currentDocItem; - QMap tocMap; + QMap tocMap; //added TOC pragraph style for current item tocMap.clear(); uint *pageCounter = new uint[currDoc->DocPages.count()]; - if (pageCounter==NULL) + if (pageCounter == NULL) return; uint pageNumberWidth=QString("%1").arg(currDoc->DocPages.count()).length(); for (int i=0;iDocPages.count();++i) - pageCounter[i]=0; - int maxDataWidth=0; + pageCounter[i] = 0; + int maxDataWidth = 0; + + //setup vectors with PS names + QVector PSnames; //Vector holds PS names for searching + QVector TOCnames; //Vector holds PS names for TOC + if ((*tocSetupIt).usePSsearching) + { + PSnames.clear(); + TOCnames.clear(); + QString trStrNone=tr("None"); + if (((*tocSetupIt).SearchStyle1text != "") && ((*tocSetupIt).SearchStyle1text != trStrNone)) + { + PSnames.append((*tocSetupIt).SearchStyle1text); + TOCnames.append((*tocSetupIt).SearchStyle1toc); + if (((*tocSetupIt).SearchStyle2text != "") && ((*tocSetupIt).SearchStyle2text != trStrNone)) + { + PSnames.append((*tocSetupIt).SearchStyle2text); + TOCnames.append((*tocSetupIt).SearchStyle2toc); + if (((*tocSetupIt).SearchStyle3text != "") && ((*tocSetupIt).SearchStyle3text != trStrNone)) + { + PSnames.append((*tocSetupIt).SearchStyle3text); + TOCnames.append((*tocSetupIt).SearchStyle3toc); + } + } + } + } + for (int d = 0; d < currDoc->DocItems.count(); ++d) { currentDocItem = currDoc->DocItems.at(d); @@ -98,19 +133,61 @@ if (!(*tocSetupIt).listNonPrintingFrames && !currentDocItem->printEnabled()) continue; ObjectAttribute objattr=currentDocItem->getObjectAttribute((*tocSetupIt).itemAttrName); - if (!objattr.name.isNull()) + + if ((*tocSetupIt).usePSsearching && currentDocItem->isTextFrame() && objattr.name != "noTOC") + //check if text frame is set to omit TOC generation (attribute "noTOC") OR other frame is set to TOC generation { - //The key is generated to produce a sequence of numbers for the page numbers - //First is the page of the item - //Second is an incremented counter for the item so multiple per page works - //Third is the section based page number which is actually used in the TOC. + //for text frames + //find paragraph with style for TOC generation (eg Header style) + PageItem_TextFrame *txtFrame = currentDocItem->asTextFrame(); + StoryText SText = txtFrame->itemText; + + for (int i = txtFrame->firstInFrame(); i < txtFrame->lastInFrame();) + { + QString ParName = SText.paragraphStyle(i).parent(); + int ParIndex = SText.nrOfParagraph(i); + + //if paragraph start at preceding page + if (SText.startOfParagraph(ParIndex) < i) + { + i = SText.startOfParagraph(ParIndex+1); + continue; + } + int PSindex = PSnames.indexOf(ParName); + if ( PSindex != -1) + { + //The key is generated to produce a sequence of numbers for the page numbers + //First is the page of the item + //Second is an incremented counter for the item so multiple per page works + //Third is the section based page number which is actually used in the TOC. + QString key=QString("%1,%2,%3").arg(currentDocItem->OwnPage + currDoc->FirstPnum, pageNumberWidth).arg(pageCounter[currentDocItem->OwnPage]++).arg(currDoc->getSectionPageNumberForPageIndex(currentDocItem->OwnPage)); + + TOCItem toc_item; + toc_item.Text = SText.text(SText.startOfParagraph(ParIndex),SText.endOfParagraph(ParIndex)-SText.startOfParagraph(ParIndex)); + toc_item.TocPs = TOCnames.at(PSindex); + if (!toc_item.Text.isEmpty()) + { + tocMap.insert(key, toc_item); + if (SText.length() > maxDataWidth) + maxDataWidth = SText.length(); + } + } + i = SText.startOfParagraph(ParIndex+1); + } + } + if (!objattr.name.isNull()) //for all frames + { QString key=QString("%1,%2,%3").arg(currentDocItem->OwnPage + currDoc->FirstPnum, pageNumberWidth).arg(pageCounter[currentDocItem->OwnPage]++).arg(currDoc->getSectionPageNumberForPageIndex(currentDocItem->OwnPage)); - tocMap.insert(key, objattr.value); + TOCItem toc_item; + toc_item.Text = objattr.value; + toc_item.TocPs = (*tocSetupIt).textStyle; + tocMap.insert(key, toc_item); if (objattr.value.length()>maxDataWidth) maxDataWidth=objattr.value.length(); } } } + //Set up the gtWriter instance with the selected paragraph style gtWriter* writer = new gtWriter(false, tocFrame); if (writer!=NULL) @@ -119,27 +196,29 @@ writer->setOverridePStyleFont(false); gtFrameStyle* fstyle = writer->getDefaultStyle(); gtParagraphStyle* pstyle = new gtParagraphStyle(*fstyle); - pstyle->setName((*tocSetupIt).textStyle); - writer->setParagraphStyle(pstyle); - + //pstyle->setName((*tocSetupIt).textStyle); + //writer->setParagraphStyle(pstyle); + QString oldTocPage=QString::null; - for (QMap::Iterator tocIt=tocMap.begin();tocIt!=tocMap.end();++tocIt) + for (QMap::Iterator tocIt=tocMap.begin();tocIt!=tocMap.end();++tocIt) { QString tocPage(tocIt.key().section( ',', 2, 2 ).trimmed()); QString tocLine; //Start with text or numbers if ((*tocSetupIt).pageLocation==End || (*tocSetupIt).pageLocation==NotShown) - tocLine = tocIt.value(); + tocLine = tocIt.value().Text; if ((*tocSetupIt).pageLocation==Beginning && oldTocPage!=tocPage) tocLine = tocPage; //Add in the tab for the leaders tocLine+="\t"; //End with text or numbers if ((*tocSetupIt).pageLocation==Beginning) - tocLine += tocIt.value(); + tocLine += tocIt.value().Text; if ((*tocSetupIt).pageLocation==End && oldTocPage!=tocPage) tocLine += tocPage; tocLine += "\n"; + pstyle->setName(tocIt.value().TocPs); + writer->setParagraphStyle(pstyle); writer->append(tocLine); } delete writer;