Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
17513 jghali 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
*/
7
 
8
 
9
#include <QApplication>
10
#include <QBitmap>
11
#include <QCursor>
12
#include <QDrag>
13
#include <QEvent>
14
#include <QHeaderView>
15
#include <QLabel>
16
#include <QList>
17
#include <QMenu>
18
#include <QMimeData>
19
#include <QMessageBox>
20
#include <QPainter>
21
 
22
#include "commonstrings.h"
23
#include "pagelayout.h"
24
#include "pagepalette_pages.h"
25
#include "pagepalette_widgets.h"
26
#include "sccombobox.h"
27
#include "scpage.h"
28
#include "scribus.h"
29
#include "scribuscore.h"
30
#include "scribusview.h"
31
#include "util_icon.h"
32
 
33
PagePalette_Pages::PagePalette_Pages(QWidget* parent) : QWidget(parent)
34
{
35
        m_scMW = ScCore->primaryMainWindow();
36
 
37
        setupUi(this);
38
 
39
        setSizePolicy( QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum));
40
 
41
        masterPageList->setMinimumSize(QSize(130,70));
42
        masterPageList->Thumb = false;
43
        masterPageList->setIconSize(QSize(60, 60));
44
 
45
        QHeaderView *Header = pageView->verticalHeader();
18194 fschmid 46
        Header->setSectionsMovable(false);
47
        Header->setSectionResizeMode(QHeaderView::Fixed);
17513 jghali 48
        Header->hide();
49
        Header = pageView->horizontalHeader();
18194 fschmid 50
        Header->setSectionsMovable(false);
51
        Header->setSectionResizeMode(QHeaderView::Fixed);
17513 jghali 52
        Header->hide();
53
        pageView->setSortingEnabled(false);
54
        pageView->setSelectionMode( QAbstractItemView::NoSelection );
55
        pageView->setRowCount(1);
56
        pageView->setColumnCount(1);
57
        pageView->setIconSize(QSize(60, 60));
58
        pageView->setMinimumSize(QSize(130,120));
59
 
60
        trash->setMinimumSize(QSize(32,32));
61
        trash->setMaximumSize(QSize(32,32));
62
 
63
        pix = loadIcon("32/page-simple.png");
64
 
65
        currView = 0;
66
        Rebuild();
67
        languageChange();
68
 
69
        connect(masterPageList, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(selMasterPage()));
70
        connect(masterPageList, SIGNAL(thumbnailChanged()), this, SLOT(rebuildMasters()));
71
        connect(masterPageList, SIGNAL(DelMaster(QString)), this, SLOT(deleteMasterPage(QString)));
72
 
73
        connect(pageLayout, SIGNAL(selectedLayout(int ))   , this, SLOT(handlePageLayout(int )));
74
        connect(pageLayout, SIGNAL(selectedFirstPage(int )), this, SLOT(handleFirstPage(int )));
75
        connect(pageView  , SIGNAL(Click(int, int, int))   , this, SLOT(pageView_gotoPage(int, int, int)));
76
        connect(pageView  , SIGNAL(movePage(int, int))     , this, SLOT(pageView_movePage(int, int)));
77
        connect(pageView  , SIGNAL(DelPage(int))           , m_scMW, SLOT(deletePage2(int)));
18558 jghali 78
        connect(pageView  , SIGNAL(UseTemp(QString, int))  , this, SLOT(pageView_applyMasterPage(QString, int)));
17513 jghali 79
        connect(pageView  , SIGNAL(NewPage(int, QString))  , m_scMW, SLOT(slotNewPageP(int, QString)));
80
        connect(trash     , SIGNAL(DelPage(int))           , m_scMW, SLOT(deletePage2(int)));
81
        connect(trash     , SIGNAL(DelMaster(QString))     , this, SLOT(deleteMasterPage(QString)));
82
 
83
        connect(this, SIGNAL(gotoPage(int))          , m_scMW, SLOT(selectPagesFromOutlines(int)));
84
}
85
 
