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 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
  <class>TOCIndexPrefs</class>
- <widget class="QWidget" name="TOCIndexPrefs" >
-  <property name="geometry" >
+ <widget class="QWidget" name="TOCIndexPrefs">
+  <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>444</width>
-    <height>234</height>
+    <width>492</width>
+    <height>559</height>
    </rect>
   </property>
-  <property name="windowTitle" >
+  <property name="windowTitle">
    <string>Table of Contents and Indexes</string>
   </property>
-  <layout class="QVBoxLayout" >
-   <property name="spacing" >
+  <layout class="QVBoxLayout">
+   <property name="spacing">
     <number>6</number>
    </property>
-   <property name="margin" >
+   <property name="margin">
     <number>0</number>
    </property>
    <item>
-    <widget class="QTabWidget" name="tabTOCIndexWidget" >
-     <widget class="QWidget" name="tab" >
-      <property name="geometry" >
-       <rect>
-        <x>0</x>
-        <y>0</y>
-        <width>436</width>
-        <height>202</height>
-       </rect>
-      </property>
-      <attribute name="title" >
+    <widget class="QTabWidget" name="tabTOCIndexWidget">
+     <widget class="QWidget" name="tab">
+      <attribute name="title">
        <string>Table Of Contents</string>
       </attribute>
-      <layout class="QHBoxLayout" >
-       <property name="spacing" >
+      <layout class="QHBoxLayout">
+       <property name="spacing">
         <number>6</number>
        </property>
-       <property name="margin" >
+       <property name="margin">
         <number>0</number>
        </property>
        <item>
-        <layout class="QVBoxLayout" >
-         <property name="spacing" >
+        <layout class="QVBoxLayout">
+         <property name="spacing">
           <number>6</number>
          </property>
-         <property name="margin" >
+         <property name="margin">
           <number>0</number>
          </property>
          <item>
-          <widget class="QListWidget" name="tocListBox" />
+          <widget class="QListWidget" name="tocListBox"/>
          </item>
          <item>
-          <widget class="QLineEdit" name="tocNameLineEdit" />
+          <widget class="QLineEdit" name="tocNameLineEdit"/>
          </item>
          <item>
-          <layout class="QHBoxLayout" >
-           <property name="spacing" >
+          <layout class="QHBoxLayout">
+           <property name="spacing">
             <number>6</number>
            </property>
-           <property name="margin" >
+           <property name="margin">
             <number>0</number>
            </property>
            <item>
-            <widget class="QPushButton" name="tocAddButton" >
-             <property name="text" >
+            <widget class="QPushButton" name="tocAddButton">
+             <property name="text">
               <string>&amp;Add</string>
              </property>
-             <property name="shortcut" >
+             <property name="shortcut">
               <string>Alt+A</string>
              </property>
             </widget>
            </item>
            <item>
-            <widget class="QPushButton" name="tocDeleteButton" >
-             <property name="text" >
+            <widget class="QPushButton" name="tocDeleteButton">
+             <property name="text">
               <string>&amp;Delete</string>
              </property>
-             <property name="shortcut" >
+             <property name="shortcut">
               <string>Alt+D</string>
              </property>
             </widget>
@@ -87,117 +80,239 @@
         </layout>
        </item>
        <item>
-        <layout class="QVBoxLayout" >
-         <property name="spacing" >
+        <layout class="QVBoxLayout">
+         <property name="spacing">
           <number>6</number>
          </property>
-         <property name="margin" >
+         <property name="margin">
           <number>0</number>
          </property>
          <item>
-          <layout class="QGridLayout" >
-           <property name="margin" >
+          <layout class="QGridLayout">
+           <property name="margin">
             <number>0</number>
            </property>
-           <property name="spacing" >
+           <property name="spacing">
             <number>6</number>
            </property>
