Subversion Repositories Scribus

Rev

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