86
void PagePalette_Pages::deleteMasterPage(QString tmp)
87
{
88
        if (tmp == CommonStrings::trMasterPageNormal)
89
                return;
90
        QString extraWarn = "";
91
        for (int i=0; i < currView->Doc->DocPages.count(); ++i )
92
        {
93
                if (currView->Doc->DocPages[i]->MPageNam == tmp)
94
                        extraWarn = tr("This master page is used at least once in the document.");
95
        }
96
        int exit = QMessageBox::warning(this,
97
                                      CommonStrings::trWarning,
98
                                      tr("Do you really want to delete this master page?")+"\n"+extraWarn,
99
                                      QMessageBox::Yes | QMessageBox::No);
100
        if (exit == QMessageBox::Yes)
101
        {
102
                bool oldMPMode = currView->Doc->masterPageMode();
103
                int  storedPageNum = currView->Doc->currentPageNumber();
104
                int  storedViewXCoor = currView->horizontalScrollBar()->value();
105
                int  storedViewYCoor = currView->verticalScrollBar()->value();
106
 
107
                currView->Doc->setMasterPageMode(true);
108
                currView->Doc->scMW()->deletePage2(currView->Doc->MasterNames[tmp]);
109
                //<<CB TODO Move back into ScribusDoc::deleteMasterPage();
110
                //This must happen after the pages have been reformed (view/doc)
111
                currView->Doc->rebuildMasterNames();
112
                // Fix up any pages that refer to the deleted master page
113
                currView->Doc->replaceMasterPage(tmp);
114
                currView->Doc->setMasterPageMode(oldMPMode);
115
                currView->Doc->setModified(true);
116
 
117
                currView->Doc->setCurrentPage(currView->Doc->DocPages.at(storedPageNum));
118
                currView->reformPages(false);
119
                currView->setContentsPos(storedViewXCoor, storedViewYCoor);
120
                currView->DrawNew();
121
        }
122
}
123
 
18558 jghali 124
void PagePalette_Pages::pageView_applyMasterPage(QString masterpageName, int pageIndex)
125
{
126
        m_scMW->Apply_MasterPage(masterpageName, pageIndex);
127
 
128
        SeItem* pageItem = pageView->GetPageItem(pageIndex);
129
        if (pageItem)
130
                pageItem->setIcon(createIcon(pageIndex, masterpageName, pix));
131
}
132
 
17513 jghali 133
void PagePalette_Pages::pageView_movePage(int r, int c)
134
{
135
        if (r == c)
136
                return;
137
        if (c > pageView->MaxC)
138
                currView->Doc->movePage(r, r + 1, c, 2);
139
        else
140
                currView->Doc->movePage(r, r + 1, c, 0);
141
        currView->reformPages();
142
        rebuildPages();
143
        currView->DrawNew();
144
//CB done by doc::reformpages
145
//      currView->Doc->setModified(true);
146
}
147
 
148
void PagePalette_Pages::pageView_gotoPage(int r, int c, int b)
149
{
150
        int p;
151
        bool dummy;
152
        if ((b == Qt::LeftButton) && (r != -1) && (c != -1))
153
        {
154
                p = pageView->GetPage(r, c, &dummy);
155
                emit gotoPage(p);
156
        }
157
}
158
 
159
void PagePalette_Pages::enablePalette(const bool enabled)
160
{
161
        pageView->setEnabled(enabled);
162
        masterPageList->setEnabled(enabled);
163
        pageLayout->setEnabled(enabled);
164
}
165
 
166
void PagePalette_Pages::handlePageLayout(int layout)
167
{
168
        pageLayout->selectFirstP(currView->Doc->pageSets()[layout].FirstPage);
169
        currView->Doc->resetPage(layout);
170
        currView->reformPages();
171
        currView->DrawNew();
172
        currView->GotoPage(currView->Doc->currentPageNumber());
173
        rebuildPages();
174
//CB done by doc::reformpages
175
//      currView->Doc->setModified(true);
176
}
177
 
178
void PagePalette_Pages::handleFirstPage(int fp)
179
{
180
//      currView->Doc->pageSets()[currView->Doc->currentPageLayout].FirstPage = fp;
181
        currView->Doc->setPageSetFirstPage(currView->Doc->pagePositioning(), fp);
182
        currView->reformPages();
183
        currView->DrawNew();
184
        currView->GotoPage(currView->Doc->currentPageNumber());
185
        rebuildPages();
186
//CB done by doc::reformpages
187
//      currView->Doc->setModified(true);
188
}
189
 
190
void PagePalette_Pages::rebuildMasters()
191
{
192
        if (m_scMW->scriptIsRunning())
193
                return;
194
        masterPageList->clear();
195
        if (currView == 0)
196
                return;
197
        QPixmap pm;
198
        QMap<QString,int>::Iterator it;
199
        for (it = currView->Doc->MasterNames.begin(); it != currView->Doc->MasterNames.end(); ++it)
200
        {
201
                if (masterPageList->Thumb)
202
                {
203
                        pm = QPixmap::fromImage(currView->MPageToPixmap(it.key(),60));
204
                        new QListWidgetItem(QIcon(pm), it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key(), masterPageList);
205
                }
206
                else
207
                        masterPageList->addItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key());
208
        }
