Subversion Repositories Scribus

Rev

Rev 4599 | Rev 5184 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
3741 cbradney 7
/***************************************************************************
8
        begin                : 2005
9
        copyright            : (C) 2005 by Craig Bradney
10
        email                : cbradney@zip.com.au
11
***************************************************************************/
3739 cbradney 12
 
3741 cbradney 13
/***************************************************************************
14
*                                                                         *
4026 craig 15
*   ScMW program is free software; you can redistribute it and/or modify  *
3741 cbradney 16
*   it under the terms of the GNU General Public License as published by  *
17
*   the Free Software Foundation; either version 2 of the License, or     *
18
*   (at your option) any later version.                                   *
19
*                                                                         *
20
***************************************************************************/
21
 
3739 cbradney 22
#include "tocindexprefs.h"
23
#include "tocindexprefs.moc"
24
 
25
#include <qvariant.h>
26
#include <qstringlist.h>
27
#include <qpushbutton.h>
28
#include <qtabwidget.h>
29
#include <qlistbox.h>
30
#include <qlineedit.h>
31
#include <qcombobox.h>
32
#include <qlabel.h>
33
#include <qcheckbox.h>
34
#include <qlayout.h>
35
#include <qtooltip.h>
36
#include <qwhatsthis.h>
4631 cbradney 37
#include "page.h"
3739 cbradney 38
#include "scribusdoc.h"
4546 subik 39
#include "commonstrings.h"
3739 cbradney 40
 
4546 subik 41
/*!
4598 cbradney 42
*  \brief Constructs a TOCIndexPrefs as a child of 'parent', with the
43
*  name 'name' and widget flags set to 'f'.
44
*/
3739 cbradney 45
TOCIndexPrefs::TOCIndexPrefs( QWidget* parent, const char* name, WFlags fl )
4598 cbradney 46
        : TOCIndexPrefsBase( parent, name, fl )
3739 cbradney 47
{
4598 cbradney 48
        languageChange();
4599 fschmid 49
        itemDestFrameComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" ));
50
        itemAttrComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" ));
51
        itemNumberPlacementComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" ));
52
        itemParagraphStyleComboBox->setMaximumWidth(fontMetrics().width( "This is a very long Name" ));
4598 cbradney 53
        resize( QSize(444, 234).expandedTo(minimumSizeHint()) );
54
        clearWState( WState_Polished );
3739 cbradney 55
 
4598 cbradney 56
        // signals and slots connections
57
        connect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
58
        connect( tocAddButton, SIGNAL( clicked() ), this, SLOT( addToC() ) );
59
        connect( tocDeleteButton, SIGNAL( clicked() ), this, SLOT( deleteToC() ) );
60
        connect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
61
        connect( itemDestFrameComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemFrameSelected(const QString&) ) );
62
        connect( itemParagraphStyleComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemParagraphStyleSelected(const QString&) ) );
63
        connect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) );
64
        connect( tocNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( setToCName(const QString&) ) );
65
        connect( itemListNonPrintingCheckBox, SIGNAL( toggled(bool) ), this, SLOT( nonPrintingFramesSelected(bool) ) );
66
        init();
3739 cbradney 67
}
68
 
69
/*
4598 cbradney 70
*  Destroys the object and frees any allocated resources
71
*/
3739 cbradney 72
TOCIndexPrefs::~TOCIndexPrefs()
73
{
4598 cbradney 74
        // no need to delete child widgets, Qt does it all for us
3739 cbradney 75
}
76
 