-           <item row="1" column="1" >
-            <widget class="QComboBox" name="itemDestFrameComboBox" >
-             <property name="toolTip" >
-              <string>The frame the table of contents will be placed into</string>
+           <item row="0" column="0">
+            <widget class="QLabel" name="tocItemAttrLabel">
+             <property name="text">
+              <string>Item Attribute Name:</string>
              </property>
+             <property name="wordWrap">
+              <bool>false</bool>
+             </property>
             </widget>
            </item>
-           <item row="2" column="0" >
-            <widget class="QLabel" name="tocNumberPlacementLabel" >
-             <property name="text" >
-              <string>Page Number Placement:</string>
+           <item row="0" column="1">
+            <widget class="QComboBox" name="itemAttrComboBox">
+             <property name="toolTip">
+              <string>The Item Attribute that will be set on frames used as a basis for creation of the entries</string>
              </property>
-             <property name="wordWrap" >
-              <bool>false</bool>
-             </property>
             </widget>
            </item>
-           <item row="0" column="0" >
-            <widget class="QLabel" name="tocItemAttrLabel" >
-             <property name="text" >
-              <string>Item Attribute Name:</string>
+           <item row="1" column="0">
+            <widget class="QLabel" name="tocDestFrameLabel">
+             <property name="text">
+              <string>Destination Frame:</string>
              </property>
-             <property name="wordWrap" >
+             <property name="wordWrap">
               <bool>false</bool>
              </property>
             </widget>
            </item>
-           <item row="0" column="1" >
-            <widget class="QComboBox" name="itemAttrComboBox" >
-             <property name="toolTip" >
-              <string>The Item Attribute that will be set on frames used as a basis for creation of the entries</string>
+           <item row="1" column="1">
+            <widget class="QComboBox" name="itemDestFrameComboBox">
+             <property name="toolTip">
+              <string>The frame the table of contents will be placed into</string>
              </property>
             </widget>
            </item>
-           <item row="2" column="1" >
-            <widget class="QComboBox" name="itemNumberPlacementComboBox" >
-             <property name="toolTip" >
+           <item row="2" column="0">
+            <widget class="QLabel" name="tocNumberPlacementLabel">
+             <property name="text">
+              <string>Page Number Placement:</string>
+             </property>
+             <property name="wordWrap">
+              <bool>false</bool>
+             </property>
+            </widget>
+           </item>
+           <item row="2" column="1">
+            <widget class="QComboBox" name="itemNumberPlacementComboBox">
+             <property name="toolTip">
               <string>Place page numbers of the entries at the beginning or the end of the line, or not at all</string>
              </property>
             </widget>
            </item>
-           <item row="4" column="0" colspan="2" >
-            <widget class="QCheckBox" name="itemListNonPrintingCheckBox" >
-             <property name="toolTip" >
-              <string>Include frames that are set to not print as well</string>
+           <item row="3" column="0">
+            <widget class="QLabel" name="tocParagraphStyleLabel">
+             <property name="text">
+              <string>TOC Paragraph Style:</string>
              </property>
-             <property name="text" >
-              <string>List Non-Printing Entries</string>
+             <property name="wordWrap">
+              <bool>false</bool>
              </property>
             </widget>
            </item>
-           <item row="3" column="1" >
-            <widget class="QComboBox" name="itemParagraphStyleComboBox" >
-             <property name="toolTip" >
+           <item row="3" column="1">
+            <widget class="QComboBox" name="itemParagraphStyleComboBox">
+             <property name="toolTip">
               <string>The paragraph style used for the entry lines</string>
              </property>
             </widget>
            </item>
-           <item row="3" column="0" >
-            <widget class="QLabel" name="tocParagraphStyleLabel" >
-             <property name="text" >
-              <string>Paragraph Style:</string>
+           <item row="14" column="0" colspan="2">
+            <widget class="QCheckBox" name="itemListNonPrintingCheckBox">
+             <property name="toolTip">
+              <string>Include frames that are set to not print as well</string>
              </property>
