Back to index

scribus-ng  1.3.4.dfsg+svn20071115
tocindexprefs.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008        begin                : 2005
00009        copyright            : (C) 2005 by Craig Bradney
00010        email                : cbradney@zip.com.au
00011 ***************************************************************************/
00012 
00013 /***************************************************************************
00014 *                                                                         *
00015 *   ScMW program is free software; you can redistribute it and/or modify  *
00016 *   it under the terms of the GNU General Public License as published by  *
00017 *   the Free Software Foundation; either version 2 of the License, or     *
00018 *   (at your option) any later version.                                   *
00019 *                                                                         *
00020 ***************************************************************************/
00021 
00022 #include "tocindexprefs.h"
00023 #include "tocindexprefs.moc"
00024 
00025 #include <qvariant.h>
00026 #include <qstringlist.h>
00027 #include <qpushbutton.h>
00028 #include <qtabwidget.h>
00029 #include <qlistbox.h>
00030 #include <qlineedit.h>
00031 #include <qcombobox.h>
00032 #include <qlabel.h>
00033 #include <qcheckbox.h>
00034 #include <qlayout.h>
00035 #include <qtooltip.h>
00036 #include <qwhatsthis.h>
00037 #include "page.h"
00038 #include "scribusdoc.h"
00039 #include "commonstrings.h"
00040 
00045 TOCIndexPrefs::TOCIndexPrefs( QWidget* parent, const char* name, WFlags fl )
00046        : TOCIndexPrefsBase( parent, name, fl )
00047 {
00048        languageChange();
00049        itemDestFrameComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" ));
00050        itemAttrComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" ));
00051        itemNumberPlacementComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" ));
00052        itemParagraphStyleComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" ));
00053        resize( QSize(444, 234).expandedTo(minimumSizeHint()) );
00054        clearWState( WState_Polished );
00055 
00056        // signals and slots connections
00057        connect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
00058        connect( tocAddButton, SIGNAL( clicked() ), this, SLOT( addToC() ) );
00059        connect( tocDeleteButton, SIGNAL( clicked() ), this, SLOT( deleteToC() ) );
00060        connect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
00061        connect( itemDestFrameComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemFrameSelected(const QString&) ) );
00062        connect( itemParagraphStyleComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemParagraphStyleSelected(const QString&) ) );
00063        connect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) );
00064        connect( tocNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( setToCName(const QString&) ) );
00065        connect( itemListNonPrintingCheckBox, SIGNAL( toggled(bool) ), this, SLOT( nonPrintingFramesSelected(bool) ) );
00066        init();
00067 }
00068 
00069 /*
00070 *  Destroys the object and frees any allocated resources
00071 */
00072 TOCIndexPrefs::~TOCIndexPrefs()
00073 {
00074        // no need to delete child widgets, Qt does it all for us
00075 }
00076 
00077 /*
00078 *  Sets the strings of the subwidgets using the current
00079 *  language.
00080 */
00081 void TOCIndexPrefs::languageChange()
00082 {
00083        setCaption( tr( "Table of Contents and Indexes" ) );
00084        tocAddButton->setText( tr( "&Add" ) );
00085        tocAddButton->setAccel( QKeySequence( tr( "Alt+A" ) ) );
00086        tocDeleteButton->setText( tr( "&Delete" ) );
00087        tocDeleteButton->setAccel( QKeySequence( tr( "Alt+D" ) ) );
00088        QToolTip::add( itemDestFrameComboBox, tr( "The frame the table of contents will be placed into" ) );
00089        tocNumberPlacementLabel->setText( tr( "Page Numbers Placed:" ) );
00090        tocItemAttrLabel->setText( tr( "Item Attribute Name:" ) );
00091        QToolTip::add( itemAttrComboBox, tr( "The Item Attribute that will be set on frames used as a basis for creation of the entries" ) );
00092        QToolTip::add( itemNumberPlacementComboBox, tr( "Place page numbers of the entries at the beginning or the end of the line, or not at all" ) );
00093        itemListNonPrintingCheckBox->setText( tr( "List Non-Printing Entries" ) );
00094        QToolTip::add( itemListNonPrintingCheckBox, tr( "Include frames that are set to not print as well" ) );
00095        QToolTip::add( itemParagraphStyleComboBox, tr( "The paragraph style used for the entry lines" ) );
00096        tocParagraphStyleLabel->setText( tr( "Paragraph Style:" ) );
00097        tocDestFrameLabel->setText( tr( "Destination Frame:" ) );
00098        tabTOCIndexWidget->changeTab( tab, tr( "Table Of Contents" ) );
00099 //     tabTOCIndexWidget->changeTab( tab_2, tr( "Inde&x" ) );
00100 }
00101 
00102 void TOCIndexPrefs::init()
00103 {
00104        disconnect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
00105        trStrNone=tr("None");
00106        strNone=CommonStrings::None;
00107        trStrPNBeginning=tr("At the beginning");
00108        strPNBeginning="At the beginning";
00109        trStrPNEnd=tr("At the end");
00110        strPNEnd="At the end";
00111        trStrPNNotShown=tr("Not Shown");
00112        strPNNotShown="Not Shown";
00113 
00114        itemNumberPlacementComboBox->clear();
00115        itemNumberPlacementComboBox->insertItem(trStrPNEnd);
00116        itemNumberPlacementComboBox->insertItem(trStrPNBeginning);
00117        itemNumberPlacementComboBox->insertItem(trStrPNNotShown);
00118        itemNumberPlacementComboBox->setCurrentText(trStrPNEnd);
00119        numSelected=999;
00120 }
00121 
00122 
00123 void TOCIndexPrefs::destroy()
00124 {
00125 
00126 }
00127 
00128 void TOCIndexPrefs::setup( ToCSetupVector* tocsetups, ScribusDoc *doc)
00129 {
00130        localToCSetupVector=* tocsetups;
00131        currDoc=doc;
00132        generatePageItemList();
00133        bool enabled=(localToCSetupVector.count()>0);
00134        if (enabled)
00135        {
00136               updateToCListBox();
00137               updateParagraphStyleComboBox();
00138               tocListBox->setCurrentItem(0);
00139               selectToC(0);
00140        }
00141        else
00142               tocListBox->clear();
00143        enableGUIWidgets();
00144        connect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
00145 }
00146 
00147 void TOCIndexPrefs::generatePageItemList()
00148 {
00149        itemDestFrameComboBox->clear();
00150        itemDestFrameComboBox->insertItem(trStrNone);
00151        if (currDoc!=NULL)
00152        {
00153               for (uint d = 0; d < currDoc->DocItems.count(); ++d)
00154               {
00155                      if (currDoc->DocItems.at(d)->itemType()==PageItem::TextFrame)
00156                             itemDestFrameComboBox->insertItem(currDoc->DocItems.at(d)->itemName());
00157               }
00158        }
00159        else
00160               itemDestFrameComboBox->setEnabled(false);
00161 }
00162 
00163 
00164 void TOCIndexPrefs::setupItemAttrs( QStringList newNames )
00165 {
00166        disconnect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
00167        itemAttrComboBox->clear();
00168        itemAttrComboBox->insertItem(trStrNone);
00169        itemAttrComboBox->insertStringList(newNames);
00170        if (numSelected!=999)
00171        {
00172               if (localToCSetupVector[numSelected].itemAttrName==strNone)
00173                      itemAttrComboBox->setCurrentText(trStrNone);
00174               else
00175                      itemAttrComboBox->setCurrentText(localToCSetupVector[numSelected].itemAttrName);
00176        }
00177        connect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
00178 }
00179 
00180 
00181 void TOCIndexPrefs::selectToC( int numberSelected )
00182 {
00183        numSelected=numberSelected;
00184        if (localToCSetupVector.isEmpty())
00185               return;
00186        if (localToCSetupVector.count()<numSelected)
00187               numSelected=0;
00188        disconnect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
00189        disconnect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
00190        disconnect( itemDestFrameComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemFrameSelected(const QString&) ) );
00191        disconnect( itemParagraphStyleComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemParagraphStyleSelected(const QString&) ) );
00192        disconnect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) );
00193        disconnect( tocNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( setToCName(const QString&) ) );
00194        disconnect( itemListNonPrintingCheckBox, SIGNAL( toggled(bool) ), this, SLOT( nonPrintingFramesSelected(bool) ) );
00195        if (localToCSetupVector[numSelected].itemAttrName==strNone)
00196               itemAttrComboBox->setCurrentText(trStrNone);
00197        else
00198               itemAttrComboBox->setCurrentText(localToCSetupVector[numSelected].itemAttrName);
00199        if (localToCSetupVector[numSelected].pageLocation==NotShown)
00200               itemNumberPlacementComboBox->setCurrentText(trStrPNNotShown);
00201        else
00202               if (localToCSetupVector[numSelected].pageLocation==Beginning)
00203               itemNumberPlacementComboBox->setCurrentText(trStrPNBeginning);
00204        else
00205               itemNumberPlacementComboBox->setCurrentText(trStrPNEnd);
00206 
00207        itemListNonPrintingCheckBox->setChecked(localToCSetupVector[numSelected].listNonPrintingFrames);
00208        if (currDoc!=NULL)
00209        {
00210               if (localToCSetupVector[numSelected].frameName==strNone)
00211                      itemDestFrameComboBox->setCurrentText(trStrNone);
00212               else
00213                      itemDestFrameComboBox->setCurrentText(localToCSetupVector[numSelected].frameName);
00214 
00215               if (itemParagraphStyleComboBox->count()>0)
00216               {
00217                      if (!paragraphStyleList.contains(localToCSetupVector[numSelected].textStyle) || localToCSetupVector[numSelected].textStyle==strNone)
00218                             itemParagraphStyleComboBox->setCurrentText(trStrNone);
00219                      else
00220                             itemParagraphStyleComboBox->setCurrentText(localToCSetupVector[numSelected].textStyle);
00221               }
00222        }
00223 
00224        //if (numSelected>=0)
00225               tocNameLineEdit->setText(tocListBox->currentText());
00226 
00227        connect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
00228        connect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
00229        connect( itemDestFrameComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemFrameSelected(const QString&) ) );
00230        connect( itemParagraphStyleComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemParagraphStyleSelected(const QString&) ) );
00231        connect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) );
00232        connect( tocNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( setToCName(const QString&) ) );
00233        connect( itemListNonPrintingCheckBox, SIGNAL( toggled(bool) ), this, SLOT( nonPrintingFramesSelected(bool) ) );
00234 }
00235 
00236 
00237 void TOCIndexPrefs::addToC()
00238 {
00239        bool found=false;
00240        QString newName=tocNameLineEdit->text();
00241        for(ToCSetupVector::Iterator it = localToCSetupVector.begin(); it!= localToCSetupVector.end(); ++it)
00242        {
00243               if ((*it).name==newName)
00244                      found=true;
00245        }
00246        if (found || newName.isEmpty())
00247               newName=tr("Table of Contents %1").arg(localToCSetupVector.count()+1);
00248        ToCSetup newToCEntry;
00249        newToCEntry.name=newName;
00250        newToCEntry.itemAttrName=strNone;
00251        newToCEntry.frameName=strNone;
00252        newToCEntry.textStyle=strNone;
00253        newToCEntry.pageLocation=End;
00254        newToCEntry.listNonPrintingFrames=false;
00255        localToCSetupVector.append(newToCEntry);
00256        disconnect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
00257        updateToCListBox();
00258        if (localToCSetupVector.count()==1) //reinit parastyles if we are adding the first TOC
00259               updateParagraphStyleComboBox();
00260        tocListBox->setCurrentItem(localToCSetupVector.count()-1);
00261        selectToC(localToCSetupVector.count()-1);
00262        enableGUIWidgets();
00263        connect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
00264 }
00265 
00266 
00267 void TOCIndexPrefs::updateToCListBox()
00268 {
00269        tocListBox->clear();
00270        for(ToCSetupVector::Iterator it = localToCSetupVector.begin(); it!= localToCSetupVector.end(); ++it)
00271               tocListBox->insertItem((*it).name);
00272 }
00273 
00274 void TOCIndexPrefs::updateParagraphStyleComboBox()
00275 {
00276        paragraphStyleList.clear();
00277        paragraphStyleList.append(trStrNone);
00278 
00279        if(currDoc!=NULL) // && currDoc->docParagraphStyles.count()>5)
00280        {
00281               for (uint i = 0; i < currDoc->paragraphStyles().count(); ++i)
00282                      paragraphStyleList.append(currDoc->paragraphStyles()[i].name());
00283        }
00284        itemParagraphStyleComboBox->clear();
00285        itemParagraphStyleComboBox->insertStringList(paragraphStyleList);
00286 }
00287 
00288 
00289 void TOCIndexPrefs::enableGUIWidgets()
00290 {
00291        bool enabled=(localToCSetupVector.count()>0);
00292        tocListBox->setEnabled(enabled);
00293        tocDeleteButton->setEnabled(enabled);
00294        itemAttrComboBox->setEnabled(enabled);
00295        itemNumberPlacementComboBox->setEnabled(enabled);
00296        bool haveDoc=enabled && currDoc!=NULL;
00297        itemDestFrameComboBox->setEnabled(haveDoc);
00298        itemParagraphStyleComboBox->setEnabled(haveDoc);
00299 }
00300 
00301 
00302 void TOCIndexPrefs::deleteToC()
00303 {
00304        int numberSelected=tocListBox->currentItem();
00305        if (numberSelected>=0)
00306        {
00307               int i=0;
00308               ToCSetupVector::Iterator it=localToCSetupVector.begin();
00309               while (it!= localToCSetupVector.end() && i<numberSelected)
00310               {
00311                      ++it;
00312                      ++i;
00313               }
00314               localToCSetupVector.erase(it);
00315               updateToCListBox();
00316               enableGUIWidgets();
00317        }
00318 }
00319 
00320 
00321 void TOCIndexPrefs::itemAttributeSelected( const QString& itemAttributeName )
00322 {
00323        int numberSelected=tocListBox->currentItem();
00324        if (numberSelected>=0)
00325        {
00326               int i=0;
00327               ToCSetupVector::Iterator it=localToCSetupVector.begin();
00328               while (it!= localToCSetupVector.end() && i<numberSelected)
00329               {
00330                      ++it;
00331                      ++i;
00332               }
00333               if (itemAttributeName==trStrNone)
00334                      (*it).itemAttrName=strNone;
00335               else
00336                      (*it).itemAttrName=itemAttributeName;
00337        }
00338 }
00339 
00340 
00341 void TOCIndexPrefs::itemFrameSelected( const QString& frameName )
00342 {
00343        int numberSelected=tocListBox->currentItem();
00344        if (numberSelected>=0)
00345        {
00346               int i=0;
00347               ToCSetupVector::Iterator it=localToCSetupVector.begin();
00348               while (it!= localToCSetupVector.end() && i<numberSelected)
00349               {
00350                      ++it;
00351                      ++i;
00352               }
00353               if (frameName==trStrNone)
00354                      (*it).frameName=strNone;
00355               else
00356                      (*it).frameName=frameName;
00357        }
00358 
00359 }
00360 
00361 
00362 void TOCIndexPrefs::itemPageNumberPlacedSelected( const QString& pageLocation )
00363 {
00364        int numberSelected=tocListBox->currentItem();
00365        if (numberSelected>=0)
00366        {
00367               int i=0;
00368               ToCSetupVector::Iterator it=localToCSetupVector.begin();
00369               while (it!= localToCSetupVector.end() && i<numberSelected)
00370               {
00371                      ++it;
00372                      ++i;
00373               }
00374               if (pageLocation==trStrPNBeginning || pageLocation==strPNBeginning)
00375                      (*it).pageLocation=Beginning;
00376               else
00377               if (pageLocation==trStrPNEnd || pageLocation==strPNEnd)
00378                      (*it).pageLocation=End;
00379               else
00380                      (*it).pageLocation=NotShown;
00381        }
00382 }
00383 
00384 
00385 void TOCIndexPrefs::itemParagraphStyleSelected( const QString& itemStyle )
00386 {
00387        int numberSelected=tocListBox->currentItem();
00388        if (numberSelected>=0)
00389        {
00390               int i=0;
00391               ToCSetupVector::Iterator it=localToCSetupVector.begin();
00392               while (it!= localToCSetupVector.end() && i<numberSelected)
00393               {
00394                      ++it;
00395                      ++i;
00396               }
00397               if (itemStyle==trStrNone)
00398                      (*it).textStyle=strNone;
00399               else
00400                      (*it).textStyle=itemStyle;
00401        }
00402 }
00403 
00404 ToCSetupVector* TOCIndexPrefs::getNewToCs()
00405 {
00406        return &localToCSetupVector;
00407 }
00408 
00409 
00410 void TOCIndexPrefs::setToCName( const QString &newName )
00411 {
00412        int numberSelected=tocListBox->currentItem();
00413        if (numberSelected!=-1)
00414        {
00415               tocListBox->changeItem(newName, numberSelected);
00416               int i=0;
00417               ToCSetupVector::Iterator it=localToCSetupVector.begin();
00418               while (it!= localToCSetupVector.end() && i<numberSelected)
00419               {
00420                      ++it;
00421                      ++i;
00422               }
00423               (*it).name=newName;
00424        }
00425 }
00426 
00427 
00428 void TOCIndexPrefs::nonPrintingFramesSelected( bool showNonPrinting )
00429 {
00430        int numberSelected=tocListBox->currentItem();
00431        if (numberSelected>=0)
00432        {
00433               int i=0;
00434               ToCSetupVector::Iterator it=localToCSetupVector.begin();
00435               while (it!= localToCSetupVector.end() && i<numberSelected)
00436               {
00437                      ++it;
00438                      ++i;
00439               }
00440               (*it).listNonPrintingFrames=showNonPrinting;
00441        }
00442 }