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.
7
/***************************************************************************
8
* Copyright (C) 2005 by Craig Bradney *
9
* cbradney@zip.com.au *
11
* This program is free software; you can redistribute it and/or modify *
12
* it under the terms of the GNU General Public License as published by *
13
* the Free Software Foundation; either version 2 of the License, or *
14
* (at your option) any later version. *
16
* This program is distributed in the hope that it will be useful, *
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
19
* GNU General Public License for more details. *
21
* You should have received a copy of the GNU General Public License *
22
* along with this program; if not, write to the *
23
* Free Software Foundation, Inc., *
24
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
25
***************************************************************************/
27
#include "docsections.h"
29
// This class implements only the non-GUI parts of the
30
// Document Sections dialog. Please use Qt Designer on
31
// ui/docsections.ui if you need to modify the layout,
32
// widget properties, etc.
37
#include <QMessageBox>
38
#include <QPushButton>
39
#include <QTableWidget>
42
#include "commonstrings.h"
43
#include "pagestructs.h"
46
DocSections::DocSections( QWidget* parent )
51
connect (sectionsTable, SIGNAL(cellChanged(int,int)), this, SLOT(tableItemChanged(int,int)));
52
connect( addButton, SIGNAL(clicked()), this, SLOT(addEntry()));
53
connect( deleteButton, SIGNAL(clicked()), this, SLOT(deleteEntry()));
56
DocSections::~DocSections()
60
void DocSections::changeEvent(QEvent *e)
62
if (e->type() == QEvent::LanguageChange)
67
QWidget::changeEvent(e);
70
void DocSections::languageChange()
72
addButton->setToolTip( "<qt>"+ tr("Add a page numbering section to the document. The new section will be added after the currently selected section.") + "</qt>");
73
deleteButton->setToolTip( "<qt>"+ tr("Delete the currently selected section.") + "</qt>");
74
sectionsTable->setToolTip( "<qt>"+ tr("<b>Name:</b> Optional name for section eg. Index<br/>"
75
"<b>Shown:</b> Select to show the page numbers in this section if there is one or more text frames setup to do so.<br/>"
76
"<b>From:</b> The page index for this section to start at.<br/>"
77
"<b>To:</b> The page index for this section to stop at.<br/>"
78
"<b>Style:</b> Select the page number style to be used.<br/>"
79
"<b>Start:</b> The index within the Style's range to star at. Eg. If Start=2 and Style=a,b,c, ..., the numbers will begin at b. For the first section in the document this replaces the older First Page Number in the new file window.") +"</qt>");
82
void DocSections::setup(const DocumentSectionMap docSections, int maxPageIndex)
84
localSections=docSections;
85
m_maxpageindex=maxPageIndex;
87
styles << tr("1, 2, 3, ...") << tr("i, ii, iii, ...") << tr("I, II, III, ...") << tr("a, b, c, ...") << tr("A, B, C, ...") << CommonStrings::tr_None;
92
void DocSections::updateTable()
94
sectionsTable->setRowCount(localSections.count());
96
for(DocumentSectionMap::Iterator it = localSections.begin(); it!= localSections.end(); ++it)
100
QTableWidgetItem *item1 = new QTableWidgetItem((*it).name);
101
sectionsTable->setItem(row, i++, item1);
103
QCheckBox *item2 = new QCheckBox();
104
item2->setChecked((*it).active);
105
sectionsTable->setCellWidget(row, i++, item2);
107
QTableWidgetItem *item3 = new QTableWidgetItem(QString::number((*it).fromindex+1));
108
sectionsTable->setItem(row, i++, item3);
110
QTableWidgetItem *item4 = new QTableWidgetItem(QString::number((*it).toindex+1));
111
sectionsTable->setItem(row, i++, item4);
113
QComboBox *item5 = new QComboBox();
114
item5->addItems(styles);
115
sectionsTable->setCellWidget(row, i++, item5);
116
if ((*it).type==Type_None)
117
item5->setCurrentIndex(styles.count()-1);
119
item5->setCurrentIndex((*it).type);
121
QTableWidgetItem *item6 = new QTableWidgetItem(QString::number((*it).sectionstartindex));
122
sectionsTable->setItem(row, i++, item6);
125
QTableItem *item7 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, QString::number((*it).sectionstartindex + (*it).toindex - (*it).fromindex));
126
item7->setEnabled(false);
127
sectionsTable->setItem(row, i++, item7);
129
QTableWidgetItem *t=sectionsTable->verticalHeaderItem(row);
131
t->setText(QString("%1").arg(row));
134
deleteButton->setEnabled(localSections.count()>1);
137
void DocSections::tableItemChanged( int row, int col )
139
bool outOfRange=false;
145
localSections[row].name=sectionsTable->item(row, col)->text();
149
QCheckBox* qcti=dynamic_cast<QCheckBox*>(sectionsTable->cellWidget(row,col));
151
localSections[row].active=qcti->isChecked();
156
// Validate to/from page specification before conversion to an index
157
//!!! There is still a problem here if m_maxpageindex == MAX_UINT ;)
158
newDocPageSpec=sectionsTable->item(row, col)->text().toUInt();
159
if (newDocPageSpec==0)
165
if (newDocPageSpec>m_maxpageindex+1)
167
newDocPageSpec=m_maxpageindex+1;
170
// Now, since newDocPageSpec >= 1, convert to index
173
localSections[row].fromindex=newDocPageSpec;
175
localSections[row].toindex=newDocPageSpec;
179
QComboBox* qcti=dynamic_cast<QComboBox*>(sectionsTable->cellWidget(row,col));
182
int index=qcti->currentIndex();
183
if (index<styles.count()-1)
184
localSections[row].type=(DocumentSectionType)index;
186
if (index==styles.count()-1)
187
localSections[row].type=Type_None;
192
localSections[row].sectionstartindex=sectionsTable->item(row, col)->text().toUInt();
201
QMessageBox::warning(parentWidget(), tr("Page Number Out Of Bounds"),"<qt>"+ tr("The value you have entered is outside the range of page numbers in the current document (%1-%2).").arg(1).arg(m_maxpageindex+1)+"</qt>",QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton);
205
void DocSections::addEntry()
207
int currRow=sectionsTable->currentRow();
209
DocumentSectionMap::Iterator it = localSections.begin();
211
for(; it!= localSections.end(); ++it)
220
if (!found) //End of map, just append
222
struct DocumentSection blank;
223
uint count=localSections.count();
225
blank.name=QString::number(count);
226
blank.fromindex=m_maxpageindex+1;
227
blank.toindex=m_maxpageindex+1;
228
blank.type=Type_1_2_3;
229
blank.sectionstartindex=1;
230
blank.reversed=false;
232
localSections.insert(count, blank);
236
//Now, copy to a temp map
237
DocumentSectionMap tempSections(localSections);
238
localSections.clear();
239
//Copy the temp map entries over. When we find the number of the current row, also insert a new entry.
241
for(DocumentSectionMap::Iterator it2 = tempSections.begin(); it2!= tempSections.end(); ++it2)
243
it2.value().number=i;
244
localSections.insert(i, it2.value());
248
struct DocumentSection blank;
250
blank.name=QString::number(i);
251
blank.fromindex=(*it).toindex+1+1;
252
blank.toindex=(*it).toindex+2+1;
253
blank.type=Type_1_2_3;
254
blank.sectionstartindex=1;
255
blank.reversed=false;
257
localSections.insert(i, blank);
265
void DocSections::deleteEntry()
267
int currRow=sectionsTable->currentRow();
268
if (currRow==0 && localSections.count()==1)
271
DocumentSectionMap::Iterator it = localSections.begin();
273
for(; it!= localSections.end(); ++it)
284
//If we arent at the start, copy the toindex of the current item
285
//to the toindex of the previous item
286
if (it!=localSections.begin())
288
DocumentSectionMap::Iterator it2(it);
289
(*--it2).toindex=(*it).toindex;
291
//Delete the currently selected entry
292
localSections.erase(it);
293
//Now, copy to a temp map and reinsert with consecutive keys again
294
DocumentSectionMap tempSections(localSections);
295
localSections.clear();
297
it = tempSections.begin();
298
for(; it!= tempSections.end(); ++it)
301
localSections.insert(i++, it.value());
303
int newCount=localSections.count();
304
//int preIndex=qMax(currentIndex-1, 0);
305
localSections[0].fromindex=0;
306
localSections[newCount-1].toindex=m_maxpageindex;
311
const DocumentSectionMap& DocSections::getNewSections()
313
return localSections;