-             <property name="wordWrap" >
-              <bool>false</bool>
+             <property name="text">
+              <string>List Non-Printing Entries</string>
              </property>
             </widget>
            </item>
-           <item row="1" column="0" >
-            <widget class="QLabel" name="tocDestFrameLabel" >
-             <property name="text" >
-              <string>Destination Frame:</string>
+          </layout>
+         </item>
+         <item>
+          <layout class="QVBoxLayout" name="verticalLayout">
+           <item>
+            <widget class="QGroupBox" name="groupBox">
+             <property name="title">
+              <string>Paragraph Style based TOC</string>
              </property>
-             <property name="wordWrap" >
-              <bool>false</bool>
-             </property>
+             <widget class="QWidget" name="gridLayoutWidget">
+              <property name="geometry">
+               <rect>
+                <x>0</x>
+                <y>20</y>
+                <width>267</width>
+                <height>239</height>
+               </rect>
+              </property>
+              <layout class="QGridLayout" name="gridLayout">
+               <item row="0" column="0" colspan="2">
+                <widget class="QCheckBox" name="itemParStyleBasedCheckBox">
+                 <property name="toolTip">
+                  <string>Turning ON seraching text for selected paragraph styles</string>
+                 </property>
+                 <property name="text">
+                  <string>Use Paragraph Style based TOC</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="1" column="0" colspan="2">
+                <widget class="QLabel" name="PSLabel1toc">
+                 <property name="text">
+                  <string>Level1</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="2" column="0">
+                <widget class="QLabel" name="PSlabel1text">
+                 <property name="text">
+                  <string>Search Paragraph Style</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="2" column="1">
+                <widget class="QComboBox" name="PScomboBox1text">
+                 <property name="toolTip">
+                  <string>The paragraph style name for searching in text</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="3" column="0">
+                <widget class="QLabel" name="PSlabel1toc">
+                 <property name="text">
+                  <string>TOC Paragraph Style</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="3" column="1">
+                <widget class="QComboBox" name="PScomboBox1toc">
+                 <property name="toolTip">
+                  <string>The paragraph style used for the entry lines</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="4" column="0">
+                <widget class="QLabel" name="PSLabel2toc">
+                 <property name="text">
+                  <string>   Level2</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="5" column="0">
+                <widget class="QLabel" name="PSlabel2text">
+                 <property name="text">
+                  <string>   Search Paragraph Style</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="6" column="0">
+                <widget class="QLabel" name="PSlabel2toc">
+                 <property name="text">
+                  <string>   TOC Paragraph Style</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="7" column="0">
+                <widget class="QLabel" name="PSLabelLtoc">
+                 <property name="text">
+                  <string>      Level3</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="8" column="0">
+                <widget class="QLabel" name="PSlabel3text">
+                 <property name="text">
+                  <string>      Search Paragraph Style</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="9" column="0">
+                <widget class="QLabel" name="PSlabel3toc">
+                 <property name="text">
+                  <string>      TOC Paragraph Style</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="5" column="1">
+                <widget class="QComboBox" name="PScomboBox2text">
+                 <property name="toolTip">
+                  <string>The paragraph style name for searching in text</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="6" column="1">
+                <widget class="QComboBox" name="PScomboBox2toc">
+                 <property name="toolTip">
+                  <string>The paragraph style used for the entry lines</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="8" column="1">
+                <widget class="QComboBox" name="PScomboBox3text">
+                 <property name="toolTip">
+                  <string>The paragraph style name for searching in text</string>
+                 </property>
+                </widget>
+               </item>
+               <item row="9" column="1">
+                <widget class="QComboBox" name="PScomboBox3toc">
+                 <property name="toolTip">
+                  <string>The paragraph style used for the entry lines</string>
+                 </property>
+                </widget>
+               </item>
+              </layout>
+             </widget>
             </widget>
            </item>
           </layout>
          </item>
