Subversion Repositories Scribus

Rev

Rev 3762 | Go to most recent revision | Details | 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);
53
                //FromIndex
54
                QTableItem *item2 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, QString::number((*it).fromindex));
55
                sectionsTable->setItem(row, i++, item2);
56
                //ToIndex
57
                QTableItem *item3 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, QString::number((*it).toindex));
58
                sectionsTable->setItem(row, i++, item3);
59
                //Style
60
                QComboTableItem *item4 = new QComboTableItem(sectionsTable, styles);
61
                sectionsTable->setItem(row, i++, item4);
62
                item4->setCurrentItem((*it).type);
63
                //Start Page Number
64
                QTableItem *item5 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, QString::number((*it).sectionstartindex));
65
                sectionsTable->setItem(row, i++, item5);
66
                //End Page Number
67
                QTableItem *item6 = new QTableItem(sectionsTable, QTableItem::WhenCurrent, QString::number((*it).sectionstartindex));
68
                item6->setEnabled(false);
69
                sectionsTable->setItem(row, i++, item6);
70
 
71
 
72
                sectionsTable->verticalHeader()->setLabel(row, QString("%1").arg(row));
73
                row++;
74
        }
75
        deleteButton->setEnabled(localSections.count()>1);
76
}
77
 
78
void DocSections::tableItemChanged( int row, int col )
79
{
80
        switch (col)
81
        {
82
        case 0:
83
                localSections[row].name=sectionsTable->text(row, col);
84
                break;
85
        case 1:
86
                localSections[row].fromindex=sectionsTable->text(row, col).toUInt();
87
                break;
88
        case 2:
89
                localSections[row].toindex=sectionsTable->text(row, col).toUInt();
90
                break;
91
        case 3:
92
                {
93
                        QComboTableItem* qcti=dynamic_cast<QComboTableItem*>(sectionsTable->item(row,col));
94
                        if (qcti!=NULL)
95
                        {
96
                                uint index=qcti->currentItem();
97
                                if (index<styles.count())
98
                                        localSections[row].type=(DocumentSectionType)index;
99
                        }
100
                }
101
                break;
102
        case 4:
103
                localSections[row].sectionstartindex=sectionsTable->text(row, col).toUInt();
104
                break;
105
        default:
106
                break;
107
        }
108
}
109
 
110
void DocSections::addEntry()
111
{
112
        struct DocumentSection blank;
113
        uint count=localSections.count();
114
        blank.number=count;
115
        blank.name=QString::number(count);
116
        blank.fromindex=maxpageindex;
117
        blank.toindex=maxpageindex;
118
        blank.type=Type_1_2_3;
119
        blank.sectionstartindex=1;
120
        blank.reversed=false;
121
        blank.active=true;
122
        localSections.insert(count, blank);
123
        updateTable();
124
}
125
 
126
void DocSections::deleteEntry()
127
{
128
        int currRow=sectionsTable->currentRow();
129
        bool found=false;
130
        DocumentSectionMap::Iterator it = localSections.begin();
131
        int count=0;
132
        for(; it!= localSections.end(); ++it)
133
        {
134
                if(count==currRow)
135
                {
136
                        found=true;
137
                        break;
138
                }
139
                ++count;
140
        }
141
        if (found)
142
        {
143
                localSections.erase(it);
144
                updateTable();
145
        }
146
}
147
 
148
const DocumentSectionMap& DocSections::getNewSections()
149
{
150
        return localSections;
151
}