Back to index

scribus-ng  1.3.4.dfsg+svn20071115
page.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 /***************************************************************************
00008                           page.cpp  -  description
00009                              -------------------
00010     begin                : Sat Apr 7 2001
00011     copyright            : (C) 2001 by Franz Schmid
00012     email                : Franz.Schmid@altmuehlnet.de
00013  ***************************************************************************/
00014 
00015 /***************************************************************************
00016  *                                                                         *
00017  *   This program is free software; you can redistribute it and/or modify  *
00018  *   it under the terms of the GNU General Public License as published by  *
00019  *   the Free Software Foundation; either version 2 of the License, or     *
00020  *   (at your option) any later version.                                   *
00021  *                                                                         *
00022  ***************************************************************************/
00023 
00024 #include "page.h"
00025 #include "scribus.h"
00026 #include "selection.h"
00027 #include "undomanager.h"
00028 #include "undostate.h"
00029 #include "frameedit.h"
00030 #include "guidemanager.h"
00031 
00032 extern QPixmap loadIcon(QString nam);
00033 
00034 
00035 Page::Page(const double x, const double y, const double b, const double h) :
00036        UndoObject(QObject::tr("Page")),
00037        Margins(40,40,40,40),
00038        initialMargins(40,40,40,40),
00039        LeftPg(0),
00040        MPageNam(""),
00041        FromMaster(),
00042        undoManager(UndoManager::instance()),
00043        m_xOffset(x),
00044        m_yOffset(y),
00045        m_width(b),
00046        m_height(h),
00047        m_initialWidth(b),
00048        m_initialHeight(h),
00049        m_PageName(""),
00050        m_Doc(NULL)
00051 {
00052        guides.setPage(this);
00053 }
00054 
00055 Page::~Page()
00056 {
00057        // Clean up any modified template items (unused)
00058        for (PageItem *currItem = FromMaster.first(); currItem; currItem = FromMaster.next())
00059        {
00060               if (currItem->ChangedMasterItem)
00061               {
00062                      FromMaster.remove(currItem);
00063                      delete currItem;
00064               }
00065        }
00066        FromMaster.clear();
00067 }
00068 
00069 void Page::setDocument(ScribusDoc *doc)
00070 {
00071        m_Doc=doc;
00072 }
00073 
00074 void Page::setPageNr(int pageNr)
00075 {
00076        m_pageNr = pageNr;
00077        if (m_PageName.isEmpty())
00078               setUName(QString(QObject::tr("Page") + " %1").arg(m_Doc->FirstPnum + m_pageNr));
00079        else
00080               setUName(m_PageName);
00081 }
00082 
00083 void Page::setPageName(const QString& newName)
00084 {
00085        m_PageName = newName;
00086        if (!newName.isEmpty())
00087               setUName(QObject::tr("Master Page ") + newName);
00088 }
00089 
00090 void Page::restore(UndoState* state, bool isUndo)
00091 {
00092        SimpleState* ss = dynamic_cast<SimpleState*>(state);
00093        if (ss)
00094        {
00095               if (ss->contains("ADD_V"))
00096               {
00097                      double position = ss->getDouble("ADD_V");
00098                      if (isUndo)
00099                             guides.deleteVertical(position, GuideManagerCore::Standard);//removeXGuide(position);
00100                      else
00101                             guides.addVertical(position, GuideManagerCore::Standard);//addXGuide(position);
00102                      m_Doc->scMW()->guidePalette->setupGui();
00103               }
00104               else if (ss->contains("ADD_H"))
00105               {
00106                      double position = ss->getDouble("ADD_H");
00107                      if (isUndo)
00108                             guides.deleteHorizontal(position, GuideManagerCore::Standard);//removeYGuide(position);
00109                      else
00110                             guides.addHorizontal(position, GuideManagerCore::Standard);//addYGuide(position);
00111                      m_Doc->scMW()->guidePalette->setupGui();
00112               }
00113               else if (ss->contains("REMOVE_V"))
00114               {
00115                      double position = ss->getDouble("REMOVE_V");
00116                      if (isUndo)
00117                             guides.addVertical(position, GuideManagerCore::Standard);//addXGuide(position);
00118                      else
00119                             guides.deleteVertical(position, GuideManagerCore::Standard);//removeXGuide(position);
00120                      m_Doc->scMW()->guidePalette->setupGui();
00121               }
00122               else if (ss->contains("REMOVE_H"))
00123               {
00124                      double position = ss->getDouble("REMOVE_H");
00125                      if (isUndo)
00126                             guides.addHorizontal(position, GuideManagerCore::Standard);//addYGuide(position);
00127                      else
00128                             guides.deleteHorizontal(position, GuideManagerCore::Standard);//removeYGuide(position);
00129                      m_Doc->scMW()->guidePalette->setupGui();
00130               }
00131               else if (ss->contains("MOVE_H_FROM"))
00132               {
00133                      double from = ss->getDouble("MOVE_H_FROM");
00134                      double to   = ss->getDouble("MOVE_H_TO");
00135                      if (isUndo)
00136                      {
00137                             guides.deleteHorizontal(to, GuideManagerCore::Standard);//removeYGuide(position);
00138                             guides.addHorizontal(from, GuideManagerCore::Standard);//addYGuide(position);
00139                      }
00140                      else
00141                      {
00142                             guides.deleteHorizontal(from, GuideManagerCore::Standard);//removeYGuide(position);
00143                             guides.addHorizontal(to, GuideManagerCore::Standard);//addYGuide(position);
00144                      }
00145                      m_Doc->scMW()->guidePalette->setupGui();
00146               }
00147               else if (ss->contains("MOVE_V_FROM"))
00148               {
00149                      double from = ss->getDouble("MOVE_V_FROM");
00150                      double to   = ss->getDouble("MOVE_V_TO");
00151                      if (isUndo)
00152                      {
00153                             guides.deleteVertical(to, GuideManagerCore::Standard);//removeXGuide(position);
00154                             guides.addVertical(from, GuideManagerCore::Standard);//removeXGuide(position);
00155                      }
00156                      else
00157                      {
00158                             guides.deleteVertical(from, GuideManagerCore::Standard);//removeXGuide(position);
00159                             guides.addVertical(to, GuideManagerCore::Standard);//removeXGuide(position);
00160                      }
00161                      m_Doc->scMW()->guidePalette->setupGui();
00162               }
00163               // automatic guides
00164               else if (ss->contains("REMOVE_HA_GAP"))
00165               {
00166                      if (isUndo)
00167                      {
00168                             guides.setHorizontalAutoCount(ss->getInt("REMOVE_HA_COUNT"));
00169                             guides.setHorizontalAutoGap(ss->getDouble("REMOVE_HA_GAP"));
00170                             guides.setHorizontalAutoRefer(ss->getInt("REMOVE_HA_REFER"));
00171                      }
00172                      else
00173                      {
00174                             guides.setHorizontalAutoCount(0);
00175                             guides.setHorizontalAutoGap(0.0);
00176                             guides.setHorizontalAutoRefer(0);
00177                      }
00178                      m_Doc->scMW()->guidePalette->setupGui();
00179               }
00180               else if (ss->contains("REMOVE_VA_GAP"))
00181               {
00182                      if (isUndo)
00183                      {
00184                             guides.setVerticalAutoCount(ss->getInt("REMOVE_VA_COUNT"));
00185                             guides.setVerticalAutoGap(ss->getDouble("REMOVE_VA_GAP"));
00186                             guides.setVerticalAutoRefer(ss->getInt("REMOVE_VA_REFER"));
00187                      }
00188                      else
00189                      {
00190                             guides.setVerticalAutoCount(0);
00191                             guides.setVerticalAutoGap(0.0);
00192                             guides.setVerticalAutoRefer(0);
00193                      }
00194                      m_Doc->scMW()->guidePalette->setupGui();
00195               }
00196               else if (ss->contains("CREATE_ITEM"))
00197                      restorePageItemCreation(dynamic_cast<ItemState<PageItem*>*>(ss), isUndo);
00198               else if (ss->contains("DELETE_ITEM"))
00199                      restorePageItemDeletion(dynamic_cast<ItemState<PageItem*>*>(ss), isUndo);
00200               else if (ss->contains("CONVERT_ITEM"))
00201                      restorePageItemConversion(dynamic_cast<ItemState<std::pair<PageItem*, PageItem*> >*>(ss), isUndo);
00202        }
00203 }
00204 
00205 void Page::restorePageItemCreation(ItemState<PageItem*> *state, bool isUndo)
00206 {
00207        if (!state)
00208               return;
00209        
00210        PageItem *ite = state->getItem();
00211        bool oldMPMode=m_Doc->masterPageMode();
00212        m_Doc->setMasterPageMode(!ite->OnMasterPage.isEmpty());
00213        if (m_Doc->EditClip) // switch off from edit shape
00214               m_Doc->scMW()->nodePalette->EndEdit();
00215        if (isUndo)
00216        {
00217               if (m_Doc->m_Selection->findItem(ite)!=-1)
00218               {
00219                      if (m_Doc->appMode == modeEdit)
00220                             m_Doc->scMW()->setAppMode(modeNormal);
00221                      m_Doc->m_Selection->removeItem(ite);
00222               }
00223               m_Doc->view()->Deselect(true);
00224               Selection tempSelection(m_Doc, false);
00225               tempSelection.addItem(ite);
00226               m_Doc->itemSelection_DeleteItem(&tempSelection, false);
00227               /*
00228               m_Doc->m_Selection->clear();
00229               m_Doc->m_Selection->addItem(ite, true);
00230               m_Doc->itemSelection_DeleteItem();
00231               m_Doc->m_Selection->clear();
00232               */
00233        }
00234        else
00235        {
00236               m_Doc->view()->Deselect(true);
00237               m_Doc->Items->append(ite);
00238               ite->ItemNr = m_Doc->Items->count()-1;
00239               m_Doc->view()->updateContents();
00240        }
00241        m_Doc->setMasterPageMode(oldMPMode);
00242 }
00243 
00244 void Page::restorePageItemDeletion(ItemState<PageItem*> *state, bool isUndo)
00245 {
00246        if (!state)
00247               return;
00248        m_Doc->view()->Deselect(true);
00249        PageItem *ite = state->getItem();
00250        bool oldMPMode=m_Doc->masterPageMode();
00251        m_Doc->setMasterPageMode(!ite->OnMasterPage.isEmpty());
00252        if (m_Doc->EditClip) // switch off from edit shape
00253               m_Doc->scMW()->nodePalette->EndEdit();
00254        if (isUndo)
00255        {
00256               //CB #3373 reinsert at old position and renumber items
00257               m_Doc->Items->insert(ite->ItemNr, ite);
00258               m_Doc->renumberItemsInListOrder();
00259 //            m_Doc->Items->append(ite);
00260 //            ite->ItemNr = m_Doc->Items->count()-1;
00261               m_Doc->view()->updateContents();
00262        }
00263        else
00264        {
00265               if (m_Doc->m_Selection->findItem(ite)!=-1)
00266               {
00267                      if (m_Doc->appMode == modeEdit)
00268                             m_Doc->scMW()->setAppMode(modeNormal);
00269                      m_Doc->m_Selection->removeItem(ite);
00270               }
00271               Selection tempSelection(m_Doc, false);
00272               tempSelection.addItem(ite);
00273               m_Doc->itemSelection_DeleteItem(&tempSelection);
00274               /*
00275               m_Doc->m_Selection->clear();
00276               m_Doc->m_Selection->addItem(ite, true);
00277               m_Doc->itemSelection_DeleteItem();
00278               m_Doc->m_Selection->clear();
00279               */
00280        }
00281        m_Doc->setMasterPageMode(oldMPMode);
00282 }
00283 
00284 void Page::restorePageItemConversion(ItemState<std::pair<PageItem*, PageItem*> >*state, bool isUndo)
00285 {
00286        if (!state)
00287               return;
00288 
00289        PageItem *oldItem=state->getItem().first;
00290        PageItem *newItem=state->getItem().second;
00291        bool oldMPMode=m_Doc->masterPageMode();
00292        m_Doc->setMasterPageMode(!oldItem->OnMasterPage.isEmpty());
00293        if (isUndo)
00294        {
00295               m_Doc->Items->take(newItem->ItemNr);
00296               m_Doc->Items->append(oldItem);
00297               oldItem->ItemNr = m_Doc->Items->count()-1;
00298               oldItem->updatePolyClip();
00299               m_Doc->AdjustItemSize(oldItem);
00300        }
00301        else
00302        {
00303               m_Doc->Items->take(oldItem->ItemNr);
00304               m_Doc->Items->append(newItem);
00305               newItem->ItemNr = m_Doc->Items->count()-1;
00306        }
00307        m_Doc->setMasterPageMode(oldMPMode);
00308 }
00309 
00310 void Page::setXOffset(const double newCanvasXOffset)
00311 {
00312        m_xOffset = newCanvasXOffset;
00313 }
00314 
00315 void Page::setYOffset(const double newCanvasYOffset)
00316 {
00317        m_yOffset = newCanvasYOffset;
00318 }
00319 
00320 void Page::setWidth(const double newWidth)
00321 {
00322        m_width = newWidth;
00323 }
00324 
00325 void Page::setHeight(const double newHeight)
00326 {
00327        m_height = newHeight;
00328 }
00329 
00330 void Page::setInitialWidth(const double newInitialWidth)
00331 {
00332        m_initialWidth = newInitialWidth;
00333 }
00334 
00335 void Page::setInitialHeight(const double newInitialHeight)
00336 {
00337        m_initialHeight = newInitialHeight;
00338 }
00339 
00340 void Page::setPageSectionNumber(const QString& newPageSectionNumber)
00341 {
00342        m_pageSectionNumber=newPageSectionNumber;
00343 }
00344 
00345 void Page::copySizingProperties(Page* sourcePage, const MarginStruct& pageMargins)
00346 {
00347        if (sourcePage==NULL)
00348               return;
00349        m_pageSize = sourcePage->m_pageSize;
00350        PageOri = sourcePage->PageOri;
00351        m_width=sourcePage->m_width;
00352        m_height=sourcePage->m_height;
00353        m_initialWidth = sourcePage->m_initialWidth;
00354        m_initialHeight = sourcePage->m_initialHeight;
00355 
00356        Margins.Top = pageMargins.Top;
00357        Margins.Bottom = pageMargins.Bottom;
00358        Margins.Left = pageMargins.Left;//todo fix for layouts
00359        Margins.Right = pageMargins.Right;
00360        initialMargins.Top = pageMargins.Top;
00361        initialMargins.Bottom = pageMargins.Bottom;
00362        initialMargins.Left = pageMargins.Left;
00363        initialMargins.Right = pageMargins.Right;
00364 }