209
}
210
 
211
void PagePalette_Pages::rebuildPages()
212
{
213
        if (m_scMW->scriptIsRunning())
214
                return;
215
        QString str;
216
        disconnect(pageLayout, SIGNAL(selectedLayout(int )), this, SLOT(handlePageLayout(int )));
217
        disconnect(pageLayout, SIGNAL(selectedFirstPage(int )), this, SLOT(handleFirstPage(int )));
218
        pageView->clearContents();
219
        pageView->setRowCount(1);
220
        pageView->setColumnCount(1);
221
        if (currView == 0)
222
        {
223
                connect(pageLayout, SIGNAL(selectedLayout(int )), this, SLOT(handlePageLayout(int )));
224
                connect(pageLayout, SIGNAL(selectedFirstPage(int )), this, SLOT(handleFirstPage(int )));
225
                return;
226
        }
227
        pageLayout->updateLayoutSelector(currView->Doc->pageSets());
228
        pageLayout->selectItem(currView->Doc->pagePositioning());
229
        pageLayout->firstPage->setCurrentIndex(currView->Doc->pageSets()[currView->Doc->pagePositioning()].FirstPage);
230
        pageView->MaxC = currView->Doc->DocPages.count()-1;
231
        int counter = currView->Doc->pageSets()[currView->Doc->pagePositioning()].FirstPage;
232
        int cols = currView->Doc->pageSets()[currView->Doc->pagePositioning()].Columns;
233
        int rows = (currView->Doc->DocPages.count()+counter) / currView->Doc->pageSets()[currView->Doc->pagePositioning()].Columns;
234
        if (((currView->Doc->DocPages.count()+counter) % currView->Doc->pageSets()[currView->Doc->pagePositioning()].Columns) != 0)
235
                rows++;
236
        int rowcounter = 0;
237
        int colmult, rowmult, coladd, rowadd;
238
        if (cols == 1)
239
        {
240
                pageView->setColumnCount(cols);
241
                pageView->setRowCount(rows*2+1);
242
                colmult = 1;
243
                coladd = 0;
244
                rowmult = 2;
245
                rowadd = 1;
246
        }
247
        else
248
        {
249
                pageView->setColumnCount(cols*2);
250
                pageView->setRowCount(rows+1);
251
                colmult = 2;
252
                coladd = 1;
253
                rowmult = 1;
254
                rowadd = 0;
255
        }
256
        for (int rr = 0; rr < pageView->rowCount(); rr++)
257
        {
258
                for (int cc = 0; cc < pageView->columnCount(); cc++)
259
                {
260
                        QTableWidgetItem *tW = new QTableWidgetItem(1001);
261
                        tW->setFlags(Qt::ItemIsEnabled);
262
                        pageView->setItem(rr, cc, tW);
263
                }
264
        }
265
        pageView->coladd = coladd;
266
        pageView->colmult = colmult;
267
        pageView->rowadd = rowadd;
268
        pageView->rowmult = rowmult;
269
        pageView->firstP = counter;
270
        pageView->cols = currView->Doc->pageSets()[currView->Doc->pagePositioning()].Columns;
271
        pageList.clear();
272
        for (int a = 0; a < currView->Doc->DocPages.count(); ++a)
273
        {
274
                str = currView->Doc->DocPages.at(a)->MPageNam;
18558 jghali 275
                SeItem *it = new SeItem(str, a, createIcon(a, str, pix));
17513 jghali 276
                pageList.append(it);
277
                pageView->setItem(rowcounter*rowmult+rowadd, counter*colmult+coladd, (QTableWidgetItem *)it);
278
                pageView->setColumnWidth(counter*colmult+coladd, pix.width());
279
                if (cols == 1)
280
                {
281
                        pageView->setRowHeight(rowcounter*rowmult, 10);
282
                        pageView->setRowHeight(rowcounter*rowmult+rowadd, pix.height());
283
                }
284
                else
285
                        pageView->setRowHeight(rowcounter*rowmult+rowadd, pix.height()+5);
286
                counter++;
287
                if (counter > currView->Doc->pageSets()[currView->Doc->pagePositioning()].Columns-1)
288
                {
289
                        counter = 0;
290
                        rowcounter++;
291
                }
292
        }
293
        pageView->setRowHeight(pageView->rowCount()-1, 10);
294
        counter = 0;
295
        if (cols != 1)
296
        {
297
                for (int c = 0; c < pageView->columnCount(); ++c)
298
                {
299
                        if ((counter % 2) == 0)
300
                                pageView->setColumnWidth(counter, 10);
301
                        else
302
                                pageView->setColumnWidth(counter, pix.width());
303
                        counter++;
304
                }
305
        }
306
        pageView->repaint();
307
        if (currView != 0)
308
                markPage(currView->Doc->currentPageNumber());
309
        connect(pageLayout, SIGNAL(selectedLayout(int )), this, SLOT(handlePageLayout(int )));
310
        connect(pageLayout, SIGNAL(selectedFirstPage(int )), this, SLOT(handleFirstPage(int )));
311
}
312
 
