r14573 by cbradney - New prefs pane for TOCs
scribus-commit
scribus-commit at lists.scribus.net
Mon Jan 25 00:35:23 CET 2010
Revision: 14573
Author: cbradney
Date: 2010-01-24T23:31:20.601624Z
Commit message: New prefs pane for TOCs
Changeset:
M /trunk/Scribus/scribus/ui/prefs_tableofcontents.h
M /trunk/Scribus/scribus/ui/preferencesdialog.cpp
M /trunk/Scribus/scribus/ui/prefs_tableofcontents.cpp
Diffs:
Index: scribus/ui/prefs_tableofcontents.h
===================================================================
--- scribus/ui/prefs_tableofcontents.h (revision 14572)
+++ scribus/ui/prefs_tableofcontents.h (revision 14573)
@@ -11,9 +11,14 @@
#include <QStringList>
#include "ui_prefs_tableofcontentsbase.h"
+//#include "page.h"
+#include "pagestructs.h"
#include "prefs_pane.h"
+#include "prefsstructs.h"
#include "scribusapi.h"
+class ScribusDoc;
+
class SCRIBUS_API Prefs_TableOfContents : public Prefs_Pane, Ui::Prefs_TableOfContents
{
Q_OBJECT
@@ -23,44 +28,43 @@
~Prefs_TableOfContents();
virtual void restoreDefaults(struct ApplicationPrefs *prefsData);
virtual void saveGuiToPrefs(struct ApplicationPrefs *prefsData) const;
+ virtual void changeEvent(QEvent *e);
+ virtual void enableGUIWidgets();
public slots:
void languageChange();
// virtual void setup( ToCSetupVector * tocsetups, ScribusDoc * doc );
-// virtual void generatePageItemList();
- void setupItemAttrs( QStringList newNames );
-// virtual void selectToC( int numberSelected );
-// virtual void addToC();
-// virtual void updateToCListBox();
-// virtual void updateParagraphStyleComboBox();
-// virtual void deleteToC();
-// virtual void itemAttributeSelected( const QString & itemAttributeName );
-// virtual void itemFrameSelected( const QString & frameName );
-// virtual void itemPageNumberPlacedSelected( const QString & pageLocation );
-// virtual void itemParagraphStyleSelected( const QString & itemStyle );
-// virtual void setToCName( const QString & newName );
-// virtual void nonPrintingFramesSelected( bool showNonPrinting );
-//
-// protected:
-// int numSelected;
-// QString strPNNotShown;
-// QString strPNEnd;
-// QString strPNBeginning;
-// QString trStrPNNotShown;
-// QString trStrPNEnd;
-// QString trStrPNBeginning;
-// ToCSetupVector localToCSetupVector;
-// QString trStrNone;
-// ScribusDoc *currDoc;
-// QString selectedTOCAttrName;
-// QStringList paragraphStyleList;
-// QString strNone;
-//
-// private:
-// void init();
-// void destroy();
+ virtual void generatePageItemList();
+ virtual void setupItemAttrs( QStringList newNames );
+ virtual void selectToC( int numberSelected );
+ virtual void addToC();
+ virtual void updateToCListBox();
+ virtual void updateParagraphStyleComboBox();
+ virtual void deleteToC();
+ virtual void itemAttributeSelected( const QString & itemAttributeName );
+ virtual void itemFrameSelected( const QString & frameName );
+ virtual void itemPageNumberPlacedSelected( const QString & pageLocation );
+ virtual void itemParagraphStyleSelected( const QString & itemStyle );
+ virtual void setToCName( const QString & newName );
+ virtual void nonPrintingFramesSelected( bool showNonPrinting );
+ protected:
+ int numSelected;
+ QString strPNNotShown;
+ QString strPNEnd;
+ QString strPNBeginning;
+ QString trStrPNNotShown;
+ QString trStrPNEnd;
+ QString trStrPNBeginning;
+ ToCSetupVector localToCSetupVector;
+ ScribusDoc* currDoc;
+ QString selectedTOCAttrName;
+ QStringList paragraphStyleList;
+
+ private:
+ void destroy();
+
};
#endif // PREFS_TABLEOFCONTENTS_H
Index: scribus/ui/preferencesdialog.cpp
===================================================================
--- scribus/ui/preferencesdialog.cpp (revision 14572)
+++ scribus/ui/preferencesdialog.cpp (revision 14573)
@@ -219,7 +219,7 @@
if (prefsStackWidget->currentWidget()==dynamic_cast<QWidget*>(prefs_ItemTools))
prefs_ItemTools->enableFontPreview(true);
if (prefsStackWidget->currentWidget()==dynamic_cast<QWidget*>(prefs_TableOfContents))
- prefs_TableOfContents->setupItemAttrs( prefs_DocumentItemAttributes->getDocAttributesNames() );;
+ prefs_TableOfContents->setupItemAttrs( prefs_DocumentItemAttributes->getDocAttributesNames() );
}
}
Index: scribus/ui/prefs_tableofcontents.cpp
===================================================================
--- scribus/ui/prefs_tableofcontents.cpp (revision 14572)
+++ scribus/ui/prefs_tableofcontents.cpp (revision 14573)
@@ -6,46 +6,391 @@
*/
#include "ui/prefs_tableofcontents.h"
+#include "pagestructs.h"
#include "prefsstructs.h"
+#include "page.h"
+#include "scribusdoc.h"
+#include "commonstrings.h"
+#include "util.h"
Prefs_TableOfContents::Prefs_TableOfContents(QWidget* parent)
- : Prefs_Pane(parent)
+ : Prefs_Pane(parent),
+ currDoc(NULL)
{
setupUi(this);
+ languageChange();
+ itemDestFrameComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" ));
+ 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" ));
+ // signals and slots connections
+ //do not connect( tocListBox, SIGNAL( currentRowChanged(int) ), this, SLOT( selectToC(int) ) );
+ connect( tocAddButton, SIGNAL( clicked() ), this, SLOT( addToC() ) );
+ connect( tocDeleteButton, SIGNAL( clicked() ), this, SLOT( deleteToC() ) );
+ 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&) ) );
+ 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) ) );
+ setCurrentComboItem(itemNumberPlacementComboBox, trStrPNEnd);
+ numSelected=999;
}
Prefs_TableOfContents::~Prefs_TableOfContents()
{
}
+
+void Prefs_TableOfContents::changeEvent(QEvent *e)
+{
+ if (e->type() == QEvent::LanguageChange)
+ {
+ languageChange();
+ }
+ else
+ QWidget::changeEvent(e);
+}
+
void Prefs_TableOfContents::restoreDefaults(struct ApplicationPrefs *prefsData)
{
-
+ localToCSetupVector=prefsData->tocPrefs.defaultToCSetups;
+ //FIXME for when handling doc prefs: currDoc=doc;
+ generatePageItemList();
+ bool enabled=(localToCSetupVector.count()>0);
+ if (enabled)
+ {
+ updateToCListBox();
+ updateParagraphStyleComboBox();
+ tocListBox->setCurrentItem(0);
+ selectToC(0);
+ }
+ else
+ tocListBox->clear();
+ enableGUIWidgets();
+ connect( tocListBox, SIGNAL( currentRowChanged(int) ), this, SLOT( selectToC(int) ) );
}
void Prefs_TableOfContents::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
{
-
+ prefsData->tocPrefs.defaultToCSetups = localToCSetupVector;
}
void Prefs_TableOfContents::languageChange()
{
+ trStrPNBeginning=tr("Beginning");
+ strPNBeginning="Beginning";
+ trStrPNEnd=tr("End");
+ strPNEnd="End";
+ trStrPNNotShown=tr("Not Shown");
+ strPNNotShown="Not Shown";
+ disconnect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) );
+ int i=itemNumberPlacementComboBox->currentIndex();
+ itemNumberPlacementComboBox->clear();
+ itemNumberPlacementComboBox->addItem(trStrPNEnd);
+ itemNumberPlacementComboBox->addItem(trStrPNBeginning);
+ itemNumberPlacementComboBox->addItem(trStrPNNotShown);
+ itemNumberPlacementComboBox->setCurrentIndex(i);
+ connect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) );
}
+void Prefs_TableOfContents::destroy()
+{
+
+}
+
+void Prefs_TableOfContents::generatePageItemList()
+{
+ itemDestFrameComboBox->clear();
+ itemDestFrameComboBox->addItem(CommonStrings::tr_None);
+ if (currDoc!=NULL)
+ {
+ for (int d = 0; d < currDoc->DocItems.count(); ++d)
+ {
+ if (currDoc->DocItems.at(d)->itemType()==PageItem::TextFrame)
+ itemDestFrameComboBox->addItem(currDoc->DocItems.at(d)->itemName());
+ }
+ }
+ else
+ itemDestFrameComboBox->setEnabled(false);
+}
+
void Prefs_TableOfContents::setupItemAttrs( QStringList newNames )
{
-// disconnect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
-// itemAttrComboBox->clear();
-// itemAttrComboBox->addItem(trStrNone);
-// itemAttrComboBox->addItems(newNames);
-// if (numSelected!=999)
-// {
-// if (localToCSetupVector[numSelected].itemAttrName==strNone)
-// setCurrentComboItem(itemAttrComboBox, trStrNone);
-// else
-// setCurrentComboItem(itemAttrComboBox, localToCSetupVector[numSelected].itemAttrName);
-// }
-// connect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
+ disconnect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
+ itemAttrComboBox->clear();
+ itemAttrComboBox->addItem(CommonStrings::tr_None);
+ itemAttrComboBox->addItems(newNames);
+ if (numSelected!=999 && numSelected!=-1)
+ {
+ if (localToCSetupVector[numSelected].itemAttrName==CommonStrings::None)
+ setCurrentComboItem(itemAttrComboBox, CommonStrings::tr_None);
+ else
+ setCurrentComboItem(itemAttrComboBox, localToCSetupVector[numSelected].itemAttrName);
+ }
+ connect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
}
+
+void Prefs_TableOfContents::selectToC( int numberSelected )
+{
+ numSelected=numberSelected;
+ if (numSelected < 0)
+ return;
+ if (localToCSetupVector.isEmpty())
+ return;
+ if (localToCSetupVector.count()<numSelected)
+ numSelected=0;
+ disconnect( tocListBox, SIGNAL( currentRowChanged(int) ), this, SLOT( selectToC(int) ) );
+ 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&) ) );
+ 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) ) );
+ if (localToCSetupVector[numSelected].itemAttrName==CommonStrings::None)
+ setCurrentComboItem(itemAttrComboBox, CommonStrings::tr_None);
+ else
+ setCurrentComboItem(itemAttrComboBox, localToCSetupVector[numSelected].itemAttrName);
+ if (localToCSetupVector[numSelected].pageLocation==NotShown)
+ setCurrentComboItem(itemNumberPlacementComboBox, trStrPNNotShown);
+ else
+ if (localToCSetupVector[numSelected].pageLocation==Beginning)
+ setCurrentComboItem(itemNumberPlacementComboBox, trStrPNBeginning);
+ else
+ setCurrentComboItem(itemNumberPlacementComboBox, trStrPNEnd);
+
+ itemListNonPrintingCheckBox->setChecked(localToCSetupVector[numSelected].listNonPrintingFrames);
+ if (currDoc!=NULL)
+ {
+ if (localToCSetupVector[numSelected].frameName==CommonStrings::None)
+ setCurrentComboItem(itemDestFrameComboBox, CommonStrings::tr_None);
+ else
+ setCurrentComboItem(itemDestFrameComboBox, localToCSetupVector[numSelected].frameName);
+
+ if (itemParagraphStyleComboBox->count()>0)
+ {
+ if (!paragraphStyleList.contains(localToCSetupVector[numSelected].textStyle) || localToCSetupVector[numSelected].textStyle==CommonStrings::None)
+ setCurrentComboItem(itemParagraphStyleComboBox, CommonStrings::tr_None);
+ else
+ setCurrentComboItem(itemParagraphStyleComboBox, localToCSetupVector[numSelected].textStyle);
+ }
+ }
+
+ if (tocListBox->currentItem())
+ tocNameLineEdit->setText(tocListBox->currentItem()->text());
+
+ connect( tocListBox, SIGNAL( currentRowChanged(int) ), this, SLOT( selectToC(int) ) );
+ 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&) ) );
+ 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) ) );
+}
+
+
+void Prefs_TableOfContents::addToC()
+{
+ bool found=false;
+ QString newName=tocNameLineEdit->text();
+ for(ToCSetupVector::Iterator it = localToCSetupVector.begin(); it!= localToCSetupVector.end(); ++it)
+ {
+ if ((*it).name==newName)
+ found=true;
+ }
+ if (found || newName.isEmpty())
+ newName=tr("Table of Contents %1").arg(localToCSetupVector.count()+1);
+ ToCSetup newToCEntry;
+ newToCEntry.name=newName;
+ newToCEntry.itemAttrName=CommonStrings::None;
+ newToCEntry.frameName=CommonStrings::None;
+ newToCEntry.textStyle=CommonStrings::None;
+ newToCEntry.pageLocation=End;
+ newToCEntry.listNonPrintingFrames=false;
+ localToCSetupVector.append(newToCEntry);
+ disconnect( tocListBox, SIGNAL( currentRowChanged(int) ), this, SLOT( selectToC(int) ) );
+ updateToCListBox();
+ if (localToCSetupVector.count()==1) //reinit parastyles if we are adding the first TOC
+ updateParagraphStyleComboBox();
+ tocListBox->setCurrentRow(localToCSetupVector.count()-1);
+ selectToC(localToCSetupVector.count()-1);
+ enableGUIWidgets();
+ connect( tocListBox, SIGNAL( currentRowChanged(int) ), this, SLOT( selectToC(int) ) );
+}
+
+
+void Prefs_TableOfContents::updateToCListBox()
+{
+ tocListBox->clear();
+ QStringList sl;
+ for(ToCSetupVector::Iterator it = localToCSetupVector.begin(); it!= localToCSetupVector.end(); ++it)
+ sl << (*it).name;
+ tocListBox->insertItems(0, sl);
+}
+
+void Prefs_TableOfContents::updateParagraphStyleComboBox()
+{
+ paragraphStyleList.clear();
+ paragraphStyleList.append(CommonStrings::tr_None);
+
+ if(currDoc!=NULL) // && currDoc->docParagraphStyles.count()>5)
+ {
+ for (int i = 0; i < currDoc->paragraphStyles().count(); ++i)
+ paragraphStyleList.append(currDoc->paragraphStyles()[i].name());
+ }
+ itemParagraphStyleComboBox->clear();
+ itemParagraphStyleComboBox->addItems(paragraphStyleList);
+}
+
+
+void Prefs_TableOfContents::enableGUIWidgets()
+{
+ bool enabled=(localToCSetupVector.count()>0);
+ tocListBox->setEnabled(enabled);
+ tocDeleteButton->setEnabled(enabled);
+ itemAttrComboBox->setEnabled(enabled);
+ itemNumberPlacementComboBox->setEnabled(enabled);
+ bool haveDoc=enabled && currDoc!=NULL;
+ itemDestFrameComboBox->setEnabled(haveDoc);
+ itemParagraphStyleComboBox->setEnabled(haveDoc);
+}
+
+
+void Prefs_TableOfContents::deleteToC()
+{
+ int numberSelected=tocListBox->currentRow();
+ if (numberSelected>=0)
+ {
+ int i=0;
+ ToCSetupVector::Iterator it=localToCSetupVector.begin();
+ while (it!= localToCSetupVector.end() && i<numberSelected)
+ {
+ ++it;
+ ++i;
+ }
+ localToCSetupVector.erase(it);
+ updateToCListBox();
+ enableGUIWidgets();
+ }
+}
+
+
+void Prefs_TableOfContents::itemAttributeSelected( const QString& itemAttributeName )
+{
+ int numberSelected=tocListBox->currentRow();
+ if (numberSelected>=0)
+ {
+ int i=0;
+ ToCSetupVector::Iterator it=localToCSetupVector.begin();
+ while (it!= localToCSetupVector.end() && i<numberSelected)
+ {
+ ++it;
+ ++i;
+ }
+ if (itemAttributeName==CommonStrings::tr_None)
+ (*it).itemAttrName=CommonStrings::None;
+ else
+ (*it).itemAttrName=itemAttributeName;
+ }
+}
+
+
+void Prefs_TableOfContents::itemFrameSelected( const QString& frameName )
+{
+ int numberSelected=tocListBox->currentRow();
+ if (numberSelected>=0)
+ {
+ int i=0;
+ ToCSetupVector::Iterator it=localToCSetupVector.begin();
+ while (it!= localToCSetupVector.end() && i<numberSelected)
+ {
+ ++it;
+ ++i;
+ }
+ if (frameName==CommonStrings::tr_None)
+ (*it).frameName=CommonStrings::None;
+ else
+ (*it).frameName=frameName;
+ }
+
+}
+
+
+void Prefs_TableOfContents::itemPageNumberPlacedSelected( const QString& pageLocation )
+{
+ int numberSelected=tocListBox->currentRow();
+ if (numberSelected>=0)
+ {
+ int i=0;
+ ToCSetupVector::Iterator it=localToCSetupVector.begin();
+ while (it!= localToCSetupVector.end() && i<numberSelected)
+ {
+ ++it;
+ ++i;
+ }
+ if (pageLocation==trStrPNBeginning || pageLocation==strPNBeginning)
+ (*it).pageLocation=Beginning;
+ else
+ if (pageLocation==trStrPNEnd || pageLocation==strPNEnd)
+ (*it).pageLocation=End;
+ else
+ (*it).pageLocation=NotShown;
+ }
+}
+
+
+void Prefs_TableOfContents::itemParagraphStyleSelected( 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==CommonStrings::tr_None)
+ (*it).textStyle=CommonStrings::None;
+ else
+ (*it).textStyle=itemStyle;
+ }
+}
+
+void Prefs_TableOfContents::setToCName( const QString &newName )
+{
+ int numberSelected=tocListBox->currentRow();
+ if (numberSelected!=-1)
+ {
+ tocListBox->item(numberSelected)->setText(newName);
+ int i=0;
+ ToCSetupVector::Iterator it=localToCSetupVector.begin();
+ while (it!= localToCSetupVector.end() && i<numberSelected)
+ {
+ ++it;
+ ++i;
+ }
+ (*it).name=newName;
+ }
+}
+
+
+void Prefs_TableOfContents::nonPrintingFramesSelected( bool showNonPrinting )
+{
+ int numberSelected=tocListBox->currentRow();
+ if (numberSelected>=0)
+ {
+ int i=0;
+ ToCSetupVector::Iterator it=localToCSetupVector.begin();
+ while (it!= localToCSetupVector.end() && i<numberSelected)
+ {
+ ++it;
+ ++i;
+ }
+ (*it).listNonPrintingFrames=showNonPrinting;
+ }
+}
+
More information about the scribus-commit
mailing list