77
/*
4598 cbradney 78
*  Sets the strings of the subwidgets using the current
79
*  language.
80
*/
3739 cbradney 81
void TOCIndexPrefs::languageChange()
82
{
4598 cbradney 83
        setCaption( tr( "Table of Contents and Indexes" ) );
84
        tocAddButton->setText( tr( "&Add" ) );
85
        tocAddButton->setAccel( QKeySequence( tr( "Alt+A" ) ) );
86
        tocDeleteButton->setText( tr( "&Delete" ) );
87
        tocDeleteButton->setAccel( QKeySequence( tr( "Alt+D" ) ) );
88
        QToolTip::add( itemDestFrameComboBox, tr( "The frame the table of contents will be placed into" ) );
89
        tocNumberPlacementLabel->setText( tr( "Page Numbers Placed:" ) );
90
        tocItemAttrLabel->setText( tr( "Item Attribute Name:" ) );
91
        QToolTip::add( itemAttrComboBox, tr( "The Item Attribute that will be set on frames used as a basis for creation of the entries" ) );
92
        QToolTip::add( itemNumberPlacementComboBox, tr( "Place page numbers of the entries at the beginning or the end of the line, or not at all" ) );
93
        itemListNonPrintingCheckBox->setText( tr( "List Non-Printing Entries" ) );
94
        QToolTip::add( itemListNonPrintingCheckBox, tr( "Include frames that are set to not print as well" ) );
95
        QToolTip::add( itemParagraphStyleComboBox, tr( "The paragraph style used for the entry lines" ) );
96
        tocParagraphStyleLabel->setText( tr( "Paragraph Style:" ) );
97
        tocDestFrameLabel->setText( tr( "Destination Frame:" ) );
98
        tabTOCIndexWidget->changeTab( tab, tr( "Table Of Contents" ) );
99
        tabTOCIndexWidget->changeTab( tab_2, tr( "Inde&x" ) );
3739 cbradney 100
}
101
 
102
void TOCIndexPrefs::init()
103
{
104
        disconnect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
105
        trStrNone=QT_TR_NOOP("None");
4546 subik 106
        strNone=CommonStrings::None;
3739 cbradney 107
        trStrPNBeginning=QT_TR_NOOP("At the beginning");
108
        strPNBeginning="At the beginning";
109
        trStrPNEnd=QT_TR_NOOP("At the end");
110
        strPNEnd="At the end";
111
        trStrPNNotShown=QT_TR_NOOP("Not Shown");
112
        strPNNotShown="Not Shown";
4546 subik 113
 
3739 cbradney 114
        itemNumberPlacementComboBox->clear();
4546 subik 115
        itemNumberPlacementComboBox->insertItem(trStrPNEnd);
3739 cbradney 116
        itemNumberPlacementComboBox->insertItem(trStrPNBeginning);
117
        itemNumberPlacementComboBox->insertItem(trStrPNNotShown);
118
        itemNumberPlacementComboBox->setCurrentText(trStrPNEnd);
119
        numSelected=999;
120
}
121
 
122
 
123
void TOCIndexPrefs::destroy()
124
{
125
 
126
}
127
 
128
void TOCIndexPrefs::setup( ToCSetupVector* tocsetups, ScribusDoc *doc)
129
{
130
        localToCSetupVector=* tocsetups;
131
        currDoc=doc;
132
        generatePageItemList();
133
        bool enabled=(localToCSetupVector.count()>0);
134
        if (enabled)
135
        {
136
                updateToCListBox();
137
                updateParagraphStyleComboBox();
138
                tocListBox->setCurrentItem(0);
139
                selectToC(0);
140
        }
141
        else
142
                tocListBox->clear();
143
        enableGUIWidgets();
144
        connect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
145
}
146
 
147
void TOCIndexPrefs::generatePageItemList()
148
{
149
        itemDestFrameComboBox->clear();
150
        itemDestFrameComboBox->insertItem(trStrNone);
151
        if (currDoc!=NULL)
152
        {
153
                for (uint d = 0; d < currDoc->DocItems.count(); ++d)
154
                {
155
                        if (currDoc->DocItems.at(d)->itemType()==PageItem::TextFrame)
156
                                itemDestFrameComboBox->insertItem(currDoc->DocItems.at(d)->itemName());
157
                }
158
        }
159
        else
160
                itemDestFrameComboBox->setEnabled(false);
161
}
162
 