-         <item>
-          <spacer>
-           <property name="orientation" >
-            <enum>Qt::Vertical</enum>
-           </property>
-           <property name="sizeType" >
-            <enum>QSizePolicy::Expanding</enum>
-           </property>
-           <property name="sizeHint" stdset="0" >
-            <size>
-             <width>16</width>
-             <height>36</height>
-            </size>
-           </property>
-          </spacer>
-         </item>
         </layout>
        </item>
       </layout>
@@ -206,7 +321,7 @@
    </item>
   </layout>
  </widget>
- <layoutdefault spacing="6" margin="0" />
+ <layoutdefault spacing="6" margin="0"/>
  <tabstops>
   <tabstop>tabTOCIndexWidget</tabstop>
   <tabstop>tocListBox</tabstop>
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<StoryText *>(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() && i<numberSelected) \
+		{ \
+			++it; ++i; \
+		} \
+		if (itemStyle==trStrNone) \
+		{ \
+		  (*it).SearchStyle##post=strNone; \
+		} \
+		else \
+		{ \
+		  (*it).SearchStyle##post=itemStyle; \
+		} \
+	} \
+}
+
+LEVEL_CB_SLOT_DEF(1text)
+LEVEL_CB_SLOT_DEF(1toc)
+LEVEL_CB_SLOT_DEF(2text)
+LEVEL_CB_SLOT_DEF(2toc)
+LEVEL_CB_SLOT_DEF(3text)
+LEVEL_CB_SLOT_DEF(3toc)
+
 ToCSetupVector* TOCIndexPrefs::getNewToCs()
 {
        return &localToCSetupVector;
@@ -453,3 +547,20 @@
                (*it).listNonPrintingFrames=showNonPrinting;
        }
 }
+
+
+void TOCIndexPrefs::usePSsearching( bool searchPS )
+{
+	int numberSelected=tocListBox->currentRow();
+	if (numberSelected>=0)
+	{
+		int i=0;
+		ToCSetupVector::Iterator it=localToCSetupVector.begin();
+		while (it!= localToCSetupVector.end() && i<numberSelected)
+		{
+			++it;
+			++i;
+		}
+		(*it).usePSsearching=searchPS;
+	}
+}
Index: Scribus/scribus/pagestructs.h
===================================================================
--- Scribus/scribus/pagestructs.h	(wersja 15812)
+++ Scribus/scribus/pagestructs.h	(kopia robocza)
@@ -36,6 +36,13 @@
        QString textStyle; //Paragraph style for text
        //QString leaderParaStyle; //Paragraph style for leaders
        //QString pageNumberParaStyle; //Paragraph style for page numbers
+	QString SearchStyle1text;//Paragraph style for searching level1
+	QString SearchStyle1toc; //Paragraph style for text level1
+	QString SearchStyle2text;//Paragraph style for searching level2
+	QString SearchStyle2toc; //Paragraph style for text level2
+	QString SearchStyle3text;//Paragraph style for searching level3
+	QString SearchStyle3toc; //Paragraph style for text level3
+	bool usePSsearching;  //Use Paragraph style based TOC
 };

 typedef QList<ToCSetup> ToCSetupVector;
Index: Scribus/scribus/tocgenerator.cpp
===================================================================
--- Scribus/scribus/tocgenerator.cpp	(wersja 15812)
+++ Scribus/scribus/tocgenerator.cpp	(kopia robocza)
@@ -22,15 +22,20 @@

 #include <QMap>
 #include <QString>
+#include <QVector>

 #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<QString, QString> tocMap;
+			QMap<QString, TOCItem> 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;i<currDoc->DocPages.count();++i)
-				pageCounter[i]=0;
-			int maxDataWidth=0;
+				pageCounter[i] = 0;
+			int maxDataWidth = 0;
+
+			//setup vectors with PS names
+			QVector<QString> PSnames;  //Vector holds PS names for searching
+			QVector<QString> 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<QString, QString>::Iterator tocIt=tocMap.begin();tocIt!=tocMap.end();++tocIt)
+				for (QMap<QString, TOCItem>::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;
