Back to index

scribus-ng  1.3.4.dfsg+svn20071115
seiten.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "seiten.h"
00008 #include "seiten.moc"
00009 #include <qcursor.h>
00010 #include "commonstrings.h"
00011 #include "scribus.h"
00012 #include "scribusview.h"
00013 #include "dynamictip.h"
00014 #include "page.h"
00015 #include "pagelayout.h"
00016 #include "sccombobox.h"
00017 extern QPixmap loadIcon(QString nam);
00018 
00019 
00020 /* Code fuer DragObjekt */
00021 SeDrag::SeDrag(QString secret, QWidget * parent, const char * name): QStoredDrag("page/magic", parent, name)
00022 {
00023        QByteArray data(secret.length());
00024        for (uint a = 0; a < secret.length(); ++a)
00025               data[a]= QChar(secret[a]);
00026        setEncodedData( data );
00027 }
00028 
00029 bool SeDrag::canDecode( QDragMoveEvent* e )
00030 {
00031        return e->provides("page/magic");
00032 }
00033 
00034 bool SeDrag::decode( QDropEvent* e, QString& str )
00035 {
00036        QByteArray payload = e->data("page/magic");
00037        if (payload.size())
00038        {
00039               e->accept();
00040               str = "";
00041               for (uint a = 0; a < payload.size(); ++a)
00042                      str += payload[a];
00043               return true;
00044        }
00045        return false;
00046 }
00047 
00048 /* IconItems Code */
00049 SeItem::SeItem(QTable* parent, QString text, uint nr, const QPixmap& Pix)
00050               : QTableItem(parent, QTableItem::Never, "", Pix)
00051 {
00052        pageNumber = nr;
00053        pageName = text;
00054        setWordWrap(true);
00055 }
00056 
00057 const QString& SeItem::getPageName()
00058 {
00059        return pageName;
00060 }
00061 
00062 /* ListBox Subclass */
00063 SeList::SeList(QWidget* parent) : QListBox(parent)
00064 {
00065        Mpressed = false;
00066        setAcceptDrops(true);
00067 }
00068 
00069 void SeList::mouseReleaseEvent(QMouseEvent *m)
00070 {
00071        Mpressed = false;
00072        if (m->button() == RightButton)
00073        {
00074               QPopupMenu *pmen = new QPopupMenu();
00075               qApp->setOverrideCursor(QCursor(ArrowCursor), true);
00076               int px = pmen->insertItem( tr("Show Page Previews"), this, SLOT(ToggleTh()));
00077               if (Thumb)
00078                      pmen->setItemChecked(px, true);
00079               pmen->exec(QCursor::pos());
00080               delete pmen;
00081        }
00082        QListBox::mouseReleaseEvent(m);
00083 }
00084 
00085 void SeList::ToggleTh()
00086 {
00087        Thumb = !Thumb;
00088        emit ThumbChanged();
00089 }
00090 
00091 void SeList::mousePressEvent(QMouseEvent* e)
00092 {
00093        e->accept();
00094        CurItem = 0;
00095        QListBoxItem *i = itemAt(e->pos());
00096        if (i)
00097        {
00098               CurItem = i;
00099               Mpos = e->pos();
00100               Mpressed = true;
00101        }
00102        QListBox::mousePressEvent(e);
00103 }
00104 
00105 void SeList::mouseMoveEvent(QMouseEvent* e)
00106 {
00107        if ((Mpressed) && ((Mpos - e->pos()).manhattanLength() > 4))
00108        {
00109               Mpressed = false;
00110               QListBoxItem *i = itemAt(Mpos);
00111               if (i)
00112               {
00113                      QDragObject *dr = new SeDrag("1"+i->text(), this, "te");
00114                      dr->setPixmap(loadIcon("doc.png"));
00115                      if (!dr->drag())
00116                             qDebug("SeList::mouseMoveEvent: couldn't start drag operation!");;
00117               }
00118        }
00119 }
00120 
00121 /* QTable Subclass */
00122 SeView::SeView(QWidget* parent) : QTable(parent)
00123 {
00124        setDragEnabled(true);
00125        setAcceptDrops(true);
00126        viewport()->setAcceptDrops(true);
00127        setShowGrid(false);
00128        Mpressed = false;
00129        Namen = true;
00130        setFocusPolicy(NoFocus);
00131 }
00132 
00133 void SeView::contentsMousePressEvent(QMouseEvent* e)
00134 {
00135        e->accept();
00136        Mpos = e->pos();
00137        Mpressed = true;
00138 }
00139 
00140 void SeView::contentsMouseReleaseEvent(QMouseEvent* e)
00141 {
00142        e->accept();
00143        Mpressed = false;
00144 /*     if (e->button() == RightButton)
00145        {
00146               QPopupMenu *pmen = new QPopupMenu();
00147               qApp->setOverrideCursor(QCursor(ArrowCursor), true);
00148               int px = pmen->insertItem( tr("Show Master Page Names"), this, SLOT(ToggleNam()));
00149               if (Namen)
00150                      pmen->setItemChecked(px, true);
00151               pmen->exec(QCursor::pos());
00152               delete pmen;
00153        } */
00154        emit Click(rowAt(e->pos().y()), columnAt(e->pos().x()), e->button());
00155 }
00156 
00157 void SeView::ToggleNam()
00158 {
00159 /*     Namen = !Namen;
00160        int val = 35;
00161        if (Namen)
00162               val = 100;
00163        setColumnWidth(1, val);
00164        setColumnWidth(3, val);
00165        hide();
00166        show(); */
00167 }
00168 
00169 void SeView::contentsMouseMoveEvent(QMouseEvent* e)
00170 {
00171        if ((Mpressed) && ((Mpos - e->pos()).manhattanLength() > 4))
00172        {
00173               Mpressed = false;
00174               int a = rowAt(e->pos().y());
00175               int b = columnAt(e->pos().x());
00176               if ((a != -1) && (b != -1))
00177               {
00178                      QTableItem* ite = item(a, b);
00179                      if (ite == 0)
00180                             return;
00181                      SeItem* it = (SeItem*)ite;
00182                      QString str(it->pageName);
00183                      bool dummy;
00184                      int p = GetPage(a, b, &dummy);
00185                      QString tmp;
00186                      QDragObject *dr = new SeDrag("2 "+tmp.setNum(p)+" "+str, this, "te");
00187                      dr->setPixmap(loadIcon("doc.png"));
00188                      dr->drag();
00189               }
00190        }
00191        QTable::contentsMouseMoveEvent(e);
00192 }
00193 
00194 void SeView::contentsDropEvent(QDropEvent * e)
00195 {
00196        QString str, tmp;
00197        bool lastPage = false;
00198        if (SeDrag::decode(e, str))
00199        {
00200               ClearPix();
00201               if (str.startsWith("1"))
00202               {
00203                      int a = rowAt(e->pos().y());
00204                      int b = columnAt(e->pos().x());
00205                      int p;
00206                      tmp = str.remove(0,1);
00207                      if ((a == -1) || (b == -1))
00208                             return;
00209                      if (a == numRows()-1)
00210                      {
00211                             emit NewPage(MaxC+1, tmp);
00212                             return;
00213                      }
00214                      p = GetPage(a, b, &lastPage);
00215                      if (numCols() == 1)
00216                      {
00217                             if ((a % 2) == 0)
00218                                    emit NewPage(p, tmp);
00219                             else
00220                             {
00221                                    emit UseTemp(tmp, p);
00222                                    QTableItem* ite = item(a, b);
00223                                    if (ite == 0)
00224                                           return;
00225                                    SeItem* it = (SeItem*)ite;
00226                                    it->pageName = tmp;
00227                             }
00228                             return;
00229                      }
00230                      else
00231                      {
00232                             if ((b % 2) == 0)
00233                             {
00234                                    if (lastPage)
00235                                           emit NewPage(p+1, tmp);
00236                                    else
00237                                           emit NewPage(p, tmp);
00238                             }
00239                             else
00240                             {
00241                                    emit UseTemp(tmp, p);
00242                                    QTableItem* ite = item(a, b);
00243                                    if (ite == 0)
00244                                           return;
00245                                    SeItem* it = (SeItem*)ite;
00246                                    it->pageName = tmp;
00247                             }
00248                             return;
00249                      }
00250               }
00251               if (str.startsWith("2"))
00252               {
00253                      int st = str.find(" ");
00254                      int en = str.find(" ", st+1);
00255                      tmp = str.mid(en+1);
00256                      int dr = str.mid(st, en-st).toInt();
00257                      int a = rowAt(e->pos().y());
00258                      int b = columnAt(e->pos().x());
00259                      int p;
00260                      if ((a == -1) || (b == -1))
00261                             return;
00262                      QTableItem* ite = item(a, b);
00263                      p = GetPage(a, b, &lastPage);
00264                      if (a == numRows()-1)
00265                      {
00266                             emit MovePage(dr, p+1);
00267                             return;
00268                      }
00269                      if (numCols() == 1)
00270                      {
00271                             if ((a % 2) == 0)
00272                                    emit MovePage(dr, p);
00273                             else
00274                             {
00275                                    emit UseTemp(tmp, p);
00276                                    if (ite == 0)
00277                                           return;
00278                                    SeItem* it = (SeItem*)ite;
00279                                    it->pageName = tmp;
00280                             }
00281                             return;
00282                      }
00283                      else
00284                      {
00285                             if ((b % 2) == 0)
00286                             {
00287                                    if (lastPage)
00288                                           emit MovePage(dr, p+1);
00289                                    else
00290                                           emit MovePage(dr, p);
00291                             }
00292                             else
00293                             {
00294                                    emit UseTemp(tmp, p);
00295                                    if (ite == 0)
00296                                           return;
00297                                    SeItem* it = (SeItem*)ite;
00298                                    it->pageName = tmp;
00299                             }
00300                             return;
00301                      }
00302               }
00303        }
00304 }
00305 
00306 void SeView::contentsDragEnterEvent(QDragEnterEvent *e)
00307 {
00308        if (SeDrag::canDecode(e))
00309               e->accept();
00310 }
00311 
00312 void SeView::contentsDragLeaveEvent(QDragLeaveEvent *)
00313 {
00314        ClearPix();
00315 }
00316 
00317 void SeView::contentsDragMoveEvent(QDragMoveEvent *e)
00318 {
00319        QString str, tmp;
00320        if (SeDrag::decode(e, str))
00321        {
00322               int a = rowAt(e->pos().y());
00323               int b = columnAt(e->pos().x());
00324               ClearPix();
00325               if ((a == -1) || (b == -1))
00326                      return;
00327               if (numCols() == 1)
00328               {
00329                      if ((a % 2) == 0)
00330                      {
00331                             QPixmap pm;
00332                             pm = QPixmap(columnWidth(b), rowHeight(a));
00333                             pm.fill(darkBlue);
00334                             setPixmap(a, 0, pm);
00335                      }
00336               }
00337               else
00338               {
00339                      if (((b % 2) == 0) || (a == numRows()-1))
00340                      {
00341                             QPixmap pm;
00342                             pm = QPixmap(columnWidth(b), rowHeight(a));
00343                             pm.fill(darkBlue);
00344                             setPixmap(a, b, pm);
00345                      }
00346               }
00347        }
00348 }
00349 
00350 void SeView::ClearPix()
00351 {
00352        int counter = 0;
00353        int rowcounter = 0;
00354        for (int a = 0; a < numRows(); ++a)
00355        {
00356               counter = 0;
00357               if (numCols() == 1)
00358               {
00359                      if ((a % 2) == 0)
00360                      {
00361                             clearCell(rowcounter, 0);
00362                             rowcounter += 2;
00363                      }
00364               }
00365               else
00366               {
00367                      for (int b = 0; b < numCols(); ++b)
00368                      {
00369                             if ((b % 2) == 0)
00370                             {
00371                                    clearCell(rowcounter, counter);
00372                                    counter += 2;
00373                             }
00374                      }
00375                      rowcounter++;
00376               }
00377        }
00378        for (int c = 0; c < numCols(); ++c)
00379        {
00380               clearCell(numRows()-1, c);
00381        }
00382 }
00383 
00384 int SeView::GetPage(int r, int c, bool *last)
00385 {
00386        int counter = firstP;
00387        int rowcounter = 0;
00388        int ret = MaxC;
00389        *last = false;
00390        if (r == numRows()-1)
00391        {
00392               *last = true;
00393               return ret;
00394        }
00395        if ((r == 0) && (c < firstP*colmult+coladd))
00396               return 0;
00397        for (int a = 0; a < MaxC+1; ++a)
00398        {
00399               if ((rowcounter*rowmult+rowadd == r) && (counter*colmult+coladd == c))
00400               {
00401                      ret = a;
00402                      return ret;
00403               }
00404               else
00405               {
00406                      if (numCols() == 1)
00407                      {
00408                             if ((rowcounter*rowmult) == r)
00409                             {
00410                                    ret = a;
00411                                    return ret;
00412                             }
00413                      }
00414                      else
00415                      {
00416                             if ((counter*colmult == c) && (rowcounter*rowmult+rowadd == r))
00417                             {
00418                                    ret = a;
00419                                    return ret;
00420                             }
00421                      }
00422               }
00423               counter++;
00424               if (counter > cols-1)
00425               {
00426                      counter = 0;
00427                      rowcounter++;
00428               }
00429        }
00430        *last = true;
00431        return ret;
00432 }
00433 
00434 /* Der Muelleimer */
00435 TrashBin::TrashBin(QWidget * parent) : QLabel(parent, "Trash")
00436 {
00437        Normal = loadIcon("trashcan.png");
00438        Offen = loadIcon("trashcan2.png");
00439        setPixmap(Normal);
00440        setScaledContents(false);
00441        setAcceptDrops(true);
00442 }
00443 
00444 void TrashBin::dragEnterEvent(QDragEnterEvent *e)
00445 {
00446        if (SeDrag::canDecode(e))
00447        {
00448               e->accept();
00449               setPixmap(Offen);
00450        }
00451 }
00452 
00453 void TrashBin::dragLeaveEvent(QDragLeaveEvent *)
00454 {
00455        setPixmap(Normal);
00456 }
00457 
00458 void TrashBin::dropEvent(QDropEvent * e)
00459 {
00460        setPixmap(Normal);
00461        QString str, tmp;
00462        if (SeDrag::decode(e, str))
00463        {
00464               if (str.startsWith("2"))
00465               {
00466                      int st = str.find(" ");
00467                      int en = str.find(" ", st+1);
00468                      emit DelPage(str.mid(st, en-st).toInt());
00469               }
00470               if (str.startsWith("1"))
00471               {
00472                      tmp = str.remove(0,1);
00473                      emit DelMaster(tmp);
00474               }
00475        }
00476 }
00477 
00478 
00479 PagePalette::PagePalette(QWidget* parent) : ScrPaletteBase( parent, "SP", false, 0)
00480 {
00481        m_scMW=(ScribusMainWindow*)parent;
00482        PagePaletteLayout = new QVBoxLayout( this );
00483        PagePaletteLayout->setSpacing( 5 );
00484        PagePaletteLayout->setMargin( 5 );
00485        Splitter1 = new QSplitter( this, "Splitter1" );
00486        Splitter1->setOrientation( QSplitter::Vertical );
00487        QWidget* privateLayoutWidget = new QWidget( Splitter1, "Layout2" );
00488        Layout2 = new QVBoxLayout( privateLayoutWidget, 0, 5, "Layout2");
00489        TextLabel1 = new QLabel( privateLayoutWidget, "TextLabel1" );
00490        Layout2->addWidget( TextLabel1 );
00491        masterPageList = new SeList(privateLayoutWidget);
00492        masterPageList->setMinimumSize(QSize(130,70));
00493        masterPageList->Thumb = false;
00494        Layout2->addWidget( masterPageList );
00495        QWidget* privateLayoutWidget_2 = new QWidget( Splitter1, "Layout3" );
00496        Layout3 = new QVBoxLayout( privateLayoutWidget_2, 0, 5, "Layout3");
00497        TextLabel2 = new QLabel( privateLayoutWidget_2, "TextLabel2" );
00498        Layout3->addWidget( TextLabel2 );
00499        pageView = new SeView(privateLayoutWidget_2);
00500        pageView->setLeftMargin(0);
00501        pageView->verticalHeader()->hide();
00502        pageView->setTopMargin(0);
00503        pageView->horizontalHeader()->hide();
00504        pageView->setSorting(false);
00505        pageView->setSelectionMode(QTable::NoSelection);
00506        pageView->setColumnMovingEnabled(false);
00507        pageView->setRowMovingEnabled(false);
00508        pageView->setNumRows(1);
00509        pageView->setNumCols(1);
00510        pageView->setMinimumSize(QSize(130,120));
00511        Layout3->addWidget( pageView );
00512        PagePaletteLayout->addWidget( Splitter1 );
00513 
00514        Layout1 = new QHBoxLayout;
00515        Layout1->setSpacing( 5 );
00516        Layout1->setMargin( 0 );
00517        QValueList<PageSet> dummy;
00518        dummy.clear();
00519        struct PageSet pageS;
00520        pageS.Name = tr( "Double sided" );
00521        pageS.FirstPage = 0;
00522        pageS.Rows = 1;
00523        pageS.Columns = 1;
00524        pageS.GapHorizontal = 0.0;
00525        pageS.GapVertical = 0.0;
00526        pageS.GapBelow = 40.0;
00527        pageS.pageNames.clear();
00528        pageS.pageNames.append( tr("Middle Right"));
00529        dummy.append(pageS);
00530        pageLayout = new PageLayouts(this, dummy, false);
00531        Layout1->addWidget( pageLayout );
00532 
00533        QSpacerItem* spacer = new QSpacerItem( 15, 15, QSizePolicy::Expanding, QSizePolicy::Minimum );
00534        Layout1->addItem( spacer );
00535 
00536        Trash = new TrashBin( this );
00537        Trash->setMinimumSize(QSize(22,22));
00538        Layout1->addWidget( Trash );
00539        PagePaletteLayout->addLayout( Layout1 );
00540        pix = loadIcon("32/page-simple.png");
00541        currView = 0;
00542        Rebuild();
00543        languageChange();
00544        dynTip = new DynamicTip(pageView);
00545        connect(masterPageList, SIGNAL(doubleClicked(QListBoxItem*)), this, SLOT(selMasterPage()));
00546        connect(masterPageList, SIGNAL(ThumbChanged()), this, SLOT(RebuildTemp()));
00547        connect(pageView, SIGNAL(Click(int, int, int)), this, SLOT(GotoPage(int, int, int)));
00548        connect(pageView, SIGNAL(MovePage(int, int)), this, SLOT(MPage(int, int)));
00549        connect(Trash, SIGNAL(DelMaster(QString)), this, SLOT(DelMPage(QString)));
00550        connect(pageLayout, SIGNAL(selectedLayout(int )), this, SLOT(handlePageLayout(int )));
00551        connect(pageLayout, SIGNAL(selectedFirstPage(int )), this, SLOT(handleFirstPage(int )));
00552        connect(this, SIGNAL(EditTemp(QString)), m_scMW, SLOT(manageMasterPages(QString)));
00553        connect(pageView, SIGNAL(UseTemp(QString, int)), m_scMW, SLOT(Apply_MasterPage(QString, int)));
00554        connect(pageView, SIGNAL(NewPage(int, QString)), m_scMW, SLOT(slotNewPageP(int, QString)));
00555        connect(Trash, SIGNAL(DelPage(int)), m_scMW, SLOT(DeletePage2(int)));
00556        connect(this, SIGNAL(GotoSeite(int)), m_scMW, SLOT(selectPagesFromOutlines(int)));
00557        
00558        QToolTip::add(Trash, "<qt>" + tr("Drag pages or master pages onto the trashbin to delete them") + "</qt>");
00559        QToolTip::add(masterPageList, "<qt>" + tr("Here are all your master pages. To create a new page, drag a master page to the page view below") + "</qt>");
00560 }
00561 
00562 void PagePalette::DelMPage(QString tmp)
00563 {
00564        if (tmp == CommonStrings::trMasterPageNormal)
00565               return;
00566        int Nr = currView->Doc->MasterNames[tmp];
00567        Page* Seite = currView->Doc->MasterPages.at(Nr);
00568        currView->Doc->MasterPages.remove(Nr);
00569        delete Seite;
00570        currView->Doc->MasterNames.clear();
00571        for (uint aa=0; aa < currView->Doc->MasterPages.count(); ++aa)
00572        {
00573               Seite = currView->Doc->MasterPages.at(aa);
00574               Seite->setPageNr(aa);
00575               if (currView->Doc->currentPageLayout == doublePage)
00576               {
00577                      Seite->Margins.Left = Seite->LeftPg ? currView->Doc->pageMargins.Right : currView->Doc->pageMargins.Left;
00578                      Seite->Margins.Right= Seite->LeftPg? currView->Doc->pageMargins.Left : currView->Doc->pageMargins.Right;
00579               }
00580               else
00581               {
00582                      Seite->Margins.Right = currView->Doc->pageMargins.Right;
00583                      Seite->Margins.Left = currView->Doc->pageMargins.Left;
00584               }
00585               Seite->Margins.Top = currView->Doc->pageMargins.Top;
00586               Seite->Margins.Bottom = currView->Doc->pageMargins.Bottom;
00587               currView->Doc->MasterNames[Seite->pageName()] = aa;
00588        }
00589        for (uint b=0; b<currView->Doc->DocPages.count(); ++b)
00590        {
00591               if (currView->Doc->DocPages.at(b)->MPageNam == tmp)
00592                      currView->Doc->DocPages.at(b)->MPageNam = CommonStrings::masterPageNormal;
00593        }
00594        currView->DrawNew();
00595        RebuildTemp();
00596        RebuildPage();
00597        currView->Doc->setModified(true);
00598 }
00599 
00600 void PagePalette::MPage(int r, int c)
00601 {
00602        if (r == c)
00603               return;
00604        if (c > pageView->MaxC)
00605               currView->Doc->movePage(r, r + 1, c, 2);
00606        else
00607               currView->Doc->movePage(r, r + 1, c, 0);
00608        currView->reformPages();
00609        RebuildPage();
00610        currView->DrawNew();
00611 //CB done by doc::reformpages
00612 //     currView->Doc->setModified(true);
00613 }
00614 
00615 void PagePalette::GotoPage(int r, int c, int b)
00616 {
00617        int p;
00618        bool dummy;
00619        if ((b == LeftButton) && (r != -1) && (c != -1))
00620        {
00621               p = pageView->GetPage(r, c, &dummy);
00622               emit GotoSeite(p);
00623        }
00624 }
00625 
00626 void PagePalette::enablePalette(const bool enabled)
00627 {
00628        pageView->setEnabled(enabled);
00629        masterPageList->setEnabled(enabled);
00630        pageLayout->setEnabled(enabled);
00631 }
00632 
00633 void PagePalette::handlePageLayout(int layout)
00634 {
00635        double tpr = currView->Doc->pageMargins.Top;
00636        double lr = currView->Doc->pageMargins.Left;
00637        double rr = currView->Doc->pageMargins.Right;
00638        double br = currView->Doc->pageMargins.Bottom;
00639        pageLayout->selectFirstP(currView->Doc->pageSets[layout].FirstPage);
00640        currView->Doc->resetPage(tpr, lr, rr, br, layout);
00641        currView->reformPages();
00642        currView->DrawNew();
00643        currView->GotoPage(currView->Doc->currentPageNumber());
00644        RebuildPage();
00645 //CB done by doc::reformpages
00646 //     currView->Doc->setModified(true);
00647 }
00648 
00649 void PagePalette::handleFirstPage(int fp)
00650 {
00651        currView->Doc->pageSets[currView->Doc->currentPageLayout].FirstPage = fp;
00652        currView->reformPages();
00653        currView->DrawNew();
00654        currView->GotoPage(currView->Doc->currentPageNumber());
00655        RebuildPage();
00656 //CB done by doc::reformpages
00657 //     currView->Doc->setModified(true);
00658 }
00659 
00660 void PagePalette::RebuildTemp()
00661 {
00662        if (m_scMW->ScriptRunning)
00663               return;
00664        masterPageList->clear();
00665        if (currView == 0)
00666               return;
00667        QPixmap pm;
00668        QMap<QString,int>::Iterator it;
00669        for (it = currView->Doc->MasterNames.begin(); it != currView->Doc->MasterNames.end(); ++it)
00670        {
00671               if (masterPageList->Thumb)
00672               {
00673                      pm.convertFromImage(currView->MPageToPixmap(it.key(),60));
00674                      masterPageList->insertItem(pm, it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key());
00675               }
00676               else
00677                      masterPageList->insertItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key());
00678        }
00679 }
00680 
00681 void PagePalette::RebuildPage()
00682 {
00683        if (m_scMW->ScriptRunning)
00684               return;
00685        QString str;
00686        disconnect(pageLayout, SIGNAL(selectedLayout(int )), this, SLOT(handlePageLayout(int )));
00687        disconnect(pageLayout, SIGNAL(selectedFirstPage(int )), this, SLOT(handleFirstPage(int )));
00688        pageView->setNumRows(1);
00689        pageView->setNumCols(1);
00690        if (currView == 0)
00691        {
00692               connect(pageLayout, SIGNAL(selectedLayout(int )), this, SLOT(handlePageLayout(int )));
00693               connect(pageLayout, SIGNAL(selectedFirstPage(int )), this, SLOT(handleFirstPage(int )));
00694               return;
00695        }
00696        pageLayout->updateLayoutSelector(currView->Doc->pageSets);
00697        pageLayout->selectItem(currView->Doc->currentPageLayout);
00698        pageLayout->firstPage->setCurrentItem(currView->Doc->pageSets[currView->Doc->currentPageLayout].FirstPage);
00699        pageView->MaxC = currView->Doc->Pages->count()-1;
00700        int counter, rowcounter, colmult, rowmult, coladd,rowadd;
00701        counter = currView->Doc->pageSets[currView->Doc->currentPageLayout].FirstPage;
00702        int cols = currView->Doc->pageSets[currView->Doc->currentPageLayout].Columns;
00703        int rows = (currView->Doc->Pages->count()+counter) / currView->Doc->pageSets[currView->Doc->currentPageLayout].Columns;
00704        if (((currView->Doc->Pages->count()+counter) % currView->Doc->pageSets[currView->Doc->currentPageLayout].Columns) != 0)
00705               rows++;
00706        rowcounter = 0;
00707        if (cols == 1)
00708        {
00709               pageView->setNumCols(cols);
00710               pageView->setNumRows(rows*2+1);
00711               colmult = 1;
00712               coladd = 0;
00713               rowmult = 2;
00714               rowadd = 1;
00715        }
00716        else
00717        {
00718               pageView->setNumCols(cols*2);
00719               pageView->setNumRows(rows+1);
00720               colmult = 2;
00721               coladd = 1;
00722               rowmult = 1;
00723               rowadd = 0;
00724        }
00725        pageView->coladd = coladd;
00726        pageView->colmult = colmult;
00727        pageView->rowadd = rowadd;
00728        pageView->rowmult = rowmult;
00729        pageView->firstP = counter;
00730        pageView->cols = currView->Doc->pageSets[currView->Doc->currentPageLayout].Columns;
00731        pageList.clear();
00732        for (uint a = 0; a < currView->Doc->Pages->count(); ++a)
00733        {
00734               str = currView->Doc->Pages->at(a)->MPageNam;
00735               SeItem *it = new SeItem(pageView, str, a, CreateIcon(a, pix));
00736               pageList.append(it);
00737               pageView->setItem(rowcounter*rowmult+rowadd, counter*colmult+coladd, (QTableItem *)it);
00738               pageView->setColumnWidth(counter*colmult+coladd, pix.width());
00739               if (cols == 1)
00740               {
00741                      pageView->setRowHeight(rowcounter*rowmult, 10);
00742                      pageView->setRowHeight(rowcounter*rowmult+rowadd, pix.height());
00743               }
00744               else
00745                      pageView->setRowHeight(rowcounter*rowmult+rowadd, pix.height()+5);
00746               counter++;
00747               if (counter > currView->Doc->pageSets[currView->Doc->currentPageLayout].Columns-1)
00748               {
00749                      counter = 0;
00750                      rowcounter++;
00751               }
00752        }
00753        pageView->setRowHeight(pageView->numRows()-1, 10);
00754        counter = 0;
00755        if (cols != 1)
00756        {
00757               for (int c = 0; c < pageView->numCols(); ++c)
00758               {
00759                      if ((counter % 2) == 0)
00760                             pageView->setColumnWidth(counter, 10);
00761                      else
00762                             pageView->setColumnWidth(counter, pix.width());
00763                      counter++;
00764               }
00765        }
00766        pageView->repaint();
00767        if (currView != 0)
00768               markPage(currView->Doc->currentPageNumber());
00769        connect(pageLayout, SIGNAL(selectedLayout(int )), this, SLOT(handlePageLayout(int )));
00770        connect(pageLayout, SIGNAL(selectedFirstPage(int )), this, SLOT(handleFirstPage(int )));
00771 }
00772 
00773 void PagePalette::Rebuild()
00774 {
00775        RebuildTemp();
00776        RebuildPage();
00777        enablePalette(currView != 0);
00778 }
00779 
00780 void PagePalette::markPage(uint nr)
00781 {
00782        if (currView != 0)
00783        {
00784               SeItem *it;
00785               for (uint a = 0; a < pageList.count(); a++)
00786               {
00787                      it = pageList.at(a);
00788                      if (it->pageNumber == nr)
00789                      {
00790                             pageView->clearSelection();
00791                             pageView->selectCells(it->row(), it->col(), it->row(), it->col());
00792                             break;
00793                      }
00794               }
00795        }
00796 }
00797 
00798 void PagePalette::setView(ScribusView *view)
00799 {
00800        currView = view;
00801 }
00802 
00803 void PagePalette::selMasterPage()
00804 {
00805        if (masterPageList->CurItem != 0)
00806               emit EditTemp(masterPageList->CurItem->text());
00807 }
00808 
00809 QPixmap PagePalette::CreateIcon(int nr, QPixmap pixin)
00810 {
00811        QPainter p;
00812        // Necessary on windows to ensure the pixmap is drawable
00813        QPixmap ret(pixin.width(), pixin.height(), pixin.depth());
00814        if (p.begin(&ret))
00815        {
00816               bitBlt( &ret, 0, 0, &pixin, 0, 0, pixin.width(), pixin.height() );
00817               if( pixin.mask() )
00818                      ret.setMask( *pixin.mask() );
00819               p.setBrush(white);
00820               p.setBackgroundColor(white);
00821               p.setBackgroundMode(QPainter::OpaqueMode);
00822               p.setPen(QPen(black, 1, SolidLine, FlatCap, MiterJoin));
00823               p.setFont(QFont("Helvetica", 12, QFont::Bold));
00824               //QString tmp = tmp.setNum(nr+1);
00825               QString tmp(currView->Doc->getSectionPageNumberForPageIndex(nr));
00826               if (tmp.isEmpty())
00827                      tmp = tmp.setNum(nr+1);
00828               QRect b = p.fontMetrics().boundingRect(tmp);
00829               QRect c = QRect((ret.width() / 2 - b.width() / 2)-2, (ret.height() / 2 - b.height() / 2)-2, b.width()+4, b.height()+4);
00830               p.drawRect(c);
00831               QRect d = QRect((ret.width() / 2 - b.width() / 2), (ret.height() / 2 - b.height() / 2), b.width(), b.height());
00832               p.setFont(QFont("Helvetica", 10, QFont::Normal));
00833               p.drawText(d, Qt::AlignCenter, tmp);
00834               p.end();
00835        }
00836        return ret;
00837 }
00838 
00839 void PagePalette::languageChange()
00840 {
00841        setCaption( tr( "Arrange Pages" ) );
00842        TextLabel1->setText( tr( "Available Master Pages:" ) );
00843        TextLabel2->setText( tr( "Document Pages:" ) );
00844 }
00845 
00846 //CB Whats this variable returned for.. its always true... ? 
00847 //CB Clean up the interface and stick it behind this member for now
00848 const bool PagePalette::getNamen()
00849 {
00850        return pageView->Namen;
00851 }
00852 
00853 //CB Whats this variable returned for.. its always true... ? 
00854 //CB Clean up the interface and stick it behind this member for now
00855 const bool PagePalette::getThumb()
00856 {
00857        return masterPageList->Thumb;
00858 }