163
 
164
void TOCIndexPrefs::setupItemAttrs( QStringList newNames )
165
{
166
        disconnect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
167
        itemAttrComboBox->clear();
168
        itemAttrComboBox->insertItem(trStrNone);
169
        itemAttrComboBox->insertStringList(newNames);
170
        if (numSelected!=999)
171
        {
172
                if (localToCSetupVector[numSelected].itemAttrName==strNone)
173
                        itemAttrComboBox->setCurrentText(trStrNone);
174
                else
175
                        itemAttrComboBox->setCurrentText(localToCSetupVector[numSelected].itemAttrName);
176
        }
177
        connect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
178
}
179
 
180
 
181
void TOCIndexPrefs::selectToC( int numberSelected )
182
{
183
        numSelected=numberSelected;
184
        if (localToCSetupVector.isEmpty())
185
                return;
186
        if (localToCSetupVector.count()<numSelected)
187
                numSelected=0;
188
        disconnect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
189
        disconnect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
190
        disconnect( itemDestFrameComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemFrameSelected(const QString&) ) );
191
        disconnect( itemParagraphStyleComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemParagraphStyleSelected(const QString&) ) );
192
        disconnect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) );
193
        disconnect( tocNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( setToCName(const QString&) ) );
194
        disconnect( itemListNonPrintingCheckBox, SIGNAL( toggled(bool) ), this, SLOT( nonPrintingFramesSelected(bool) ) );
195
        if (localToCSetupVector[numSelected].itemAttrName==strNone)
196
                itemAttrComboBox->setCurrentText(trStrNone);
197
        else
198
                itemAttrComboBox->setCurrentText(localToCSetupVector[numSelected].itemAttrName);
199
        if (localToCSetupVector[numSelected].pageLocation==NotShown)
200
                itemNumberPlacementComboBox->setCurrentText(trStrPNNotShown);
201
        else
202
                if (localToCSetupVector[numSelected].pageLocation==Beginning)
203
                itemNumberPlacementComboBox->setCurrentText(trStrPNBeginning);
204
        else
205
                itemNumberPlacementComboBox->setCurrentText(trStrPNEnd);
4546 subik 206
 
3739 cbradney 207
        itemListNonPrintingCheckBox->setChecked(localToCSetupVector[numSelected].listNonPrintingFrames);
208
        if (currDoc!=NULL)
4546 subik 209
        {
3739 cbradney 210
                if (localToCSetupVector[numSelected].frameName==strNone)
211
                        itemDestFrameComboBox->setCurrentText(trStrNone);
212
                else
213
                        itemDestFrameComboBox->setCurrentText(localToCSetupVector[numSelected].frameName);
4546 subik 214
 
3739 cbradney 215
                if (itemParagraphStyleComboBox->count()>0)
216
                {
217
                        if (!paragraphStyleList.contains(localToCSetupVector[numSelected].textStyle) || localToCSetupVector[numSelected].textStyle==strNone)
218
                                itemParagraphStyleComboBox->setCurrentText(trStrNone);
219
                        else
220
                                itemParagraphStyleComboBox->setCurrentText(localToCSetupVector[numSelected].textStyle);
221
                }
222
        }
4546 subik 223
 
3739 cbradney 224
        //if (numSelected>=0)
225
                tocNameLineEdit->setText(tocListBox->currentText());
4546 subik 226
 
3739 cbradney 227
        connect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
228
        connect( itemAttrComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemAttributeSelected(const QString&) ) );
229
        connect( itemDestFrameComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemFrameSelected(const QString&) ) );
230
        connect( itemParagraphStyleComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemParagraphStyleSelected(const QString&) ) );
