Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
3760 cbradney 1
#include "docsections.h"
2
#include "docsections.moc"
3
 
4
// This class implements only the non-GUI parts of the
5
// Document Sections dialog. Please use Qt Designer on
6
// ui/docsectionsbase.ui if you need to modify the layout,
7
// widget properties, etc.
8
 
9
#include <qtable.h>
10
#include <qpushbutton.h>
11
 
12
#include "pagestructs.h"
13
#include "scribusdoc.h"
14
 
15
DocSections::DocSections( QWidget* parent )
16
        : DocSectionsBase( parent, "DocSections" )
17
{
18
        languageChange();
19
        connect( sectionsTable, SIGNAL(valueChanged(int, int)), this, SLOT(tableItemChanged(int, int)));
20
        connect( addButton, SIGNAL(clicked()), this, SLOT(addEntry()));
21
        connect( deleteButton, SIGNAL(clicked()), this, SLOT(deleteEntry()));
22
}
23
 
24
DocSections::~DocSections()
25
{
26
}
27
 
28
void DocSections::languageChange()
29
{
30
}
31
 
32
void DocSections::setup(ScribusDoc *doc)
33
{
34
        currDoc=doc;
35
        localSections=currDoc->sections;
36
        maxpageindex=currDoc->DocPages.count()-1;
37
 
38
        styles << tr("1, 2, 3, ...") << tr("i, ii, iii, ...") << tr("I, II, III, ...") << tr("a, b, c, ...") << tr("A, B, C, ...");
39
 
40
        updateTable();
41
}
42
 
43
void DocSections::updateTable()
44
{
45
        sectionsTable->setNumRows(localSections.count());
46
        int row=0;
47
        for(DocumentSectionMap::Iterator it = localSections.begin(); it!= localSections.end(); ++it)
48
        {
49
                uint i=0;
50
                //Name
51
                QTableItem *item1 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, (*it).name);
52
                sectionsTable->setItem(row, i++, item1);
3762 cbradney 53
                //Active
54
                QCheckTableItem *item2 = new QCheckTableItem(sectionsTable,"");
55
                item2->setChecked((*it).active);
56
                sectionsTable->setItem(row, i++, item2);
3760 cbradney 57
                //FromIndex
3762 cbradney 58
                QTableItem *item3 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, QString::number((*it).fromindex));
59
                sectionsTable->setItem(row, i++, item3);
3760 cbradney 60
                //ToIndex
3762 cbradney 61
                QTableItem *item4 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, QString::number((*it).toindex));
62
                sectionsTable->setItem(row, i++, item4);
3760 cbradney 63
                //Style
3762 cbradney 64
                QComboTableItem *item5 = new QComboTableItem(sectionsTable, styles);
65
                sectionsTable->setItem(row, i++, item5);
66
                item5->setCurrentItem((*it).type);
3760 cbradney 67
                //Start Page Number
3762 cbradney 68
                QTableItem *item6 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, QString::number((*it).sectionstartindex));
69
                sectionsTable->setItem(row, i++, item6);
3760 cbradney 70
                //End Page Number
3762 cbradney 71
                QTableItem *item7 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, QString::number((*it).sectionstartindex));
3760 cbradney 72
                item6->setEnabled(false);
3762 cbradney 73
                sectionsTable->setItem(row, i++, item7);
3760 cbradney 74
 
75
                sectionsTable->verticalHeader()->setLabel(row, QString("%1").arg(row));
76
                row++;
77
        }
78
        deleteButton->setEnabled(localSections.count()>1);
79
}
80
 
81
void DocSections::tableItemChanged( int row, int col )
82
{
83
        switch (col)
84
        {
85
        case 0:
86
                localSections[row].name=sectionsTable->text(row, col);
87
                break;
88
        case 1:
3762 cbradney 89
                localSections[row].active=static_cast<QCheckTableItem*>(sectionsTable->item(row, col))->isChecked();
90
                break;
91
        case 2:
3760 cbradney 92
                localSections[row].fromindex=sectionsTable->text(row, col).toUInt();
93
                break;
3762 cbradney 94
        case 3:
3760 cbradney 95
                localSections[row].toindex=sectionsTable->text(row, col).toUInt();
96
                break;
3762 cbradney 97
        case 4:
3760 cbradney 98
                {
99
                        QComboTableItem* qcti=dynamic_cast<QComboTableItem*>(sectionsTable->item(row,col));
100
                        if (qcti!=NULL)
101
                        {
102
                                uint index=qcti->currentItem();
103
                                if (index<styles.count())
104
                                        localSections[row].type=(DocumentSectionType)index;
105
                        }
106
                }
107
                break;
3762 cbradney 108
        case 5:
3760 cbradney 109
                localSections[row].sectionstartindex=sectionsTable->text(row, col).toUInt();
110
                break;
111
        default:
112
                break;
113
        }
114
}
115
 
116
void DocSections::addEntry()
117
{
118
        struct DocumentSection blank;
119
        uint count=localSections.count();
120
        blank.number=count;
121
        blank.name=QString::number(count);
122
        blank.fromindex=maxpageindex;
123
        blank.toindex=maxpageindex;
124
        blank.type=Type_1_2_3;
125
        blank.sectionstartindex=1;
126
        blank.reversed=false;
127
        blank.active=true;
128
        localSections.insert(count, blank);
129
        updateTable();
130
}
131
 
132
void DocSections::deleteEntry()
133
{
134
        int currRow=sectionsTable->currentRow();
3765 cbradney 135
        if (currRow==0 && localSections.count()==1)
136
                return;
3760 cbradney 137
        bool found=false;
138
        DocumentSectionMap::Iterator it = localSections.begin();
139
        int count=0;
140
        for(; it!= localSections.end(); ++it)
141
        {
142
                if(count==currRow)
143
                {
144
                        found=true;
145
                        break;
146
                }
147
                ++count;
148
        }
149
        if (found)
150
        {
3765 cbradney 151
                int currentIndex=it.key();
152
                bool isLast=currentIndex==localSections.count()-1;
153
                bool isFirst=currentIndex==0;
154
 
155
                //if (isFirst && !isLast)
156
                //      localSections[currentIndex+1].fromindex=localSections[currentIndex].fromindex;
157
                //if (isLast && !isFirst)
158
                //      localSections[currentIndex-1].toindex=localSections[currentIndex].toindex;
159
                localSections.remove(it);
160
                DocumentSectionMap tempSections(localSections);
161
                localSections.clear();
162
                uint i=0;
163
                it = tempSections.begin();
164
                for(; it!= tempSections.end(); ++it)
165
                {
166
                        it.data().number=i;
167
                        localSections.insert(i++, it.data());
168
                }
169
                int newCount=localSections.count();
170
                //int preIndex=QMAX(currentIndex-1, 0);
171
                localSections[0].fromindex=0;
172
                localSections[newCount-1].toindex=maxpageindex;
3760 cbradney 173
                updateTable();
174
        }
175
}
176
 
177
const DocumentSectionMap& DocSections::getNewSections()
178
{
179
        return localSections;
180
}