313
void PagePalette_Pages::Rebuild()
314
{
315
        rebuildMasters();
316
        rebuildPages();
317
        enablePalette(currView != 0);
318
}
319
 
320
void PagePalette_Pages::markPage(uint nr)
321
{
322
        if (currView == 0)
323
                return;
324
 
325
        SeItem *it;
326
        for (int a = 0; a < pageList.count(); a++)
327
        {
328
                it = pageList.at(a);
329
                if (it->pageNumber == nr)
330
                {
331
                        pageView->clearSelection();
332
                        pageView->item(it->row(), it->column())->setSelected(true);
333
                        pageView->scrollToItem(pageView->item(it->row(), it->column()), QAbstractItemView::EnsureVisible);
334
                        break;
335
                }
336
        }
337
}
338
 
339
void PagePalette_Pages::setView(ScribusView *view)
340
{
341
        if (m_scMW->scriptIsRunning())
342
                return;
343
        currView = view;
344
}
345
 
346
void PagePalette_Pages::selMasterPage()
347
{
348
        if (masterPageList->CurItem != 0)
349
                emit gotoMasterPage(masterPageList->CurItem->text());
350
}
351
 
18558 jghali 352
QPixmap PagePalette_Pages::createIcon(int nr, QString masterPage, QPixmap pixin)
17513 jghali 353
{
354
        QPainter p;
355
        // Necessary on windows to ensure the pixmap is drawable
356
        QPixmap ret(pixin.width(), pixin.height()); // Qt4, pixin.depth());
357
        if (p.begin(&ret))
358
        {
359
                p.drawPixmap( 0, 0, pixin );
360
//              if( !pixin.mask().isNull() )
361
//                      ret.setMask( pixin.mask() );
362
                p.setBrush(Qt::white);
363
                p.setBackground(Qt::white);
364
                p.setBackgroundMode(Qt::OpaqueMode);
18503 craig 365
                p.setPen(QPen(Qt::black, 0, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin));
366
                //p.setFont(QFont("Helvetica", 12, QFont::Bold));
17513 jghali 367
                //QString tmp = tmp.setNum(nr+1);
368
                QString tmp(currView->Doc->getSectionPageNumberForPageIndex(nr));
369
                if (tmp.isEmpty())
370
                        tmp = tmp.setNum(nr+1);
18558 jghali 371
                QRegExp Exp ("([A-Z]*[0-9]*)( *[\\.|\\-|_] *)(.*)");
372
                if (Exp.indexIn(masterPage) != -1)
373
                        masterPage = Exp.cap(1);
18503 craig 374
                QRect d = QRect(0, 0, ret.width(), ret.height());
375
                p.setFont(QFont("Helvetica", 7, QFont::Normal));
18558 jghali 376
                p.drawText(d, Qt::AlignCenter, tmp+"\n"+masterPage);
17513 jghali 377
                p.end();
378
                if( !pixin.mask().isNull() )
379
                        ret.setMask( pixin.mask() );
380
        }
381
        return ret;
382
}
383
 
384
void PagePalette_Pages::changeEvent(QEvent *e)
385
{
386
        if (e->type() == QEvent::LanguageChange)
387
        {
388
                languageChange();
389
                return;
390
        }
391
 
392
        QWidget::changeEvent(e);
393
}
394
 
395
void PagePalette_Pages::languageChange()
396
{
397
        setWindowTitle( tr( "Arrange Pages" ) );
398
        textLabel1->setText( tr( "Available Master Pages:" ) );
399
        textLabel2->setText( tr( "Document Pages:" ) );
400
 
401
        masterPageList->setToolTip( "<qt>" + tr( "List of master pages in the document. Master page names may be dragged onto the page view below to apply master pages, or onto the empty space between pages to create new pages." ) + "</qt>");
402
        pageView->setToolTip( "<qt>" + tr( "List of normal pages in the document, shown with the document layout. Pages may be dragged to rearrange or delete them.")  + "</qt>");
403
        trash->setToolTip( "<qt>" + tr("Drag pages or master pages onto the trash to delete them") + "</qt>");
404
}