231
        connect( itemNumberPlacementComboBox, SIGNAL( activated(const QString&) ), this, SLOT( itemPageNumberPlacedSelected(const QString&) ) );
232
        connect( tocNameLineEdit, SIGNAL( textChanged(const QString&) ), this, SLOT( setToCName(const QString&) ) );
233
        connect( itemListNonPrintingCheckBox, SIGNAL( toggled(bool) ), this, SLOT( nonPrintingFramesSelected(bool) ) );
234
}
235
 
236
 
237
void TOCIndexPrefs::addToC()
238
{
239
        bool found=false;
240
        QString newName=tocNameLineEdit->text();
241
        for(ToCSetupVector::Iterator it = localToCSetupVector.begin(); it!= localToCSetupVector.end(); ++it)
242
        {
243
                if ((*it).name==newName)
244
                        found=true;
245
        }
246
        if (found || newName.isEmpty())
247
                newName=QString("Table of Contents %1").arg(localToCSetupVector.count()+1);
248
        ToCSetup newToCEntry;
249
        newToCEntry.name=newName;
250
        newToCEntry.itemAttrName=strNone;
251
        newToCEntry.frameName=strNone;
252
        newToCEntry.textStyle=strNone;
253
        newToCEntry.pageLocation=End;
254
        newToCEntry.listNonPrintingFrames=false;
255
        localToCSetupVector.append(newToCEntry);
256
        disconnect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
257
        updateToCListBox();
258
        tocListBox->setCurrentItem(localToCSetupVector.count()-1);
259
        selectToC(localToCSetupVector.count()-1);
260
        enableGUIWidgets();
261
        connect( tocListBox, SIGNAL( highlighted(int) ), this, SLOT( selectToC(int) ) );
262
}
263
 
264
 
265
void TOCIndexPrefs::updateToCListBox()
266
{
267
        tocListBox->clear();
268
        for(ToCSetupVector::Iterator it = localToCSetupVector.begin(); it!= localToCSetupVector.end(); ++it)
269
                tocListBox->insertItem((*it).name);
270
}
271
 
272
void TOCIndexPrefs::updateParagraphStyleComboBox()
273
{
274
        paragraphStyleList.clear();
275
        paragraphStyleList.append(trStrNone);
4546 subik 276
 
3739 cbradney 277
        if(currDoc!=NULL && currDoc->docParagraphStyles.count()>5)
278
        {
279
                for (uint i = 5; i < currDoc->docParagraphStyles.count(); ++i)
280
                        paragraphStyleList.append(currDoc->docParagraphStyles[i].Vname);
281
        }
282
        itemParagraphStyleComboBox->clear();
283
        itemParagraphStyleComboBox->insertStringList(paragraphStyleList);
284
}
285
 
286
 
287
void TOCIndexPrefs::enableGUIWidgets()
288
{
289
        bool enabled=(localToCSetupVector.count()>0);
290
        tocListBox->setEnabled(enabled);
291
        tocDeleteButton->setEnabled(enabled);
292
        itemAttrComboBox->setEnabled(enabled);
293
        itemNumberPlacementComboBox->setEnabled(enabled);
294
        bool haveDoc=enabled && currDoc!=NULL;
295
        itemDestFrameComboBox->setEnabled(haveDoc);
296
        itemParagraphStyleComboBox->setEnabled(haveDoc);
297
}
298
 
299
 
300
void TOCIndexPrefs::deleteToC()
301
{
302
        int numberSelected=tocListBox->currentItem();
303
        if (numberSelected>=0)
304
        {
305
                int i=0;
306
                ToCSetupVector::Iterator it;
307
                for(it = localToCSetupVector.begin(); it!= localToCSetupVector.end(), i<numberSelected ; ++it, ++i)
308
                        ;
309
                localToCSetupVector.erase(it);
310
                updateToCListBox();
311
                enableGUIWidgets();
312
        }
313
}
314
 
315
 
316
void TOCIndexPrefs::itemAttributeSelected( const QString& itemAttributeName )
317
{
318
        int numberSelected=tocListBox->currentItem();
319
        if (numberSelected>=0)
320
        {
321
                int i=0;
322
                ToCSetupVector::Iterator it;
323
                for(it = localToCSetupVector.begin(); it!= localToCSetupVector.end(), i<numberSelected ; ++it, ++i)
324
                        ;
325
                if (itemAttributeName==trStrNone)
326
                        (*it).itemAttrName=strNone;
327
                else
328
                        (*it).itemAttrName=itemAttributeName;
329
        }
330
}
331
 
332
 
333
void TOCIndexPrefs::itemFrameSelected( const QString& frameName )
334
{
335
        int numberSelected=tocListBox->currentItem();
336
        if (numberSelected>=0)
337
        {
338
                int i=0;
339
                ToCSetupVector::Iterator it;
340
                for(it = localToCSetupVector.begin(); it!= localToCSetupVector.end(), i<numberSelected ; ++it, ++i)
341
                        ;
342
                if (frameName==trStrNone)
343
                        (*it).frameName=strNone;
344
                else
345
                        (*it).frameName=frameName;
346
        }
347
 
348
}
349
 
350
 
351
void TOCIndexPrefs::itemPageNumberPlacedSelected( const QString& pageLocation )
352
{
353
        int numberSelected=tocListBox->currentItem();
354
        if (numberSelected>=0)
355
        {
356
                int i=0;
357
                ToCSetupVector::Iterator it;
358
                for(it = localToCSetupVector.begin(); it!= localToCSetupVector.end(), i<numberSelected ; ++it, ++i)
359
                        ;
360
                if (pageLocation==trStrPNBeginning || pageLocation==strPNBeginning)
361
                        (*it).pageLocation=Beginning;
362
                else
363
                if (pageLocation==trStrPNEnd || pageLocation==strPNEnd)
364
                        (*it).pageLocation=End;
365
                else
366
                        (*it).pageLocation=NotShown;
367
        }
368
}
369
 
370
 
371
void TOCIndexPrefs::itemParagraphStyleSelected( const QString& itemStyle )
372
{
373
        int numberSelected=tocListBox->currentItem();
374
        if (numberSelected>=0)
375
        {
376
                int i=0;
377
                ToCSetupVector::Iterator it;
378
                for(it = localToCSetupVector.begin(); it!= localToCSetupVector.end(), i<numberSelected ; ++it, ++i)
379
                        ;
380
                if (itemStyle==trStrNone)
381
                        (*it).textStyle=strNone;
382
                else
383
                        (*it).textStyle=itemStyle;
384
        }
385
}
386
 
387
ToCSetupVector* TOCIndexPrefs::getNewToCs()
388
{
389
        return &localToCSetupVector;
390
}
391
 
392
 
393
void TOCIndexPrefs::setToCName( const QString &newName )
394
{
395
        int numberSelected=tocListBox->currentItem();
396
        if (numberSelected!=-1)
397
        {
398
                tocListBox->changeItem(newName, numberSelected);
399
                int i=0;
400
                ToCSetupVector::Iterator it;
401
                for(it = localToCSetupVector.begin(); it!= localToCSetupVector.end(), i<numberSelected ; ++it, ++i)
402
                        ;
403
                (*it).name=newName;
404
        }
405
}
406
 
407
 
408
void TOCIndexPrefs::nonPrintingFramesSelected( bool showNonPrinting )
409
{
410
        int numberSelected=tocListBox->currentItem();
411
        if (numberSelected>=0)
412
        {
413
                int i=0;
414
                ToCSetupVector::Iterator it;
415
                for(it = localToCSetupVector.begin(); it!= localToCSetupVector.end(), i<numberSelected ; ++it, ++i)
416
                        ;
417
                (*it).listNonPrintingFrames=showNonPrinting;
418
        }
419
}