Back to index

scribus-ng  1.3.4.dfsg+svn20071115
scribus.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                           scribus.cpp  -  description
00009                              -------------------
00010     begin                : Fre Apr  6 21:09:31 CEST 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 <qaccel.h>
00025 #include <qapplication.h>
00026 #include <qeventloop.h>
00027 #include <qcolordialog.h>
00028 #include <qcolor.h>
00029 #include <qiconset.h>
00030 #include <qtextstream.h>
00031 #include <qstylefactory.h>
00032 #include <qregexp.h>
00033 #include <qtextcodec.h>
00034 #include <qcursor.h>
00035 #include <qvbox.h>
00036 #include <qpixmap.h>
00037 #include <qkeysequence.h>
00038 
00039 #include <cstdio>
00040 #include <cstdlib>
00041 #include <cmath>
00042 #include <cassert>
00043 
00044 #include "scconfig.h"
00045 
00046 #ifdef HAVE_DLFCN_H
00047 #include <dlfcn.h>
00048 #endif
00049 
00050 #ifdef HAVE_UNISTD_H
00051 #include <unistd.h>
00052 #endif
00053 
00054 #include <iostream>
00055 #include <sstream>
00056 #include <signal.h>
00057 #include <string>
00058 
00059 #include "sccombobox.h"
00060 #include "scribusapp.h"
00061 #include "scribuscore.h"
00062 #include "scribus.h"
00063 #include "scribus.moc"
00064 #include "newfile.h"
00065 #include "page.h"
00066 #include "query.h"
00067 #include "mdup.h"
00068 #include "multipleduplicate.h"
00069 #include "docinfo.h"
00070 #include "reformdoc.h"
00071 #include "serializer.h"
00072 #include "aligndistribute.h"
00073 #include "fmitem.h"
00074 #include "fontprefs.h"
00075 #include "prefs.h"
00076 #include "prefscontext.h"
00077 #include "prefstable.h"
00078 #include "pdfopts.h"
00079 #include "pdflib.h"
00080 #include "inspage.h"
00081 #include "delpages.h"
00082 #include "movepage.h"
00083 #include "helpbrowser.h"
00084 #include "scribusXml.h"
00085 #include "about.h"
00086 #include "aboutplugins.h"
00087 #include "pslib.h"
00088 #include "druck.h"
00089 #include "editformats.h"
00090 #include "muster.h"
00091 #include "newtemp.h"
00092 #include "applytemplatedialog.h"
00093 #include "picstatus.h"
00094 #include "customfdialog.h"
00095 #include "cmsprefs.h"
00096 #include "annot.h"
00097 #include "annota.h"
00098 #include "javadocs.h"
00099 #include "colorm.h"
00100 #include "mpalette.h"
00101 #include "cpalette.h"
00102 #include "bookpalette.h"
00103 #include "seiten.h"
00104 #include "layers.h"
00105 #include "frameedit.h"
00106 #include "splash.h"
00107 #include "measurements.h"
00108 #include "gtgettext.h"
00109 #include "fileloader.h"
00110 #include "arrowchooser.h"
00111 #include "tabtypography.h"
00112 #include "tabguides.h"
00113 #include "tabtools.h"
00114 #include "undogui.h"
00115 #include "filewatcher.h"
00116 #include "charselect.h"
00117 #include "checkDocument.h"
00118 #include "tabcheckdoc.h"
00119 #include "tabpdfoptions.h"
00120 #include "docitemattrprefs.h"
00121 #include "pageitemattributes.h"
00122 #include "pageitem_textframe.h"
00123 #include "pageitem_imageframe.h"
00124 #include "tocindexprefs.h"
00125 #include "tocgenerator.h"
00126 #include "collect4output.h"
00127 #include "fpoint.h"
00128 #include "fpointarray.h"
00129 #include "hysettings.h"
00130 #include "guidemanager.h"
00131 #include "mergedoc.h"
00132 #include "lineformats.h"
00133 #include "story.h"
00134 #include "autoform.h"
00135 #include "tabmanager.h"
00136 #include "search.h"
00137 #include "fontcombo.h"
00138 #include "colorcombo.h"
00139 #include "prefsfile.h"
00140 #include "undomanager.h"
00141 #include "polygonwidget.h"
00142 #include "werktoolb.h"
00143 #include "units.h"
00144 #include "hruler.h"
00145 #include "vruler.h"
00146 #include "pageselector.h"
00147 #include "scraction.h"
00148 #include "menumanager.h"
00149 #include "undostate.h"
00150 #include "tree.h"
00151 #include "scrap.h"
00152 #include "pluginmanager.h"
00153 #include "scpaths.h"
00154 #include "pdfoptions.h"
00155 #include "actionmanager.h"
00156 #include "documentinformation.h"
00157 #include "effectsdialog.h"
00158 #include "documentchecker.h"
00159 #include "gsutil.h"
00160 #include "pagesize.h"
00161 #include "loremipsum.h"
00162 #include "marginWidget.h"
00163 #include "margindialog.h"
00164 #include "prefsmanager.h"
00165 #include "pagelayout.h"
00166 #include "commonstrings.h"
00167 #include "preview.h"
00168 #include "scribuswin.h"
00169 #include "hyphenator.h"
00170 #include "scmessagebox.h"
00171 #include "imageinfodialog.h"
00172 #include "resourcecollection.h"
00173 #include "selection.h"
00174 #include "stylemanager.h"
00175 #include "smlinestyle.h"
00176 #include "util.h"
00177 #include "text/nlsconfig.h"
00178 #include "plugins/formatidlist.h"
00179 #include "scgtplugin.h"
00180 #include "stencilreader.h"
00181 #include "langmgr.h"
00182 #include "smtextstyles.h"
00183 #include "insertaframe.h"
00184 #include "patterndialog.h"
00185 #include "sccolorengine.h"
00186 #include "desaxe/saxXML.h"
00187 #include "desaxe/digester.h"
00188 #include "desaxe/simple_actions.h"
00189 
00190 #if defined(_WIN32)
00191 #include "scwinprint.h"
00192 #include "scdocoutput_ps2.h"
00193 #endif
00194 
00195 using namespace std;
00196 
00197 bool previewDinUse;
00198 bool printDinUse;
00199 
00200 QString DocDir;
00201 
00202 //extern ScribusCore* ScCore;
00203 extern ScribusQApp* ScQApp;
00204 extern bool emergencyActivated;
00205 
00206 ScribusMainWindow::ScribusMainWindow()
00207 {
00208        actionManager=0;
00209        scrMenuMgr=0;
00210        prefsManager=0;
00211        mainWindowStatusLabel=0;
00212        ExternalApp=0;
00213 #ifdef Q_WS_MAC
00214        noIcon = loadIcon("noicon.xpm");
00215 #endif
00216 } // ScribusMainWindow::ScribusMainWindow()
00217 
00218 /*
00219  * retval 0 - ok, 1 - no fonts, ...
00220  */
00221 int ScribusMainWindow::initScMW(bool primaryMainWindow)
00222 {
00223        int retVal=0;
00224 
00225 //     CommonStrings::languageChange();
00226        previewDinUse = false;
00227        printDinUse = false;
00228 //     guiLanguage = newGuiLanguage;
00229 //     initSplash(showSplash);
00230        setUsesBigPixmaps(true);
00231        CurrStED = NULL;
00232        setCaption( tr("Scribus " VERSION));
00233        setKeyCompression(false);
00234        setIcon(loadIcon("AppIcon.png"));
00235        scrActionGroups.clear();
00236        scrActionGroups.setAutoDelete(true);
00237        scrActions.clear();
00238        scrRecentFileActions.clear();
00239        scrRecentPasteActions.clear();
00240        scrWindowsActions.clear();
00241        scrLayersActions.clear();
00242        scrMenuMgr = new MenuManager(menuBar());
00243        prefsManager = PrefsManager::instance();
00244        objectSpecificUndo = false;
00245 
00246        undoManager = UndoManager::instance();
00247        PrefsContext *undoPrefs = prefsManager->prefsFile->getContext("undo");
00248        undoManager->setUndoEnabled(undoPrefs->getBool("enabled", true));
00249        tocGenerator = new TOCGenerator();
00250 
00251 
00252        initDefaultValues();
00253 
00254        initStatusBar();
00255 
00256        qApp->processEvents();
00257 
00258        BuFromApp = false;
00259 
00260        actionManager = new ActionManager(this, "actionManager");
00261        actionManager->init(this);
00262        initMenuBar();
00263        initToolBars();
00264        buildFontMenu();
00265        ScCore->pluginManager->setupPluginActions(this);
00266        ScCore->pluginManager->languageChange();
00267        initKeyboardShortcuts();
00268        if (primaryMainWindow)
00269               ScCore->setSplashStatus( tr("Setting up Shortcuts") );
00270        SetShortCut();
00271 
00272        resize(610, 600);
00273        QVBox* vb = new QVBox( this );
00274        vb->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken );
00275        wsp = new QWorkspace( vb );
00276        setCentralWidget( vb );
00277        connect(wsp, SIGNAL(windowActivated(QWidget *)), this, SLOT(newActWin(QWidget *)));
00278        //Connect windows cascade and tile actions to the workspace after its created. Only depends on wsp created.
00279        connect( scrActions["windowsCascade"], SIGNAL(activated()) , wsp, SLOT(cascade()) );
00280        connect( scrActions["windowsTile"], SIGNAL(activated()) , wsp, SLOT(tile()) );
00281        initPalettes();
00282 
00283        prefsManager->setupMainWindow(this);
00284 
00285        if (primaryMainWindow)
00286               ScCore->setSplashStatus( tr("Initializing Story Editor") );
00287        storyEditor = new StoryEditor(this);
00288 
00289        DocDir = prefsManager->documentDir();
00290 
00291 
00292        if (primaryMainWindow)
00293               ScCore->setSplashStatus( tr("Initializing Hyphenator") );
00294        QString preLang = prefsManager->appPrefs.Language;
00295        initHyphenator();
00296        if (Sprachen.contains(preLang))
00297               prefsManager->appPrefs.Language = preLang;
00298        if (primaryMainWindow)
00299               ScCore->setSplashStatus( tr("Reading Scrapbook") );
00300        initScrapbook();
00301 
00302        scrActions["helpTooltips"]->setOn(prefsManager->appPrefs.showToolTips);
00303        scrActions["stickyTools"]->setOn(prefsManager->appPrefs.stickyTools);
00304        ToggleTips();
00305        propertiesPalette->setFontSize();
00306        if (scrActions["SaveAsDocumentTemplate"])
00307               scrActions["SaveAsDocumentTemplate"]->setEnabled(false);
00308 
00309        connect(ScCore->fileWatcher, SIGNAL(fileDeleted(QString )), this, SLOT(removeRecent(QString)));
00310        connect(this, SIGNAL(TextStyle(const ParagraphStyle&)), propertiesPalette, SLOT(updateStyle(const ParagraphStyle&)));
00311        // to go:  (av)
00312        connect(this, SIGNAL(TextIFont(const QString&)), this, SLOT(AdjustFontMenu(const QString&)));
00313        connect(this, SIGNAL(TextIFont(const QString&)), propertiesPalette, SLOT(setFontFace(const QString&)));
00314        connect(this, SIGNAL(TextISize(int)), this, SLOT(setFSizeMenu(int)));
00315        connect(this, SIGNAL(TextISize(int)), propertiesPalette, SLOT(setSize(int)));
00316        connect(this, SIGNAL(TextUSval(int)), propertiesPalette, SLOT(setExtra(int)));
00317        connect(this, SIGNAL(TextStil(int)), propertiesPalette, SLOT(setStil(int)));
00318        connect(this, SIGNAL(TextScale(int)), propertiesPalette, SLOT(setTScale(int)));
00319        connect(this, SIGNAL(TextScaleV(int)), propertiesPalette, SLOT(setTScaleV(int)));
00320        connect(this, SIGNAL(TextBase(int)), propertiesPalette, SLOT(setTBase(int)));
00321        connect(this, SIGNAL(TextShadow(int, int )), propertiesPalette, SLOT(setShadowOffs(int, int )));
00322        connect(this, SIGNAL(TextOutline(int)), propertiesPalette, SLOT(setOutlineW(int)));
00323        connect(this, SIGNAL(TextUnderline(int, int)), propertiesPalette, SLOT(setUnderline(int, int)));
00324        connect(this, SIGNAL(TextStrike(int, int)), propertiesPalette, SLOT(setStrike(int, int)));
00325        connect(this, SIGNAL(TextFarben(QString, QString, int, int)), propertiesPalette, SLOT(setActFarben(QString, QString, int, int)));
00326        connect(ClipB, SIGNAL(dataChanged()), this, SLOT(ClipChange()));
00327 //     connect(ClipB, SIGNAL(selectionChanged()), this, SLOT(ClipChange()));
00328        setAcceptDrops(true);
00329        return retVal;
00330 }
00331 
00332 ScribusMainWindow::~ScribusMainWindow()
00333 {
00334 }
00335 
00336 
00337 void ScribusMainWindow::initToolBars()
00338 {
00339        fileToolBar = new ScToolBar( tr("File"), "File", this);
00340        scrActions["fileNew"]->addTo(fileToolBar);
00341        scrActions["fileOpen"]->addTo(fileToolBar);
00342        scrMenuMgr->addMenuToWidgetOfAction("FileOpenRecent", scrActions["fileOpen"]);
00343        scrActions["fileSave"]->addTo(fileToolBar);
00344        scrActions["fileClose"]->addTo(fileToolBar);
00345        scrActions["filePrint"]->addTo(fileToolBar);
00346        scrActions["toolsPreflightVerifier"]->addTo(fileToolBar);
00347        scrActions["fileExportAsPDF"]->addTo(fileToolBar);
00348 
00349        editToolBar = new ScToolBar( tr("Edit"), "Edit", this);
00350        UndoWidget* uWidget = new UndoWidget(editToolBar, "uWidget");
00351        undoManager->registerGui(uWidget);
00352 
00353        mainToolBar = new ModeToolBar(this);
00354        pdfToolBar = new PDFToolBar(this);
00355 
00356        connect(mainToolBar, SIGNAL(visibilityChanged(bool)), scrActions["toolsToolbarTools"], SLOT(setOn(bool)));
00357        connect(scrActions["toolsToolbarPDF"], SIGNAL(toggled(bool)), pdfToolBar, SLOT(setShown(bool)));
00358        connect(pdfToolBar, SIGNAL(visibilityChanged(bool)), scrActions["toolsToolbarPDF"], SLOT(setOn(bool)));
00359        connect(scrActions["toolsToolbarTools"], SIGNAL(toggled(bool)), mainToolBar, SLOT(setShown(bool)) );
00360 }
00361 
00362 void ScribusMainWindow::initDefaultValues()
00363 {
00364        HaveDoc = false;
00365        ScriptRunning = false;
00366        view = NULL;
00367        doc = NULL;
00368        Buffer2 = "";
00369        DocNr = 1;
00370        PrinterUsed = false;
00371        PDef.Pname = "";
00372        PDef.Dname = "";
00373        PDef.Command = "";
00374        keyrep = false;
00375        _arrowKeyDown = false;
00376        ClipB = QApplication::clipboard();
00377        palettesStatus[0] = false;
00378        guidesStatus[0] = false;
00379 }
00380 
00381 void ScribusMainWindow::initKeyboardShortcuts()
00382 {
00383        for( QMap<QString, QGuardedPtr<ScrAction> >::Iterator it = scrActions.begin(); it!=scrActions.end(); ++it )
00384        {
00385               if ((ScrAction*)(it.data())!=NULL)
00386               {
00387                      QString accelerator=it.data()->accel();
00388                      prefsManager->setKeyEntry(it.key(), it.data()->cleanMenuText(), accelerator,0);
00389               }
00390               //else
00391               //     qDebug(it.key());
00392               //qDebug(QString("|-\n|%1||%2||%3").arg(it.key()).arg(it.data()->cleanMenuText()).arg(QString(it.data()->accel())));
00393        }
00394 }
00395 
00396 void ScribusMainWindow::initPalettes()
00397 {
00398        //CB TODO hide the publicly available members of some palettes
00399        // these must be filtered too as they take control of the palettes events
00400        outlinePalette = new Tree(this);
00401        outlinePalette->setMainWindow(this);
00402        connect( scrActions["toolsOutline"], SIGNAL(toggled(bool)) , outlinePalette, SLOT(setPaletteShown(bool)) );
00403        connect( outlinePalette, SIGNAL(paletteShown(bool)), scrActions["toolsOutline"], SLOT(setOn(bool)));
00404        propertiesPalette = new Mpalette(ScCore->m_PaletteParent);
00405        propertiesPalette->setMainWindow(this);
00406        connect( scrActions["toolsProperties"], SIGNAL(toggled(bool)) , propertiesPalette, SLOT(setPaletteShown(bool)) );
00407        connect( propertiesPalette, SIGNAL(paletteShown(bool)), scrActions["toolsProperties"], SLOT(setOn(bool)));
00408 
00409        //CB dont need this until we have a doc...
00410        //propertiesPalette->Cpal->SetColors(prefsManager->colorSet());
00411        propertiesPalette->Fonts->RebuildList(0);
00412        propertiesPalette->installEventFilter(this);
00413        nodePalette = new NodePalette(this);
00414        nodePalette->installEventFilter(this);
00415        layerPalette = new LayerPalette(this);
00416        guidePalette = new GuideManager(this);
00417        charPalette = new CharSelect(this);
00418        connect( scrActions["toolsLayers"], SIGNAL(toggled(bool)) , layerPalette, SLOT(setPaletteShown(bool)) );
00419        connect( layerPalette, SIGNAL(paletteShown(bool)), scrActions["toolsLayers"], SLOT(setOn(bool)));
00420        layerPalette->installEventFilter(this);
00421        layerPalette->Table->installEventFilter(this);
00422        scrapbookPalette = new Biblio(this);
00423        connect( scrActions["toolsScrapbook"], SIGNAL(toggled(bool)) , scrapbookPalette, SLOT(setPaletteShown(bool)) );
00424        connect( scrapbookPalette, SIGNAL(paletteShown(bool)), scrActions["toolsScrapbook"], SLOT(setOn(bool)));
00425        scrapbookPalette->installEventFilter(this);
00426        pagePalette = new PagePalette(this);
00427        connect( scrActions["toolsPages"], SIGNAL(toggled(bool)) , pagePalette, SLOT(setPaletteShown(bool)) );
00428        connect( scrActions["toolsPages"], SIGNAL(toggled(bool)) , this, SLOT(setPagePalette(bool)) );
00429        connect( pagePalette, SIGNAL(paletteShown(bool)), scrActions["toolsPages"], SLOT(setOn(bool)));
00430        pagePalette->installEventFilter(this);
00431        bookmarkPalette = new BookPalette(this);
00432        connect( scrActions["toolsBookmarks"], SIGNAL(toggled(bool)) , bookmarkPalette, SLOT(setPaletteShown(bool)) );
00433        connect( bookmarkPalette, SIGNAL(paletteShown(bool)), scrActions["toolsBookmarks"], SLOT(setOn(bool)));
00434        bookmarkPalette->installEventFilter(this);
00435        measurementPalette = new Measurements(this);
00436        connect( scrActions["toolsMeasurements"], SIGNAL(toggled(bool)) , measurementPalette, SLOT(setPaletteShown(bool)) );
00437        connect( scrActions["toolsMeasurements"], SIGNAL(toggledData(bool, int)) , this, SLOT(setAppModeByToggle(bool, int)) );
00438        connect( measurementPalette, SIGNAL(paletteShown(bool)), scrActions["toolsMeasurements"], SLOT(setOn(bool)));
00439        measurementPalette->installEventFilter(this);
00440        measurementPalette->hide();
00441        docCheckerPalette = new CheckDocument(this, false);
00442        connect( scrActions["toolsPreflightVerifier"], SIGNAL(toggled(bool)) , docCheckerPalette, SLOT(setPaletteShown(bool)) );
00443        connect( scrActions["toolsPreflightVerifier"], SIGNAL(toggled(bool)) , this, SLOT(docCheckToggle(bool)) );
00444        connect( docCheckerPalette, SIGNAL(paletteShown(bool)), scrActions["toolsPreflightVerifier"], SLOT(setOn(bool)));
00445        connect( docCheckerPalette, SIGNAL(paletteShown(bool)), this, SLOT(docCheckToggle(bool)));
00446        docCheckerPalette->installEventFilter(this);
00447        docCheckerPalette->hide();
00448 
00449        alignDistributePalette = new AlignDistributePalette(this, "AlignDistributePalette", false);
00450        connect( scrActions["toolsAlignDistribute"], SIGNAL(toggled(bool)) , alignDistributePalette, SLOT(setPaletteShown(bool)) );
00451        connect( alignDistributePalette, SIGNAL(paletteShown(bool)), scrActions["toolsAlignDistribute"], SLOT(setOn(bool)));
00452        connect( alignDistributePalette, SIGNAL(documentChanged()), this, SLOT(slotDocCh()));
00453        alignDistributePalette->installEventFilter(this);
00454 
00455        undoPalette = new UndoPalette(this, "undoPalette");
00456        undoPalette->installEventFilter(this);
00457        undoManager->registerGui(undoPalette);
00458        connect(undoPalette, SIGNAL(paletteShown(bool)), this, SLOT(setUndoPalette(bool)));
00459        connect(undoPalette, SIGNAL(objectMode(bool)), this, SLOT(setUndoMode(bool)));
00460 
00461        // initializing style manager here too even it's not strictly a palette
00462        styleManager = new StyleManager(this, "styleManager");
00463        styleManager->addStyle(new SMLineStyle());
00464        SMCharacterStyle *tmpCS = new SMCharacterStyle();
00465        styleManager->addStyle(new SMParagraphStyle(tmpCS->tmpStyles()));
00466        styleManager->addStyle(tmpCS);
00467        connect( scrActions["editStyles"], SIGNAL(toggled(bool)) , styleManager, SLOT(setPaletteShown(bool)) );
00468        connect( styleManager, SIGNAL(paletteShown(bool)), scrActions["editStyles"], SLOT(setOn(bool)));
00469        styleManager->installEventFilter(this);
00470 
00471        connect(docCheckerPalette, SIGNAL(selectElement(int, int)), this, SLOT(selectItemsFromOutlines(int, int)));
00472        connect(docCheckerPalette, SIGNAL(selectPage(int)), this, SLOT(selectPagesFromOutlines(int)));
00473        connect(docCheckerPalette, SIGNAL(selectMasterPage(QString)), this, SLOT(manageMasterPages(QString)));
00474        connect(outlinePalette, SIGNAL(selectElement(int, int, bool)), this, SLOT(selectItemsFromOutlines(int, int, bool)));
00475        connect(outlinePalette, SIGNAL(selectPage(int)), this, SLOT(selectPagesFromOutlines(int)));
00476        connect(outlinePalette, SIGNAL(selectMasterPage(QString)), this, SLOT(manageMasterPages(QString)));
00477        connect(propertiesPalette->paraStyleCombo, SIGNAL(newStyle(const QString&)), this, SLOT(setNewParStyle(const QString&)));
00478        connect(propertiesPalette->charStyleCombo, SIGNAL(newStyle(const QString&)), this, SLOT(setNewCharStyle(const QString&)));
00479 //     connect(propertiesPalette, SIGNAL(EditLSt()), this, SLOT(slotEditLineStyles()));
00480        connect(nodePalette, SIGNAL(Schliessen()), this, SLOT(NoFrameEdit()));
00481        connect(nodePalette, SIGNAL(DocChanged()), this, SLOT(slotDocCh()));
00482        connect(layerPalette, SIGNAL(LayerChanged()), this, SLOT(showLayer()));
00483 
00484        connect(bookmarkPalette->BView, SIGNAL(MarkMoved()), this, SLOT(StoreBookmarks()));
00485        connect(bookmarkPalette->BView, SIGNAL(changed()), this, SLOT(slotDocCh()));
00486        connect(bookmarkPalette->BView, SIGNAL(SelectElement(PageItem *)), this, SLOT(selectItemsFromOutlines(PageItem *)));
00487        // guides
00488        connect(scrActions["pageManageGuides"], SIGNAL(toggled(bool)), guidePalette, SLOT(setPaletteShown(bool)));
00489        connect(guidePalette, SIGNAL(paletteShown(bool)), scrActions["pageManageGuides"], SLOT(setOn(bool)));
00490        // char palette
00491        connect(scrActions["insertGlyph"], SIGNAL(toggled(bool)), charPalette, SLOT(setPaletteShown(bool)));
00492        connect(charPalette, SIGNAL(paletteShown(bool)), scrActions["insertGlyph"], SLOT(setOn(bool)));
00493 }
00494 
00495 void ScribusMainWindow::initScrapbook()
00496 {
00497        QString scrapbookFileO = QDir::convertSeparators(prefsManager->preferencesLocation()+"/scrap13.scs");
00498        QFileInfo scrapbookFileInfoO = QFileInfo(scrapbookFileO);
00499        if (scrapbookFileInfoO.exists())
00500        {
00501               scrapbookPalette->readOldContents(scrapbookFileO, QDir::convertSeparators(prefsManager->preferencesLocation()+"/scrapbook/main"));
00502               QDir d = QDir();
00503               d.rename(scrapbookFileO, QDir::convertSeparators(prefsManager->preferencesLocation()+"/scrap13.backup"));
00504        }
00505        QString scrapbookTemp = QDir::convertSeparators(prefsManager->preferencesLocation()+"/scrapbook/tmp");
00506        QFileInfo scrapbookTempInfo = QFileInfo(scrapbookTemp);
00507        if (scrapbookTempInfo.exists())
00508               scrapbookPalette->readTempContents(scrapbookTemp);
00509        QString scrapbookFile = QDir::convertSeparators(prefsManager->preferencesLocation()+"/scrapbook/main");
00510        QFileInfo scrapbookFileInfo = QFileInfo(scrapbookFile);
00511        if (scrapbookFileInfo.exists())
00512               scrapbookPalette->readContents(scrapbookFile);
00513        scrapbookPalette->setScrapbookFileName(scrapbookFile);
00514        scrapbookPalette->setOpenScrapbooks(prefsManager->appPrefs.RecentScrapbooks);
00515        rebuildRecentPasteMenu();
00516        connect(scrapbookPalette, SIGNAL(updateRecentMenue()), this, SLOT(rebuildRecentPasteMenu()));
00517 }
00518 
00519 bool ScribusMainWindow::warningVersion(QWidget *parent)
00520 {
00521        bool retval = false;
00522        int t = ScMessageBox::warning(parent, QObject::tr("Scribus Development Version"), "<qt>" +
00523                                                          QObject::tr("You are running a development version of Scribus 1.3.x. The document you are working with was created in Scribus 1.2.x.  Saving the current file under 1.3.x renders it unable to be edited in Scribus 1.2.x versions. To preserve the ability to edit in 1.2.x, save this file under a different name and further edit the newly named file and the original will be untouched. Are you sure you wish to proceed with this operation?") + "</qt>",
00524                                                          CommonStrings::tr_OK, CommonStrings::tr_Cancel, "", 1, 0);
00525        if (t == 0)
00526               retval = true;
00527        return retval;
00528 }
00529 
00530 void ScribusMainWindow::initMenuBar()
00531 {
00532        RecentDocs.clear();
00533 
00534        scrMenuMgr->createMenu("File", tr("&File"));
00535        scrMenuMgr->addMenuItem(scrActions["fileNew"], "File");
00536        scrMenuMgr->addMenuItem(scrActions["fileOpen"], "File");
00537        recentFileMenuName="FileOpenRecent";
00538        scrMenuMgr->createMenu(recentFileMenuName, QIconSet(noIcon), tr("Open &Recent"), "File");
00539        scrMenuMgr->addMenuSeparator("File");
00540        scrMenuMgr->addMenuItem(scrActions["fileClose"], "File");
00541        scrMenuMgr->addMenuItem(scrActions["fileSave"], "File");
00542        scrMenuMgr->addMenuItem(scrActions["fileSaveAs"], "File");
00543        scrMenuMgr->addMenuItem(scrActions["fileRevert"], "File");
00544        scrMenuMgr->addMenuItem(scrActions["fileCollect"], "File");
00545        scrMenuMgr->addMenuSeparator("File");
00546        scrMenuMgr->createMenu("FileImport", QIconSet(noIcon), tr("&Import"), "File");
00547        scrMenuMgr->addMenuItem(scrActions["fileImportText"], "FileImport");
00548 //     scrMenuMgr->addMenuItem(scrActions["fileImportText2"], "FileImport");
00549        scrMenuMgr->addMenuItem(scrActions["fileImportAppendText"], "FileImport");
00550        scrMenuMgr->addMenuItem(scrActions["fileImportImage"], "FileImport");
00551        scrMenuMgr->createMenu("FileExport", QIconSet(noIcon), tr("&Export"), "File");
00552        scrMenuMgr->addMenuItem(scrActions["fileExportText"], "FileExport");
00553        scrMenuMgr->addMenuItem(scrActions["fileExportAsEPS"], "FileExport");
00554        scrMenuMgr->addMenuItem(scrActions["fileExportAsPDF"], "FileExport");
00555        scrMenuMgr->addMenuSeparator("File");
00556        scrMenuMgr->addMenuItem(scrActions["fileDocSetup"], "File");
00557        scrMenuMgr->addMenuItem(scrActions["filePreferences"], "File");
00558        scrMenuMgr->addMenuSeparator("File");
00559        scrMenuMgr->addMenuItem(scrActions["filePrint"], "File");
00560        scrMenuMgr->addMenuItem(scrActions["PrintPreview"], "File");
00561        scrMenuMgr->addMenuSeparator("File");
00562        scrMenuMgr->addMenuItem(scrActions["fileQuit"], "File");
00563 
00564        scrActions["fileClose"]->setEnabled(false);
00565        scrActions["fileSave"]->setEnabled(false);
00566        scrActions["fileSaveAs"]->setEnabled(false);
00567        scrActions["fileRevert"]->setEnabled(false);
00568        scrActions["fileCollect"]->setEnabled(false);
00569        scrActions["fileImportText"]->setEnabled(false);
00570        scrActions["fileImportText2"]->setEnabled(false);
00571        scrActions["fileImportImage"]->setEnabled(false);
00572        scrActions["fileImportAppendText"]->setEnabled(false);
00573        scrActions["pageImport"]->setEnabled(false);
00574        scrActions["fileExportText"]->setEnabled(false);
00575        scrActions["fileExportAsEPS"]->setEnabled(false);
00576        scrActions["fileExportAsPDF"]->setEnabled(false);
00577        scrMenuMgr->setMenuEnabled("FileImport", false);
00578        scrMenuMgr->setMenuEnabled("FileExport", false);
00579        scrActions["fileDocSetup"]->setEnabled(false);
00580        scrActions["filePrint"]->setEnabled(false);
00581        scrActions["PrintPreview"]->setEnabled(false);
00582 
00583        scrMenuMgr->createMenu("Edit", tr("&Edit"));
00584        scrMenuMgr->addMenuItem(scrActions["editUndoAction"], "Edit");
00585        scrMenuMgr->addMenuItem(scrActions["editRedoAction"], "Edit");
00586        scrMenuMgr->addMenuItem(scrActions["editActionMode"], "Edit");
00587        scrMenuMgr->addMenuSeparator("Edit");
00588        scrMenuMgr->addMenuItem(scrActions["editCut"], "Edit");
00589        scrMenuMgr->addMenuItem(scrActions["editCopy"], "Edit");
00590        scrMenuMgr->addMenuItem(scrActions["editPaste"], "Edit");
00591        recentPasteMenuName="EditPasteRecent";
00592        scrMenuMgr->createMenu(recentPasteMenuName, QIconSet(noIcon), tr("Paste Recent"), "Edit");
00593        scrMenuMgr->createMenu("EditContents", QPixmap(noIcon), tr("Contents"), "Edit");
00594        scrMenuMgr->addMenuItem(scrActions["editCopyContents"], "EditContents");
00595        scrMenuMgr->addMenuItem(scrActions["editPasteContents"], "EditContents");
00596        scrMenuMgr->addMenuItem(scrActions["editPasteContentsAbs"], "EditContents");
00597        scrMenuMgr->addMenuItem(scrActions["editClearContents"], "EditContents");
00598        scrMenuMgr->addMenuSeparator("Edit");
00599        scrMenuMgr->addMenuItem(scrActions["editSelectAll"], "Edit");
00600        scrMenuMgr->addMenuItem(scrActions["editDeselectAll"], "Edit");
00601        scrMenuMgr->addMenuSeparator("Edit");
00602        scrMenuMgr->addMenuItem(scrActions["editSearchReplace"], "Edit");
00603        scrMenuMgr->addMenuItem(scrActions["toolsEditWithStoryEditor"], "Edit");
00604        scrMenuMgr->addMenuItem(scrActions["editEditWithImageEditor"], "Edit");
00605        scrMenuMgr->addMenuSeparator("Edit");
00606        scrMenuMgr->addMenuItem(scrActions["editColors"], "Edit");
00607        scrMenuMgr->addMenuItem(scrActions["editPatterns"], "Edit");
00608        scrMenuMgr->addMenuItem(scrActions["editStyles"], "Edit");
00609        scrMenuMgr->addMenuItem(scrActions["editMasterPages"], "Edit");
00610        scrMenuMgr->addMenuItem(scrActions["editJavascripts"], "Edit");
00611        scrActions["editUndoAction"]->setEnabled(false);
00612        scrActions["editRedoAction"]->setEnabled(false);
00613        scrActions["editActionMode"]->setEnabled(true);
00614        scrActions["editCut"]->setEnabled(false);
00615        scrActions["editCopy"]->setEnabled(false);
00616        scrActions["editPaste"]->setEnabled(false);
00617        scrMenuMgr->setMenuEnabled("EditPasteRecent", false);
00618        scrMenuMgr->setMenuEnabled("EditContents", false);
00619        scrActions["editCopyContents"]->setEnabled(false);
00620        scrActions["editPasteContents"]->setEnabled(false);
00621        scrActions["editPasteContentsAbs"]->setEnabled(false);
00622        scrActions["editClearContents"]->setEnabled(false);
00623        scrActions["editSelectAll"]->setEnabled(false);
00624        scrActions["editDeselectAll"]->setEnabled(false);
00625        scrActions["editSearchReplace"]->setEnabled(false);
00626        scrActions["editPatterns"]->setEnabled(false);
00627        scrActions["editStyles"]->setEnabled(false);
00628        scrActions["editMasterPages"]->setEnabled(false);
00629        scrActions["editJavascripts"]->setEnabled(false);
00630        scrActions["toolsEditWithStoryEditor"]->setEnabled(false);
00631        scrActions["editEditWithImageEditor"]->setEnabled(false);
00632 
00633        //Style Menu
00634        scrMenuMgr->createMenu("Style", tr("St&yle"));
00635        //Color menu
00636        // CB TODO
00637        scrMenuMgr->createMenu("Color", tr("&Color"));
00638        ColorMenC = new ColorCombo(false);
00639        ColorMenC->setEditable(false);
00640        scrMenuMgr->addMenuItem(ColorMenC, "Color");
00641 
00642        //Text size menu
00643        scrMenuMgr->createMenu("FontSize", tr("&Size"));
00644        scrActionGroups["fontSize"]->addTo(scrMenuMgr->getLocalPopupMenu("FontSize"));
00645 
00646        //Shade menu
00647        scrMenuMgr->createMenu("Shade", tr("&Shade"));
00648        scrActionGroups["shade"]->addTo(scrMenuMgr->getLocalPopupMenu("Shade"));
00649 
00650        //Font menu
00651        scrMenuMgr->createMenu("Font", tr("&Font"));
00652        FontMenu = scrMenuMgr->getLocalPopupMenu("Font");
00653 
00654        //Type style menu
00655        scrMenuMgr->createMenu("TypeEffects", tr("&Effects"));
00656        scrActionGroups["typeEffects"]->addTo(scrMenuMgr->getLocalPopupMenu("TypeEffects"));
00657 
00658        //Item Menu
00659        scrMenuMgr->createMenu("Item", tr("&Item"));
00660        scrMenuMgr->addMenuItem(scrActions["itemDuplicate"], "Item");
00661        scrMenuMgr->addMenuItem(scrActions["itemMulDuplicate"], "Item");
00662        scrMenuMgr->addMenuItem(scrActions["itemDelete"], "Item");
00663        scrMenuMgr->addMenuSeparator("Item");
00664        scrMenuMgr->addMenuItem(scrActions["itemGroup"], "Item");
00665        scrMenuMgr->addMenuItem(scrActions["itemUngroup"], "Item");
00666        scrMenuMgr->addMenuItem(scrActions["itemLock"], "Item");
00667        scrMenuMgr->addMenuItem(scrActions["itemLockSize"], "Item");
00668        scrMenuMgr->addMenuSeparator("Item");
00669        scrMenuMgr->createMenu("ItemLevel", tr("Level"));
00670        scrMenuMgr->addMenuToMenu("ItemLevel", "Item");
00671        scrMenuMgr->addMenuItem(scrActions["itemRaise"], "ItemLevel");
00672        scrMenuMgr->addMenuItem(scrActions["itemLower"], "ItemLevel");
00673        scrMenuMgr->addMenuItem(scrActions["itemRaiseToTop"], "ItemLevel");
00674        scrMenuMgr->addMenuItem(scrActions["itemLowerToBottom"], "ItemLevel");
00675        scrMenuMgr->createMenu("ItemLayer", tr("Send to La&yer"));
00676        scrMenuMgr->addMenuToMenu("ItemLayer", "Item");
00677        layerMenuName="ItemLayer";
00678        scrMenuMgr->addMenuItem(scrActions["itemSendToScrapbook"], "Item");
00679        scrMenuMgr->addMenuItem(scrActions["itemSendToPattern"], "Item");
00680        scrMenuMgr->addMenuSeparator("Item");
00681        scrMenuMgr->addMenuItem(scrActions["itemAdjustFrameToImage"], "Item");
00682        scrMenuMgr->addMenuItem(scrActions["itemExtendedImageProperties"], "Item");
00683        scrMenuMgr->addMenuItem(scrActions["itemUpdateImage"], "Item");
00684        scrMenuMgr->createMenu("ItemPreviewSettings", tr("Preview Settings"), "Item");
00685        scrMenuMgr->addMenuItem(scrActions["itemImageIsVisible"], "ItemPreviewSettings");
00686        scrMenuMgr->addMenuSeparator("ItemPreviewSettings");
00687        scrMenuMgr->addMenuItem(scrActions["itemPreviewLow"], "ItemPreviewSettings");
00688        scrMenuMgr->addMenuItem(scrActions["itemPreviewNormal"], "ItemPreviewSettings");
00689        scrMenuMgr->addMenuItem(scrActions["itemPreviewFull"], "ItemPreviewSettings");
00690        scrMenuMgr->addMenuSeparator("Item");
00691        scrMenuMgr->addMenuItem(scrActions["itemAttributes"], "Item");
00692        scrMenuMgr->createMenu("ItemPDFOptions", tr("&PDF Options"));
00693        scrMenuMgr->addMenuToMenu("ItemPDFOptions", "Item");
00694        scrMenuMgr->addMenuItem(scrActions["itemPDFIsAnnotation"], "ItemPDFOptions");
00695        scrMenuMgr->addMenuItem(scrActions["itemPDFIsBookmark"], "ItemPDFOptions");
00696        scrMenuMgr->addMenuItem(scrActions["itemPDFAnnotationProps"], "ItemPDFOptions");
00697        scrMenuMgr->addMenuItem(scrActions["itemPDFFieldProps"], "ItemPDFOptions");
00698        scrMenuMgr->createMenu("ItemShapes", tr("&Shape"), "Item");
00699        // CB TODO
00700        //Shape menu
00701        SCustom = new Autoforms(0);
00702        scrMenuMgr->addMenuItem(SCustom, "ItemShapes");
00703        connect(SCustom, SIGNAL(FormSel(int, int, double *)), this, SLOT(MakeFrame(int, int, double *)));
00704        scrMenuMgr->addMenuItem(scrActions["itemShapeEdit"], "ItemShapes");
00705        scrMenuMgr->createMenu("ItemConvertTo", QPixmap(noIcon), tr("C&onvert To"), "Item");
00706        //scrMenuMgr->createMenu("ItemConvertTo", tr("C&onvert To"));
00707        //scrMenuMgr->addMenuToMenu("ItemConvertTo", "Item");
00708        scrMenuMgr->addMenuItem(scrActions["itemConvertToBezierCurve"], "ItemConvertTo");
00709        scrMenuMgr->addMenuItem(scrActions["itemConvertToImageFrame"], "ItemConvertTo");
00710        scrMenuMgr->addMenuItem(scrActions["itemConvertToOutlines"], "ItemConvertTo");
00711        scrMenuMgr->addMenuItem(scrActions["itemConvertToPolygon"], "ItemConvertTo");
00712        scrMenuMgr->addMenuItem(scrActions["itemConvertToTextFrame"], "ItemConvertTo");
00713 
00714        scrMenuMgr->addMenuItem(scrActions["itemAttachTextToPath"], "Item");
00715        scrMenuMgr->addMenuItem(scrActions["itemDetachTextFromPath"], "Item");
00716        scrMenuMgr->addMenuItem(scrActions["itemCombinePolygons"], "Item");
00717        scrMenuMgr->addMenuItem(scrActions["itemSplitPolygons"], "Item");
00718        scrMenuMgr->setMenuEnabled("ItemShapes", false);
00719        scrActions["itemGroup"]->setEnabled(false);
00720        scrActions["itemUngroup"]->setEnabled(false);
00721        scrActions["itemAttachTextToPath"]->setEnabled(false);
00722        scrActions["itemDetachTextFromPath"]->setEnabled(false);
00723        scrActions["itemCombinePolygons"]->setEnabled(false);
00724        scrActions["itemSplitPolygons"]->setEnabled(false);
00725        scrActions["itemLock"]->setEnabled(false);
00726        scrActions["itemLockSize"]->setEnabled(false);
00727        scrActions["itemPrintingEnabled"]->setEnabled(false);
00728        scrActions["itemImageIsVisible"]->setEnabled(false);
00729        scrMenuMgr->setMenuEnabled("ItemConvertTo", false);
00730        scrActions["itemConvertToBezierCurve"]->setEnabled(false);
00731        scrActions["itemConvertToImageFrame"]->setEnabled(false);
00732        scrActions["itemConvertToOutlines"]->setEnabled(false);
00733        scrActions["itemConvertToPolygon"]->setEnabled(false);
00734        scrActions["itemConvertToTextFrame"]->setEnabled(false);
00735 
00736        //Insert menu
00737        scrMenuMgr->createMenu("Insert", tr("I&nsert"));
00738        scrMenuMgr->addMenuItem(scrActions["insertFrame"], "Insert");
00739        scrMenuMgr->addMenuSeparator("Insert");
00740        scrMenuMgr->addMenuItem(scrActions["toolsInsertTextFrame"], "Insert");
00741        scrMenuMgr->addMenuItem(scrActions["toolsInsertImageFrame"], "Insert");
00742        scrMenuMgr->addMenuItem(scrActions["toolsInsertTableFrame"], "Insert");
00743        scrMenuMgr->addMenuItem(scrActions["toolsInsertShape"], "Insert");
00744        scrMenuMgr->addMenuItem(scrActions["toolsInsertPolygon"], "Insert");
00745        scrMenuMgr->addMenuItem(scrActions["toolsInsertLine"], "Insert");
00746        scrMenuMgr->addMenuItem(scrActions["toolsInsertBezier"], "Insert");
00747        scrMenuMgr->addMenuItem(scrActions["toolsInsertFreehandLine"], "Insert");
00748        scrMenuMgr->addMenuSeparator("Insert");
00749        scrMenuMgr->addMenuItem(scrActions["stickyTools"], "Insert");
00750        scrMenuMgr->addMenuSeparator("Insert");
00751        scrMenuMgr->addMenuItem(scrActions["insertGlyph"], "Insert");
00752 
00753        scrMenuMgr->createMenu("InsertChar", QPixmap(noIcon), tr("&Character"), "Insert");
00754        //scrMenuMgr->addMenuToMenu("InsertChar", "Insert");
00755        scrMenuMgr->addMenuItem(scrActions["unicodePageNumber"], "InsertChar");
00756        scrMenuMgr->addMenuItem(scrActions["unicodeSmartHyphen"], "InsertChar");
00757        scrMenuMgr->addMenuItem(scrActions["unicodeNonBreakingHyphen"], "InsertChar");
00758        scrMenuMgr->addMenuSeparator("InsertChar");
00759        scrMenuMgr->addMenuItem(scrActions["unicodeCopyRight"], "InsertChar");
00760        scrMenuMgr->addMenuItem(scrActions["unicodeRegdTM"], "InsertChar");
00761        scrMenuMgr->addMenuItem(scrActions["unicodeTM"], "InsertChar");
00762        scrMenuMgr->addMenuItem(scrActions["unicodeSolidus"], "InsertChar");
00763        scrMenuMgr->addMenuItem(scrActions["unicodeBullet"], "InsertChar");
00764        scrMenuMgr->addMenuItem(scrActions["unicodeMidpoint"], "InsertChar");
00765        scrMenuMgr->addMenuSeparator("InsertChar");
00766        scrMenuMgr->addMenuItem(scrActions["unicodeDashEm"], "InsertChar");
00767        scrMenuMgr->addMenuItem(scrActions["unicodeDashEn"], "InsertChar");
00768        scrMenuMgr->addMenuItem(scrActions["unicodeDashFigure"], "InsertChar");
00769        scrMenuMgr->addMenuItem(scrActions["unicodeDashQuotation"], "InsertChar");
00770 
00771        scrMenuMgr->createMenu("InsertQuote", QPixmap(noIcon), tr("&Quote"), "Insert");
00772        //scrMenuMgr->addMenuToMenu("InsertQuote", "Insert");
00773        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteApostrophe"], "InsertQuote");
00774        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteStraight"], "InsertQuote");
00775        scrMenuMgr->addMenuSeparator("InsertQuote");
00776        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteSingleLeft"], "InsertQuote");
00777        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteSingleRight"], "InsertQuote");
00778        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteDoubleLeft"], "InsertQuote");
00779        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteDoubleRight"], "InsertQuote");
00780        scrMenuMgr->addMenuSeparator("InsertQuote");
00781        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteSingleReversed"], "InsertQuote");
00782        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteDoubleReversed"], "InsertQuote");
00783        scrMenuMgr->addMenuSeparator("InsertQuote");
00784        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteLowSingleComma"], "InsertQuote");
00785        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteLowDoubleComma"], "InsertQuote");
00786        scrMenuMgr->addMenuSeparator("InsertQuote");
00787        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteSingleLeftGuillemet"], "InsertQuote");
00788        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteSingleRightGuillemet"], "InsertQuote");
00789        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteDoubleLeftGuillemet"], "InsertQuote");
00790        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteDoubleRightGuillemet"], "InsertQuote");
00791        scrMenuMgr->addMenuSeparator("InsertQuote");
00792        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteCJKSingleLeft"], "InsertQuote");
00793        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteCJKSingleRight"], "InsertQuote");
00794        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteCJKDoubleLeft"], "InsertQuote");
00795        scrMenuMgr->addMenuItem(scrActions["unicodeQuoteCJKDoubleRight"], "InsertQuote");
00796 
00797        scrMenuMgr->createMenu("InsertSpace", QPixmap(noIcon), tr("S&paces && Breaks"), "Insert");
00798        scrMenuMgr->addMenuItem(scrActions["unicodeNonBreakingSpace"], "InsertSpace");
00799        scrMenuMgr->addMenuItem(scrActions["unicodeSpaceEN"], "InsertSpace");
00800        scrMenuMgr->addMenuItem(scrActions["unicodeSpaceEM"], "InsertSpace");
00801        scrMenuMgr->addMenuItem(scrActions["unicodeSpaceThin"], "InsertSpace");
00802        scrMenuMgr->addMenuItem(scrActions["unicodeSpaceThick"], "InsertSpace");
00803        scrMenuMgr->addMenuItem(scrActions["unicodeSpaceMid"], "InsertSpace");
00804        scrMenuMgr->addMenuItem(scrActions["unicodeSpaceHair"], "InsertSpace");
00805        scrMenuMgr->addMenuSeparator("InsertSpace");
00806        scrMenuMgr->addMenuItem(scrActions["unicodeNewLine"], "InsertSpace");
00807        scrMenuMgr->addMenuItem(scrActions["unicodeFrameBreak"], "InsertSpace");
00808        scrMenuMgr->addMenuItem(scrActions["unicodeColumnBreak"], "InsertSpace");
00809        scrMenuMgr->addMenuItem(scrActions["unicodeZerowidthSpace"], "InsertSpace");
00810 
00811        scrMenuMgr->createMenu("InsertLigature", QPixmap(noIcon), tr("Liga&ture"), "Insert");
00812        scrMenuMgr->addMenuItem(scrActions["unicodeLigature_ff"], "InsertLigature");
00813        scrMenuMgr->addMenuItem(scrActions["unicodeLigature_fi"], "InsertLigature");
00814        scrMenuMgr->addMenuItem(scrActions["unicodeLigature_fl"], "InsertLigature");
00815        scrMenuMgr->addMenuItem(scrActions["unicodeLigature_ffi"], "InsertLigature");
00816        scrMenuMgr->addMenuItem(scrActions["unicodeLigature_ffl"], "InsertLigature");
00817        scrMenuMgr->addMenuItem(scrActions["unicodeLigature_ft"], "InsertLigature");
00818        scrMenuMgr->addMenuItem(scrActions["unicodeLigature_st"], "InsertLigature");
00819 
00820        scrMenuMgr->addMenuSeparator("Insert");
00821        scrMenuMgr->addMenuItem(scrActions["insertSampleText"], "Insert");
00822        scrActions["insertFrame"]->setEnabled(false);
00823 
00824        //Page menu
00825        scrMenuMgr->createMenu("Page", tr("&Page"));
00826        scrMenuMgr->addMenuItem(scrActions["pageInsert"], "Page");
00827        scrMenuMgr->addMenuItem(scrActions["pageImport"], "Page");
00828        scrMenuMgr->addMenuItem(scrActions["pageDelete"], "Page");
00829        scrMenuMgr->addMenuItem(scrActions["pageCopy"], "Page");
00830        scrMenuMgr->addMenuItem(scrActions["pageMove"], "Page");
00831        scrMenuMgr->addMenuItem(scrActions["pageApplyMasterPage"], "Page");
00832        scrMenuMgr->addMenuItem(scrActions["pageCopyToMasterPage"], "Page");
00833        scrMenuMgr->addMenuItem(scrActions["pageManageGuides"], "Page");
00834        scrMenuMgr->addMenuItem(scrActions["pageManageMargins"], "Page");
00835        scrMenuMgr->addMenuSeparator("Page");
00836        scrMenuMgr->addMenuItem(scrActions["viewSnapToGrid"], "Page");
00837        scrMenuMgr->addMenuItem(scrActions["viewSnapToGuides"], "Page");
00838        scrActions["pageDelete"]->setEnabled(false);
00839        scrActions["pageMove"]->setEnabled(false);
00840 
00841        //View menu
00842        scrMenuMgr->createMenu("View", tr("&View"));
00843        scrMenuMgr->addMenuItem(scrActions["viewFitInWindow"], "View");
00844        scrMenuMgr->addMenuItem(scrActions["viewFitWidth"], "View");
00845        scrMenuMgr->addMenuItem(scrActions["viewFit50"], "View");
00846        scrMenuMgr->addMenuItem(scrActions["viewFit75"], "View");
00847        scrMenuMgr->addMenuItem(scrActions["viewFit100"], "View");
00848        scrMenuMgr->addMenuItem(scrActions["viewFit200"], "View");
00849        scrMenuMgr->addMenuSeparator("View");
00850        scrMenuMgr->addMenuItem(scrActions["viewFitPreview"], "View");
00851        scrMenuMgr->addMenuSeparator("View");
00852        scrMenuMgr->addMenuItem(scrActions["viewShowMargins"], "View");
00853        scrMenuMgr->addMenuItem(scrActions["viewShowBleeds"], "View");
00854        scrMenuMgr->addMenuItem(scrActions["viewShowFrames"], "View");
00855        scrMenuMgr->addMenuItem(scrActions["viewShowLayerMarkers"], "View");
00856        scrMenuMgr->addMenuItem(scrActions["viewShowImages"], "View");
00857        scrMenuMgr->addMenuItem(scrActions["viewShowGrid"], "View");
00858        scrMenuMgr->addMenuItem(scrActions["viewShowGuides"], "View");
00859        scrMenuMgr->addMenuItem(scrActions["viewShowColumnBorders"], "View");
00860        scrMenuMgr->addMenuItem(scrActions["viewShowBaseline"], "View");
00861        scrMenuMgr->addMenuItem(scrActions["viewShowTextChain"], "View");
00862        scrMenuMgr->addMenuItem(scrActions["viewShowTextControls"], "View");
00863        scrMenuMgr->addMenuItem(scrActions["viewShowRulers"], "View");
00864        scrMenuMgr->addMenuItem(scrActions["viewRulerMode"], "View");
00865 
00866        scrActions["viewShowRulers"]->setEnabled(false);
00867 
00868        //CB If this is viewNewView imeplemented, it should be on the windows menu
00869 //     scrMenuMgr->addMenuItem(scrActions["viewNewView"], "View");
00870 
00871        //Tool menu
00872        /*
00873        scrMenuMgr->createMenu("Tools", tr("&Tools"));
00874        scrMenuMgr->addMenuItem(scrActions["toolsProperties"], "Tools");
00875        scrMenuMgr->addMenuItem(scrActions["toolsOutline"], "Tools");
00876        scrMenuMgr->addMenuItem(scrActions["toolsScrapbook"], "Tools");
00877        scrMenuMgr->addMenuItem(scrActions["toolsLayers"], "Tools");
00878        scrMenuMgr->addMenuItem(scrActions["toolsPages"], "Tools");
00879        scrMenuMgr->addMenuItem(scrActions["toolsBookmarks"], "Tools");
00880        scrMenuMgr->addMenuItem(scrActions["toolsMeasurements"], "Tools");
00881        scrMenuMgr->addMenuItem(scrActions["toolsActionHistory"], "Tools");
00882        scrMenuMgr->addMenuItem(scrActions["toolsPreflightVerifier"], "Tools");
00883        scrMenuMgr->addMenuItem(scrActions["toolsAlignDistribute"], "Tools");
00884        scrMenuMgr->addMenuSeparator("Tools");
00885        scrMenuMgr->addMenuItem(scrActions["toolsToolbarTools"], "Tools");
00886        scrMenuMgr->addMenuItem(scrActions["toolsToolbarPDF"], "Tools");
00887        //scrActions["toolsPreflightVerifier"]->setEnabled(false);*/
00888 
00889        //Extra menu
00890        scrMenuMgr->createMenu("Extras", tr("E&xtras"));
00891        scrMenuMgr->addMenuItem(scrActions["extrasManagePictures"], "Extras");
00892        scrMenuMgr->addMenuItem(scrActions["extrasHyphenateText"], "Extras");
00893        scrMenuMgr->addMenuItem(scrActions["extrasDeHyphenateText"], "Extras");
00894        scrMenuMgr->addMenuItem(scrActions["extrasGenerateTableOfContents"], "Extras");
00895 
00896        scrMenuMgr->setMenuEnabled("Extras", false);
00897        scrActions["extrasHyphenateText"]->setEnabled(false);
00898        scrActions["extrasDeHyphenateText"]->setEnabled(false);
00899 
00900        //Window menu
00901         scrMenuMgr->createMenu("Windows", tr("&Windows"), QString::null, true);
00902        connect(FontMenu, SIGNAL(aboutToShow()), this, SLOT(fontMenuAboutToShow()));
00903        connect(scrMenuMgr->getLocalPopupMenu("Windows"), SIGNAL(aboutToShow()), this, SLOT(windowsMenuAboutToShow()));
00904        addDefaultWindowMenuItems();
00905 
00906        //Help menu
00907        scrMenuMgr->createMenu("Help", tr("&Help"));
00908        scrMenuMgr->addMenuItem(scrActions["helpManual"], "Help");
00909        scrMenuMgr->addMenuSeparator("Help");
00910        scrMenuMgr->addMenuItem(scrActions["helpTooltips"], "Help");
00911        scrMenuMgr->addMenuSeparator("Help");
00912        scrMenuMgr->addMenuItem(scrActions["helpAboutScribus"], "Help");
00913        scrMenuMgr->addMenuItem(scrActions["helpAboutPlugins"], "Help");
00914        scrMenuMgr->addMenuItem(scrActions["helpAboutQt"], "Help");
00915        
00916        scrMenuMgr->addMenuToMenuBar("File");
00917        scrMenuMgr->addMenuToMenuBar("Edit");
00918        scrMenuMgr->addMenuToMenuBar("Style");
00919        scrMenuMgr->setMenuEnabled("Style", false);
00920        scrMenuMgr->addMenuToMenuBar("Item");
00921        scrMenuMgr->setMenuEnabled("Item", false);
00922        scrMenuMgr->addMenuToMenuBar("Insert");
00923        scrMenuMgr->setMenuEnabled("Insert", false);
00924        scrMenuMgr->addMenuToMenuBar("Page");
00925        scrMenuMgr->setMenuEnabled("Page", false);
00926        scrMenuMgr->addMenuToMenuBar("View");
00927        scrMenuMgr->setMenuEnabled("View", false);
00928        //scrMenuMgr->addMenuToMenuBar("Tools");
00929        scrMenuMgr->addMenuToMenuBar("Extras");
00930        scrMenuMgr->setMenuEnabled("Extras", false);
00931        scrMenuMgr->addMenuToMenuBar("Windows");
00932        //scrMenuMgr->setMenuEnabled("Windows", false);
00933        menuBar()->insertSeparator();
00934        scrMenuMgr->addMenuToMenuBar("Help");
00935 
00936        //Alignment menu
00937        scrMenuMgr->createMenu("Alignment", tr("&Alignment"));
00938        scrMenuMgr->addMenuItem(scrActions["alignLeft"], "Alignment");
00939        scrMenuMgr->addMenuItem(scrActions["alignCenter"], "Alignment");
00940        scrMenuMgr->addMenuItem(scrActions["alignRight"], "Alignment");
00941        scrMenuMgr->addMenuItem(scrActions["alignBlock"], "Alignment");
00942        scrMenuMgr->addMenuItem(scrActions["alignForced"], "Alignment");
00943 
00944        connect(ColorMenC, SIGNAL(activated(int)), this, SLOT(setItemFarbe(int)));
00945        connect(FontMenu, SIGNAL(activated(int)), this, SLOT(setItemFont(int)));
00946 }
00947 
00948 void ScribusMainWindow::addDefaultWindowMenuItems()
00949 {
00950        scrMenuMgr->clearMenu("Windows");
00951        scrMenuMgr->addMenuItem(scrActions["windowsCascade"], "Windows");
00952        scrMenuMgr->addMenuItem(scrActions["windowsTile"], "Windows");
00953        scrMenuMgr->addMenuSeparator("Windows");
00954 
00955        scrMenuMgr->addMenuItem(scrActions["toolsProperties"], "Windows");
00956        scrMenuMgr->addMenuItem(scrActions["toolsOutline"], "Windows");
00957        scrMenuMgr->addMenuItem(scrActions["toolsScrapbook"], "Windows");
00958        scrMenuMgr->addMenuItem(scrActions["toolsLayers"], "Windows");
00959        scrMenuMgr->addMenuItem(scrActions["toolsPages"], "Windows");
00960        scrMenuMgr->addMenuItem(scrActions["toolsBookmarks"], "Windows");
00961        scrMenuMgr->addMenuItem(scrActions["toolsMeasurements"], "Windows");
00962        scrMenuMgr->addMenuItem(scrActions["toolsActionHistory"], "Windows");
00963        scrMenuMgr->addMenuItem(scrActions["toolsPreflightVerifier"], "Windows");
00964        scrMenuMgr->addMenuItem(scrActions["toolsAlignDistribute"], "Windows");
00965        scrMenuMgr->addMenuSeparator("Windows");
00966        scrMenuMgr->addMenuItem(scrActions["toolsToolbarTools"], "Windows");
00967        scrMenuMgr->addMenuItem(scrActions["toolsToolbarPDF"], "Windows");
00968 }
00969 
00970 
00971 void ScribusMainWindow::initStatusBar()
00972 {
00973        mainWindowStatusLabel = new QLabel( "           ", statusBar(), "ft");
00974        mainWindowProgressBar = new QProgressBar(statusBar(), "p");
00975        mainWindowProgressBar->setCenterIndicator(true);
00976        mainWindowProgressBar->setFixedWidth( 100 );
00977        mainWindowProgressBar->reset();
00978        mainWindowXPosLabel = new QLabel( "X-Pos:", statusBar(), "xt");
00979        mainWindowYPosLabel = new QLabel( "Y-Pos:", statusBar(), "yt");
00980        mainWindowXPosDataLabel = new QLabel( "        ", statusBar(), "dt");
00981        mainWindowYPosDataLabel = new QLabel( "        ", statusBar(), "ydt");
00982 
00983        statusBar()->addWidget(mainWindowStatusLabel, 6, true);
00984        statusBar()->addWidget(mainWindowProgressBar, 0, true);
00985        statusBar()->addWidget(mainWindowXPosLabel, 0, true);
00986        statusBar()->addWidget(mainWindowXPosDataLabel, 1, true);
00987        statusBar()->addWidget(mainWindowYPosLabel, 0, true);
00988        statusBar()->addWidget(mainWindowYPosDataLabel, 1, true);
00989 }
00990 
00991 void ScribusMainWindow::setStatusBarMousePosition(double xp, double yp)
00992 {
00993        double xn = xp;
00994        double yn = yp;
00995        if (doc->guidesSettings.rulerMode)
00996        {
00997               xn -= doc->currentPage()->xOffset();
00998               yn -= doc->currentPage()->yOffset();
00999        }
01000        xn -= doc->rulerXoffset;
01001        yn -= doc->rulerYoffset;
01002        QString suffix=unitGetSuffixFromIndex(doc->unitIndex());
01003        int multiplier=unitGetDecimalsFromIndex(doc->unitIndex());
01004        double divisor=static_cast<double>(multiplier);
01005        int precision=unitGetPrecisionFromIndex(doc->unitIndex());
01006        QString tmp;
01007        mainWindowXPosDataLabel->setText(tmp.setNum(qRound(xn*doc->unitRatio() * multiplier) / divisor, 'f', precision) + suffix);
01008        mainWindowYPosDataLabel->setText(tmp.setNum(qRound(yn*doc->unitRatio() * multiplier) / divisor, 'f', precision) + suffix);
01009 }
01010 
01011 void ScribusMainWindow::setStatusBarInfoText(QString newText)
01012 {
01013        if (mainWindowStatusLabel)
01014               mainWindowStatusLabel->setText(newText);
01015 }
01016 
01017 //CB-->Doc
01018 void ScribusMainWindow::setTBvals(PageItem *currItem)
01019 {
01020        if (currItem->itemText.length() != 0)
01021        {
01022 //            int ChPos = QMIN(currItem->CPos, static_cast<int>(currItem->itemText.length()-1));
01023               const ParagraphStyle& currPStyle(currItem->currentStyle());
01024               setAbsValue(currPStyle.alignment());
01025               propertiesPalette->setParStyle(currPStyle.parent());
01026               propertiesPalette->setCharStyle(currItem->currentCharStyle().parent());
01027               doc->currentStyle = currItem->currentStyle();
01028               doc->currentStyle.charStyle() = currItem->currentCharStyle();
01029               emit TextStyle(doc->currentStyle);
01030               // to go: (av)
01031               emit TextUnderline(doc->currentStyle.charStyle().underlineOffset(), doc->currentStyle.charStyle().underlineWidth());
01032               emit TextStrike(doc->currentStyle.charStyle().strikethruOffset(), doc->currentStyle.charStyle().strikethruWidth());
01033               emit TextShadow(doc->currentStyle.charStyle().shadowXOffset(), doc->currentStyle.charStyle().shadowYOffset());
01034               emit TextFarben(doc->currentStyle.charStyle().strokeColor(),
01035                                           doc->currentStyle.charStyle().fillColor(),
01036                                           doc->currentStyle.charStyle().strokeShade(),
01037                                           doc->currentStyle.charStyle().fillShade());
01038               emit TextIFont(doc->currentStyle.charStyle().font().scName());
01039               emit TextISize(doc->currentStyle.charStyle().fontSize());
01040               emit TextUSval(doc->currentStyle.charStyle().tracking());
01041               emit TextStil(doc->currentStyle.charStyle().effects());
01042               emit TextScale(doc->currentStyle.charStyle().scaleH());
01043               emit TextScaleV(doc->currentStyle.charStyle().scaleV());
01044               emit TextBase(doc->currentStyle.charStyle().baselineOffset());
01045               emit TextOutline(doc->currentStyle.charStyle().outlineWidth());
01046        }
01047 }
01048 
01049 void ScribusMainWindow::wheelEvent(QWheelEvent *w)
01050 {
01051        if (HaveDoc)
01052        {
01053               int wheelVal=prefsManager->mouseWheelValue();
01054               if ((w->orientation() != Qt::Vertical) || ( w->state() & ShiftButton ))
01055               {
01056                      if (w->delta() < 0)
01057                             view->scrollBy(wheelVal, 0);
01058                      else
01059                             view->scrollBy(-wheelVal, 0);
01060               }
01061               else
01062               {
01063                      if (w->delta() < 0)
01064                             view->scrollBy(0, wheelVal);
01065                      else
01066                             view->scrollBy(0, -wheelVal);
01067               }
01068               w->accept();
01069        }
01070 }
01071 
01072 //Special keys assigned to actions are stolen by the action and not passed to
01073 //keyPressEvent so process them here.
01074 void ScribusMainWindow::specialActionKeyEvent(const QString& actionName, int unicodevalue)
01075 {
01076        if (HaveDoc)
01077        {
01078               if (doc->appMode==modeEdit)
01079               {
01080                      if (doc->m_Selection->count() == 1)
01081                      {
01082                             PageItem *currItem = doc->m_Selection->itemAt(0);
01083                             if (currItem!=NULL)
01084                             {
01085                                    if (unicodevalue!=-1)
01086                                    {
01087                                           if (currItem->HasSel && currItem->itemType()==PageItem::TextFrame)
01088                                                  currItem->asTextFrame()->deleteSelectedTextFromFrame();
01089 
01090                                           currItem->itemText.insertChars(currItem->CPos, QString(QChar(unicodevalue)), true);
01091                                           currItem->CPos += 1;
01092 //                                        currItem->Tinput = true;
01093                                           view->RefreshItem(currItem);
01094                                    }
01095                                    else if (actionName=="unicodeSmartHyphen") //ignore the char as we use an attribute if the text item, for now.
01096                                    {
01097                                           // this code is currently dead since unicodeSmartHyphen
01098                                           // doesnt have unicodevalue == -1 any more
01099                                           if (currItem->CPos-1>0)
01100                                           {
01101 #if 0
01102                                                  StyleFlag fl = currItem->itemText.item(QMAX(currItem->CPos-1,0))->effects();
01103                                                  fl |= ScStyle_HyphenationPossible;
01104                                                  currItem->itemText.item(QMAX(currItem->CPos-1,0))->setEffects(fl);
01105 #else
01106                                                  currItem->itemText.insertChars(currItem->CPos, QString(SpecialChars::SHYPHEN), true);
01107                                                  currItem->CPos += 1;
01108 #endif
01109 //                                               currItem->Tinput = true;
01110                                                  view->RefreshItem(currItem);
01111                                           }
01112                                    }
01113                             }
01114                      }
01115               }
01116        }
01117 }
01118 
01119 bool ScribusMainWindow::eventFilter( QObject* /*o*/, QEvent *e )
01120 {
01121        bool retVal;
01122        if ( e->type() == QEvent::KeyPress ) {
01123               QKeyEvent *k = (QKeyEvent *)e;
01124               int keyMod=0;
01125               if (k->state() & ShiftButton)
01126                      keyMod |= SHIFT;
01127               if (k->state() & ControlButton)
01128                      keyMod |= CTRL;
01129               if (k->state() & AltButton)
01130                      keyMod |= ALT;
01131 
01132               QKeySequence currKeySeq = QKeySequence(k->key() | keyMod);
01133               if (QString(currKeySeq).isNull())
01134                      return false;
01135               retVal=true;
01136               //Palette actions
01137               if (currKeySeq == scrActions["specialToggleAllPalettes"]->accel())
01138                      scrActions["specialToggleAllPalettes"]->activate();
01139               else
01140               if (currKeySeq == scrActions["toolsProperties"]->accel())
01141                      scrActions["toolsProperties"]->toggle();
01142               else
01143               if (currKeySeq == scrActions["toolsOutline"]->accel())
01144                      scrActions["toolsOutline"]->toggle();
01145               else
01146               if (currKeySeq == scrActions["toolsScrapbook"]->accel())
01147                      scrActions["toolsScrapbook"]->toggle();
01148               else
01149               if (currKeySeq == scrActions["toolsLayers"]->accel())
01150                      scrActions["toolsLayers"]->toggle();
01151               else
01152               if (currKeySeq == scrActions["toolsPages"]->accel())
01153                      scrActions["toolsPages"]->toggle();
01154               else
01155               if (currKeySeq == scrActions["toolsBookmarks"]->accel())
01156                      scrActions["toolsBookmarks"]->toggle();
01157               else
01158               if (currKeySeq == scrActions["toolsActionHistory"]->accel())
01159                      scrActions["toolsActionHistory"]->toggle();
01160               else
01161               if (currKeySeq == scrActions["toolsPreflightVerifier"]->accel())
01162                      scrActions["toolsPreflightVerifier"]->toggle();
01163               else
01164               if (currKeySeq == scrActions["toolsAlignDistribute"]->accel())
01165                      scrActions["toolsAlignDistribute"]->toggle();
01166               else
01167               //Edit actions
01168               if (currKeySeq == scrActions["editStyles"]->accel())
01169                      scrActions["editStyles"]->toggle();
01170               else
01171               if (currKeySeq == scrActions["editUndoAction"]->accel() && scrActions["editUndoAction"]->isEnabled())
01172                      scrActions["editUndoAction"]->activate();
01173               else
01174               if (currKeySeq == scrActions["editRedoAction"]->accel() && scrActions["editRedoAction"]->isEnabled())
01175                      scrActions["editRedoAction"]->activate();
01176               else
01177               //Other actions
01178               if (currKeySeq == scrActions["fileQuit"]->accel())
01179                      scrActions["fileQuit"]->activate();
01180               else
01181               //Zoom actions
01182               if (currKeySeq == scrActions["toolsZoomIn"]->accel())
01183                      scrActions["toolsZoomIn"]->activate();
01184               else
01185               if (currKeySeq == scrActions["toolsZoomOut"]->accel())
01186                      scrActions["toolsZoomOut"]->activate();
01187               else
01188                      retVal=false;
01189        }
01190        else
01191               retVal=false;
01192        //Return false to pass event to object
01193        return retVal;
01194 }
01195 
01196 void ScribusMainWindow::keyPressEvent(QKeyEvent *k)
01197 {
01198        QWidgetList windows;
01199        QWidget* w = NULL;
01200        int kk = k->key();
01201        QString uc = k->text();
01202        QString cr, Tcha, Twort;
01203        if (HaveDoc)
01204        {
01205               if ((doc->appMode == modeMagnifier) && (kk == Key_Shift))
01206               {
01207                      qApp->setOverrideCursor(QCursor(loadIcon("LupeZm.xpm")), true);
01208                      return;
01209               }
01210        }
01211        if (keyrep)
01212               return;
01213        keyrep = true;
01214        int KeyMod;
01215        switch (k->state())
01216        {
01217        case ShiftButton:
01218               KeyMod = SHIFT;
01219               break;
01220        case AltButton:
01221               KeyMod = ALT;
01222               break;
01223        case ControlButton:
01224               KeyMod = CTRL;
01225               break;
01226        default:
01227               KeyMod = 0;
01228               break;
01229        }
01230        //User presses escape and we have a doc open, and we have an item selected
01231        if ((kk == Key_Escape) && (HaveDoc))
01232        {
01233               keyrep = false;
01234               PageItem *currItem;
01235               if (doc->m_Selection->count() != 0)
01236               {
01237                      currItem = doc->m_Selection->itemAt(0);
01238                      switch (doc->appMode)
01239                      {
01240                             case modeNormal:
01241                                    currItem->Sizing = false;
01242                                    if (doc->SubMode != -1)
01243                                    {
01244                                           view->Deselect(false);
01245                                           doc->Items->remove(currItem->ItemNr);
01246                                    }
01247                                    else
01248                                           view->Deselect(false);
01249                                    break;
01250                             case modeEdit:
01251                                    break;
01252                             case modeLinkFrames:
01253                             case modeUnlinkFrames:
01254                             case modeRotation:
01255                             case modeEditGradientVectors:
01256                             case modeCopyProperties:
01257                                    view->Deselect(false);
01258                             case modePanning:
01259                                    break;
01260                             case modeDrawBezierLine:
01261                                    currItem->PoLine.resize(currItem->PoLine.size()-2);
01262                                    if (currItem->PoLine.size() < 4)
01263                                    {
01264                                           view->Deselect(false);
01265                                           doc->Items->remove(currItem->ItemNr);
01266                                    }
01267                                    else
01268                                    {
01269                                           doc->SizeItem(currItem->PoLine.WidthHeight().x(), currItem->PoLine.WidthHeight().y(), currItem->ItemNr, false, false);
01270                                           currItem->setPolyClip(qRound(QMAX(currItem->lineWidth() / 2.0, 1)));
01271                                           doc->AdjustItemSize(currItem);
01272                                           currItem->ContourLine = currItem->PoLine.copy();
01273                                           currItem->ClipEdited = true;
01274                                           currItem->FrameType = 3;
01275                                           slotDocCh();
01276                                    }
01277                                    view->FirstPoly = true;
01278                                    break;
01279                             default:
01280                                    view->Deselect(false);
01281                                    doc->Items->remove(currItem->ItemNr);
01282                                    break;
01283                      }
01284               }
01285               view->m_MouseButtonPressed = false;
01286               doc->DragP = false;
01287               doc->leaveDrag = false;
01288               view->operItemMoving = false;
01289               view->operItemResizing = false;
01290               view->inItemCreation = false;
01291               view->MidButt = false;
01292               doc->SubMode = -1;
01293               doc->ElemToLink = NULL;
01294               NoFrameEdit();
01295               slotSelect();
01296               return;
01297        }
01298        ButtonState buttonState = k->state();
01300        if ((HaveDoc) && (!view->zoomSpinBox->hasFocus()) && (!view->pageSelector->hasFocus()))
01301        {
01310               if ((doc->appMode != modeEdit) && (doc->m_Selection->count() == 0))
01311               {
01312                      int pg;
01313                      int wheelVal = prefsManager->mouseWheelValue();
01314                      if ((buttonState & ShiftButton) && !(buttonState & ControlButton) && !(buttonState & AltButton))
01315                             wheelVal = QMAX(qRound(wheelVal / 10.0), 1);
01316                      switch (kk)
01317                      {
01318                      case Key_Space:
01319                             keyrep = false;
01320                             if (doc->appMode == modePanning)
01321                                    setAppMode(modeNormal);
01322                             else
01323                                    setAppMode(modePanning);
01324                             return;
01325                             break;
01326                      case Key_Prior:
01327                             if (doc->masterPageMode())
01328                                    view->scrollBy(0, -prefsManager->mouseWheelValue());
01329                             else
01330                             {
01331                                    pg = doc->currentPageNumber();
01332                                    if ((buttonState & ShiftButton) && !(buttonState & ControlButton) && !(buttonState & AltButton))
01333                                           pg--;
01334                                    else
01335                                           pg -= doc->pageSets[doc->currentPageLayout].Columns;
01336                                    if (pg > -1)
01337                                           view->GotoPage(pg);
01338                             }
01339                             keyrep = false;
01340                             return;
01341                             break;
01342                      case Key_Next:
01343                             if (doc->masterPageMode())
01344                                    view->scrollBy(0, prefsManager->mouseWheelValue());
01345                             else
01346                             {
01347                                    pg = doc->currentPageNumber();
01348                                    if ((buttonState & ShiftButton) && !(buttonState & ControlButton) && !(buttonState & AltButton))
01349                                           pg++;
01350                                    else
01351                                           pg += doc->pageSets[doc->currentPageLayout].Columns;
01352                                    if (pg < static_cast<int>(doc->Pages->count()))
01353                                           view->GotoPage(pg);
01354                             }
01355                             keyrep = false;
01356                             return;
01357                             break;
01358                      case Key_Left:
01359                             view->scrollBy(-wheelVal, 0);
01360                             keyrep = false;
01361                             return;
01362                             break;
01363                      case Key_Right:
01364                             view->scrollBy(wheelVal, 0);
01365                             keyrep = false;
01366                             return;
01367                             break;
01368                      case Key_Up:
01369                             view->scrollBy(0, -wheelVal);
01370                             keyrep = false;
01371                             return;
01372                             break;
01373                      case Key_Down:
01374                             view->scrollBy(0, wheelVal);
01375                             keyrep = false;
01376                             return;
01377                             break;
01378                      case Key_Tab:
01379                             keyrep = false;
01380                             windows = wsp->windowList();
01381                             if (windows.count() > 1)
01382                             {
01383                                    for (int i = 0; i < static_cast<int>(windows.count()); ++i)
01384                                    {
01385                                           if (wsp->activeWindow() == windows.at(i))
01386                                           {
01387                                                  if (i == static_cast<int>(windows.count()-1))
01388                                                         w = windows.at(0);
01389                                                  else
01390                                                         w = windows.at(i+1);
01391                                                  break;
01392                                           }
01393                                    }
01394                                    outlinePalette->buildReopenVals();
01395                                    docCheckerPalette->clearErrorList();
01396                                    if ( w )
01397                                           w->showNormal();
01398                                    newActWin(w);
01399                             }
01400                             return;
01401                             break;
01402                      }
01403               }
01431               if (doc->m_Selection->count() != 0)
01432               {
01433                      double moveBy=1.0;
01434                      if (doc->unitIndex()!=SC_INCHES)
01435                      {
01436                             if ((buttonState & ShiftButton) && !(buttonState & ControlButton) && !(buttonState & AltButton))
01437                                    moveBy=0.1;
01438                             else if (!(buttonState & ShiftButton) && (buttonState & ControlButton) && !(buttonState & AltButton))
01439                                    moveBy=10.0;
01440                             else if ((buttonState & ShiftButton) && (buttonState & ControlButton) && !(buttonState & AltButton))
01441                                    moveBy=0.01;
01442 
01443                             moveBy/=doc->unitRatio();//Lets allow movement by the current doc ratio, not only points
01444                      }
01445                      else
01446                      {
01447                             if ((buttonState & ShiftButton) && !(buttonState & ControlButton) && !(buttonState & AltButton))
01448                                    moveBy=0.1/doc->unitRatio();
01449                             else if (!(buttonState & ShiftButton) && (buttonState & ControlButton) && !(buttonState & AltButton))
01450                                    moveBy=1.0/doc->unitRatio();
01451                             else if ((buttonState & ShiftButton) && (buttonState & ControlButton) && !(buttonState & AltButton))
01452                                    moveBy=0.01/doc->unitRatio();
01453                      }
01454                      bool resizing=((buttonState & AltButton) && !(buttonState & ControlButton));
01455                      bool resizingsmaller=(resizing && (buttonState & ShiftButton));
01456                      double resizeBy=1.0;
01457                      //CB with control locked out due to the requirement of moveby of 0.01, we cannot support
01458                      //resizeby 10 units unless we move to supporting modifier keys that most people dont have.
01459                      //if (buttonState & ControlButton)
01460                      //     resizeBy*=10.0;
01461                      resizeBy/=doc->unitRatio();
01462                      if (resizingsmaller)
01463                             resizeBy*=-1.0;
01464 
01465 
01466                      PageItem *currItem = doc->m_Selection->itemAt(0);
01467                      switch (doc->appMode)
01468                      {
01469                      case modeNormal:
01470                             switch (kk)
01471                             {
01472                             case Key_Backspace:
01473                             case Key_Delete:
01474                                    doc->itemSelection_DeleteItem();
01475                                    break;
01476                             case Key_Prior:
01477                                    if (!currItem->locked())
01478                                    {
01479                                           view->RaiseItem();
01480                                    }
01481                                    break;
01482                             case Key_Next:
01483                                    if (!currItem->locked())
01484                                    {
01485                                           view->LowerItem();
01486                                    }
01487                                    break;
01488                             case Key_Left:
01489                                    if (!currItem->locked())
01490                                    {
01491                                           if (!resizing)
01492                                           {
01493                                                  if ((doc->EditClip) && (view->ClRe != -1))
01494                                                  {
01495                                                         FPoint np;
01496                                                         if (view->EditContour)
01497                                                                np = currItem->ContourLine.point(view->ClRe);
01498                                                         else
01499                                                                np = currItem->PoLine.point(view->ClRe);
01500                                                         np = np - FPoint(moveBy, 0);
01501                                                         view->MoveClipPoint(currItem, np);
01502                                                  }
01503                                                  else
01504                                                  {
01505                                                  /* Don't use Grid or Guide Snapping when dragging Items or Groups with the keyboard */
01506                                                  /* as the user might be trying to fine tune a position */
01507                                                         bool sav1 = doc->SnapGuides;
01508                                                         bool sav2 = doc->useRaster;
01509                                                         doc->SnapGuides = false;
01510                                                         doc->useRaster = false;
01511                                                         view->moveGroup(-moveBy, 0);
01512                                                         doc->SnapGuides = sav1;
01513                                                         doc->useRaster = sav2;
01514                                                  }
01515                                           }
01516                                           else
01517                                           {
01518                                                  //CB If in EditContour mode, allow contour line to be scaled with arrow keys too
01519                                                  if(view->EditContour)
01520                                                         view->TransformPoly(10, 0, resizeBy/unitGetRatioFromIndex(doc->unitIndex()));
01521                                                  else
01522                                                  {
01523                                                         if (resizingsmaller)
01524                                                         {
01525                                                                currItem->Sizing = false;
01526                                                                doc->SizeItem(currItem->width()+resizeBy, currItem->height(), currItem->ItemNr, true);
01527                                                         }
01528                                                         else
01529                                                         {
01530                                                                doc->MoveItem(-resizeBy, 0, currItem, false);
01531                                                                currItem->moveImageXYOffsetBy(resizeBy/currItem->imageXScale(), 0);
01532                                                                currItem->Sizing = false;
01533                                                                doc->SizeItem(currItem->width()+resizeBy, currItem->height(), currItem->ItemNr, true);
01534                                                         }
01535                                                  }
01536                                           }
01537                                           view->updateContents();
01538                                           slotDocCh();
01539                                    }
01540                                    break;
01541                             case Key_Right:
01542                                    if (!currItem->locked())
01543                                    {
01544                                           if (!resizing)
01545                                           {
01546                                                  if ((doc->EditClip) && (view->ClRe != -1))
01547                                                  {
01548                                                         FPoint np;
01549                                                         if (view->EditContour)
01550                                                                np = currItem->ContourLine.point(view->ClRe);
01551                                                         else
01552                                                                np = currItem->PoLine.point(view->ClRe);
01553                                                         np = np + FPoint(moveBy, 0);
01554                                                         view->MoveClipPoint(currItem, np);
01555                                                  }
01556                                                  else
01557                                                  {
01558                                                  /* Don't use Grid or Guide Snapping when dragging Items or Groups with the keyboard */
01559                                                  /* as the user might be trying to fine tune a position */
01560                                                         bool sav1 = doc->SnapGuides;
01561                                                         bool sav2 = doc->useRaster;
01562                                                         doc->SnapGuides = false;
01563                                                         doc->useRaster = false;
01564                                                         view->moveGroup(moveBy, 0);
01565                                                         doc->SnapGuides = sav1;
01566                                                         doc->useRaster = sav2;
01567                                                  }
01568                                           }
01569                                           else
01570                                           {
01571                                                  //CB If in EditContour mode, allow contour line to be scaled with arrow keys too
01572                                                  if(view->EditContour)
01573                                                         view->TransformPoly(11, 0, resizeBy/unitGetRatioFromIndex(doc->unitIndex()));
01574                                                  else
01575                                                  {
01576                                                         if (resizingsmaller)
01577                                                         {
01578                                                                doc->MoveItem(-resizeBy, 0, currItem, false);
01579                                                                currItem->moveImageXYOffsetBy(resizeBy/currItem->imageXScale(), 0);
01580                                                                currItem->Sizing = false;
01581                                                                doc->SizeItem(currItem->width()+resizeBy, currItem->height(), currItem->ItemNr, true);
01582                                                         }
01583                                                         else
01584                                                         {
01585                                                                currItem->Sizing = false;
01586                                                                doc->SizeItem(currItem->width()+resizeBy, currItem->height(), currItem->ItemNr, true);
01587                                                         }
01588                                                  }
01589                                           }
01590                                           view->updateContents();
01591                                           slotDocCh();
01592                                    }
01593                                    break;
01594                             case Key_Up:
01595                                    if (!currItem->locked())
01596                                    {
01597                                           if (!resizing)
01598                                           {
01599                                                  if ((doc->EditClip) && (view->ClRe != -1))
01600                                                  {
01601                                                         FPoint np;
01602                                                         if (view->EditContour)
01603                                                                np = currItem->ContourLine.point(view->ClRe);
01604                                                         else
01605                                                                np = currItem->PoLine.point(view->ClRe);
01606                                                         np = np - FPoint(0, moveBy);
01607                                                         view->MoveClipPoint(currItem, np);
01608                                                  }
01609                                                  else
01610                                                  {
01611                                                  /* Don't use Grid or Guide Snapping when dragging Items or Groups with the keyboard */
01612                                                  /* as the user might be trying to fine tune a position */
01613                                                         bool sav1 = doc->SnapGuides;
01614                                                         bool sav2 = doc->useRaster;
01615                                                         doc->SnapGuides = false;
01616                                                         doc->useRaster = false;
01617                                                         view->moveGroup(0, -moveBy);
01618                                                         doc->SnapGuides = sav1;
01619                                                         doc->useRaster = sav2;
01620                                                  }
01621                                           }
01622                                           else
01623                                           {
01624                                                  //CB If in EditContour mode, allow contour line to be scaled with arrow keys too
01625                                                  if(view->EditContour)
01626                                                         view->TransformPoly(12, 0, resizeBy/unitGetRatioFromIndex(doc->unitIndex()));
01627                                                  else
01628                                                  {
01629                                                         if (resizingsmaller)
01630                                                         {
01631                                                                currItem->Sizing = false;
01632                                                                doc->SizeItem(currItem->width(), currItem->height()+resizeBy, currItem->ItemNr, true);
01633                                                         }
01634                                                         else
01635                                                         {
01636                                                                doc->MoveItem(0, -resizeBy, currItem, false);
01637                                                                currItem->moveImageXYOffsetBy(0, resizeBy/currItem->imageYScale());
01638                                                                currItem->Sizing = false;
01639                                                                doc->SizeItem(currItem->width(), currItem->height()+resizeBy, currItem->ItemNr, true);
01640                                                         }
01641                                                  }
01642                                           }
01643                                           view->updateContents();
01644                                           slotDocCh();
01645                                    }
01646                                    break;
01647                             case Key_Down:
01648                                    if (!currItem->locked())
01649                                    {
01650                                           if (!resizing)
01651                                           {
01652                                                  if ((doc->EditClip) && (view->ClRe != -1))
01653                                                  {
01654                                                         FPoint np;
01655                                                         if (view->EditContour)
01656                                                                np = currItem->ContourLine.point(view->ClRe);
01657                                                         else
01658                                                                np = currItem->PoLine.point(view->ClRe);
01659                                                         np = np + FPoint(0, moveBy);
01660                                                         view->MoveClipPoint(currItem, np);
01661                                                  }
01662                                                  else
01663                                                  {
01664                                                  /* Don't use Grid or Guide Snapping when dragging Items or Groups with the keyboard */
01665                                                  /* as the user might be trying to fine tune a position */
01666                                                         bool sav1 = doc->SnapGuides;
01667                                                         bool sav2 = doc->useRaster;
01668                                                         doc->SnapGuides = false;
01669                                                         doc->useRaster = false;
01670                                                         view->moveGroup(0, moveBy);
01671                                                         doc->SnapGuides = sav1;
01672                                                         doc->useRaster = sav2;
01673                                                  }
01674                                           }
01675                                           else
01676                                           {
01677                                                  //CB If in EditContour mode, allow contour line to be scaled with arrow keys too
01678                                                  if(view->EditContour)
01679                                                         view->TransformPoly(13, 0, resizeBy/unitGetRatioFromIndex(doc->unitIndex()));
01680                                                  else
01681                                                  {
01682                                                         if (resizingsmaller)
01683                                                         {
01684                                                                doc->MoveItem(0, -resizeBy, currItem, false);
01685                                                                currItem->moveImageXYOffsetBy(0, resizeBy/currItem->imageYScale());
01686                                                                currItem->Sizing = false;
01687                                                                doc->SizeItem(currItem->width(), currItem->height()+resizeBy, currItem->ItemNr, true);
01688                                                         }
01689                                                         else
01690                                                         {
01691                                                                currItem->Sizing = false;
01692                                                                doc->SizeItem(currItem->width(), currItem->height()+resizeBy, currItem->ItemNr, true);
01693                                                         }
01694                                                  }
01695                                           }
01696                                           view->updateContents();
01697                                           slotDocCh();
01698                                    }
01699                                    break;
01700                             default:
01701                                    break;
01702                             }
01703                             break;
01704                      case modeEdit:
01705                             if (currItem->asImageFrame() && !currItem->locked())
01706                             {
01707                                    currItem->handleModeEditKey(k, keyrep);
01708                                    /*
01709                                    double dX=0.0,dY=0.0;
01710                                    switch (kk)
01711                                    {
01712                                           case Key_Left:
01713                                                  dX=-moveBy;
01714                                                  break;
01715                                           case Key_Right:
01716                                                  dX=moveBy;
01717                                                  break;
01718                                           case Key_Up:
01719                                                  dY=-moveBy;
01720                                                  break;
01721                                           case Key_Down:
01722                                                  dY=moveBy;
01723                                                  break;
01724                                    }
01725                                    if (dX!=0.0 || dY!=0.0)
01726                                    {
01727                                           currItem->moveImageInFrame(dX, dY);
01728                                           view->updateContents(currItem->getRedrawBounding(view->scale()));
01729                                    }*/
01730                             }
01731                             view->oldCp = currItem->CPos;
01732                             if (currItem->itemType() == PageItem::TextFrame)
01733                             {
01734                                    bool kr=keyrep;
01735                                    currItem->handleModeEditKey(k, keyrep);
01736                                    keyrep=kr;
01737                             }
01738                             slotDocCh(false);
01739                             break;
01740                      }
01741               }
01742        }
01743        switch(kk)
01744        {
01745               case Key_Left:
01746               case Key_Right:
01747               case Key_Up:
01748               case Key_Down:
01749                      _arrowKeyDown = true;
01750        }
01751        keyrep = false;
01752 }
01753 
01754 void ScribusMainWindow::keyReleaseEvent(QKeyEvent *k)
01755 {
01756        if (HaveDoc && (k->state() & ControlButton))
01757        {
01758               if ((doc->appMode == modePanning) && (k->state() & Qt::RightButton))
01759                      setAppMode(modeNormal);
01760        }
01761        if (HaveDoc)
01762        {
01763               if (doc->appMode == modeMagnifier)
01764                      qApp->setOverrideCursor(QCursor(loadIcon("LupeZ.xpm")), true);
01765        }
01766        if (k->isAutoRepeat() || !_arrowKeyDown)
01767               return;
01768        switch(k->key())
01769        {
01770               case Key_Left:
01771               case Key_Right:
01772               case Key_Up:
01773               case Key_Down:
01774                      _arrowKeyDown = false;
01775                      if ((HaveDoc) && (!view->zoomSpinBox->hasFocus()) && (!view->pageSelector->hasFocus()))
01776                      {
01777                             uint docSelectionCount=doc->m_Selection->count();
01778                             if ((docSelectionCount != 0) && (doc->appMode == modeNormal) && (doc->EditClip) && (view->ClRe != -1))
01779                                    view->updateContents();
01780                             for (uint i = 0; i < docSelectionCount; ++i)
01781                                    doc->m_Selection->itemAt(i)->checkChanges(true);
01782                             if (docSelectionCount > 1 && view->groupTransactionStarted())
01783                                    undoManager->commit();
01784                      }
01785                      break;
01786        }
01787 }
01788 
01789 void ScribusMainWindow::closeEvent(QCloseEvent *ce)
01790 {
01791        QWidgetList windows = wsp->windowList();
01792        ScribusWin* tw;
01793        disconnect(wsp, SIGNAL(windowActivated(QWidget *)), this, SLOT(newActWin(QWidget *)));
01794        if (!windows.isEmpty())
01795        {
01796               uint windowCount=windows.count();
01797               for ( uint i = 0; i < windowCount; ++i )
01798               {
01799                      newActWin(windows.at(i));
01800                      tw = ActWin;
01801                      slotSelect();
01802                      ActWin->close();
01803                      if (tw == ActWin)
01804                      {
01805                             ce->ignore();
01806                             connect(wsp, SIGNAL(windowActivated(QWidget *)), this, SLOT(newActWin(QWidget *)));
01807                             return;
01808                      }
01809               }
01810        }
01811        propertiesPalette->hide();
01812        outlinePalette->hide();
01813        scrapbookPalette->hide();
01814        bookmarkPalette->hide();
01815        layerPalette->hide();
01816        pagePalette->hide();
01817        measurementPalette->hide();
01818        docCheckerPalette->hide();
01819        undoPalette->hide();
01820        alignDistributePalette->hide();
01821        guidePalette->hide();
01822        charPalette->hide();
01823 
01824        // Clean up plugins, THEN save prefs to disk
01825        ScCore->pluginManager->cleanupPlugins();
01826        if (!prefsManager->appPrefs.persistentScrapbook)
01827               scrapbookPalette->CleanUpTemp();
01828        prefsManager->appPrefs.RecentScrapbooks.clear();
01829        prefsManager->appPrefs.RecentScrapbooks = scrapbookPalette->getOpenScrapbooks();
01830        if (!emergencyActivated)
01831               prefsManager->SavePrefs();
01832        UndoManager::deleteInstance();
01833        qApp->setOverrideCursor(QCursor(ArrowCursor), true);
01834        exit(0);
01835 }
01836 
01838 // SLOT IMPLEMENTATION
01840 
01841 
01842 bool ScribusMainWindow::arrowKeyDown()
01843 {
01844        return _arrowKeyDown;
01845 }
01846 
01847 void ScribusMainWindow::startUpDialog()
01848 {
01849        bool docSet = false;
01850        PrefsContext* docContext = prefsManager->prefsFile->getContext("docdirs", false);
01851        NewDoc* dia = new NewDoc(this, RecentDocs, true);
01852        if (dia->exec())
01853        {
01854               if (dia->tabSelected == 0)
01855               {
01856                      int facingPages = dia->choosenLayout;
01857                      int firstPage = dia->firstPage->currentItem();
01858                      docSet = dia->startDocSetup->isChecked();
01859                      double topMargin = dia->marginGroup->top();
01860                      double bottomMargin = dia->marginGroup->bottom();
01861                      double leftMargin = dia->marginGroup->left();
01862                      double rightMargin = dia->marginGroup->right();
01863                      double columnDistance = dia->Dist;
01864                      double pageWidth = dia->pageWidth;
01865                      double pageHeight = dia->pageHeight;
01866                      double numberCols = dia->numberOfCols->value();
01867                      bool autoframes = dia->autoTextFrame->isChecked();
01868                      int orientation = dia->Orient;
01869                      int pageCount=dia->pageCountSpinBox->value();
01870                      QString pagesize;
01871                      if (dia->pageSizeComboBox->currentText() == CommonStrings::trCustomPageSize)
01872                             pagesize = CommonStrings::customPageSize;
01873                      else
01874                      {
01875                             PageSize ps2(dia->pageSizeComboBox->currentText());
01876                             pagesize = ps2.name();
01877                      }
01878                      doFileNew(pageWidth, pageHeight, topMargin, leftMargin, rightMargin, bottomMargin, columnDistance, numberCols, autoframes, facingPages, dia->unitOfMeasureComboBox->currentItem(), firstPage, orientation, 1, pagesize, true, pageCount);
01879                      doc->pageSets[facingPages].FirstPage = firstPage;
01880                      doc->bleeds.Bottom = dia->bleedBottom;
01881                      doc->bleeds.Top = dia->bleedTop;
01882                      doc->bleeds.Left = dia->bleedLeft;
01883                      doc->bleeds.Right = dia->bleedRight;
01884                      HaveNewDoc();
01885               }
01886               else
01887               {
01888                      if (dia->tabSelected == 1)
01889                      {
01890                             QString fileName(dia->fileDialog->selectedFile());
01891                             if (!fileName.isEmpty())
01892                             {
01893                                    docContext->set("docsopen", fileName.left(fileName.findRev("/")));
01894                                    loadDoc(fileName);
01895                             }
01896                      }
01897                      else
01898                      {
01899                             QString fileName(dia->recentDocListBox->currentText());
01900                             if (!fileName.isEmpty())
01901                                    loadRecent(ScPaths::separatorsToSlashes(fileName));
01902                      }
01903               }
01904        }
01905        prefsManager->setShowStartupDialog(!dia->startUpDialog->isChecked());
01906        delete dia;
01907        mainWindowStatusLabel->setText( tr("Ready"));
01908        if (docSet)
01909               slotDocSetup();
01910 }
01911 
01912 bool ScribusMainWindow::slotFileNew()
01913 {
01914        if (HaveDoc && doc->EditClip)
01915               ToggleFrameEdit();
01916        bool retVal = false;
01917        bool docSet = false;
01918        NewDoc* dia = new NewDoc(this, RecentDocs);
01919        if (dia->exec())
01920        {
01921               int facingPages = dia->choosenLayout;
01922               int firstPage = dia->firstPage->currentItem();
01923               docSet = dia->startDocSetup->isChecked();
01924               double topMargin = dia->marginGroup->top();
01925               double bottomMargin = dia->marginGroup->bottom();
01926               double leftMargin = dia->marginGroup->left();
01927               double rightMargin = dia->marginGroup->right();
01928               double columnDistance = dia->Dist;
01929               double pageWidth = dia->pageWidth;
01930               double pageHeight = dia->pageHeight;
01931               double numberCols = dia->numberOfCols->value();
01932               bool autoframes = dia->autoTextFrame->isChecked();
01933               int orientation = dia->Orient;
01934               int pageCount=dia->pageCountSpinBox->value();
01935               QString pagesize;
01936               if (dia->pageSizeComboBox->currentText() == CommonStrings::trCustomPageSize)
01937                      pagesize = CommonStrings::customPageSize;
01938               else
01939               {
01940                      PageSize ps2(dia->pageSizeComboBox->currentText());
01941                      pagesize = ps2.name();
01942               }
01943               if (doFileNew(pageWidth, pageHeight, topMargin, leftMargin, rightMargin, bottomMargin, columnDistance, numberCols, autoframes, facingPages, dia->unitOfMeasureComboBox->currentItem(), firstPage, orientation, 1, pagesize, true, pageCount))
01944               {
01945                      doc->pageSets[facingPages].FirstPage = firstPage;
01946                      doc->bleeds.Bottom = dia->bleedBottom;
01947                      doc->bleeds.Top = dia->bleedTop;
01948                      doc->bleeds.Left = dia->bleedLeft;
01949                      doc->bleeds.Right = dia->bleedRight;
01950                      mainWindowStatusLabel->setText( tr("Ready"));
01951                      HaveNewDoc();
01952                      retVal = true;
01953               }
01954        }
01955        delete dia;
01956        if (docSet)
01957               slotDocSetup();
01958        return retVal;
01959 }
01960 
01961 //TODO move to core, assign doc to doc list, optionally create gui for it
01962 ScribusDoc *ScribusMainWindow::newDoc(double width, double height, double topMargin, double leftMargin, double rightMargin, double bottomMargin, double columnDistance, double columnCount, bool autoTextFrames, int pageArrangement, int unitIndex, int firstPageLocation, int orientation, int firstPageNumber, const QString& defaultPageSize, bool requiresGUI, int pageCount, bool showView)
01963 {
01964        return doFileNew(width, height, topMargin, leftMargin, rightMargin, bottomMargin, columnDistance, columnCount, autoTextFrames, pageArrangement, unitIndex, firstPageLocation, orientation, firstPageNumber, defaultPageSize, requiresGUI, pageCount, showView);
01965        /* TODO CB finish later this week.
01966        if (HaveDoc)
01967               doc->OpenNodes = outlinePalette->buildReopenVals();
01968        MarginStruct margins(topMargin, leftMargin, bottomMargin, rightMargin);
01969        DocPagesSetup pagesSetup(pageArrangement, firstPageLocation, firstPageNumber, orientation, autoTextFrames, columnDistance, columnCount);
01970        QString newDocName(tr("Document")+"-"+QString::number(DocNr));
01971        doc = new ScribusDoc(newDocName, unitindex, pagesize, margins, pagesSetup);
01972               doc->setLoading(true);
01973        doc->setup(unitIndex, pageArrangement, firstPageLocation, orientation, firstPageNumber, defaultPageSize, newDocName);
01974        HaveDoc++;
01975        DocNr++;
01976        if (ScCore->haveCMS() && doc->CMSSettings.CMSinUse)
01977               recalcColors();
01978        //CB NOTE should be all done now
01979        doc->setPage(width, height, topMargin, leftMargin, rightMargin, bottomMargin, columnDistance, columnCount, autoTextFrames, pageArrangement);
01980        doc->setMasterPageMode(false);
01981        doc->addMasterPage(0, CommonStrings::masterPageNormal);
01982        int createCount=QMAX(pageCount,1);
01983        for (int i = 0; i < createCount; ++i)
01984               doc->addPage(i, CommonStrings::masterPageNormal, true);
01985        doc->addSection();
01986        doc->setFirstSectionFromFirstPageNumber();
01987        doc->setModified(false);
01988        doc->OpenNodes.clear();
01989        actionManager->disconnectNewDocActions();
01990        actionManager->connectNewDocActions(doc);
01991        //<<View and window code
01992        ScribusWin* w = new ScribusWin(wsp, doc);
01993        w->setMainWindow(this);
01994        if (view!=NULL)
01995        {
01996               actionManager->disconnectNewViewActions();
01997               disconnect(view, SIGNAL(signalGuideInformation(int, double)), alignDistributePalette, SLOT(setGuide(int, double)));
01998        }
01999        view = new ScribusView(w, this, doc);
02000        doc->setCurrentPage(doc->Pages->at(0));
02001        doc->setGUI(this, view);
02002        doc->setLoading(false);
02003        //run after setGUI to set up guidepalette ok
02004 
02005        view->setScale(prefsManager->displayScale());
02006        actionManager->connectNewViewActions(view);
02007        alignDistributePalette->setDoc(doc);
02008        docCheckerPalette->clearErrorList();
02009        w->setView(view);
02010        ActWin = w;
02011        doc->WinHan = w;
02012        w->setCentralWidget(view);
02013        doc->connectDocSignals(); //Must be before the first reformpages
02014        view->reformPages(true);
02015        //>>
02016 
02017        connect(undoManager, SIGNAL(undoRedoDone()), view, SLOT(DrawNew()));
02018        //connect(w, SIGNAL(Schliessen()), this, SLOT(DoFileClose()));
02019        connect(view, SIGNAL(signalGuideInformation(int, double)), alignDistributePalette, SLOT(setGuide(int, double)));
02020        //     connect(w, SIGNAL(SaveAndClose()), this, SLOT(DoSaveClose()));
02021 
02022        //Independent finishing tasks after doc setup
02023        if (showView)
02024        {
02025               if ( wsp->windowList().isEmpty() )
02026                      w->showMaximized();
02027               else
02028                      w->show();
02029               view->show();
02030        }
02031        connect(w, SIGNAL(AutoSaved()), this, SLOT(slotAutoSaved()));
02032        connect(ScCore->fileWatcher, SIGNAL(fileChanged(QString)), doc, SLOT(updatePict(QString)));
02033        connect(ScCore->fileWatcher, SIGNAL(fileDeleted(QString)), doc, SLOT(removePict(QString)));
02034        scrActions["fileSave"]->setEnabled(false);
02035        undoManager->switchStack(doc->DocName);
02036        styleManager->currentDoc(doc);
02037        tocGenerator->setDoc(doc);
02038 
02039        return doc;
02040        */
02041 }
02042 
02043 ScribusDoc *ScribusMainWindow::doFileNew(double width, double height, double topMargin, double leftMargin, double rightMargin, double bottomMargin, double columnDistance, double columnCount, bool autoTextFrames, int pageArrangement, int unitIndex, int firstPageLocation, int orientation, int firstPageNumber, const QString& defaultPageSize, bool requiresGUI, int pageCount, bool showView)
02044 {
02045        if (HaveDoc)
02046               outlinePalette->buildReopenVals();
02047        undoManager->setUndoEnabled(false);
02048        MarginStruct margins(topMargin, leftMargin, bottomMargin, rightMargin);
02049        DocPagesSetup pagesSetup(pageArrangement, firstPageLocation, firstPageNumber, orientation, autoTextFrames, columnDistance, columnCount);
02050        QString newDocName( tr("Document")+"-"+QString::number(DocNr));
02051        ScribusDoc *tempDoc = new ScribusDoc();
02052        if (requiresGUI)
02053               doc=tempDoc;
02054        //tempDoc = new ScribusDoc(newDocName, unitindex, pagesize, margins, pagesSetup);
02055        tempDoc->setLoading(true);
02056        outlinePalette->setDoc(tempDoc);
02057        tempDoc->setup(unitIndex, pageArrangement, firstPageLocation, orientation, firstPageNumber, defaultPageSize, newDocName);
02058        if (requiresGUI)
02059        {
02060               HaveDoc++;
02061               DocNr++;
02062        }
02063        if (ScCore->haveCMS() && tempDoc->CMSSettings.CMSinUse)
02064               recalcColors();
02065        //CB NOTE should be all done now
02066        tempDoc->setPage(width, height, topMargin, leftMargin, rightMargin, bottomMargin, columnCount, columnDistance, autoTextFrames, pageArrangement);
02067        tempDoc->setMasterPageMode(false);
02068        tempDoc->createDefaultMasterPages();
02069        tempDoc->createNewDocPages(pageCount);
02070        tempDoc->addSection();
02071        tempDoc->setFirstSectionFromFirstPageNumber();
02072        tempDoc->setModified(false);
02073        tempDoc->OpenNodes.clear();
02074        if (requiresGUI)
02075        {
02076               actionManager->disconnectNewDocActions();
02077               actionManager->connectNewDocActions(tempDoc);
02078        }
02079        //<<View and window code
02080        QWorkspace* qwsp=0;
02081        if (requiresGUI)
02082               qwsp=wsp;
02083        ScribusWin* w = new ScribusWin(qwsp, tempDoc);
02084        w->setMainWindow(this);
02085        if (requiresGUI && view!=NULL)
02086        {
02087               actionManager->disconnectNewViewActions();
02088               disconnect(view, SIGNAL(signalGuideInformation(int, double)), alignDistributePalette, SLOT(setGuide(int, double)));
02089        }
02090        ScribusView* tempView = new ScribusView(w, this, tempDoc);
02091        if (requiresGUI)
02092               view = tempView;
02093        tempDoc->setCurrentPage(tempDoc->Pages->at(0));
02094        tempDoc->setGUI(requiresGUI, this, tempView);
02095        tempDoc->setLoading(false);
02096        //run after setGUI to set up guidepalette ok
02097 
02098        tempView->setScale(prefsManager->displayScale());
02099        if (requiresGUI)
02100        {
02101               actionManager->connectNewViewActions(tempView);
02102               alignDistributePalette->setDoc(tempDoc);
02103               docCheckerPalette->clearErrorList();
02104        }
02105        w->setView(tempView);
02106        ActWin = w;
02107        tempDoc->WinHan = w;
02108        w->setCentralWidget(tempView);
02109        if (requiresGUI)
02110               tempDoc->connectDocSignals(); //Must be before the first reformpages
02111        tempView->reformPages(true);
02112        //>>
02113        if (requiresGUI)
02114        {
02115               connect(undoManager, SIGNAL(undoRedoDone()), tempView, SLOT(DrawNew()));
02116               //connect(w, SIGNAL(Schliessen()), this, SLOT(DoFileClose()));
02117               connect(tempView, SIGNAL(signalGuideInformation(int, double)), alignDistributePalette, SLOT(setGuide(int, double)));
02118               //     connect(w, SIGNAL(SaveAndClose()), this, SLOT(DoSaveClose()));
02119        }
02120        //Independent finishing tasks after tempDoc setup
02121        if (showView)
02122        {
02123               if ( wsp->windowList().isEmpty() )
02124                      w->showMaximized();
02125               else
02126                      w->show();
02127               tempView->show();
02128        }
02129        if (requiresGUI)
02130        {
02131               connect(w, SIGNAL(AutoSaved()), this, SLOT(slotAutoSaved()));
02132               connect(ScCore->fileWatcher, SIGNAL(fileChanged(QString)), tempDoc, SLOT(updatePict(QString)));
02133               connect(ScCore->fileWatcher, SIGNAL(fileDeleted(QString)), tempDoc, SLOT(removePict(QString)));
02134               //scrActions["fileSave"]->setEnabled(false);
02135               tempView->cmsToolbarButton->setOn(tempDoc->HasCMS);
02136               undoManager->switchStack(tempDoc->DocName);
02137               styleManager->setDoc(tempDoc);
02138               tocGenerator->setDoc(tempDoc);
02139        }
02140        undoManager->setUndoEnabled(true);
02141        return tempDoc;
02142 }
02143 
02144 void ScribusMainWindow::newView()
02145 {
02146        ScribusWin* w = new ScribusWin(wsp, doc);
02147        w->setMainWindow(this);
02148        view = new ScribusView(w, this, doc);
02149        view->setScale(prefsManager->displayScale());
02150        w->setView(view);
02151        ActWin = w;
02152        w->setCentralWidget(view);
02153        actionManager->connectNewViewActions(view);
02154        alignDistributePalette->setDoc(doc);
02155        connect(undoManager, SIGNAL(undoRedoDone()), view, SLOT(DrawNew()));
02156        view->show();
02157        //connect(w, SIGNAL(Schliessen()), this, SLOT(DoFileClose()));
02158 }
02159 
02160 void ScribusMainWindow::fontMenuAboutToShow()
02161 {
02162        QString df;
02163        if (doc->m_Selection->count() != 0)
02164        {
02165               PageItem *currItem = doc->m_Selection->itemAt(0);
02166               FontSub->RebuildList(doc, currItem->isAnnotation());
02167        }
02168        FontSub->setCurrentText(currentFontForFontMenu);
02169        //propertiesPalette->Fonts->setCurrentFont(nf);
02170        for (uint a = 2; a < FontMenu->count(); ++a)
02171        {
02172               df = FontID[FontMenu->idAt(a)];
02173               FontMenu->setItemChecked(FontMenu->idAt(a), (df == currentFontForFontMenu));
02174        }
02175 }
02176 
02177 void ScribusMainWindow::windowsMenuAboutToShow()
02178 {
02179        for( QMap<QString, QGuardedPtr<ScrAction> >::Iterator it = scrWindowsActions.begin(); it!=scrWindowsActions.end(); ++it )
02180               scrMenuMgr->removeMenuItem((*it), "Windows");
02181        scrWindowsActions.clear();
02182        addDefaultWindowMenuItems();
02183        QWidgetList windows = wsp->windowList();
02184        bool windowsListNotEmpty=!windows.isEmpty();
02185        scrActions["windowsCascade"]->setEnabled(windowsListNotEmpty);
02186        scrActions["windowsTile"]->setEnabled(windowsListNotEmpty);
02187        if (windowsListNotEmpty)
02188        {
02189               int windowCount=static_cast<int>(windows.count());
02190               if (windowCount>1)
02191                      scrMenuMgr->addMenuSeparator("Windows");
02192               for ( int i = 0; i < windowCount; ++i )
02193               {
02194                      QString docInWindow=windows.at(i)->caption();
02195                      scrWindowsActions.insert(docInWindow, new ScrAction( ScrAction::Window, noIcon, docInWindow, QKeySequence(), this, docInWindow, i));
02196                      scrWindowsActions[docInWindow]->setToggleAction(true);
02197                      connect( scrWindowsActions[docInWindow], SIGNAL(activatedData(int)), this, SLOT(windowsMenuActivated(int)) );
02198                      if (windowCount>1)
02199                             scrMenuMgr->addMenuItem(scrWindowsActions[docInWindow], "Windows");
02200                      scrWindowsActions[docInWindow]->setOn(wsp->activeWindow() == windows.at(i));
02201               }
02202        }
02203 }
02204 
02205 void ScribusMainWindow::newActWin(QWidget *w)
02206 {
02207        if (w == NULL)
02208        {
02209               ActWin = NULL;
02210               return;
02211        }
02212        if (doc!=0 && doc->EditClip)
02213               ToggleFrameEdit();
02214        ScribusWin* scw = (ScribusWin*)w;
02215        if (scw && scw->doc())
02216               if (!scw->doc()->hasGUI())
02217                      return;
02218        ActWin = scw;
02219        if (ActWin->doc()==NULL)
02220               return;
02221 
02222        if (doc != NULL)
02223        {
02224               if ((HaveDoc) && (doc != ActWin->doc()))
02225                      outlinePalette->buildReopenVals();
02226        }
02227        docCheckerPalette->clearErrorList();
02228 
02229        doc = ActWin->doc();
02230        undoManager->switchStack(doc->DocName);
02231 
02232        if (view!=NULL)
02233        {
02234               actionManager->disconnectNewViewActions();
02235               disconnect(view, SIGNAL(signalGuideInformation(int, double)), alignDistributePalette, SLOT(setGuide(int, double)));
02236               if (ScCore->usingGUI())
02237               {
02238                      disconnect(doc->m_Selection, SIGNAL(selectionIsMultiple(bool)), 0, 0);
02239                      //disconnect(doc->m_Selection, SIGNAL(empty()), 0, 0);
02240               }
02241        }
02242 
02243        view = ActWin->view();
02244        actionManager->connectNewViewActions(view);
02245        actionManager->disconnectNewDocActions();
02246        actionManager->connectNewDocActions(doc);
02247        connect(view, SIGNAL(signalGuideInformation(int, double)), alignDistributePalette, SLOT(setGuide(int, double)));
02248        if (ScCore->usingGUI())
02249        {
02250               connect(doc->m_Selection, SIGNAL(selectionIsMultiple(bool)), propertiesPalette, SLOT( setMultipleSelection(bool)));
02251               connect(doc->m_Selection, SIGNAL(selectionIsMultiple(bool)), actionManager, SLOT( handleMultipleSelections(bool)));
02252               //connect(doc->m_Selection, SIGNAL(empty()), propertiesPalette, SLOT( unsetItem()));
02253        }
02254 
02255        pagePalette->setView(view);
02256        alignDistributePalette->setDoc(doc);
02257        if (!doc->isLoading())
02258        {
02259               scanDocument();
02260               docCheckerPalette->buildErrorList(doc);
02261               SwitchWin();
02262               QWidgetList windows = wsp->windowList();
02263               ScribusWin* swin;
02264               for ( int i = 0; i < static_cast<int>(windows.count()); ++i )
02265               {
02266                      swin = (ScribusWin*)windows.at(i);
02267                      if (swin==ActWin && doc->masterPageMode())
02268                             swin->setMasterPagesPaletteShown(true);
02269                      else
02270                             swin->setMasterPagesPaletteShown(false);
02271               }
02272               //if (doc->masterPageMode())
02273               //     ActWin->setMasterPagesPaletteShown(true);
02274               setAppMode(doc->appMode);
02275        }
02276        w->setFocus();
02277        wsp->setScrollBarsEnabled(!(w->isMaximized()));
02278        scrActions["viewShowMargins"]->setOn(doc->guidesSettings.marginsShown);
02279        scrActions["viewShowBleeds"]->setOn(doc->guidesSettings.showBleed);
02280        scrActions["viewShowFrames"]->setOn(doc->guidesSettings.framesShown);
02281        scrActions["viewShowLayerMarkers"]->setOn(doc->guidesSettings.layerMarkersShown);
02282        scrActions["viewShowGrid"]->setOn(doc->guidesSettings.gridShown);
02283        scrActions["viewShowGuides"]->setOn(doc->guidesSettings.guidesShown);
02284        scrActions["viewShowColumnBorders"]->setOn(doc->guidesSettings.colBordersShown);
02285        scrActions["viewShowBaseline"]->setOn(doc->guidesSettings.baseShown);
02286        scrActions["viewShowImages"]->setOn(doc->guidesSettings.showPic);
02287        scrActions["viewShowTextChain"]->setOn(doc->guidesSettings.linkShown);
02288        scrActions["viewShowTextControls"]->setOn(doc->guidesSettings.showControls);
02289        scrActions["viewShowRulers"]->setOn(doc->guidesSettings.rulersShown);
02290        scrActions["viewRulerMode"]->setOn(doc->guidesSettings.rulerMode);
02291        scrActions["extrasGenerateTableOfContents"]->setEnabled(doc->hasTOCSetup());
02292        if (!doc->masterPageMode())
02293               pagePalette->Rebuild();
02294        outlinePalette->setDoc(doc);
02295        if (outlinePalette->isVisible())
02296        {
02297               outlinePalette->BuildTree(false);
02298               outlinePalette->reopenTree();
02299        }
02300        RestoreBookMarks();
02301        if (!doc->isLoading())
02302        {
02303               if (doc->m_Selection->count() != 0)
02304               {
02305                      HaveNewSel(doc->m_Selection->itemAt(0)->itemType());
02306                      doc->m_Selection->itemAt(0)->emitAllToGUI();
02307               }
02308               else
02309                      HaveNewSel(-1);
02310        }
02311        tocGenerator->setDoc(doc);
02312        styleManager->setDoc(doc);
02313 }
02314 
02315 void ScribusMainWindow::windowsMenuActivated( int id )
02316 {
02317        QWidget* windowWidget = wsp->windowList().at( id );
02318        if ( windowWidget )
02319               windowWidget->showNormal();
02320        newActWin(windowWidget);
02321 }
02322 
02323 void ScribusMainWindow::docSetup(ReformDoc* dia)
02324 {
02325        slotChangeUnit(dia->getSelectedUnit(), false);
02326        dia->updateDocumentSettings();
02327        if (dia->imageResolutionChanged())
02328        {
02329               setStatusBarInfoText( tr("Updating Pictures"));
02330               mainWindowProgressBar->reset();
02331               qApp->setOverrideCursor(QCursor(waitCursor), true);
02332               qApp->processEvents();
02333               doc->recalcPicturesRes(true);
02334               qApp->setOverrideCursor(QCursor(arrowCursor), true);
02335               setStatusBarInfoText("");
02336               mainWindowProgressBar->reset();
02337        }
02338        FontSub->RebuildList(doc);
02339        propertiesPalette->Fonts->RebuildList(doc);
02340        scrActions["viewShowMargins"]->setOn(doc->guidesSettings.marginsShown);
02341        scrActions["viewShowBleeds"]->setOn(doc->guidesSettings.showBleed);
02342        scrActions["viewShowFrames"]->setOn(doc->guidesSettings.framesShown);
02343        scrActions["viewShowLayerMarkers"]->setOn(doc->guidesSettings.layerMarkersShown);
02344        scrActions["viewShowGrid"]->setOn(doc->guidesSettings.gridShown);
02345        scrActions["viewShowGuides"]->setOn(doc->guidesSettings.guidesShown);
02346        scrActions["viewShowColumnBorders"]->setOn(doc->guidesSettings.colBordersShown);
02347        scrActions["viewShowBaseline"]->setOn(doc->guidesSettings.baseShown);
02348        scrActions["viewShowImages"]->setOn(doc->guidesSettings.showPic);
02349        scrActions["viewShowTextChain"]->setOn(doc->guidesSettings.linkShown);
02350        scrActions["viewShowTextControls"]->setOn(doc->guidesSettings.showControls);
02351        scrActions["viewShowRulers"]->setOn(doc->guidesSettings.rulersShown);
02352        scrActions["viewRulerMode"]->setOn(doc->guidesSettings.rulerMode);
02353        scrActions["extrasGenerateTableOfContents"]->setEnabled(doc->hasTOCSetup());
02354        view->cmsToolbarButton->setOn(doc->HasCMS);
02355        //doc emits changed() via this
02356        doc->setMasterPageMode(true);
02357        view->reformPages();
02358        doc->setMasterPageMode(false);
02359 /*     doc->setLoading(true);
02360        uint pageCount=doc->DocPages.count();
02361        for (uint c=0; c<pageCount; ++c)
02362               Apply_MasterPage(doc->DocPages.at(c)->MPageNam, c, false);
02363        doc->setLoading(false); */
02364        view->reformPages();
02365        view->GotoPage(doc->currentPage()->pageNr());
02366        view->DrawNew();
02367        propertiesPalette->ShowCMS();
02368        pagePalette->RebuildPage();
02369 }
02370 
02371 bool ScribusMainWindow::slotDocSetup()
02372 {
02373        bool ret = false;
02374        ReformDoc* dia = new ReformDoc(this, doc);
02375        Q_CHECK_PTR(dia);
02376        if (dia->exec())
02377        {
02378               docSetup(dia);
02379               ret = true;
02380        }
02381        delete dia;
02382        return ret;
02383 }
02384 
02385 void ScribusMainWindow::SwitchWin()
02386 {
02387        updateColorMenu();
02388        buildFontMenu();
02389        propertiesPalette->Cpal->ChooseGrad(0);
02390        updateActiveWindowCaption(doc->DocName);
02391        scrActions["shade100"]->setOn(true);
02392        propertiesPalette->setDoc(doc);
02393        pagePalette->setView(view);
02394        FontSub->RebuildList(doc);
02395        propertiesPalette->Fonts->RebuildList(doc);
02396        layerPalette->setDoc(doc);
02397        guidePalette->setDoc(doc);
02398        charPalette->setDoc(doc);
02399        outlinePalette->setDoc(doc);
02400        rebuildLayersList();
02401        view->updateLayerMenu();
02402        view->setLayerMenuText(doc->activeLayerName());
02403        //Do not set this!, it doesnt get valid pointers unless its in EditClip mode and its not
02404        //if we are switching windows #4357
02405        //nodePalette->setDoc(doc, view);
02406        slotChangeUnit(doc->unitIndex(), false);
02407        if (doc->EditClip)
02408        {
02409               doc->EditClip = !doc->EditClip;
02410               ToggleFrameEdit();
02411        }
02412        scrActions["fileClose"]->setEnabled(true);
02413        if (doc->masterPageMode())
02414        {
02415               scrActions["pageInsert"]->setEnabled(false);
02416               scrActions["pageDelete"]->setEnabled(false);
02417               scrActions["pageCopy"]->setEnabled(false);
02418               scrActions["pageMove"]->setEnabled(false);
02419               scrActions["pageApplyMasterPage"]->setEnabled(false);
02420               scrActions["pageCopyToMasterPage"]->setEnabled(false);
02421               scrActions["editMasterPages"]->setEnabled(false);
02422               scrActions["fileNew"]->setEnabled(false);
02423               scrActions["fileSave"]->setEnabled(true);
02424               scrActions["fileOpen"]->setEnabled(false);
02425               scrActions["fileClose"]->setEnabled(false);
02426               scrActions["fileRevert"]->setEnabled(false);
02427               scrMenuMgr->setMenuEnabled("FileOpenRecent", false);
02428               pagePalette->enablePalette(false);
02429        }
02430        else
02431        {
02432               scrMenuMgr->setMenuEnabled("Page", true);
02433               scrActions["editMasterPages"]->setEnabled(true);
02434               scrActions["fileNew"]->setEnabled(true);
02435               scrActions["fileOpen"]->setEnabled(true);
02436               scrActions["fileClose"]->setEnabled(true);
02437               scrActions["fileSave"]->setEnabled(true);
02438               //CB TODO  Huh? Why different to the above?, fileMenu->setItemEnabled(M_FileSave, ActWin->MenuStat[2]);
02439               scrActions["fileSaveAs"]->setEnabled(ActWin->menuStatus(3));
02440               scrActions["fileCollect"]->setEnabled(ActWin->menuStatus(3));
02441               scrActions["fileRevert"]->setEnabled(false);
02442               scrMenuMgr->setMenuEnabled("FileOpenRecent", true);
02443 
02444               if (doc->isModified())
02445                      slotDocCh(false);
02446               else
02447               {
02448                      bool setter = doc->Pages->count() > 1 ? true : false;
02449                      scrActions["pageDelete"]->setEnabled(setter);
02450                      scrActions["pageMove"]->setEnabled(setter);
02451               }
02452               scrActions["fileSaveAs"]->setEnabled(true);
02453               scrActions["fileCollect"]->setEnabled(true);
02454               pagePalette->enablePalette(true);
02455        }
02456 }
02457 
02458 void ScribusMainWindow::HaveNewDoc()
02459 {
02460        scrActions["filePrint"]->setEnabled(true);
02461        scrActions["fileSave"]->setEnabled(true);
02462        scrActions["fileClose"]->setEnabled(true);
02463        scrActions["fileDocSetup"]->setEnabled(true);
02464        scrActions["fileRevert"]->setEnabled(false);
02465        scrActions["fileCollect"]->setEnabled(true);
02466        scrActions["fileSaveAs"]->setEnabled(true);
02467        scrMenuMgr->setMenuEnabled("FileImport", true);
02468        scrMenuMgr->setMenuEnabled("FileExport", true);
02469        scrActions["fileExportAsEPS"]->setEnabled(true);
02470        scrActions["fileExportAsPDF"]->setEnabled(true);
02471        scrActions["pageImport"]->setEnabled(true);
02472        //scrActions["toolsPreflightVerifier"]->setEnabled(true);
02473 
02474        if ( ScCore->haveGS()==0 || ScCore->isWinGUI() )
02475               scrActions["PrintPreview"]->setEnabled(true);
02476 
02477        if (scrActions["SaveAsDocumentTemplate"])
02478               scrActions["SaveAsDocumentTemplate"]->setEnabled(true);
02479 
02480        scrActions["editCut"]->setEnabled(false);
02481        scrActions["editCopy"]->setEnabled(false);
02482        scrActions["editPaste"]->setEnabled((!Buffer2.isEmpty()) || (scrapbookPalette->tempBView->objectMap.count() > 0));
02483        scrMenuMgr->setMenuEnabled("EditPasteRecent", scrapbookPalette->tempBView->objectMap.count() > 0);
02484        scrMenuMgr->setMenuEnabled("EditContents", false);
02485        scrActions["editCopyContents"]->setEnabled(false);
02486        scrActions["editPasteContents"]->setEnabled(false);
02487        scrActions["editPasteContentsAbs"]->setEnabled(false);
02488        scrActions["editSelectAll"]->setEnabled(true);
02489        scrActions["editDeselectAll"]->setEnabled(false);
02490        scrActions["editPatterns"]->setEnabled(true);
02491        scrActions["editStyles"]->setEnabled(true);
02492        scrActions["editMasterPages"]->setEnabled(true);
02493        scrActions["editJavascripts"]->setEnabled(true);
02494 
02495        scrMenuMgr->setMenuEnabled("View", true);
02496        scrActions["viewSnapToGrid"]->setOn(doc->useRaster);
02497        scrActions["viewSnapToGuides"]->setOn(doc->SnapGuides);
02498        scrActions["viewShowRulers"]->setEnabled(true);
02499 
02500        scrMenuMgr->setMenuEnabled("Insert", true);
02501        scrActions["insertFrame"]->setEnabled(true);
02502        //scrMenuMgr->setMenuEnabled("Windows", true);
02503        scrMenuMgr->setMenuEnabled("Page", true);
02504        scrMenuMgr->setMenuEnabled("Extras", true);
02505 
02506        scrActions["toolsSelect"]->setEnabled(true);
02507        scrActions["toolsZoom"]->setEnabled(true);
02508        scrActions["toolsInsertTextFrame"]->setEnabled(true);
02509        scrActions["toolsInsertImageFrame"]->setEnabled(true);
02510        scrActions["toolsInsertTableFrame"]->setEnabled(true);
02511        scrActions["toolsInsertShape"]->setEnabled(true);
02512        scrActions["toolsInsertLine"]->setEnabled(true);
02513        scrActions["toolsInsertBezier"]->setEnabled(true);
02514        scrActions["toolsInsertFreehandLine"]->setEnabled(true);
02515        scrActions["toolsInsertPolygon"]->setEnabled(true);
02516        scrActions["toolsMeasurements"]->setEnabled(true);
02517        scrActions["toolsEyeDropper"]->setEnabled(true);
02518        scrActions["toolsPDFPushButton"]->setEnabled(true);
02519        scrActions["toolsPDFTextField"]->setEnabled(true);
02520        scrActions["toolsPDFCheckBox"]->setEnabled(true);
02521        scrActions["toolsPDFComboBox"]->setEnabled(true);
02522        scrActions["toolsPDFListBox"]->setEnabled(true);
02523        scrActions["toolsPDFAnnotText"]->setEnabled(true);
02524        scrActions["toolsPDFAnnotLink"]->setEnabled(true);
02525 
02526        bool setter = doc->Pages->count() > 1 ? true : false;
02527        scrActions["pageDelete"]->setEnabled(setter);
02528        scrActions["pageMove"]->setEnabled(setter);
02529 
02530        updateColorMenu();
02531        //Update palettes
02532        updateActiveWindowCaption(doc->DocName);
02533        scrActions["shade100"]->setOn(true);
02534        propertiesPalette->setDoc(doc);
02535        propertiesPalette->Cpal->ChooseGrad(0);
02536 //     propertiesPalette->updateColorList();
02537        pagePalette->setView(view);
02538        layerPalette->setDoc(doc);
02539        guidePalette->setDoc(doc);
02540        charPalette->setDoc(doc);
02541        outlinePalette->setDoc(doc);
02542        if (outlinePalette->isVisible())
02543               outlinePalette->BuildTree();
02544        rebuildLayersList();
02545        view->updateLayerMenu();
02546        view->setLayerMenuText(doc->activeLayerName());
02547        slotChangeUnit(doc->unitIndex());
02548        buildFontMenu();
02549        windowsMenuAboutToShow();
02550        connect(view, SIGNAL(changeUN(int)), this, SLOT(slotChangeUnit(int)));
02551        connect(view, SIGNAL(changeLA(int)), layerPalette, SLOT(markActiveLayer(int)));
02552        connect(view->horizRuler, SIGNAL(MarkerMoved(double, double)), this, SLOT(setStatusBarMousePosition(double, double)));
02553        connect(view->horizRuler, SIGNAL(DocChanged(bool)), this, SLOT(slotDocCh(bool)));
02554        connect(view, SIGNAL(ClipPo(double, double)), nodePalette, SLOT(SetXY(double, double)));
02555        connect(view, SIGNAL(PolyOpen()), nodePalette, SLOT(IsOpen()));
02556        connect(view, SIGNAL(PStatus(int, uint)), nodePalette, SLOT(PolyStatus(int, uint)));
02557        connect(view, SIGNAL(ItemPos(double, double)), propertiesPalette, SLOT(setXY(double, double)));
02558        connect(view, SIGNAL(ItemGeom(double, double)), propertiesPalette, SLOT(setBH(double, double)));
02559        connect(view, SIGNAL(ChBMText(PageItem *)), this, SLOT(BookMarkTxT(PageItem *)));
02560        connect(view, SIGNAL(HaveSel(int)), this, SLOT(HaveNewSel(int)));
02561        connect(view, SIGNAL(SetAngle(double)), propertiesPalette, SLOT(setR(double)));
02562        connect(view, SIGNAL(SetSizeValue(double)), propertiesPalette, SLOT(setSvalue(double)));
02563        connect(view, SIGNAL(SetLocalValues(double, double, double, double)), propertiesPalette, SLOT(setLvalue(double, double, double, double)));
02564        connect(view, SIGNAL(SetLineArt(Qt::PenStyle, Qt::PenCapStyle, Qt::PenJoinStyle)), propertiesPalette, SLOT( setLIvalue(Qt::PenStyle, Qt::PenCapStyle, Qt::PenJoinStyle)));
02565 //     connect(view, SIGNAL(ItemFarben(QString, QString, int, int)), this, SLOT(setCSMenu(QString, QString, int, int)));
02566 //     connect(view, SIGNAL(ItemFarben(QString, QString, int, int)), propertiesPalette->Cpal, SLOT(setActFarben(QString, QString, int, int)));
02567 //     connect(view, SIGNAL(ItemGradient(int)), propertiesPalette->Cpal, SLOT(setActGradient(int)));
02568 //     connect(view, SIGNAL(ItemTrans(double, double)), propertiesPalette->Cpal, SLOT(setActTrans(double, double)));
02569 //     connect(view, SIGNAL(ItemBlend(int, int)), propertiesPalette->Cpal, SLOT(setActBlend(int, int)));
02570        connect(view, SIGNAL(ItemTextAttr(double)), propertiesPalette, SLOT(setLsp(double)));
02571        connect(view, SIGNAL(ItemTextUSval(int)), propertiesPalette, SLOT(setExtra(int)));
02572 //     connect(view, SIGNAL(ItemTextCols(int, double)), propertiesPalette, SLOT(setCols(int, double)));
02573        connect(view, SIGNAL(SetDistValues(double, double, double, double)), propertiesPalette, SLOT(setDvals(double, double, double, double)));
02574        connect(view, SIGNAL(ItemTextAbs(int)), propertiesPalette, SLOT(setAli(int)));
02575        connect(view, SIGNAL(ItemTextFont(const QString&)), this, SLOT(AdjustFontMenu(const QString&)));
02576        connect(view, SIGNAL(ItemTextFont(const QString&)), propertiesPalette, SLOT(setFontFace(const QString&)));
02577        connect(view, SIGNAL(ItemTextSize(int)), propertiesPalette, SLOT(setSize(int)));
02578        //connect(view, SIGNAL(ItemRadius(double)), propertiesPalette, SLOT(setRR(double)));
02579        connect(view, SIGNAL(Amode(int)), this, SLOT(setAppMode(int)));
02580        connect(view, SIGNAL(PaintingDone()), this, SLOT(slotSelect()));
02581        connect(view, SIGNAL(DocChanged()), this, SLOT(slotDocCh()));
02582        //connect(view, SIGNAL(HavePoint(bool, bool)), nodePalette, SLOT(HaveNode(bool, bool)));
02583        connect(view, SIGNAL(MousePos(double, double)), this, SLOT(setStatusBarMousePosition(double, double)));
02584        //connect(view, SIGNAL(ItemRadius(double)), propertiesPalette, SLOT(setRR(double)));
02585        connect(view, SIGNAL(ItemTextStil(int)), propertiesPalette, SLOT(setStil(int)));
02586        connect(view, SIGNAL(ItemTextSca(int)), propertiesPalette, SLOT(setTScale(int)));
02587        connect(view, SIGNAL(ItemTextScaV(int)), propertiesPalette, SLOT(setTScaleV(int)));
02588        connect(view, SIGNAL(ItemTextBase(int)), propertiesPalette, SLOT(setTBase(int)));
02589        connect(view, SIGNAL(ItemTextShadow(int, int )), propertiesPalette, SLOT(setShadowOffs(int, int )));
02590        connect(view, SIGNAL(ItemTextUnderline(int, int)), propertiesPalette, SLOT(setUnderline(int, int)));
02591        connect(view, SIGNAL(ItemTextStrike(int, int)), propertiesPalette, SLOT(setStrike(int, int)));
02592        connect(view, SIGNAL(ItemTextOutline(int)), propertiesPalette, SLOT(setOutlineW(int)));
02593        connect(view, SIGNAL(ItemTextSize(int)), this, SLOT(setFSizeMenu(int)));
02594        connect(view, SIGNAL(ItemTextStil(int)), this, SLOT(setStilvalue(int)));
02595        connect(view, SIGNAL(ItemTextAbs(int)), this, SLOT(setAbsValue(int)));
02596        connect(view, SIGNAL(ItemTextFarben(QString, QString, int, int)), propertiesPalette, SLOT(setActFarben(QString, QString, int, int)));
02597        connect(view, SIGNAL(HasTextSel()), this, SLOT(EnableTxEdit()));
02598        connect(view, SIGNAL(HasNoTextSel()), this, SLOT(DisableTxEdit()));
02599        connect(view, SIGNAL(CopyItem()), this, SLOT(slotEditCopy()));
02600        connect(view, SIGNAL(CutItem()), this, SLOT(slotEditCut()));
02601        connect(view, SIGNAL(LoadPic()), this, SLOT(slotGetContent()));
02602        connect(view, SIGNAL(AppendText()), this, SLOT(slotFileAppend()));
02603        connect(view, SIGNAL(AnnotProps()), this, SLOT(ModifyAnnot()));
02604        //connect(view, SIGNAL(EditGuides()), this, SLOT(ManageGuides()));
02605        connect(view, SIGNAL(LoadElem(QString, double ,double, bool, bool, ScribusDoc *, ScribusView*)), this, SLOT(slotElemRead(QString, double, double, bool, bool, ScribusDoc *, ScribusView*)));
02606        connect(view, SIGNAL(AddBM(PageItem *)), this, SLOT(AddBookMark(PageItem *)));
02607        connect(view, SIGNAL(DelBM(PageItem *)), this, SLOT(DelBookMark(PageItem *)));
02608        connect(view, SIGNAL(RasterPic(bool)), this, SLOT(HaveRaster(bool)));
02609        connect(view, SIGNAL(DoGroup()), this, SLOT(GroupObj()));
02610        connect(view, SIGNAL(EndNodeEdit()), this, SLOT(ToggleFrameEdit()));
02611        connect(view, SIGNAL(LevelChanged(uint )), propertiesPalette, SLOT(setLevel(uint)));
02612        connect(view, SIGNAL(callGimp()), this, SLOT(callImageEditor()));
02613 }
02614 
02615 void ScribusMainWindow::HaveNewSel(int Nr)
02616 {
02617        PageItem *currItem = NULL;
02618        if (Nr != -1)
02619        {
02620               if (doc->m_Selection->count() != 0)
02621               {
02622                      uint lowestItem = 999999;
02623                      for (uint a=0; a<doc->m_Selection->count(); ++a)
02624                      {
02625                             currItem = doc->m_Selection->itemAt(a);
02626                             lowestItem = QMIN(lowestItem, currItem->ItemNr);
02627                      }
02628                      currItem = doc->Items->at(lowestItem);
02629 //                   doc->m_Selection->removeItem(currItem);
02630 //                   doc->m_Selection->prependItem(currItem);
02631 //                   currItem = doc->m_Selection->itemAt(0);
02632                      if (!currItem)
02633                             Nr=-1;
02634               }
02635               else
02636                      Nr = -1;
02637        }
02638        actionManager->disconnectNewSelectionActions();
02639        scrActions["editDeselectAll"]->setEnabled(Nr!=-1);
02640        scrActions["itemDetachTextFromPath"]->setEnabled(false);
02641        charPalette->setEnabled(false, 0);
02642        scrActions["itemUpdateImage"]->setEnabled(Nr==PageItem::ImageFrame && currItem->PicAvail);
02643        scrActions["itemAdjustFrameToImage"]->setEnabled(Nr==PageItem::ImageFrame && currItem->PicAvail && !currItem->isTableItem);
02644        scrActions["itemExtendedImageProperties"]->setEnabled(Nr==PageItem::ImageFrame && currItem->PicAvail && currItem->pixm.imgInfo.valid);
02645        scrMenuMgr->setMenuEnabled("ItemPreviewSettings", Nr==PageItem::ImageFrame);
02646        scrActions["itemImageIsVisible"]->setEnabled(Nr==PageItem::ImageFrame);
02647        scrActions["itemPreviewLow"]->setEnabled(Nr==PageItem::ImageFrame);
02648        scrActions["itemPreviewNormal"]->setEnabled(Nr==PageItem::ImageFrame);
02649        scrActions["itemPreviewFull"]->setEnabled(Nr==PageItem::ImageFrame);
02650        scrActions["styleImageEffects"]->setEnabled(Nr==PageItem::ImageFrame);
02651        scrActions["editCopyContents"]->setEnabled(Nr==PageItem::ImageFrame && currItem->PicAvail);
02652        scrActions["editPasteContents"]->setEnabled(Nr==PageItem::ImageFrame);
02653        scrActions["editPasteContentsAbs"]->setEnabled(Nr==PageItem::ImageFrame);
02654        scrActions["editEditWithImageEditor"]->setEnabled(Nr==PageItem::ImageFrame && currItem->PicAvail && currItem->isRaster);
02655        if (Nr!=PageItem::ImageFrame)
02656        {
02657               scrActions["itemImageIsVisible"]->setOn(false);
02658               scrActions["itemPreviewLow"]->setOn(false);
02659               scrActions["itemPreviewNormal"]->setOn(false);
02660               scrActions["itemPreviewFull"]->setOn(false);
02661        }
02662        if ((Nr==-1) || (Nr!=-1 && !currItem->asTextFrame()))
02663               enableTextActions(&scrActions, false);
02664        scrActions["insertSampleText"]->setEnabled(false);
02665 
02666        view->horizRuler->ItemPosValid = false;
02667        view->horizRuler->repaint();
02668        switch (Nr)
02669        {
02670        case -1: // None
02671               scrActions["fileImportText"]->setEnabled(false);
02672               scrActions["fileImportText2"]->setEnabled(false);
02673               scrActions["fileImportImage"]->setEnabled(false);
02674               scrActions["fileImportAppendText"]->setEnabled(false);
02675               scrActions["fileExportText"]->setEnabled(false);
02676               scrMenuMgr->setMenuEnabled("Item", false);
02677               scrMenuMgr->setMenuEnabled("ItemShapes", false);
02678               scrMenuMgr->setMenuEnabled("ItemConvertTo", false);
02679               scrActions["itemConvertToBezierCurve"]->setEnabled(false);
02680               scrActions["itemConvertToImageFrame"]->setEnabled(false);
02681               scrActions["itemConvertToOutlines"]->setEnabled(false);
02682               scrActions["itemConvertToPolygon"]->setEnabled(false);
02683               scrActions["itemConvertToTextFrame"]->setEnabled(false);
02684               scrActions["itemLock"]->setEnabled(false);
02685               scrActions["itemLockSize"]->setEnabled(false);
02686               scrActions["itemPrintingEnabled"]->setEnabled(false);
02687               scrActions["editCut"]->setEnabled(false);
02688               scrActions["editCopy"]->setEnabled(false);
02689               scrActions["editCopyContents"]->setEnabled(false);
02690               scrActions["editSearchReplace"]->setEnabled(false);
02691               scrActions["extrasHyphenateText"]->setEnabled(false);
02692               scrActions["extrasDeHyphenateText"]->setEnabled(false);
02693 
02694               scrActions["toolsUnlinkTextFrame"]->setEnabled(false);
02695               scrActions["toolsLinkTextFrame"]->setEnabled(false);
02696               scrActions["toolsEditContents"]->setEnabled(false);
02697               scrActions["toolsEditWithStoryEditor"]->setEnabled(false);
02698               scrActions["toolsRotate"]->setEnabled(false);
02699               scrActions["toolsCopyProperties"]->setEnabled(false);
02700               //CB 061005 moved to cpalette choosegrad
02701               //propertiesPalette->Cpal->gradientQCombo->setCurrentItem(0);
02702               outlinePalette->slotShowSelect(doc->currentPageNumber(), -1);
02703               propertiesPalette->setGradientEditMode(false);
02704               break;
02705        case PageItem::ImageFrame: //Image Frame
02706               scrActions["fileImportAppendText"]->setEnabled(false);
02707               scrActions["fileImportText"]->setEnabled(false);
02708               scrActions["fileImportText2"]->setEnabled(false);
02709               scrActions["fileImportImage"]->setEnabled(true);
02710               scrActions["editCut"]->setEnabled(true);
02711               scrActions["editCopy"]->setEnabled(true);
02712               scrMenuMgr->setMenuEnabled("EditContents", true);
02713               scrActions["editClearContents"]->setEnabled(true);
02714               scrActions["editSearchReplace"]->setEnabled(false);
02715               scrActions["extrasHyphenateText"]->setEnabled(false);
02716               scrActions["extrasDeHyphenateText"]->setEnabled(false);
02717               scrMenuMgr->setMenuEnabled("Item", true);
02718               scrMenuMgr->setMenuEnabled("ItemShapes", !(currItem->isTableItem && currItem->isSingleSel));
02719               scrMenuMgr->setMenuEnabled("ItemConvertTo", true);
02720               scrActions["itemConvertToBezierCurve"]->setEnabled(false);
02721               scrActions["itemConvertToImageFrame"]->setEnabled(false);
02722               scrActions["itemConvertToOutlines"]->setEnabled(false);
02723               scrActions["itemConvertToPolygon"]->setEnabled(!currItem->isTableItem && doc->appMode != modeEdit);
02724               scrActions["itemConvertToTextFrame"]->setEnabled(doc->appMode != modeEdit);
02725               scrActions["toolsUnlinkTextFrame"]->setEnabled(false);
02726               scrActions["toolsLinkTextFrame"]->setEnabled(false);
02727               scrActions["toolsEditContents"]->setEnabled(currItem->ScaleType);
02728               scrActions["toolsEditWithStoryEditor"]->setEnabled(false);
02729               scrActions["toolsRotate"]->setEnabled(true);
02730               scrActions["toolsCopyProperties"]->setEnabled(true);
02731               scrActions["itemImageIsVisible"]->setOn(currItem->imageShown());
02732               scrActions["itemPreviewLow"]->setOn(currItem->pixm.imgInfo.lowResType==scrActions["itemPreviewLow"]->actionInt());
02733               scrActions["itemPreviewNormal"]->setOn(currItem->pixm.imgInfo.lowResType==scrActions["itemPreviewNormal"]->actionInt());
02734               scrActions["itemPreviewFull"]->setOn(currItem->pixm.imgInfo.lowResType==scrActions["itemPreviewFull"]->actionInt());
02735 
02736               break;
02737        case PageItem::TextFrame: //Text Frame
02738               FontSub->RebuildList(doc, currItem->isAnnotation());
02739               propertiesPalette->Fonts->RebuildList(doc, currItem->isAnnotation());
02740               scrActions["fileImportText"]->setEnabled(true);
02741               scrActions["fileImportText2"]->setEnabled(true);
02742               scrActions["fileImportImage"]->setEnabled(false);
02743               scrActions["fileImportAppendText"]->setEnabled(true);
02744               scrActions["fileExportText"]->setEnabled(true);
02745               scrActions["editCut"]->setEnabled(true);
02746               scrActions["editCopy"]->setEnabled(true);
02747               scrMenuMgr->setMenuEnabled("EditContents", true);
02748               scrActions["editClearContents"]->setEnabled(true);
02749               scrActions["editSearchReplace"]->setEnabled(currItem->itemText.length() != 0);
02750               scrActions["extrasHyphenateText"]->setEnabled(currItem->itemText.length() != 0);
02751               scrActions["extrasDeHyphenateText"]->setEnabled(currItem->itemText.length() != 0);
02752               scrMenuMgr->setMenuEnabled("Item", true);
02753               scrMenuMgr->setMenuEnabled("ItemShapes", !(currItem->isTableItem && currItem->isSingleSel));
02754               scrMenuMgr->setMenuEnabled("ItemConvertTo", true);
02755               scrActions["itemConvertToBezierCurve"]->setEnabled(false);
02756               scrActions["itemConvertToImageFrame"]->setEnabled(doc->appMode != modeEdit);
02757               scrActions["itemConvertToOutlines"]->setEnabled(!currItem->isTableItem && doc->appMode != modeEdit);
02758               scrActions["itemConvertToPolygon"]->setEnabled(!currItem->isTableItem && doc->appMode != modeEdit);
02759               scrActions["itemConvertToTextFrame"]->setEnabled(false);
02760 
02761               scrActions["toolsRotate"]->setEnabled(true);
02762               scrActions["toolsCopyProperties"]->setEnabled(true);
02763               scrActions["toolsEditWithStoryEditor"]->setEnabled(true);
02764               scrActions["insertSampleText"]->setEnabled(true);
02765               if ((currItem->nextInChain() != 0) || (currItem->prevInChain() != 0))
02766               {
02767                      scrActions["itemConvertToBezierCurve"]->setEnabled(false);
02768                      scrActions["itemConvertToImageFrame"]->setEnabled(false);
02769 //                   scrActions["itemConvertToOutlines"]->setEnabled(false);
02770                      scrActions["itemConvertToPolygon"]->setEnabled(false);
02771                      scrActions["itemConvertToTextFrame"]->setEnabled(false);
02772                      scrActions["toolsUnlinkTextFrame"]->setEnabled(true);
02773                      // FIXME: once there's one itemtext per story, always enable editcontents
02774                      if ((currItem->prevInChain() != 0) && (currItem->itemText.length() == 0))
02775                             scrActions["toolsEditContents"]->setEnabled(false);
02776                      else
02777                             scrActions["toolsEditContents"]->setEnabled(true);
02778               }
02779               else
02780               {
02781                      scrActions["toolsEditContents"]->setEnabled(true);
02782                      scrActions["toolsUnlinkTextFrame"]->setEnabled(false);
02783               }
02784               if (currItem->nextInChain() == 0)
02785                      scrActions["toolsLinkTextFrame"]->setEnabled(true);
02786 //            if (doc->masterPageMode())
02787 //                   scrActions["toolsLinkTextFrame"]->setEnabled(false);
02788               if (doc->appMode == modeEdit)
02789               {
02790                      setTBvals(currItem);
02791                      scrActions["editSelectAll"]->setEnabled(true);
02792                      charPalette->setEnabled(true, currItem);
02793                      if (currItem->asTextFrame())
02794                             enableTextActions(&scrActions, true, currItem->currentStyle().charStyle().font().scName());
02795                      view->horizRuler->setItem(currItem);
02796                      if (currItem->lineColor() != CommonStrings::None)
02797                             view->horizRuler->lineCorr = currItem->lineWidth() / 2.0;
02798                      else
02799                             view->horizRuler->lineCorr = 0;
02800                      view->horizRuler->ColGap = currItem->ColGap;
02801                      view->horizRuler->Cols = currItem->Cols;
02802                      view->horizRuler->Extra = currItem->textToFrameDistLeft();
02803                      view->horizRuler->RExtra = currItem->textToFrameDistRight();
02804                      view->horizRuler->First = currItem->currentStyle().firstIndent();
02805                      view->horizRuler->Indent = currItem->currentStyle().leftMargin();
02806                      double columnWidth = (currItem->width() - (currItem->columnGap() * (currItem->columns() - 1))
02807                             - currItem->textToFrameDistLeft() - currItem->textToFrameDistLeft()
02808                             - 2*view->horizRuler->lineCorr) / currItem->columns();
02809                      view->horizRuler->RMargin = columnWidth - currItem->currentStyle().rightMargin();
02810                      if (currItem->imageFlippedH() || (currItem->reversed()))
02811                             view->horizRuler->Revers = true;
02812                      else
02813                             view->horizRuler->Revers = false;
02814                      view->horizRuler->ItemPosValid = true;
02815                      view->horizRuler->TabValues = currItem->currentStyle().tabValues();
02816                      view->horizRuler->repaint();
02817               }
02818               else
02819               {
02820                      doc->currentStyle = currItem->itemText.defaultStyle();
02821                      emit TextStyle(doc->currentStyle);
02822                      // to go: (av)
02823                      emit TextStrike(doc->currentStyle.charStyle().strikethruOffset(), doc->currentStyle.charStyle().strikethruWidth());
02824                      emit TextUnderline(doc->currentStyle.charStyle().underlineOffset(), doc->currentStyle.charStyle().underlineWidth());
02825                      emit TextShadow(doc->currentStyle.charStyle().shadowXOffset(), doc->currentStyle.charStyle().shadowYOffset());
02826                      emit TextFarben(doc->currentStyle.charStyle().strokeColor(), doc->currentStyle.charStyle().fillColor(), doc->currentStyle.charStyle().strokeShade(), doc->currentStyle.charStyle().fillShade());
02827                      emit TextScale(doc->currentStyle.charStyle().scaleH());
02828                      emit TextScaleV(doc->currentStyle.charStyle().scaleV());
02829                      emit TextBase(doc->currentStyle.charStyle().baselineOffset());
02830                      emit TextOutline(doc->currentStyle.charStyle().outlineWidth());
02831 //                   emit TextStil(doc->currentStyle.charStyle().effects());
02832                      setStilvalue(doc->currentStyle.charStyle().effects());
02833               }
02834 
02835 //            doc->docParagraphStyles[0].setLineSpacingMode(static_cast<ParagraphStyle::LineSpacingMode>(currItem->lineSpacingMode()));
02836 //            doc->docParagraphStyles[0].setLineSpacing(currItem->lineSpacing());
02837 //            doc->docParagraphStyles[0].setAlignment(currItem->textAlignment);
02838 
02839               break;
02840        case PageItem::PathText: //Path Text
02841               FontSub->RebuildList(doc, currItem->isAnnotation());
02842               propertiesPalette->Fonts->RebuildList(doc, currItem->isAnnotation());
02843               scrActions["fileImportText"]->setEnabled(true);
02844               scrActions["fileImportText2"]->setEnabled(true);
02845               scrActions["fileImportImage"]->setEnabled(false);
02846               scrActions["fileImportAppendText"]->setEnabled(true);
02847               scrActions["fileExportText"]->setEnabled(true);
02848               scrActions["editCut"]->setEnabled(true);
02849               scrActions["editCopy"]->setEnabled(true);
02850               scrActions["editClearContents"]->setEnabled(false);
02851               scrActions["editSearchReplace"]->setEnabled(false);
02852               scrActions["extrasHyphenateText"]->setEnabled(false);
02853               scrActions["extrasDeHyphenateText"]->setEnabled(false);
02854               scrMenuMgr->setMenuEnabled("Item", true);
02855               scrMenuMgr->setMenuEnabled("ItemShapes", false);
02856               scrActions["itemDetachTextFromPath"]->setEnabled(true);
02857               scrMenuMgr->setMenuEnabled("ItemConvertTo", true);
02858               scrActions["itemConvertToBezierCurve"]->setEnabled(false);
02859               scrActions["itemConvertToImageFrame"]->setEnabled(false);
02860               scrActions["itemConvertToOutlines"]->setEnabled(true);
02861               scrActions["itemConvertToPolygon"]->setEnabled(false);
02862               scrActions["itemConvertToTextFrame"]->setEnabled(false);
02863 
02864               scrActions["toolsRotate"]->setEnabled(true);
02865               scrActions["toolsCopyProperties"]->setEnabled(true);
02866               scrActions["toolsEditContents"]->setEnabled(false);
02867               scrActions["toolsEditWithStoryEditor"]->setEnabled(true);
02868               scrActions["toolsLinkTextFrame"]->setEnabled(false);
02869               scrActions["toolsUnlinkTextFrame"]->setEnabled(false);
02870               if (doc->appMode == modeEdit)
02871                      setTBvals(currItem);
02872               else
02873               {
02874                      doc->currentStyle = currItem->itemText.defaultStyle();
02875                      emit TextStyle(doc->currentStyle);
02876                      // to go: (av)
02877                      emit TextStrike(doc->currentStyle.charStyle().strikethruOffset(), doc->currentStyle.charStyle().strikethruWidth());
02878                      emit TextUnderline(doc->currentStyle.charStyle().underlineOffset(), doc->currentStyle.charStyle().underlineWidth());
02879                      emit TextShadow(doc->currentStyle.charStyle().shadowXOffset(), doc->currentStyle.charStyle().shadowYOffset());
02880                      emit TextFarben(doc->currentStyle.charStyle().strokeColor(), doc->currentStyle.charStyle().fillColor(), doc->currentStyle.charStyle().strokeShade(), doc->currentStyle.charStyle().fillShade());
02881                      emit TextScale(doc->currentStyle.charStyle().scaleH());
02882                      emit TextScaleV(doc->currentStyle.charStyle().scaleV());
02883                      emit TextBase(doc->currentStyle.charStyle().baselineOffset());
02884                      emit TextOutline(doc->currentStyle.charStyle().outlineWidth());
02885 //                   emit TextStil(doc->currentStyle.charStyle().effects());
02886                      setStilvalue(doc->currentStyle.charStyle().effects());
02887               }
02888               break;
02889        default:
02890               scrActions["fileImportText"]->setEnabled(false);
02891               scrActions["fileImportText2"]->setEnabled(false);
02892               scrActions["fileImportImage"]->setEnabled(false);
02893               scrActions["fileImportAppendText"]->setEnabled(false);
02894               scrActions["fileExportText"]->setEnabled(false);
02895               scrActions["editCut"]->setEnabled(true);
02896               scrActions["editCopy"]->setEnabled(true);
02897               scrMenuMgr->setMenuEnabled("EditContents", false);
02898               scrActions["editClearContents"]->setEnabled(false);
02899               scrActions["editSearchReplace"]->setEnabled(false);
02900 
02901               scrActions["extrasHyphenateText"]->setEnabled(false);
02902               scrActions["extrasDeHyphenateText"]->setEnabled(false);
02903               scrMenuMgr->setMenuEnabled("Item", true);
02904               if (Nr == 6) //Polygon
02905               {
02906                      scrMenuMgr->setMenuEnabled("ItemShapes", true);
02907                      scrMenuMgr->setMenuEnabled("ItemConvertTo", true);
02908                      scrActions["itemConvertToBezierCurve"]->setEnabled(doc->appMode != modeEdit);
02909                      scrActions["itemConvertToImageFrame"]->setEnabled(doc->appMode != modeEdit);
02910                      scrActions["itemConvertToOutlines"]->setEnabled(false);
02911                      scrActions["itemConvertToPolygon"]->setEnabled(false);
02912                      scrActions["itemConvertToTextFrame"]->setEnabled(doc->appMode != modeEdit);
02913               }
02914               scrActions["toolsEditContents"]->setEnabled(false);
02915               scrActions["toolsEditWithStoryEditor"]->setEnabled(false);
02916               scrActions["toolsUnlinkTextFrame"]->setEnabled(false);
02917               scrActions["toolsLinkTextFrame"]->setEnabled(false);
02918 //            if (Nr != 5)
02919                      scrActions["toolsRotate"]->setEnabled(true);
02920 //            else
02921 //                   scrActions["toolsRotate"]->setEnabled(false);
02922               scrActions["toolsCopyProperties"]->setEnabled(true);
02923               break;
02924        }
02925        doc->CurrentSel = Nr;
02926        rebuildStyleMenu(Nr);
02927        propertiesPalette->RotationGroup->setButton(doc->RotMode);
02928        uint docSelectionCount=doc->m_Selection->count();
02929        if (docSelectionCount > 1)
02930        {
02931               scrActions["itemConvertToBezierCurve"]->setEnabled(false);
02932               scrActions["itemConvertToImageFrame"]->setEnabled(false);
02933               //scrActions["itemConvertToOutlines"]->setEnabled(false);
02934               scrActions["itemConvertToPolygon"]->setEnabled(false);
02935               scrActions["itemConvertToTextFrame"]->setEnabled(false);
02936               scrActions["editSearchReplace"]->setEnabled(false);
02937 
02938               bool hPoly = false;
02939               bool isGroup = true;
02940               int firstElem = -1;
02941               if (currItem->Groups.count() != 0)
02942                      firstElem = currItem->Groups.top();
02943               for (uint bx=0; bx<docSelectionCount; ++bx)
02944               {
02945                      PageItem* bxi=doc->m_Selection->itemAt(bx);
02946                      if ((bxi->asPolygon()) || (bxi->asPolyLine()))
02947                             hPoly = true;
02948                      if (bxi->Groups.count() != 0)
02949                      {
02950                             if (bxi->Groups.top() != firstElem)
02951                                    isGroup = false;
02952                      }
02953                      else
02954                             isGroup = false;
02955               }
02956               scrActions["itemGroup"]->setEnabled(!isGroup);
02957               scrActions["itemCombinePolygons"]->setEnabled(hPoly);
02958               if (docSelectionCount == 2)
02959               {
02960                      PageItem* bx=doc->m_Selection->itemAt(1);
02961                      if ((currItem->asTextFrame() && (bx->asPolygon() || bx->asPolyLine())) || (bx->asTextFrame() && (currItem->asPolygon() || currItem->asPolyLine())))
02962                      {
02963                             if ((currItem->nextInChain() == 0) && (currItem->prevInChain() == 0) && (bx->nextInChain() == 0) && (bx->prevInChain() == 0) && (currItem->Groups.count() == 0) && (bx->Groups.count() == 0))
02964                                    scrActions["itemAttachTextToPath"]->setEnabled(true);
02965                      }
02966 
02967               }
02968        }
02969        else
02970        {
02971               scrActions["itemGroup"]->setEnabled(false);
02972               scrActions["itemAttachTextToPath"]->setEnabled(false);
02973               scrActions["itemCombinePolygons"]->setEnabled(false);
02974        }
02975        if (docSelectionCount != 0)
02976        {
02977               actionManager->setPDFActions(view);
02978               updateItemLayerList();
02979               //propertiesPalette->textFlowsAroundFrame->setChecked(currItem->textFlowsAroundFrame());
02980               propertiesPalette->setTextFlowMode(currItem->textFlowMode());
02981               scrActions["itemLock"]->setEnabled(true);
02982               scrActions["itemLockSize"]->setEnabled(true);
02983               scrActions["itemPrintingEnabled"]->setEnabled(true);
02984               if (currItem->Groups.count() != 0)
02985                      scrActions["itemUngroup"]->setEnabled(true);
02986               else
02987               {
02988                      scrActions["itemUngroup"]->setEnabled(false);
02989                      scrActions["itemSplitPolygons"]->setEnabled( (currItem->asPolygon()) && (currItem->Segments.count() != 0) );
02990               }
02991               if (currItem->locked())
02992               {
02993                      scrMenuMgr->setMenuEnabled("ItemShapes", false);
02994                      scrMenuMgr->setMenuEnabled("ItemConvertTo", false);
02995                      scrActions["itemConvertToBezierCurve"]->setEnabled(false);
02996                      scrActions["itemConvertToImageFrame"]->setEnabled(false);
02997                      scrActions["itemConvertToOutlines"]->setEnabled(false);
02998                      scrActions["itemConvertToPolygon"]->setEnabled(false);
02999                      scrActions["itemConvertToTextFrame"]->setEnabled(false);
03000                      scrActions["itemSplitPolygons"]->setEnabled(false);
03001                      scrActions["itemAttachTextToPath"]->setEnabled(false);
03002                      scrActions["itemDetachTextFromPath"]->setEnabled(false);
03003                      scrActions["itemCombinePolygons"]->setEnabled(false);
03004                      scrActions["itemDelete"]->setEnabled(false);
03005                      scrActions["itemLowerToBottom"]->setEnabled(false);
03006                      scrActions["itemRaiseToTop"]->setEnabled(false);
03007                      scrActions["itemRaise"]->setEnabled(false);
03008                      scrActions["itemLower"]->setEnabled(false);
03009                      scrActions["itemSendToScrapbook"]->setEnabled(!(currItem->isTableItem && currItem->isSingleSel));
03010                      scrActions["itemSendToPattern"]->setEnabled(!(currItem->isTableItem && currItem->isSingleSel));
03011                      scrActions["editCut"]->setEnabled(false);
03012                      scrActions["editClearContents"]->setEnabled(false);
03013                      scrActions["toolsRotate"]->setEnabled(false);
03014               }
03015               else
03016               {
03017                      bool setter=!(currItem->isTableItem && currItem->isSingleSel && currItem->isGroupControl);
03018                      scrActions["itemDuplicate"]->setEnabled(setter);
03019                      scrActions["itemMulDuplicate"]->setEnabled(setter);
03020                      scrActions["itemDelete"]->setEnabled(!currItem->isSingleSel);
03021                      scrActions["itemLowerToBottom"]->setEnabled(setter);
03022                      scrActions["itemRaiseToTop"]->setEnabled(setter);
03023                      scrActions["itemRaise"]->setEnabled(setter);
03024                      scrActions["itemLower"]->setEnabled(setter);
03025                      scrActions["itemSendToScrapbook"]->setEnabled(setter);
03026                      scrActions["itemSendToPattern"]->setEnabled(setter);
03027               }
03028               scrActions["itemLock"]->setOn(currItem->locked());
03029               scrActions["itemLockSize"]->setOn(currItem->sizeLocked());
03030               scrActions["itemPrintingEnabled"]->setOn(currItem->printEnabled());
03031        }
03032 
03033        //propertiesPalette->NewSel(Nr);
03034        if (Nr != -1)
03035        {
03036               //propertiesPalette->SetCurItem(currItem);
03037               outlinePalette->slotShowSelect(currItem->OwnPage, currItem->ItemNr);
03038               if (currItem->FrameType == 0)
03039                      SCustom->setPixmap(SCustom->getIconPixmap(0));
03040               if (currItem->FrameType == 1)
03041                      SCustom->setPixmap(SCustom->getIconPixmap(1));
03042               if (currItem->FrameType > 3)
03043                      SCustom->setPixmap(SCustom->getIconPixmap(currItem->FrameType-2));
03044               actionManager->connectNewSelectionActions(view, doc);
03045 //            propertiesPalette->NewSel(Nr);
03046        }
03047        else
03048               propertiesPalette->NewSel(Nr);
03049 }
03050 
03051 void ScribusMainWindow::rebuildStyleMenu(int itemType)
03052 {
03053        scrMenuMgr->clearMenu("Style");
03054        int iT=itemType;
03055        if (!HaveDoc)
03056               iT=-1;
03057        if (iT != -1)
03058        {
03059               if (doc->m_Selection->count() == 0)
03060                      iT = -1;
03061               else
03062               {
03063                      PageItem *currItem = doc->m_Selection->itemAt(0);
03064                      if (!currItem)
03065                             iT=-1;
03066               }
03067        }
03068        if (iT==PageItem::TextFrame || iT==PageItem::PathText)
03069        {
03070               scrMenuMgr->addMenuToMenu("Font","Style");
03071               scrMenuMgr->addMenuToMenu("FontSize","Style");
03072               scrMenuMgr->addMenuToMenu("TypeEffects","Style");
03073               scrMenuMgr->addMenuToMenu("Alignment","Style");
03074               scrMenuMgr->addMenuToMenu("Color","Style");
03075               scrMenuMgr->addMenuToMenu("Shade","Style");
03076               if (itemType==PageItem::TextFrame)
03077                      scrMenuMgr->addMenuItem(scrActions["styleTabulators"], "Style");
03078               scrMenuMgr->setMenuEnabled("Style", true);
03079        }
03080        else
03081               scrMenuMgr->setMenuEnabled("Style", false);
03082 }
03083 
03084 void ScribusMainWindow::slotDocCh(bool /*reb*/)
03085 {
03086        if (!doc->isLoading() && docCheckerPalette->isVisible())
03087        {
03088               scanDocument();
03089               docCheckerPalette->buildErrorList(doc);
03090        }
03091        if (!doc->isModified())
03092               doc->setModified(true);
03093        updateActiveWindowCaption(doc->DocName + "*");
03094 //     scrActions["fileSave"]->setEnabled(true);
03095 //     scrActions["fileSaveAs"]->setEnabled(true);
03096        scrActions["fileCollect"]->setEnabled(true);
03097        if (!doc->masterPageMode())
03098        {
03099               scrActions["fileClose"]->setEnabled(true);
03100               if (doc->hasName)
03101                      scrActions["fileRevert"]->setEnabled(true);
03102 
03103               bool setter = doc->Pages->count() > 1 ? true : false;
03104               scrActions["pageDelete"]->setEnabled(setter);
03105               scrActions["pageMove"]->setEnabled(setter);
03106        }
03107 
03108        ActWin->setMenuStatus(0, scrActions["fileSave"]->isEnabled());
03109        ActWin->setMenuStatus(1, scrActions["fileClose"]->isEnabled());
03110        ActWin->setMenuStatus(2, scrActions["fileSave"]->isEnabled());
03111        ActWin->setMenuStatus(3, scrActions["fileSaveAs"]->isEnabled());
03112        if (outlinePalette->isVisible())
03113               outlinePalette->BuildTree();
03114 }
03115 
03116 void ScribusMainWindow::updateRecent(QString fn)
03117 {
03118        if (RecentDocs.findIndex(fn) == -1)
03119        {
03120               RecentDocs.prepend(fn);
03121               ScCore->fileWatcher->addFile(fn);
03122        }
03123        else
03124        {
03125               RecentDocs.remove(fn);
03126               RecentDocs.prepend(fn);
03127        }
03128        rebuildRecentFileMenu();
03129 }
03130 
03131 void ScribusMainWindow::removeRecent(QString fn)
03132 {
03133        if (RecentDocs.findIndex(fn) != -1)
03134        {
03135               RecentDocs.remove(fn);
03136               ScCore->fileWatcher->removeFile(fn);
03137        }
03138        rebuildRecentFileMenu();
03139 }
03140 
03141 void ScribusMainWindow::loadRecent(QString fn)
03142 {
03143        QFileInfo fd(fn);
03144        if (!fd.exists())
03145        {
03146               removeRecent(fn);
03147               return;
03148        }
03149        loadDoc(fn);
03150 }
03151 
03152 void ScribusMainWindow::rebuildRecentFileMenu()
03153 {
03154        for( QMap<QString, QGuardedPtr<ScrAction> >::Iterator it = scrRecentFileActions.begin(); it!=scrRecentFileActions.end(); ++it )
03155               scrMenuMgr->removeMenuItem((*it), recentFileMenuName);
03156 
03157        scrRecentFileActions.clear();
03158        uint max = QMIN(prefsManager->appPrefs.RecentDCount, RecentDocs.count());
03159        QString strippedName, localName;
03160        for (uint m = 0; m < max; ++m)
03161        {
03162               strippedName=RecentDocs[m];
03163               strippedName.remove(QDir::separator());
03164               localName=QDir::convertSeparators(RecentDocs[m]);
03165               scrRecentFileActions.insert(strippedName, new ScrAction(ScrAction::RecentFile, QIconSet(), QString("&%1 %2").arg(m+1).arg(localName), QKeySequence(), this, strippedName,0,0.0,RecentDocs[m]));
03166               connect( scrRecentFileActions[strippedName], SIGNAL(activatedData(QString)), this, SLOT(loadRecent(QString)) );
03167               scrMenuMgr->addMenuItem(scrRecentFileActions[strippedName], recentFileMenuName);
03168        }
03169 }
03170 
03171 void ScribusMainWindow::rebuildRecentPasteMenu()
03172 {
03173        for( QMap<QString, QGuardedPtr<ScrAction> >::Iterator it = scrRecentPasteActions.begin(); it!=scrRecentPasteActions.end(); ++it )
03174               scrMenuMgr->removeMenuItem((*it), recentPasteMenuName);
03175 
03176        scrRecentPasteActions.clear();
03177        uint max = QMIN(static_cast<uint>(prefsManager->appPrefs.numScrapbookCopies), scrapbookPalette->tempBView->objectMap.count());
03178        if (max > 0)
03179        {
03180               QMap<QString,BibView::Elem>::Iterator it;
03181               it = scrapbookPalette->tempBView->objectMap.end();
03182               it--;
03183               QString strippedName;
03184               for (uint m = 0; m < max; ++m)
03185               {
03186                      strippedName = it.key();
03187                      QPixmap pm = it.data().Preview;
03188                      scrRecentPasteActions.insert(strippedName, new ScrAction(ScrAction::RecentPaste, QIconSet(pm), QString("&%1 %2").arg(m+1).arg(strippedName), QKeySequence(), this, strippedName,0,0.0,it.key()));
03189                      connect( scrRecentPasteActions[strippedName], SIGNAL(activatedData(QString)), this, SLOT(pasteRecent(QString)) );
03190                      scrMenuMgr->addMenuItem(scrRecentPasteActions[strippedName], recentPasteMenuName);
03191                      it--;
03192               }
03193        }
03194 }
03195 
03196 void ScribusMainWindow::pasteRecent(QString fn)
03197 {
03198        QString data = scrapbookPalette->tempBView->objectMap[fn].Data;
03199        QFileInfo fi(data);
03200        if (fi.extension(true).lower() == "sml")
03201        {
03202               QString f = "";
03203               loadText(data, &f);
03204               StencilReader *pre = new StencilReader();
03205               data = pre->createObjects(f);
03206               delete pre;
03207        }
03208        else if (fi.extension(true).lower() == "shape")
03209        {
03210               QString f = "";
03211               loadText(data, &f);
03212               StencilReader *pre = new StencilReader();
03213               data = pre->createShape(f);
03214               delete pre;
03215        }
03216        else if (fi.extension(true).lower() == "sce")
03217        {
03218               QString f = "";
03219               loadText(data, &f);
03220               data = f;
03221        }
03222        view->Deselect(true);
03223        uint ac = doc->Items->count();
03224        bool savedAlignGrid = doc->useRaster;
03225        bool savedAlignGuides = doc->SnapGuides;
03226        doc->useRaster = false;
03227        doc->SnapGuides = false;
03228        slotElemRead(data, doc->currentPage()->xOffset(), doc->currentPage()->yOffset(), false, true, doc, view);
03229        doc->useRaster = savedAlignGrid;
03230        doc->SnapGuides = savedAlignGuides;
03231        for (uint as = ac; as < doc->Items->count(); ++as)
03232        {
03233               PageItem* currItem = doc->Items->at(as);
03234               if (currItem->isBookmark)
03235                      AddBookMark(currItem);
03236               view->SelectItemNr(as);
03237        }
03238               slotDocCh(false);
03239 }
03240 
03241 void ScribusMainWindow::rebuildLayersList()
03242 {
03243        if (HaveDoc)
03244        {
03245               for( QMap<QString, QGuardedPtr<ScrAction> >::Iterator it0 = scrLayersActions.begin(); it0 != scrLayersActions.end(); ++it0 )
03246                      scrMenuMgr->removeMenuItem((*it0), layerMenuName);
03247               scrLayersActions.clear();
03248               QValueList<Layer>::iterator it;
03249               if (doc->Layers.count()!= 0)
03250               {
03251                      for (it = doc->Layers.begin(); it != doc->Layers.end(); ++it)
03252                      {
03253                             scrLayersActions.insert(QString("%1").arg((*it).LNr), new ScrAction( ScrAction::Layer, QIconSet(), (*it).Name, QKeySequence(), this, (*it).Name, (*it).LNr));
03254                             scrLayersActions[QString("%1").arg((*it).LNr)]->setToggleAction(true);
03255                      }
03256               }
03257               int currActiveLayer=doc->activeLayer();
03258               bool found=false;
03259               for (it = doc->Layers.begin(); it != doc->Layers.end(); ++it)
03260               {
03261                      if ((*it).LNr == currActiveLayer)
03262                      {
03263                             found=true;
03264                             break;
03265                      }
03266               }
03267               Q_ASSERT(found);
03268               scrLayersActions[QString("%1").arg((*it).LNr)]->setOn(true);
03269 
03270               for( QMap<QString, QGuardedPtr<ScrAction> >::Iterator it = scrLayersActions.begin(); it!=scrLayersActions.end(); ++it )
03271               {
03272                      scrMenuMgr->addMenuItem((*it), layerMenuName);
03273                      connect( (*it), SIGNAL(activatedData(int)), doc, SLOT(itemSelection_SendToLayer(int)) );
03274               }
03275        }
03276 }
03277 
03278 void ScribusMainWindow::updateItemLayerList()
03279 {
03280        if (HaveDoc)
03281        {
03282               QMap<QString, QGuardedPtr<ScrAction> >::Iterator itend=scrLayersActions.end();
03283               for( QMap<QString, QGuardedPtr<ScrAction> >::Iterator it = scrLayersActions.begin(); it!=itend; ++it )
03284               {
03285                      disconnect( (*it), SIGNAL(activatedData(int)), 0, 0 );
03286                      (*it)->setOn(false);
03287               }
03288               if (doc->m_Selection->count()>0 && doc->m_Selection->itemAt(0))
03289                      scrLayersActions[QString("%1").arg(doc->m_Selection->itemAt(0)->LayerNr)]->setOn(true);
03290               for( QMap<QString, QGuardedPtr<ScrAction> >::Iterator it = scrLayersActions.begin(); it!=itend; ++it )
03291                      connect( (*it), SIGNAL(activatedData(int)), doc, SLOT(itemSelection_SendToLayer(int)) );
03292        }
03293 }
03294 
03295 bool ScribusMainWindow::slotDocOpen()
03296 {
03297        PrefsContext* docContext = prefsManager->prefsFile->getContext("docdirs", false);
03298        QString docDir = ".";
03299        QString prefsDocDir=prefsManager->documentDir();
03300        if (!prefsDocDir.isEmpty())
03301               docDir = docContext->get("docsopen", prefsDocDir);
03302        else
03303               docDir = docContext->get("docsopen", ".");
03304        QString formats(FileLoader::getLoadFilterString());
03305        formats.remove("PDF (*.pdf *.PDF);;");
03306        QString fileName = CFileDialog( docDir, tr("Open"), formats);
03307        if (fileName.isEmpty())
03308               // User cancelled
03309               return false;
03310        docContext->set("docsopen", fileName.left(fileName.findRev("/")));
03311        return loadDoc(fileName);
03312 }
03313 
03314 bool ScribusMainWindow::slotPageImport()
03315 {
03316        Q_ASSERT(!doc->masterPageMode());
03317        bool ret = false;
03318        MergeDoc *dia = new MergeDoc(this, false, doc->DocPages.count(), doc->currentPage()->pageNr() + 1);
03319        if (dia->exec())
03320        {
03321               mainWindowStatusLabel->setText( tr("Importing Pages..."));
03322               qApp->setOverrideCursor(QCursor(waitCursor), true);
03323               std::vector<int> pageNs;
03324               parsePagesString(dia->getPageNumbers(), &pageNs, dia->getPageCounter());
03325               int startPage=0, nrToImport=pageNs.size();
03326               bool doIt = true;
03327               if (doc->masterPageMode())
03328               {
03329                      if (nrToImport > 1)
03330                             loadPage(dia->getFromDoc(), pageNs[0] - 1, false);
03331                      doIt = false;
03332               }
03333               else if (dia->getCreatePageChecked())
03334               {
03335                      int importWhere=dia->getImportWhere();
03336                      if (importWhere == 0)
03337                             startPage = dia->getImportWherePage();
03338                      else if (importWhere == 1)
03339                             startPage = dia->getImportWherePage() + 1;
03340                      else
03341                             startPage = doc->DocPages.count() + 1;
03342                      addNewPages(dia->getImportWherePage(), importWhere, nrToImport, doc->pageHeight, doc->pageWidth, doc->PageOri, doc->m_pageSize, true);
03343               }
03344               else
03345               {
03346                      startPage = doc->currentPage()->pageNr() + 1;
03347                      if (static_cast<uint>(nrToImport) > (doc->DocPages.count() - doc->currentPage()->pageNr()))
03348                      {
03349                             qApp->setOverrideCursor(QCursor(arrowCursor), true);
03350                             int scmReturn=ScMessageBox::information(this, tr("Import Page(s)"), "<qt>" +
03351                             QObject::tr("<p>You are trying to import more pages than there are available in the current document counting from the active page.</p>Choose one of the following:<br>"
03352                             "<ul><li><b>Create</b> missing pages</li>"
03353                             "<li><b>Import</b> pages until the last page</li>"
03354                             "<li><b>Cancel</b></li></ul>") + "</qt>",
03355                             QObject::tr("C&reate"),
03356                             QObject::tr("&Import"),
03357                             CommonStrings::tr_Cancel, 2, 2);
03358                             switch( scmReturn )
03359                             {
03360                                    case 0:
03361                                           addNewPages(doc->DocPages.count(), 2,
03362                                                                nrToImport - (doc->DocPages.count() - doc->currentPage()->pageNr()),
03363                                                                doc->pageHeight, doc->pageWidth, doc->PageOri, doc->m_pageSize, true);
03364                                           break;
03365                                    case 1:
03366                                           nrToImport = doc->DocPages.count() - doc->currentPage()->pageNr();
03367                                           break;
03368                                    case 2:
03369                                           doIt = false;
03370                                           mainWindowStatusLabel->setText("");
03371                                           break;
03372                             }
03373                             qApp->setOverrideCursor(QCursor(waitCursor), true);
03374                      }
03375               }
03376               if (doIt)
03377               {
03378                      if (nrToImport > 0)
03379                      {
03380                             mainWindowProgressBar->reset();
03381                             mainWindowProgressBar->setTotalSteps(nrToImport);
03382                             int counter = startPage;
03383                             for (int i = 0; i < nrToImport; ++i)
03384                             {
03385                                    view->GotoPa(counter);
03386                                    loadPage(dia->getFromDoc(), pageNs[i] - 1, false);
03387                                    counter++;
03388                                    mainWindowProgressBar->setProgress(i + 1);
03389                             }
03390                             view->GotoPa(startPage);
03391                             mainWindowProgressBar->reset();
03392                             mainWindowStatusLabel->setText( tr("Import done"));
03393                      }
03394                      else
03395                      {
03396                             mainWindowStatusLabel->setText( tr("Found nothing to import"));
03397                             doIt = false;
03398                      }
03399               }
03400               qApp->setOverrideCursor(QCursor(arrowCursor), true);
03401               ret = doIt;
03402        }
03403        delete dia;
03404        return ret;
03405 }
03406 
03407 bool ScribusMainWindow::loadPage(QString fileName, int Nr, bool Mpa, const QString& renamedPageName)
03408 {
03409        bool ret = false;
03410        if (!fileName.isEmpty())
03411        {
03412               FileLoader *fl = new FileLoader(fileName);
03413               if (fl->TestFile() == -1)
03414               {
03415                      delete fl;
03416                      return false;
03417               }
03418               doc->setLoading(true);
03419               uint oldItemsCount = doc->Items->count();
03420               if(!fl->LoadPage(doc, Nr, Mpa, renamedPageName))
03421               {
03422                      delete fl;
03423                      doc->setLoading(false);
03424                      return false;
03425               }
03426               delete fl;
03427               if (ScCore->haveCMS() && doc->CMSSettings.CMSinUse)
03428               {
03429                      recalcColors();
03430                      doc->RecalcPictures(&ScCore->InputProfiles, &ScCore->InputProfilesCMYK);
03431               }
03432               uint docItemsCount=doc->Items->count();
03433               for (uint i = oldItemsCount; i < docItemsCount; ++i)
03434               {
03435                      PageItem *ite = doc->Items->at(i);
03436 //                   if ((docItemsCount - oldItemsCount) > 1)
03437 //                          ite->Groups.push(doc->GroupCounter);
03438                      if (ite->locked())
03439                             ite->setLocked(false);
03440                      if ((ite->asTextFrame()) && (ite->isBookmark))
03441                             bookmarkPalette->BView->AddPageItem(ite);
03442               }
03443 //            if ((docItemsCount - oldItemsCount) > 1)
03444 //                   doc->GroupCounter++;
03445               propertiesPalette->updateColorList();
03446               propertiesPalette->paraStyleCombo->setDoc(doc);
03447               propertiesPalette->charStyleCombo->setDoc(doc);
03448               propertiesPalette->SetLineFormats(doc);
03449               propertiesPalette->startArrow->rebuildList(&doc->arrowStyles);
03450               propertiesPalette->endArrow->rebuildList(&doc->arrowStyles);
03451               if (!Mpa)
03452               {
03453                      scanDocument();
03454                      docCheckerPalette->buildErrorList(doc);
03455               }
03456               slotDocCh();
03457               rebuildLayersList();
03458               view->updateLayerMenu();
03459               layerPalette->rebuildList();
03460               doc->setLoading(false);
03461               ret = true;
03462        }
03463        if (!Mpa)
03464               pagePalette->Rebuild();
03465        view->reformPages();
03466        view->DrawNew();
03467        return ret;
03468 }
03469 
03470 bool ScribusMainWindow::loadDoc(QString fileName)
03471 {
03472        undoManager->setUndoEnabled(false);
03473        QFileInfo fi(fileName);
03474        if (!fi.exists())
03475               return false;
03476        qApp->setOverrideCursor(QCursor(waitCursor), true);
03477        if (HaveDoc)
03478               outlinePalette->buildReopenVals();
03479        bool ret = false;
03480        QWidgetList windows = wsp->windowList();
03481        ScribusWin* ActWinOld = NULL;
03482        if (windows.count() != 0)
03483               ActWinOld = ActWin;
03484        bool found = false;
03485        uint id = 0;
03486        QString platfName = QDir::convertSeparators(fileName);
03487        uint windowCount=windows.count();
03488        for ( uint i = 0; i < windowCount; ++i )
03489        {
03490               if (windows.at(i)->caption() == platfName)
03491               {
03492                      found = true;
03493                      id = i;
03494                      break;
03495               }
03496        }
03497        if (found)
03498        {
03499               windowsMenuActivated(id);
03500               return true;
03501        }
03502        if (!fileName.isEmpty())
03503        {
03504               QString FName = fi.absFilePath();
03505               QString DPath = fi.dirPath(true);
03506               // Necessary on win32 platform for setCurrent() to succeed
03507               // if document is located at drive root
03508               if( !DPath.endsWith("/") )
03509                      DPath += "/";
03510               QDir::setCurrent(DPath);
03511               FileLoader *fileLoader = new FileLoader(FName);
03512               int testResult=fileLoader->TestFile();
03513               if (testResult == -1)
03514               {
03515                      delete fileLoader;
03516                      qApp->setOverrideCursor(QCursor(arrowCursor), true);
03517                      QMessageBox::critical(this, tr("Fatal Error"), "<qt>"+ tr("File %1 is not in an acceptable format").arg(FName)+"</qt>", CommonStrings::tr_OK);
03518                      return false;
03519               }
03520               bool is12doc=false;
03521               if (testResult == 0)
03522               {
03523                      qApp->setOverrideCursor(QCursor(arrowCursor), true);
03524                      //Scribus 1.3.x warning, remove at a later stage
03525                      is12doc=true;
03526               }
03527 
03528               ScCore->getCMSProfilesDir(fi.dirPath(true)+"/", false, false);
03529               prefsManager->appPrefs.AvailFonts.AddScalableFonts(fi.dirPath(true)+"/", FName);
03530               prefsManager->appPrefs.AvailFonts.updateFontMap();
03531               doc=new ScribusDoc();
03532               doc->is12doc=is12doc;
03533               doc->appMode = modeNormal;
03534               doc->HasCMS = false;
03535               //doc->setActiveLayer(0); //CB should not need this, the file load process sets it to ALAYER from the doc
03536               doc->OpenNodes.clear();
03537               doc->setLoading(true);
03538               mainWindowStatusLabel->setText( tr("Loading..."));
03539               mainWindowProgressBar->reset();
03540               ScribusWin* w = new ScribusWin(wsp, doc);
03541               w->setMainWindow(this);
03542               view = new ScribusView(w, this, doc);
03543               doc->setGUI(true, this, view);
03544               view->setScale(prefsManager->displayScale());
03545               w->setView(view);
03546               alignDistributePalette->setDoc(doc);
03547               ActWin = w;
03548               doc->WinHan = w;
03549               w->setCentralWidget(view);
03550               w->setUpdatesEnabled(false);
03551               view->updatesOn(false);
03552               doc->SoftProofing = false;
03553               doc->Gamut = false;
03554               ScriptRunning = true;
03555               bool loadSuccess=fileLoader->LoadFile(doc);
03556               //Do the font replacement check from here, when we have a GUI. TODO do this also somehow without the GUI
03557               //This also gives the user the opportunity to cancel the load when finding theres a replacement required.
03558               if (loadSuccess && ScCore->usingGUI())
03559                      loadSuccess=fileLoader->postLoad(doc);
03560               if(!loadSuccess)
03561               {
03562                      view->close();
03563                      delete fileLoader;
03564                      delete view;
03565                      delete doc;
03566                      delete w;
03567                      view=NULL;
03568                      doc=NULL;
03569                      ScriptRunning = false;
03570                      qApp->setOverrideCursor(QCursor(arrowCursor), true);
03571                      mainWindowStatusLabel->setText("");
03572                      mainWindowProgressBar->reset();
03573                      ActWin = NULL;
03574                      undoManager->setUndoEnabled(true);
03575                      if (windows.count() != 0)
03576                             newActWin(ActWinOld);
03577                      return false;
03578               }
03579               outlinePalette->setDoc(doc);
03580               fileLoader->informReplacementFonts();
03581               view->unitSwitcher->setCurrentText(unitGetStrFromIndex(doc->unitIndex()));
03582               view->unitChange();
03583               ScriptRunning = false;
03584               view->Deselect(true);
03585               mainWindowStatusLabel->setText("");
03586               mainWindowProgressBar->reset();
03587               HaveDoc++;
03588               if (doc->checkerProfiles.count() == 0)
03589               {
03590                      prefsManager->initDefaultCheckerPrefs(&doc->checkerProfiles);
03591                      doc->curCheckProfile = tr("PostScript");
03592               }
03593               if (doc->PDF_Options.LPISettings.count() == 0)
03594               {
03595                      struct LPIData lpo;
03596                      lpo.Frequency = 75;
03597                      lpo.SpotFunc = 2;
03598                      lpo.Angle = 105;
03599                      doc->PDF_Options.LPISettings.insert("Cyan", lpo);
03600                      lpo.Angle = 75;
03601                      doc->PDF_Options.LPISettings.insert("Magenta", lpo);
03602                      lpo.Angle = 90;
03603                      doc->PDF_Options.LPISettings.insert("Yellow", lpo);
03604                      lpo.Angle = 45;
03605                      doc->PDF_Options.LPISettings.insert("Black", lpo);
03606               }
03607               //connect(w, SIGNAL(Schliessen()), this, SLOT(DoFileClose()));
03608               if (!doc->CMSSettings.CMSinUse)
03609                      doc->HasCMS = false;
03610               if ((ScCore->haveCMS()) && (doc->CMSSettings.CMSinUse))
03611               {
03612                      bool cmsWarning = false;
03613                      QStringList missing;
03614                      QStringList replacement;
03615                      if (!ScCore->InputProfiles.contains(doc->CMSSettings.DefaultImageRGBProfile))
03616                      {
03617                             cmsWarning = true;
03618                             missing.append(doc->CMSSettings.DefaultImageRGBProfile);
03619                             replacement.append(prefsManager->appPrefs.DCMSset.DefaultImageRGBProfile);
03620                             doc->CMSSettings.DefaultImageRGBProfile = prefsManager->appPrefs.DCMSset.DefaultImageRGBProfile;
03621                      }
03622                      if (!ScCore->InputProfilesCMYK.contains(doc->CMSSettings.DefaultImageCMYKProfile))
03623                      {
03624                             cmsWarning = true;
03625                             missing.append(doc->CMSSettings.DefaultImageCMYKProfile);
03626                             replacement.append(prefsManager->appPrefs.DCMSset.DefaultImageCMYKProfile);
03627                             doc->CMSSettings.DefaultImageCMYKProfile = prefsManager->appPrefs.DCMSset.DefaultImageCMYKProfile;
03628                      }
03629                      if (!ScCore->InputProfiles.contains(doc->CMSSettings.DefaultSolidColorRGBProfile))
03630                      {
03631                             cmsWarning = true;
03632                             missing.append(doc->CMSSettings.DefaultSolidColorRGBProfile);
03633                             replacement.append(prefsManager->appPrefs.DCMSset.DefaultSolidColorRGBProfile);
03634                             doc->CMSSettings.DefaultSolidColorRGBProfile = prefsManager->appPrefs.DCMSset.DefaultSolidColorRGBProfile;
03635                      }
03636                      if (!ScCore->InputProfilesCMYK.contains(doc->CMSSettings.DefaultSolidColorCMYKProfile))
03637                      {
03638                             cmsWarning = true;
03639                             missing.append(doc->CMSSettings.DefaultSolidColorCMYKProfile);
03640                             replacement.append(prefsManager->appPrefs.DCMSset.DefaultSolidColorCMYKProfile);
03641                             doc->CMSSettings.DefaultSolidColorCMYKProfile = prefsManager->appPrefs.DCMSset.DefaultSolidColorCMYKProfile;
03642                      }
03643                      if (!ScCore->MonitorProfiles.contains(doc->CMSSettings.DefaultMonitorProfile))
03644                      {
03645                             cmsWarning = true;
03646                             missing.append(doc->CMSSettings.DefaultMonitorProfile);
03647                             replacement.append(prefsManager->appPrefs.DCMSset.DefaultMonitorProfile);
03648                             doc->CMSSettings.DefaultMonitorProfile = prefsManager->appPrefs.DCMSset.DefaultMonitorProfile;
03649                      }
03650                      if (!ScCore->PrinterProfiles.contains(doc->CMSSettings.DefaultPrinterProfile))
03651                      {
03652                             cmsWarning = true;
03653                             missing.append(doc->CMSSettings.DefaultPrinterProfile);
03654                             replacement.append(prefsManager->appPrefs.DCMSset.DefaultPrinterProfile);
03655                             doc->CMSSettings.DefaultPrinterProfile = prefsManager->appPrefs.DCMSset.DefaultPrinterProfile;
03656                      }
03657                      if (!ScCore->PrinterProfiles.contains(doc->PDF_Options.PrintProf))
03658                      {
03659                             cmsWarning = true;
03660                             missing.append(doc->PDF_Options.PrintProf);
03661                             replacement.append(prefsManager->appPrefs.DCMSset.DefaultPrinterProfile);
03662                             doc->PDF_Options.PrintProf = doc->CMSSettings.DefaultPrinterProfile;
03663                      }
03664                      if (!ScCore->InputProfiles.contains(doc->PDF_Options.ImageProf))
03665                      {
03666                             cmsWarning = true;
03667                             missing.append(doc->PDF_Options.ImageProf);
03668                             replacement.append(prefsManager->appPrefs.DCMSset.DefaultImageRGBProfile);
03669                             doc->PDF_Options.ImageProf = doc->CMSSettings.DefaultImageRGBProfile;
03670                      }
03671                      if (!ScCore->InputProfiles.contains(doc->PDF_Options.SolidProf))
03672                      {
03673                             cmsWarning = true;
03674                             missing.append(doc->PDF_Options.SolidProf);
03675                             replacement.append(prefsManager->appPrefs.DCMSset.DefaultSolidColorRGBProfile);
03676                             doc->PDF_Options.SolidProf = doc->CMSSettings.DefaultSolidColorRGBProfile;
03677                      }
03678                      if (cmsWarning)
03679                      {
03680                             qApp->setOverrideCursor(QCursor(arrowCursor), true);
03681                             QString mess = tr("Some ICC profiles used by this document are not installed:")+"\n\n";
03682                             for (uint m = 0; m < missing.count(); ++m)
03683                             {
03684                                    mess += missing[m] + tr(" was replaced by: ")+replacement[m]+"\n";
03685                             }
03686                             QMessageBox::warning(this, CommonStrings::trWarning, mess, 1, 0, 0);
03687                      }
03688                      doc->SoftProofing = doc->CMSSettings.SoftProofOn;
03689                      doc->Gamut = doc->CMSSettings.GamutCheck;
03690                      doc->IntentColors = doc->CMSSettings.DefaultIntentColors;
03691                      doc->IntentImages = doc->CMSSettings.DefaultIntentImages;
03692                      if (doc->OpenCMSProfiles(ScCore->InputProfiles, ScCore->InputProfilesCMYK, ScCore->MonitorProfiles, ScCore->PrinterProfiles))
03693                      {
03694                             doc->HasCMS = true;
03695                             doc->PDF_Options.SComp = doc->CMSSettings.ComponentsInput2;
03696                      }
03697                      if (doc->HasCMS)
03698                      {
03699                             recalcColors();
03700                             doc->RecalcPictures(&ScCore->InputProfiles, &ScCore->InputProfilesCMYK);
03701                      }
03702               }
03703               else
03704               {
03705                      doc->CMSSettings.CMSinUse = false;
03706               }
03707 //            propertiesPalette->updateColorList();
03708 //            propertiesPalette->Cpal->ChooseGrad(0);
03709               if (fileLoader->FileType > FORMATID_NATIVEIMPORTEND)
03710               {
03711                      doc->setName(FName+ tr("(converted)"));
03712                      QFileInfo fi(doc->DocName);
03713                      doc->setName(fi.fileName());
03714               }
03715               else
03716                      doc->setName(FName);
03717               doc->setMasterPageMode(false);
03718               doc->Language = GetLang(doc->Language);
03719               HaveNewDoc();
03720 //            propertiesPalette->Cpal->ChooseGrad(0);
03721 //            propertiesPalette->updateCList();
03722               doc->hasName = true;
03723               if (doc->MasterPages.count() == 0)
03724                      doc->addMasterPage(0, CommonStrings::masterPageNormal);
03725               //Add doc sections if we have none
03726               if (doc->sections.count()==0)
03727               {
03728                      doc->addSection(-1);
03729                      doc->setFirstSectionFromFirstPageNumber();
03730               }
03731               doc->RePos = true;
03732               doc->setMasterPageMode(true);
03733               doc->reformPages();
03734               doc->setLoading(false);
03735               for (uint azz=0; azz<doc->MasterItems.count(); ++azz)
03736               {
03737                      PageItem *ite = doc->MasterItems.at(azz);
03738                      // TODO fix that for Groups on Masterpages
03739 //                   if (ite->Groups.count() != 0)
03740 //                          view->GroupOnPage(ite);
03741 //                   qDebug(QString("load M: %1 %2 %3").arg(azz).arg((uint)ite).arg(ite->itemType()));
03742                      ite->layout();
03743               }
03744 //            RestoreBookMarks();
03745               doc->setMasterPageMode(false);
03746               uint docItemsCount=doc->Items->count();
03747               for (uint azz=0; azz<docItemsCount; ++azz)
03748               {
03749                      PageItem *ite = doc->Items->at(azz);
03750                      //CB dont need this as we get it from the loading page in 1.2.x docs. 1.3.x items have this anyway.
03751                      /*
03752                      if (ite->Groups.count() != 0)
03753                             doc->GroupOnPage(ite);
03754                      else
03755                             ite->OwnPage = doc->OnPage(ite);
03756                      */
03757                      //view->setRedrawBounding(ite);
03758 //                   qDebug(QString("load D: %1 %2 %3").arg(azz).arg((uint)ite).arg(ite->itemType()));
03759                      if(ite->nextInChain() == NULL)
03760                             ite->layout();
03761 /*                   if (doc->OldBM)
03762                      {
03763                             if ((ite->itemType() == PageItem::TextFrame) && (ite->isBookmark))
03764                                    bookmarkPalette->BView->AddPageItem(ite);
03765                      }
03766                      else
03767                      {
03768                             if ((ite->itemType() == PageItem::TextFrame) && (ite->isBookmark))
03769                                    bookmarkPalette->BView->ChangeItem(ite->BMnr, ite->ItemNr);
03770                      } */
03771               }
03772               for (uint azz=0; azz<doc->FrameItems.count(); ++azz)
03773               {
03774                      PageItem *ite = doc->FrameItems.at(azz);
03775 //                   qDebug(QString("load F: %1 %2 %3").arg(azz).arg((uint)ite).arg(ite->itemType()));
03776                      if(ite->nextInChain() == NULL)
03777                             ite->layout();
03778               }
03779 //            if (doc->OldBM)
03780 //                   StoreBookmarks();
03781               doc->RePos = false;
03782               doc->setModified(false);
03783               updateRecent(FName);
03784               mainWindowStatusLabel->setText( tr("Ready"));
03785               ret = true;
03786               doc->setLoading(true);
03787               for (uint p = 0; p < doc->DocPages.count(); ++p)
03788               {
03789                      Apply_MasterPage(doc->DocPages.at(p)->MPageNam, p, false);
03790               }
03791               doc->setLoading(false);
03792 /*            if (fileLoader->FileType > FORMATID_NATIVEIMPORTEND)
03793               {
03794                      doc->hasName = false;
03795                      slotFileSaveAs();
03796               } */
03797               delete fileLoader;
03798               view->updatesOn(true);
03799               w->setUpdatesEnabled(true);
03800               disconnect(wsp, SIGNAL(windowActivated(QWidget *)), this, SLOT(newActWin(QWidget *)));
03801               if ((wsp->windowList().isEmpty()) || (wsp->windowList().count() == 1))
03802                      w->showMaximized();
03803               else
03804                      w->show();
03805               view->show();
03806               newActWin(w);
03807               doc->setCurrentPage(doc->DocPages.at(0));
03808               view->cmsToolbarButton->setOn(doc->HasCMS);
03809               view->slotDoZoom();
03810               view->GotoPage(0);
03811               connect(wsp, SIGNAL(windowActivated(QWidget *)), this, SLOT(newActWin(QWidget *)));
03812               connect(w, SIGNAL(AutoSaved()), this, SLOT(slotAutoSaved()));
03813               connect(ScCore->fileWatcher, SIGNAL(fileChanged(QString )), doc, SLOT(updatePict(QString)));
03814               connect(ScCore->fileWatcher, SIGNAL(fileDeleted(QString )), doc, SLOT(removePict(QString)));
03815               connect(undoManager, SIGNAL(undoRedoDone()), view, SLOT(DrawNew()));
03816               doc->connectDocSignals();
03817               if (doc->AutoSave)
03818                      doc->autoSaveTimer->start(doc->AutoSaveTime);
03819 //            scrActions["fileSave"]->setEnabled(false);
03820               doc->NrItems = bookmarkPalette->BView->NrItems;
03821               doc->First = bookmarkPalette->BView->First;
03822               doc->Last = bookmarkPalette->BView->Last;
03823        }
03824        else
03825        {
03826               pagePalette->setView(0);
03827        }
03828        undoManager->switchStack(doc->DocName);
03829        pagePalette->Rebuild();
03830        qApp->setOverrideCursor(QCursor(arrowCursor), true);
03831        undoManager->setUndoEnabled(true);
03832        doc->setModified(false);
03833        return ret;
03834 }
03835 
03836 bool ScribusMainWindow::postLoadDoc()
03837 {
03838        //FIXME Just return for now, if we arent using the GUI
03839        if (!ScCore->usingGUI())
03840               return false;
03841        return true;
03842 }
03843 
03844 // This method was once named slotFileOpen(...) but it hasn't had anything to
03845 // do with file->open for a LONG time. It's used for get text / get picture.
03846 void ScribusMainWindow::slotGetContent()
03847 {
03848        if (doc->m_Selection->count() != 0)
03849        {
03850               PageItem *currItem = doc->m_Selection->itemAt(0);
03851               if (currItem->itemType() == PageItem::ImageFrame)
03852               {
03853                      QString formatD(setupImageFormats());
03854                      QString docDir = ".";
03855                      QString prefsDocDir=prefsManager->documentDir();
03856                      if (!prefsDocDir.isEmpty())
03857                             docDir = prefsManager->prefsFile->getContext("dirs")->get("images", prefsDocDir);
03858                      else
03859                             docDir = prefsManager->prefsFile->getContext("dirs")->get("images", ".");
03860                      QString fileName = CFileDialog( docDir, tr("Open"), formatD, "", fdShowPreview | fdExistingFiles);
03861                      if (!fileName.isEmpty())
03862                      {
03863                             prefsManager->prefsFile->getContext("dirs")->set("images", fileName.left(fileName.findRev("/")));
03864                             currItem->EmProfile = "";
03865                             currItem->pixm.imgInfo.isRequest = false;
03866                             currItem->UseEmbedded = true;
03867                             currItem->IProfile = doc->CMSSettings.DefaultImageRGBProfile;
03868                             currItem->IRender = doc->CMSSettings.DefaultIntentImages;
03869                             qApp->setOverrideCursor( QCursor(Qt::WaitCursor) );
03870                             qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
03871                             doc->LoadPict(fileName, currItem->ItemNr, false, true);
03872                             //view->AdjustPictScale(currItem, false);
03873                             //false was ignored anyway
03874                             currItem->AdjustPictScale();
03875                             propertiesPalette->setLvalue(currItem->imageXScale(), currItem->imageYScale(), currItem->imageXOffset(), currItem->imageYOffset());
03876                             qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
03877                             qApp->restoreOverrideCursor();
03878                             view->DrawNew();
03879                             propertiesPalette->updateColorList();
03880                             propertiesPalette->ShowCMS();
03881                      }
03882               }
03883               if (currItem->asTextFrame())
03884               {
03885                      gtGetText* gt = new gtGetText(doc);
03886                      ImportSetup impsetup=gt->run();
03887                      if (impsetup.runDialog)
03888                      {
03889                             if (currItem->itemText.length() != 0)
03890                             {
03891                                    int t = ScMessageBox::warning(this, CommonStrings::trWarning, tr("Do you really want to clear all your text?"), QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
03892                                    if (t == QMessageBox::No)
03893                                           return;
03894                             }
03895                             gt->launchImporter(impsetup.importer, impsetup.filename, impsetup.textOnly, impsetup.encoding, false);
03896                      }
03897                      delete gt;
03898                      if (doc->docHyphenator->AutoCheck)
03899                             doc->docHyphenator->slotHyphenate(currItem);
03900                      for (uint a = 0; a < doc->Items->count(); ++a)
03901                      {
03902                             if (doc->Items->at(a)->isBookmark)
03903                                    bookmarkPalette->BView->ChangeText(doc->Items->at(a));
03904                      }
03905                      view->DrawNew();
03906                      slotDocCh();
03907               }
03908        }
03909 }
03910 
03911 void ScribusMainWindow::slotGetContent2() // kk2006
03912 {
03913        if (doc->m_Selection->count() == 0)
03914               return; // nothing to do, no selection
03915 
03916        PageItem *currItem = doc->m_Selection->itemAt(0);
03917 
03918        if (!currItem->asTextFrame())
03919               return; // not a text frame
03920 
03921        ScGTPluginManager::instance()->run();
03922        if (doc->docHyphenator->AutoCheck)
03923               doc->docHyphenator->slotHyphenate(currItem);
03924        for (uint a = 0; a < doc->Items->count(); ++a)
03925        {
03926               if (doc->Items->at(a)->isBookmark)
03927                      bookmarkPalette->BView->ChangeText(doc->Items->at(a));
03928        }
03929        view->DrawNew();
03930        slotDocCh();
03931 }
03932 
03933 void ScribusMainWindow::slotFileAppend()
03934 {
03935        if (doc->m_Selection->count() != 0)
03936        {
03937               gtGetText* gt = new gtGetText(doc);
03938               ImportSetup impsetup=gt->run();
03939               if (impsetup.runDialog)
03940               {
03941                      gt->launchImporter(impsetup.importer, impsetup.filename, impsetup.textOnly, impsetup.encoding, true);
03942               }
03943               delete gt;
03944               //CB Hyphenating now emits doc changed, plus we change lang as appropriate
03945               if (doc->docHyphenator->AutoCheck)
03946                      doc->itemSelection_DoHyphenate();
03947                      //doc->docHyphenator->slotHyphenate(doc->m_Selection->itemAt(0));
03948               view->DrawNew();
03949               //slotDocCh();
03950        }
03951 }
03952 
03953 void ScribusMainWindow::slotFileRevert()
03954 {
03955        if ((doc->hasName) && (doc->isModified()) && (!doc->masterPageMode()))
03956        {
03957               int t = ScMessageBox::warning(this, CommonStrings::trWarning, "<qt>" +
03958                                                          QObject::tr("The changes to your document have not been saved and you have requested to revert them. Do you wish to continue?") + "</qt>",
03959                                                          QMessageBox::Yes, QMessageBox::No | QMessageBox::Default);
03960               if (t == QMessageBox::No)
03961                      return;
03962 
03963               QString fn(doc->DocName);
03964               QFileInfo fi(fn);
03965               QDir::setCurrent(fi.dirPath(true));
03966               doc->setModified(false);
03967               if (doc==storyEditor->currentDocument())
03968                      storyEditor->close();
03969               slotFileClose();
03970               qApp->processEvents();
03971               loadDoc(fn);
03972        }
03973 }
03974 
03975 void ScribusMainWindow::slotAutoSaved()
03976 {
03977        if (ActWin == sender())
03978               updateActiveWindowCaption(doc->DocName);
03979 }
03980 
03981 bool ScribusMainWindow::slotFileSave()
03982 {
03983        bool ret = false;
03984        if (doc->hasName)
03985        {
03986               //Scribus 1.3.x warning, remove at a later stage
03987               if (doc->is12doc && !warningVersion(this))
03988                      return false;
03989 
03990               QString fn(doc->DocName);
03991               ret = DoFileSave(fn);
03992               if (!ret)
03993                      QMessageBox::warning(this, CommonStrings::trWarning, tr("Cannot write the file: \n%1").arg(fn), CommonStrings::tr_OK);
03994        }
03995        else
03996               ret = slotFileSaveAs();
03997        return ret;
03998 }
03999 
04000 bool ScribusMainWindow::slotFileSaveAs()
04001 {
04002        //Scribus 1.3.x warning, remove at a later stage
04003        if (doc->is12doc)
04004               if (!warningVersion(this))
04005                      return false;
04006        //Turn off the warnings once the docs is saved.
04007        doc->is12doc=false;
04008        //
04009        bool ret = false;
04010        QString fna;
04011        PrefsContext* docContext = prefsManager->prefsFile->getContext("docdirs", false);
04012        QString wdir = ".";
04013        if (doc->hasName)
04014        {
04015               QFileInfo fi(doc->DocName);
04016               wdir = fi.dirPath();
04017               fna = fi.dirPath()+"/"+fi.baseName()+".sla";
04018        }
04019        else
04020        {
04021               QString prefsDocDir=prefsManager->documentDir();
04022               if (!prefsDocDir.isEmpty())
04023                      wdir = docContext->get("save_as", prefsDocDir);
04024               else
04025                      wdir = docContext->get("save_as", ".");
04026               if (wdir.right(1) != "/")
04027                      fna = wdir + "/";
04028               else
04029                      fna = wdir;
04030               fna += doc->DocName + ".sla";
04031        }
04032        QString fileSpec=tr("Documents (*.sla *.sla.gz);;All Files (*)");
04033 //     bool setter=true;
04034        int optionFlags = fdCompressFile;
04035        QString fn = CFileDialog( wdir, tr("Save As"), fileSpec, fna, optionFlags);
04036        if (!fn.isEmpty())
04037        {
04038               docContext->set("save_as", fn.left(fn.findRev("/")));
04039               if ((fn.endsWith(".sla")) || (fn.endsWith(".sla.gz")))
04040                      fna = fn;
04041               else
04042                      fna = fn+".sla";
04043               if (overwrite(this, fna))
04044               {
04045                      ret = DoFileSave(fna);
04046                      if (!ret)
04047                             QMessageBox::warning(this, CommonStrings::trWarning, tr("Cannot write the file: \n%1").arg(fn), CommonStrings::tr_OK);
04048                      else
04049                             doc->PDF_Options.Datei = ""; // #1482 reset the pdf file name
04050               }
04051        }
04052        mainWindowStatusLabel->setText( tr("Ready"));
04053        return ret;
04054 }
04055 
04056 bool ScribusMainWindow::DoFileSave(QString fn)
04057 {
04058        ScCore->fileWatcher->forceScan();
04059        ScCore->fileWatcher->stop();
04060        doc->reorganiseFonts();
04061        buildFontMenu();
04062        mainWindowStatusLabel->setText( tr("Saving..."));
04063        mainWindowProgressBar->reset();
04064        bool ret=doc->save(fn);
04065        qApp->processEvents();
04066        if (ret)
04067        {
04068               updateActiveWindowCaption(fn);
04069               undoManager->renameStack(fn);
04070 //            scrActions["fileSave"]->setEnabled(false);
04071               scrActions["fileRevert"]->setEnabled(false);
04072               updateRecent(fn);
04073        }
04074        mainWindowStatusLabel->setText("");
04075        mainWindowProgressBar->reset();
04076        ScCore->fileWatcher->start();
04077        return ret;
04078 }
04079 
04080 bool ScribusMainWindow::slotFileClose()
04081 {
04082        ScribusWin* tw = ActWin;
04083        ActWin->close();
04084        if (tw == ActWin)
04085               return false;
04086        else
04087               return true;
04088        windowsMenuAboutToShow();
04089 }
04090 
04091 bool ScribusMainWindow::DoFileClose()
04092 {
04093        view->Deselect(false);
04094        if (doc==storyEditor->currentDocument())
04095               storyEditor->close();
04096        actionManager->disconnectNewDocActions();
04097        actionManager->disconnectNewViewActions();
04098        disconnect(view, SIGNAL(signalGuideInformation(int, double)), alignDistributePalette, SLOT(setGuide(int, double)));
04099        if (doc->viewCount > 1)
04100        {
04101               --doc->viewCount;
04102               closeActiveWindowMasterPageEditor();
04103               setAppMode(modeNormal);
04104               disconnect(ScCore->fileWatcher, SIGNAL(fileChanged(QString )), doc, SLOT(updatePict(QString)));
04105               disconnect(ScCore->fileWatcher, SIGNAL(fileDeleted(QString )), doc, SLOT(removePict(QString)));
04106               view->close();
04107               delete view;
04108               view = NULL;
04109               doc = NULL;
04110               ActWin = NULL;
04111               return true;
04112        }
04113        undoManager->removeStack(doc->DocName);
04114        closeActiveWindowMasterPageEditor();
04115        setAppMode(modeNormal);
04116        doc->autoSaveTimer->stop();
04117        disconnect(doc->autoSaveTimer, SIGNAL(timeout()), doc->WinHan, SLOT(slotAutoSave()));
04118        disconnect(doc->WinHan, SIGNAL(AutoSaved()), this, SLOT(slotAutoSaved()));
04119        disconnect(ScCore->fileWatcher, SIGNAL(fileChanged(QString )), doc, SLOT(updatePict(QString)));
04120        disconnect(ScCore->fileWatcher, SIGNAL(fileDeleted(QString )), doc, SLOT(removePict(QString)));
04121        for (uint a = 0; a < doc->DocItems.count(); ++a)
04122        {
04123               PageItem *currItem = doc->DocItems.at(a);
04124               if (currItem->PicAvail)
04125                      ScCore->fileWatcher->removeFile(currItem->Pfile);
04126        }
04127        for (uint a = 0; a < doc->MasterItems.count(); ++a)
04128        {
04129               PageItem *currItem = doc->MasterItems.at(a);
04130               if (currItem->PicAvail)
04131                      ScCore->fileWatcher->removeFile(currItem->Pfile);
04132        }
04133        for (uint a = 0; a < doc->FrameItems.count(); ++a)
04134        {
04135               PageItem *currItem = doc->FrameItems.at(a);
04136               if (currItem->PicAvail)
04137                      ScCore->fileWatcher->removeFile(currItem->Pfile);
04138        }
04139        QStringList patterns = doc->docPatterns.keys();
04140        for (uint c = 0; c < patterns.count(); ++c)
04141        {
04142               ScPattern pa = doc->docPatterns[patterns[c]];
04143               for (uint o = 0; o < pa.items.count(); o++)
04144               {
04145                      PageItem *currItem = pa.items.at(o);
04146                      if (currItem->PicAvail)
04147                             ScCore->fileWatcher->removeFile(currItem->Pfile);
04148               }
04149        }
04150        if (ScCore->haveCMS())
04151               doc->CloseCMSProfiles();
04152        //<<Palettes
04153 //     propertiesPalette->NewSel(-1);
04154        propertiesPalette->unsetDoc();
04155        pagePalette->setView(0);
04156        pagePalette->Rebuild();
04157        if (doc->EditClip)
04158               NoFrameEdit();
04159        bookmarkPalette->BView->clear();
04160        bookmarkPalette->BView->NrItems = 0;
04161        bookmarkPalette->BView->First = 1;
04162        bookmarkPalette->BView->Last = 0;
04163        outlinePalette->unsetDoc();
04164        alignDistributePalette->setDoc(NULL);
04165        //>>
04166        if ((wsp->windowList().isEmpty()) || (wsp->windowList().count() == 1))
04167        {
04168               scrActions["fileDocSetup"]->setEnabled(false);
04169               scrActions["filePrint"]->setEnabled(false);
04170               scrActions["fileSave"]->setEnabled(false);
04171               scrActions["fileSaveAs"]->setEnabled(false);
04172               scrActions["fileRevert"]->setEnabled(false);
04173               scrActions["fileCollect"]->setEnabled(false);
04174               scrActions["fileClose"]->setEnabled(false);
04175               scrActions["PrintPreview"]->setEnabled(false);
04176               if (scrActions["SaveAsDocumentTemplate"])
04177                      scrActions["SaveAsDocumentTemplate"]->setEnabled(false);
04178               scrMenuMgr->setMenuEnabled("FileImport", false);
04179               scrMenuMgr->setMenuEnabled("FileExport", false);
04180               scrActions["fileExportAsPDF"]->setEnabled(false);
04181               scrActions["fileExportText"]->setEnabled(false);
04182               scrActions["fileExportAsEPS"]->setEnabled(false);
04183               scrActions["fileImportText"]->setEnabled(false);
04184               scrActions["fileImportText2"]->setEnabled(false);
04185               scrActions["fileImportImage"]->setEnabled(false);
04186               scrActions["fileImportAppendText"]->setEnabled(false);
04187               scrActions["pageImport"]->setEnabled(false);
04188 
04189               scrActions["editUndoAction"]->setEnabled(false);
04190               scrActions["editRedoAction"]->setEnabled(false);
04191               scrActions["editCut"]->setEnabled(false);
04192               scrActions["editCopy"]->setEnabled(false);
04193               scrActions["editPaste"]->setEnabled(false);
04194               scrMenuMgr->setMenuEnabled("EditPasteRecent", false);
04195               scrActions["editClearContents"]->setEnabled(false);
04196               scrActions["editSelectAll"]->setEnabled(false);
04197               scrActions["editDeselectAll"]->setEnabled(false);
04198               scrActions["editPatterns"]->setEnabled(false);
04199               scrActions["editStyles"]->setEnabled(false);
04200               scrActions["editSearchReplace"]->setEnabled(false);
04201               scrActions["editMasterPages"]->setEnabled(false);
04202               scrActions["editJavascripts"]->setEnabled(false);
04203 
04204               //scrActions["toolsPreflightVerifier"]->setEnabled(false);
04205 
04206               scrActions["extrasHyphenateText"]->setEnabled(false);
04207               scrActions["extrasDeHyphenateText"]->setEnabled(false);
04208               scrMenuMgr->setMenuEnabled("View", false);
04209               //scrMenuMgr->setMenuEnabled("Windows", false);
04210               scrActions["viewSnapToGuides"]->setOn(false);
04211               scrActions["viewSnapToGrid"]->setOn(false);
04212               scrActions["viewShowRulers"]->setEnabled(false);
04213 
04214               scrMenuMgr->setMenuEnabled("Insert", false);
04215               scrActions["insertFrame"]->setEnabled(false);
04216               scrMenuMgr->setMenuEnabled("Page", false);
04217               scrMenuMgr->setMenuEnabled("Extras", false);
04218               scrMenuMgr->setMenuEnabled("Style", false);
04219               scrMenuMgr->setMenuEnabled("Item", false);
04220 
04221               scrActions["toolsSelect"]->setEnabled(false);
04222               scrActions["toolsRotate"]->setEnabled(false);
04223               scrActions["toolsEditContents"]->setEnabled(false);
04224               scrActions["toolsEditWithStoryEditor"]->setEnabled(false);
04225               scrActions["toolsZoom"]->setEnabled(false);
04226               scrActions["toolsInsertTextFrame"]->setEnabled(false);
04227               scrActions["toolsInsertImageFrame"]->setEnabled(false);
04228               scrActions["toolsInsertTableFrame"]->setEnabled(false);
04229               scrActions["toolsInsertShape"]->setEnabled(false);
04230               scrActions["toolsInsertLine"]->setEnabled(false);
04231               scrActions["toolsInsertBezier"]->setEnabled(false);
04232               scrActions["toolsInsertFreehandLine"]->setEnabled(false);
04233               scrActions["toolsInsertPolygon"]->setEnabled(false);
04234               scrActions["toolsLinkTextFrame"]->setEnabled(false);
04235               scrActions["toolsUnlinkTextFrame"]->setEnabled(false);
04236               scrActions["toolsMeasurements"]->setEnabled(false);
04237               scrActions["toolsCopyProperties"]->setEnabled(false);
04238               scrActions["toolsEyeDropper"]->setEnabled(false);
04239               scrActions["toolsPDFPushButton"]->setEnabled(false);
04240               scrActions["toolsPDFTextField"]->setEnabled(false);
04241               scrActions["toolsPDFCheckBox"]->setEnabled(false);
04242               scrActions["toolsPDFComboBox"]->setEnabled(false);
04243               scrActions["toolsPDFListBox"]->setEnabled(false);
04244               scrActions["toolsPDFAnnotText"]->setEnabled(false);
04245               scrActions["toolsPDFAnnotLink"]->setEnabled(false);
04246               ColorMenC->clear();
04247               //CB dont need this until we have a doc...
04248               //propertiesPalette->Cpal->SetColors(prefsManager->colorSet());
04249               propertiesPalette->Cpal->ChooseGrad(0);
04250               mainWindowStatusLabel->setText( tr("Ready"));
04251               PrinterUsed = false;
04252        }
04253        QString fName(view->Doc->DocName);
04254        view->close();
04255        delete view;
04256        doc->setLoading(true);
04257        guidePalette->setDoc(0);
04258        charPalette->setDoc(0);
04259        layerPalette->ClearInhalt();
04260        docCheckerPalette->buildErrorList(0);
04261        ScCore->fileWatcher->removeFile(fName);
04262        HaveDoc--;
04263        view = NULL;
04264        delete doc;
04265        doc = NULL;
04266        ActWin = NULL;
04267        tocGenerator->setDoc(doc);
04268        if ( HaveDoc == 0 )
04269        {
04270               QString prefsDocDir( PrefsManager::instance()->documentDir() );
04271               if ( QDir().exists(prefsDocDir) )
04272                      QDir::setCurrent( PrefsManager::instance()->documentDir() );
04273               else
04274                      QDir::setCurrent( QDir::homeDirPath() );
04275        }
04276        styleManager->setDoc(0);
04277        return true;
04278 }
04279 
04280 void ScribusMainWindow::slotFilePrint()
04281 {
04282        if (doc->checkerProfiles[doc->curCheckProfile].autoCheck)
04283        {
04284               if (scanDocument())
04285               {
04286                      if (doc->checkerProfiles[doc->curCheckProfile].ignoreErrors)
04287                      {
04288                             int t = ScMessageBox::warning(this, CommonStrings::trWarning,
04289                                                                              "<qt>"+ tr("Scribus has detected some errors. Consider using the Preflight Verifier to correct them")+"</qt>",
04290                                                                              tr("&Ignore"), tr("&Abort"), 0, 0, 0);
04291                             if (t == 1)
04292                                    return;
04293                      }
04294                      else
04295                      {
04296                             connect(docCheckerPalette, SIGNAL(ignoreAllErrors()), this, SLOT(slotReallyPrint()));
04297                             docCheckerPalette->setIgnoreEnabled(true);
04298                             docCheckerPalette->checkMode = CheckDocument::checkPrint;
04299                             docCheckerPalette->buildErrorList(doc);
04300                             docCheckerPalette->show();
04301                             scrActions["toolsPreflightVerifier"]->setOn(true);
04302                             return;
04303                      }
04304               }
04305        }
04306        slotReallyPrint();
04307 }
04308 
04309 void ScribusMainWindow::slotReallyPrint()
04310 {
04311        bool done;
04312        if (docCheckerPalette->isIgnoreEnabled())
04313        {
04314               docCheckerPalette->setIgnoreEnabled(false);
04315               docCheckerPalette->hide();
04316               docCheckerPalette->checkMode = CheckDocument::checkNULL;
04317               scrActions["toolsPreflightVerifier"]->setOn(false);
04318               disconnect(docCheckerPalette, SIGNAL(ignoreAllErrors()), this, SLOT(slotReallyPrint()));
04319        }
04320        PrintOptions options;
04321        mainWindowStatusLabel->setText( tr("Printing..."));
04322        if (PrinterUsed)
04323        {
04324               doc->Print_Options.printer = PDef.Pname;
04325               doc->Print_Options.filename = PDef.Dname;
04326        }
04327        else
04328        {
04329               doc->Print_Options.printer = "";
04330               if (!doc->DocName.startsWith( tr("Document")))
04331               {
04332                      QFileInfo fi(doc->DocName);
04333                      doc->Print_Options.filename = fi.dirPath()+"/"+fi.baseName()+".ps";
04334               }
04335               else
04336               {
04337                      QDir di = QDir();
04338                      doc->Print_Options.filename = di.currentDirPath()+"/"+doc->DocName+".ps";
04339               }
04340        }
04341        doc->Print_Options.copies = 1;
04342        ColorList usedSpots;
04343        doc->getUsedColors(usedSpots, true);
04344        QStringList spots = usedSpots.keys();
04345        qDebug(QString("scribus.cpp: before print dialog color=%1 copies = %2").arg(doc->Print_Options.useColor).arg(doc->Print_Options.copies));
04346        Druck *printer = new Druck(this, doc, doc->Print_Options.filename, doc->Print_Options.printer, PDef.Command, PDef.DevMode, prefsManager->appPrefs.GCRMode, spots);
04347        printer->setMinMax(1, doc->Pages->count(), doc->currentPage()->pageNr()+1);
04348        printDinUse = true;
04349        connect(printer, SIGNAL(doPreview()), this, SLOT(doPrintPreview()));
04350        if (printer->exec())
04351        {
04352               qDebug(QString("scribus.cpp: before print dialog color=%1 copies = %2").arg(doc->Print_Options.useColor).arg(doc->Print_Options.copies));
04353               ReOrderText(doc, view);
04354               qApp->setOverrideCursor(QCursor(waitCursor), true);
04355               doc->Print_Options.pageNumbers.clear();
04356               if (printer->CurrentPage->isChecked())
04357               {
04358                      doc->Print_Options.pageNumbers.push_back(doc->currentPage()->pageNr()+1);
04359               }
04360               else
04361               {
04362                      if (printer->RadioButton1->isChecked())
04363                             parsePagesString("*", &doc->Print_Options.pageNumbers, doc->DocPages.count());
04364                      else
04365                             parsePagesString(printer->pageNr->text(), &doc->Print_Options.pageNumbers, doc->DocPages.count());
04366               }
04367               PrinterUsed = true;
04368 #ifdef _WIN32
04369               SHORT shiftState = GetKeyState( VK_SHIFT );
04370               bool forceGDI = ( shiftState & 0x8000 ) ? true : false;
04371               if (doc->Print_Options.toFile == false)
04372               {
04373                      ScWinPrint winPrint;
04374                      done = winPrint.print( doc, doc->Print_Options, printer->DevMode, forceGDI );
04375               }
04376               else
04377                      done = doPrint(doc->Print_Options);
04378 #else
04379               done = doPrint(doc->Print_Options);
04380 #endif
04381               if (!done)
04382               {
04383                      qApp->setOverrideCursor(QCursor(arrowCursor), true);
04384                      QMessageBox::warning(this, CommonStrings::trWarning, tr("Printing failed!"), CommonStrings::tr_OK);
04385               }
04386               else
04387                      doc->Print_Options.firstUse = false;
04388               qApp->setOverrideCursor(QCursor(arrowCursor), true);
04389        }
04390        printDinUse = false;
04391        disconnect(printer, SIGNAL(doPreview()), this, SLOT(doPrintPreview()));
04392        delete printer;
04393        mainWindowStatusLabel->setText( tr("Ready"));
04394 }
04395 
04396 bool ScribusMainWindow::doPrint(PrintOptions &options)
04397 {
04398        bool retw = false;
04399        QMap<QString, QMap<uint, FPointArray> > ReallyUsed;
04400        QString filename(options.filename);
04401        ReallyUsed.clear();
04402        doc->getUsedFonts(ReallyUsed);
04403        ColorList usedColors;
04404        doc->getUsedColors(usedColors);
04405        ScCore->fileWatcher->forceScan();
04406        ScCore->fileWatcher->stop();
04407        PSLib *dd = new PSLib(options, true, prefsManager->appPrefs.AvailFonts, ReallyUsed, usedColors, false, options.useSpotColors);
04408        if (dd != NULL)
04409        {
04410               if (!options.toFile)
04411                      filename = prefsManager->preferencesLocation()+"/tmp.ps";
04412               else
04413               {
04414                      qApp->setOverrideCursor(QCursor(arrowCursor), true);
04415                      if (!overwrite(this, filename))
04416                      {
04417                             delete dd;
04418                             ScCore->fileWatcher->start();
04419                             return true;
04420                      }
04421                      qApp->setOverrideCursor(QCursor(waitCursor), true);
04422               }
04423               bool PSfile = dd->PS_set_file(filename);
04424               filename = QDir::convertSeparators(filename);
04425               if (PSfile)
04426               {
04427                      // Write the PS to a file
04428                      int psCreationRetVal=dd->CreatePS(doc, options);
04429                      if (psCreationRetVal!=0)
04430                      {
04431                             unlink(filename);
04432                             if (psCreationRetVal==2)
04433                                    return true;
04434                             else
04435                                    return false;
04436                      }
04437                      if (options.PSLevel != 3)
04438                      {
04439                             // use gs to convert our PS to a lower version
04440                             QString tmp;
04441                             QStringList opts;
04442                             opts.append( QString("-dDEVICEWIDTHPOINTS=%1").arg(tmp.setNum(doc->pageWidth)) );
04443                             opts.append( QString("-dDEVICEHEIGHTPOINTS=%1").arg(tmp.setNum(doc->pageHeight)) );
04444                             convertPS2PS(filename, filename + ".tmp", opts, options.PSLevel);
04445                             moveFile( filename + ".tmp", filename );
04446                      }
04447                      if (!options.toFile)
04448                      {
04449                             // print and delete the PS file
04450                             QString cmd;
04451                             if (options.useAltPrintCommand)
04452                             {
04453                                    cmd = options.printerCommand + " "+filename;
04454                                    system(cmd);
04455                             }
04456                             else
04457                             {
04458                                    QString cc;
04459                                    cmd = "lpr -P '" + options.printer + "'";
04460                                    if (options.copies > 1)
04461                                           cmd += " -#" + cc.setNum(options.copies);
04462                                    cmd += options.printerOptions;
04463                                    cmd += " "+filename;
04464                                    system(cmd);
04465                             }
04466 // Disabled that for now, as kprinter won't work otherwise
04467 // leaving that file around doesn't harm, as it will be overwritten the next time.
04468 //                          unlink(filename);
04469                      }
04470                      retw = true;
04471               }
04472               else
04473                      retw = false;
04474               delete dd;
04475        }
04476        ScCore->fileWatcher->start();
04477        return retw;
04478 }
04479 
04480 void ScribusMainWindow::slotFileQuit()
04481 {
04482        propertiesPalette->unsetDoc();
04483        ScCore->pluginManager->savePreferences();
04484        close();
04485 }
04486 
04487 
04488 static bool hasXMLRootElem(const QString& buffer, const QString& elemtag)
04489 {
04490        return buffer.findRev(elemtag, 50 + elemtag.length()) >= 0;
04491 }
04492 
04493 
04494 void ScribusMainWindow::slotEditCut()
04495 {
04496 //     int a;
04497        NoFrameEdit();
04498        QString BufferI = "";
04499        uint docSelectionCount=doc->m_Selection->count();
04500        if ((HaveDoc) && (docSelectionCount != 0))
04501        {
04502               PageItem *currItem;
04503               for (uint i = 0; i < docSelectionCount; ++i)
04504               {
04505                      currItem=doc->m_Selection->itemAt(i);
04506                      if ((currItem->asTextFrame() || currItem->asPathText()) && currItem==storyEditor->currentItem() && doc==storyEditor->currentDocument())
04507                      {
04508                                    QMessageBox::critical(this, tr("Cannot Cut In-Use Item"), tr("The item %1 is currently being edited by Story Editor. The cut operation will be cancelled").arg(currItem->itemName()), QMessageBox::Ok, QMessageBox::NoButton, QMessageBox::NoButton);
04509                                    return;
04510                      }
04511               }
04512               if (UndoManager::undoEnabled())
04513               {
04514                      if (docSelectionCount > 1)
04515                             undoManager->beginTransaction(Um::SelectionGroup, Um::IGroup, Um::Cut,"",Um::ICut);
04516                      else
04517                      {
04518                             PageItem* item=doc->m_Selection->itemAt(0);
04519                             undoManager->beginTransaction(item->getUName(), item->getUPixmap(), Um::Cut, "", Um::ICut);
04520                      }
04521               }
04522               Buffer2 = "<SCRIBUSTEXT>";
04523               currItem = doc->m_Selection->itemAt(0);
04524               if (doc->appMode == modeEdit)
04525               {
04526                      if ((currItem->itemText.length() == 0) || (!currItem->HasSel))
04527                             return;
04528                      StoryText itemText(doc);
04529                      itemText.setDefaultStyle(currItem->itemText.defaultStyle());
04530                      itemText.insert(0, currItem->itemText, true);
04531                      
04532                      BufferI = itemText.text(0, itemText.length());
04533                      
04534                      std::ostringstream xmlString;
04535                      SaxXML xmlStream(xmlString);
04536                      xmlStream.beginDoc();
04537                      itemText.saxx(xmlStream, "SCRIBUSTEXT");
04538                      xmlStream.endDoc();
04539                      std::string xml(xmlString.str());
04540                      Buffer2 = QString::fromUtf8(xml.c_str(), xml.length());
04541                      
04542                      /*                   PageItem *nextItem = currItem;
04543                      while (nextItem != 0)
04544                      {
04545                             if (nextItem->prevInChain() != 0)
04546                                    nextItem = nextItem->prevInChain();
04547                             else
04548                                    break;
04549                      }
04550                      if (nextItem != 0)
04551                      {
04552                             for (a = 0; a < nextItem->itemText.length(); ++a)
04553                             {
04554                                    if (nextItem->itemText.selected(a))
04555                                    {
04556                                           if (nextItem->itemText.text(a) == QChar(13))
04557                                           {
04558                                                  Buffer2 += QChar(5);
04559                                                  BufferI += QChar(10);
04560                                           }
04561                                           else if (nextItem->itemText.text(a) == QChar(9))
04562                                           {
04563                                                  Buffer2 += QChar(4);
04564                                                  BufferI += QChar(9);
04565                                           }
04566                                           else
04567                                           {
04568                                                  Buffer2 += nextItem->itemText.text(a);
04569                                                  BufferI += nextItem->itemText.text(a);
04570                                           }
04571                                           Buffer2 += "\t";
04572                                           Buffer2 += nextItem->itemText.charStyle(a).font().scName()+"\t";
04573                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).fontSize())+"\t";
04574                                           Buffer2 += nextItem->itemText.charStyle(a).fillColor()+"\t";
04575                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).tracking())+"\t";
04576                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).fillShade())+'\t';
04577                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).effects())+'\t';
04578                                           Buffer2 += QString::number(findParagraphStyle(doc, nextItem->itemText.paragraphStyle(a)))+'\t';
04579                                           Buffer2 += nextItem->itemText.charStyle(a).strokeColor()+"\t";
04580                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).strokeShade())+'\t';
04581                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).scaleH())+"\t";
04582                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).scaleV())+'\t';
04583                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).baselineOffset())+'\t';
04584                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).shadowXOffset())+'\t';
04585                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).shadowYOffset())+'\t';
04586                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).outlineWidth())+'\t';
04587                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).underlineOffset())+'\t';
04588                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).underlineWidth())+'\t';
04589                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).strikethruOffset())+'\t';
04590                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).strikethruWidth())+'\n';
04591                                    }
04592                             }
04593                             dynamic_cast<PageItem_TextFrame*>(nextItem)->deleteSelectedTextFromFrame();
04594                             nextItem = nextItem->nextInChain();
04595                      }
04596                      */
04597                      dynamic_cast<PageItem_TextFrame*>(currItem)->deleteSelectedTextFromFrame();
04598                      view->RefreshItem(currItem);
04599               }
04600               else
04601               {
04602                      if (((currItem->isSingleSel) && (currItem->isGroupControl)) || ((currItem->isSingleSel) && (currItem->isTableItem)))
04603                             return;
04604                      
04605                      // old version:
04606                      ScriXmlDoc *ss = new ScriXmlDoc();
04607                      Buffer2 = ss->WriteElem(doc, view, doc->m_Selection);
04608                      
04609                      // new version:
04610                      std::ostringstream xmlString;
04611                      SaxXML xmlStream(xmlString);
04612 //                   qDebug(QString("call serializer: %1").arg((ulong) & (doc->m_Selection)));
04613                      Serializer::serializeObjects(*doc->m_Selection, xmlStream);
04614                      std::string xml(xmlString.str());
04615                      BufferI = QString::fromUtf8(xml.c_str(), xml.length());
04616                      
04617                      if (prefsManager->appPrefs.doCopyToScrapbook)
04618                      {
04619                             scrapbookPalette->ObjFromCopyAction(Buffer2);
04620                             rebuildRecentPasteMenu();
04621                      }
04622                      Buffer2 = BufferI;
04623                      for (uint i=0; i < doc->m_Selection->count(); ++i)
04624                      {
04625                             PageItem* frame = doc->m_Selection->itemAt(i);
04626                             if (frame->asTextFrame() && frame->prevInChain() == NULL)
04627                                    frame->clearContents();
04628                      }
04629                      doc->itemSelection_DeleteItem();
04630                      delete ss;
04631               }
04632               slotDocCh();
04633               BuFromApp = true;
04634               ClipB->setText(BufferI);
04635               scrActions["editPaste"]->setEnabled(true);
04636               scrMenuMgr->setMenuEnabled("EditPasteRecent", scrapbookPalette->tempBView->objectMap.count() != 0);
04637               if (UndoManager::undoEnabled())
04638                      undoManager->commit();
04639        }
04640 }
04641 
04642 void ScribusMainWindow::slotEditCopy()
04643 {
04644 //     int a;
04645        NoFrameEdit();
04646        QString BufferI = "";
04647        if ((HaveDoc) && (doc->m_Selection->count() != 0))
04648        {
04649               Buffer2 = "<SCRIBUSTEXT/>";
04650               PageItem *currItem = doc->m_Selection->itemAt(0);
04651               if ((doc->appMode == modeEdit) && (currItem->HasSel))
04652               {
04653                      StoryText itemText(doc);
04654                      itemText.setDefaultStyle(currItem->itemText.defaultStyle());
04655                      itemText.insert(0, currItem->itemText, true);
04656                      
04657                      BufferI = itemText.text(0, itemText.length());
04658                      
04659                      std::ostringstream xmlString;
04660                      SaxXML xmlStream(xmlString);
04661                      xmlStream.beginDoc();
04662                      itemText.saxx(xmlStream, "SCRIBUSTEXT");
04663                      xmlStream.endDoc();
04664                      std::string xml(xmlString.str());
04665                      Buffer2 = QString::fromUtf8(xml.c_str(), xml.length());
04666 //                   qDebug(Buffer2);
04667                      
04668 /*                   PageItem *nextItem = currItem;
04669                      while (nextItem != 0)
04670                      {
04671                             if (nextItem->prevInChain() != 0)
04672                                    nextItem = nextItem->prevInChain();
04673                             else
04674                                    break;
04675                      }
04676                      if (nextItem != 0)
04677                      {
04678                             for (a = 0; a < nextItem->itemText.length(); ++a)
04679                             {
04680                                    if (nextItem->itemText.selected(a))
04681                                    {
04682                                           if (nextItem->itemText.text(a) == SpecialChars::PARSEP)
04683                                           {
04684                                                  Buffer2 += QChar(5);
04685                                                  BufferI += QChar(10);
04686                                           }
04687                                           else if (nextItem->itemText.text(a) == SpecialChars::TAB)
04688                                           {
04689                                                  Buffer2 += QChar(4);
04690                                                  BufferI += QChar(9);
04691                                           }
04692                                           else
04693                                           {
04694                                                  Buffer2 += nextItem->itemText.text(a);
04695                                                  BufferI += nextItem->itemText.text(a);
04696                                           }
04697                                           Buffer2 += "\t";
04698                                           Buffer2 += nextItem->itemText.charStyle(a).font().scName()+"\t";
04699                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).fontSize())+"\t";
04700                                           Buffer2 += nextItem->itemText.charStyle(a).fillColor()+"\t";
04701                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).tracking())+"\t";
04702                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).fillShade())+"\t";
04703                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).effects())+"\t";
04704                                           Buffer2 += QString::number(findParagraphStyle(doc, nextItem->itemText.paragraphStyle(a)))+"\t";
04705                                           Buffer2 += nextItem->itemText.charStyle(a).strokeColor()+"\t";
04706                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).strokeShade())+"\t";
04707                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).scaleH())+"\t";
04708                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).scaleV())+'\t';
04709                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).baselineOffset())+'\t';
04710                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).shadowXOffset())+'\t';
04711                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).shadowYOffset())+'\t';
04712                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).outlineWidth())+'\t';
04713                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).underlineOffset())+'\t';
04714                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).underlineWidth())+'\t';
04715                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).strikethruOffset())+'\t';
04716                                           Buffer2 += QString::number(nextItem->itemText.charStyle(a).strikethruWidth())+'\n';
04717                                    }
04718                             }
04719                             nextItem = nextItem->nextInChain();
04720                      }
04721                      */
04722               }
04723               else
04724               {
04725                      if (((currItem->isSingleSel) && (currItem->isGroupControl)) || ((currItem->isSingleSel) && (currItem->isTableItem)))
04726                             return;
04727                      
04728                      // old version:
04729                      ScriXmlDoc *ss = new ScriXmlDoc();
04730                      Buffer2 = ss->WriteElem(doc, view, doc->m_Selection);
04731                      
04732                      // new version:
04733                      std::ostringstream xmlString;
04734                      SaxXML xmlStream(xmlString);
04735                      Serializer::serializeObjects(*doc->m_Selection, xmlStream);
04736                      std::string xml(xmlString.str());
04737                      BufferI = QString::fromUtf8(xml.c_str(), xml.length());
04738                      
04739 #ifdef DESAXE_DEBUG
04740                      // debug:
04741                      SaxXML tmpfile1("tmp-scribus1.xml", true);
04742                      Serializer::serializeObjects(*doc->m_Selection, tmpfile1);
04743                      Serializer digester(*doc);
04744                      QFile file ("tmp-scribus1.xml");
04745                      Selection objects = digester.deserializeObjects(file);
04746                      SaxXML tmpfile2("tmp-scribus2.xml", true);
04747                      Serializer::serializeObjects(objects, tmpfile2);
04748                      doc->itemSelection_DeleteItem(&objects);
04749 #endif
04750                      
04751                      if (prefsManager->appPrefs.doCopyToScrapbook)
04752                      {
04753                             scrapbookPalette->ObjFromCopyAction(Buffer2);
04754                             rebuildRecentPasteMenu();
04755                      }
04756                      Buffer2 = BufferI;
04757                      delete ss;
04758               }
04759               BuFromApp = true;
04760               ClipB->setText(BufferI);
04761               scrActions["editPaste"]->setEnabled(true);
04762               scrMenuMgr->setMenuEnabled("EditPasteRecent", scrapbookPalette->tempBView->objectMap.count() != 0);
04763        }
04764 }
04765 
04766 void ScribusMainWindow::slotEditPaste()
04767 {
04768        NoFrameEdit();
04769        if (HaveDoc)
04770        {
04771               if (Buffer2.isNull())
04772                      return;
04773               if (UndoManager::undoEnabled())
04774                      undoManager->beginTransaction(doc->currentPage()->getUName(), 0, Um::Paste, "", Um::IPaste);
04775               if (doc->appMode == modeEdit)
04776               {
04777                      PageItem_TextFrame *currItem = dynamic_cast<PageItem_TextFrame*>(doc->m_Selection->itemAt(0));
04778                      if (currItem->HasSel)
04779                             currItem->deleteSelectedTextFromFrame();
04780 
04781                      if (currItem->CPos < 0)
04782                             currItem->CPos = 0;
04783                      if (currItem->CPos > currItem->itemText.length())
04784                             currItem->CPos = currItem->itemText.length();
04785                      
04786                      if (hasXMLRootElem(Buffer2, "<SCRIBUSTEXT"))
04787                      {
04788                             Serializer dig(*doc);
04789                             dig.store<ScribusDoc>("<scribusdoc>", doc);
04790                             StoryText::desaxeRules("/", dig, "SCRIBUSTEXT");
04791                             dig.addRule("/SCRIBUSTEXT", desaxe::Result<StoryText>());
04792 
04793                             QCString xml( Buffer2.utf8() );
04794                             dig.parseMemory(xml, xml.length());
04795                             
04796                             StoryText* story = dig.result<StoryText>();
04797                             
04798                             currItem->itemText.insert(currItem->CPos, *story);
04799                             currItem->CPos += story->length();
04800                             
04801                             delete story;
04802                             
04803 /*                          QString Buf = Buffer2.mid(13);
04804                             QTextStream t(&Buf, IO_ReadOnly);
04805                             QString cc;
04806                             while (!t.atEnd())
04807                             {
04808                                    cc = t.readLine();
04809                                    QStringList wt;
04810                                    QStringList::Iterator it;
04811                                    wt = QStringList::split("\t", cc);
04812                                    it = wt.begin();
04813                                    CharStyle nstyle;
04814                                    QString ch = (*it);
04815                                    if (ch == QChar(5))
04816                                           ch = SpecialChars::PARSEP;
04817                                    if (ch == QChar(4))
04818                                           ch = SpecialChars::TAB;
04819                                           Don't copy inline frames for now, as this is a very complicated thing.
04820                                           We need to figure out a good way to copy inline frames, this must
04821                                           be able to preserve them across documents. No idea how to solve
04822                                           that yet. *--/
04823                                    if (ch == SpecialChars::OBJECT)
04824                                           ch = QChar(32);
04825                                    it++;
04826                                    nstyle.setFont((*doc->AllFonts)[*it]);
04827                                    it++;
04828                                    nstyle.setFontSize((*it).toInt());
04829                                    it++;
04830                                    nstyle.setFillColor(*it);
04831                                    it++;
04832                                    nstyle.setTracking((*it).toInt());
04833                                    it++;
04834                                    nstyle.setFillShade((*it).toInt());
04835                                    it++;
04836                                    nstyle.setFeatures(static_cast<StyleFlag>((*it).toInt()).featureList());
04837                                    it++;
04838                                    int cab = (*it).toInt();
04839                                    it++;
04840                                    if (it == NULL)
04841                                           nstyle.setStrokeColor(CommonStrings::None);
04842                                    else
04843                                           nstyle.setStrokeColor(*it);
04844                                    it++;
04845                                    if (it == NULL)
04846                                           nstyle.setStrokeShade(100);
04847                                    else
04848                                           nstyle.setStrokeShade((*it).toInt());
04849                                    it++;
04850                                    if (it == NULL)
04851                                           nstyle.setScaleH(1000);
04852                                    else
04853                                           nstyle.setScaleH((*it).toInt());
04854                                    it++;
04855                                    if (it == NULL)
04856                                           nstyle.setScaleV(1000);
04857                                    else
04858                                           nstyle.setScaleV(QMIN(QMAX((*it).toInt(), 100), 4000));
04859                                    it++;
04860                                    nstyle.setBaselineOffset(it == NULL ? 0 : (*it).toInt());
04861                                    it++;
04862                                    nstyle.setShadowXOffset(it == NULL ? 50 : (*it).toInt());
04863                                    it++;
04864                                    nstyle.setShadowYOffset(it == NULL ? -50 : (*it).toInt());
04865                                    it++;
04866                                    nstyle.setOutlineWidth(it == NULL ? 10 : (*it).toInt());
04867                                    it++;
04868                                    nstyle.setUnderlineOffset(it == NULL ? -1 : (*it).toInt());
04869                                    it++;
04870                                    nstyle.setUnderlineWidth(it == NULL ? -1 : (*it).toInt());
04871                                    it++;
04872                                    nstyle.setStrikethruOffset(it == NULL ? -1 : (*it).toInt());
04873                                    it++;
04874                                    nstyle.setStrikethruWidth(it == NULL ? -1 : (*it).toInt());
04875                                    currItem->itemText.insertChars(currItem->CPos, ch);
04876                                    if (ch == SpecialChars::PARSEP) {
04877                                           currItem->itemText.applyStyle(currItem->CPos, doc->paragraphStyles()[cab]);
04878                                    }
04879                                    else {
04880                                           currItem->itemText.applyCharStyle(currItem->CPos, 1, nstyle);
04881                                    }
04882                                    currItem->CPos += 1;
04883                             }
04884 */
04885                      }
04886                      else if (hasXMLRootElem(Buffer2, "<SCRIBUSELEM") || hasXMLRootElem(Buffer2, "<SCRIBUSFRAGMENT"))
04887                      {
04888                             bool savedAlignGrid = doc->useRaster;
04889                             bool savedAlignGuides = doc->SnapGuides;
04890                             uint ac = doc->Items->count();
04891                             bool isGroup = false;
04892                             double gx, gy, gh, gw;
04893                             FPoint minSize = doc->minCanvasCoordinate;
04894                             FPoint maxSize = doc->maxCanvasCoordinate;
04895                             doc->useRaster = false;
04896                             doc->SnapGuides = false;
04897                             if (hasXMLRootElem(Buffer2, "<SCRIBUSELEM"))
04898                                    slotElemRead(Buffer2, 0, 0, false, true, doc, view);
04899                             else 
04900                                    Serializer(*doc).deserializeObjects(Buffer2.utf8());
04901 
04902                             // update style lists:
04903                             styleManager->setDoc(doc);
04904                             propertiesPalette->unsetDoc();
04905                             propertiesPalette->setDoc(doc);
04906                             
04907                             doc->useRaster = savedAlignGrid;
04908                             doc->SnapGuides = savedAlignGuides;
04909                             //int tempList=doc->m_Selection->backupToTempList(0);
04910                             Selection tempSelection(*doc->m_Selection);
04911                             doc->m_Selection->clear();
04912                             if (doc->Items->count() - ac > 1)
04913                                    isGroup = true;
04914                             for (uint as = ac; as < doc->Items->count(); ++as)
04915                             {
04916                                    doc->m_Selection->addItem(doc->Items->at(as));
04917                                    if (isGroup)
04918                                           doc->Items->at(as)->Groups.push(doc->GroupCounter);
04919                             }
04920                             if (isGroup)
04921                                    doc->GroupCounter++;
04922                             doc->m_Selection->setGroupRect();
04923                             doc->m_Selection->getGroupRect(&gx, &gy, &gw, &gh);
04924                             PageItem* currItem3 = doc->Items->at(ac);
04925                             for (uint as = ac; as < doc->Items->count(); ++as)
04926                             {
04927                                    PageItem* currItem2 = doc->Items->at(as);
04928                                    currItem2->isEmbedded = true;
04929                                    currItem2->setIsAnnotation(false);
04930                                    currItem2->isBookmark = false;
04931                                    currItem2->gXpos = currItem2->xPos() - gx;
04932                                    currItem2->gYpos = currItem2->yPos() - gy;
04933                                    currItem2->gWidth = gw;
04934                                    currItem2->gHeight = gh;
04935                                    currItem2->ItemNr = doc->FrameItems.count();
04936                                    doc->FrameItems.append(currItem2);
04937                             }
04938                             uint acc = doc->Items->count();
04939                             for (uint as = ac; as < acc; ++as)
04940                             {
04941                                    doc->Items->take(ac);
04942                             }
04943                             doc->m_Selection->clear();
04944                             //doc->m_Selection->restoreFromTempList(0, tempList);
04945                             *doc->m_Selection=tempSelection;
04946                             view->resizeContents(qRound((maxSize.x() - minSize.x()) * view->scale()), qRound((maxSize.y() - minSize.y()) * view->scale()));
04947                             view->scrollBy(qRound((doc->minCanvasCoordinate.x() - minSize.x()) * view->scale()), qRound((doc->minCanvasCoordinate.y() - minSize.y()) * view->scale()));
04948                             doc->minCanvasCoordinate = minSize;
04949                             doc->maxCanvasCoordinate = maxSize;
04950                             if (outlinePalette->isVisible())
04951                                    outlinePalette->BuildTree();
04952                             currItem->itemText.insertObject(currItem->CPos, currItem3);
04953                             currItem->CPos += 1;
04954                      }
04955                      else
04956                      {
04957                             // K.I.S.S.:
04958                             currItem->itemText.insertChars(currItem->CPos, Buffer2, true);
04959                      }
04960                      view->RefreshItem(currItem);
04961               }
04962               else
04963               {
04964                      if (hasXMLRootElem(Buffer2, "<SCRIBUSELEM") || hasXMLRootElem(Buffer2, "<SCRIBUSFRAGMENT"))
04965                      {
04966                             view->Deselect(true);
04967                             uint ac = doc->Items->count();
04968                             bool savedAlignGrid = doc->useRaster;
04969                             bool savedAlignGuides = doc->SnapGuides;
04970                             doc->useRaster = false;
04971                             doc->SnapGuides = false;
04972 //                          qDebug(Buffer2);
04973                             if (hasXMLRootElem(Buffer2, "<SCRIBUSELEM"))
04974                                    slotElemRead(Buffer2, doc->currentPage()->xOffset(), doc->currentPage()->yOffset(), false, true, doc, view);
04975                             else 
04976                             {
04977                                    Selection pastedObjects = Serializer(*doc).deserializeObjects(Buffer2.utf8());
04978                                    for (uint i=0; i < pastedObjects.count(); ++i)
04979                                           pastedObjects.itemAt(i)->LayerNr = doc->activeLayer();
04980                                    
04981                                    /*double x = doc->currentPage()->xOffset();
04982                                    double y = doc->currentPage()->yOffset();
04983                                    for (uint i=0; i < pastedObjects.count(); ++i)
04984                                           if (! pastedObjects.itemAt(i)->isEmbedded) 
04985                                           {
04986                                           //     const Page* pg = doc->Pages->at(doc->OnPage(pastedObjects.itemAt(i)));
04987                                           //     if (!pg)
04988                                           //            pg = doc->Pages->at(doc->Pages->count() - 1);
04989                                           //     if (pg)
04990                                           //            pastedObjects.itemAt(i)->moveBy(x - pg->xOffset(), y - pg->yOffset(), true);
04991                                                  qDebug(QString("move pasted: %1 %2,%3 + %4,%5").arg((ulong)pastedObjects.itemAt(i)).arg(x).arg(y).arg(pastedObjects.itemAt(i)->xPos()).arg(pastedObjects.itemAt(i)->yPos()));
04992                                                  pastedObjects.itemAt(i)->moveBy(x, y, true);
04993                                           }
04994                                    */
04995                             }
04996 
04997                             // update style lists:
04998                             styleManager->setDoc(doc);
04999                             propertiesPalette->unsetDoc();
05000                             propertiesPalette->setDoc(doc);
05001                                                         
05002                             doc->useRaster = savedAlignGrid;
05003                             doc->SnapGuides = savedAlignGuides;
05004                             for (uint as = ac; as < doc->Items->count(); ++as)
05005                             {
05006                                    PageItem* currItem = doc->Items->at(as);
05007                                    if (currItem->isBookmark)
05008                                           AddBookMark(currItem);
05009                                    doc->m_Selection->addItem(currItem);
05010                             }
05011                             int docSelectionCount=doc->m_Selection->count();
05012                             if (docSelectionCount > 1)
05013                             {
05014                                    doc->m_Selection->setGroupRect();
05015                                    view->paintGroupRect();
05016                                    double x, y, w, h;
05017                                    doc->m_Selection->getGroupRect(&x, &y, &w, &h);
05018                                    propertiesPalette->setXY(x, y);
05019                                    propertiesPalette->setBH(w, h);
05020                             }
05021                             if (docSelectionCount > 0)
05022                                    HaveNewSel(doc->m_Selection->itemAt(0)->itemType());
05023                      }
05024                      view->DrawNew();
05025               }
05026               if (UndoManager::undoEnabled())
05027                      undoManager->commit();
05028               slotDocCh(false);
05029        }
05030 }
05031 
05032 //CB-->Doc ?????
05033 void ScribusMainWindow::SelectAll()
05034 {
05035        if (doc->appMode == modeEdit)
05036        {
05037               PageItem *currItem = doc->m_Selection->itemAt(0);
05038               PageItem *nextItem = currItem;
05039               while (nextItem != 0)
05040               {
05041                      if (nextItem->prevInChain() != 0)
05042                             nextItem = nextItem->prevInChain();
05043                      else
05044                             break;
05045               }
05046               while (nextItem != 0)
05047               {
05048                      nextItem->itemText.selectAll();
05049                      nextItem->HasSel = true;
05050                      nextItem = nextItem->nextInChain();
05051               }
05052               view->DrawNew();
05053               EnableTxEdit();
05054        }
05055        else
05056        {
05057               PageItem *currItem;
05058               view->Deselect();
05059               uint docItemsCount=doc->Items->count();
05060               for (uint a = 0; a < docItemsCount; ++a)
05061               {
05062                      currItem = doc->Items->at(a);
05063                      if ((currItem->LayerNr == doc->activeLayer()) && (!doc->layerLocked(currItem->LayerNr)))
05064                      {
05065                             if (!currItem->isSelected())
05066                             {
05067                                    doc->m_Selection->addItem(currItem);
05068                                    currItem->FrameOnly = true;
05069                                    currItem->paintObj();
05070                             }
05071                      }
05072               }
05073               int docSelectionCount=doc->m_Selection->count();
05074               if (docSelectionCount > 1)
05075               {
05076                      doc->m_Selection->setGroupRect();
05077                      view->paintGroupRect();
05078                      double x, y, w, h;
05079                      doc->m_Selection->getGroupRect(&x, &y, &w, &h);
05080                      propertiesPalette->setXY(x, y);
05081                      propertiesPalette->setBH(w, h);
05082               }
05083               if (docSelectionCount > 0)
05084               {
05085                      currItem = doc->m_Selection->itemAt(0);
05086                      HaveNewSel(currItem->itemType());
05087               }
05088        }
05089 }
05090 
05091 void ScribusMainWindow::deselectAll()
05092 {
05093        if (view!=NULL)
05094               view->Deselect(true);
05095 }
05096 
05097 void ScribusMainWindow::ClipChange()
05098 {
05099        QString cc;
05100 #if QT_VERSION  >= 0x030100
05101 //     cc = ClipB->text(QClipboard::Selection);
05102 //     if (cc.isNull())
05103        cc = ClipB->text(QClipboard::Clipboard);
05104 #else
05105        cc = ClipB->text();
05106 #endif
05107 
05108        if (!cc.isNull())
05109        {
05110               if (!BuFromApp)
05111                      Buffer2 = cc;
05112               BuFromApp = false;
05113        }
05114        scrActions["editPaste"]->setEnabled(HaveDoc && 
05115                                                                       (hasXMLRootElem(Buffer2, "<SCRIBUSELEM") 
05116                                                                        || hasXMLRootElem(Buffer2, "<SCRIBUSFRAGMENT") 
05117                                                                        || doc->appMode == modeEdit));
05118 }
05119 
05120 void ScribusMainWindow::EnableTxEdit()
05121 {
05122        scrActions["editCut"]->setEnabled(true);
05123        scrActions["editCopy"]->setEnabled(true);
05124        //scrActions["editClearContents"]->setEnabled(true);
05125 }
05126 
05127 void ScribusMainWindow::DisableTxEdit()
05128 {
05129        scrActions["editCut"]->setEnabled(false);
05130        scrActions["editCopy"]->setEnabled(false);
05131        //scrActions["editClearContents"]->setEnabled(false);
05132 }
05133 
05134 void ScribusMainWindow::slotHelpAbout()
05135 {
05136        About* dia = new About(this);
05137        dia->exec();
05138        delete dia;
05139 }
05140 
05141 void ScribusMainWindow::slotHelpAboutPlugins()
05142 {
05143        AboutPlugins* dia = new AboutPlugins(this);
05144        dia->exec();
05145        delete dia;
05146 }
05147 
05148 void ScribusMainWindow::slotHelpAboutQt()
05149 {
05150        QMessageBox::aboutQt(this, tr("About Qt"));
05151 }
05152 
05153 void ScribusMainWindow::slotOnlineHelp()
05154 {
05155        HelpBrowser *dia = new HelpBrowser(0, tr("Scribus Manual"), ScCore->getGuiLanguage());
05156        dia->show();
05157 }
05158 
05159 void ScribusMainWindow::ToggleTips()
05160 {
05161        QToolTip::setGloballyEnabled(scrActions["helpTooltips"]->isOn());
05162        prefsManager->appPrefs.showToolTips = scrActions["helpTooltips"]->isOn();
05163 }
05164 
05165 void ScribusMainWindow::SaveText()
05166 {
05167        LoadEnc = "";
05168        QString wdir = ".";
05169        QString prefsDocDir=prefsManager->documentDir();
05170        if (!prefsDocDir.isEmpty())
05171               wdir = prefsManager->prefsFile->getContext("dirs")->get("save_text", prefsDocDir);
05172        else
05173               wdir = prefsManager->prefsFile->getContext("dirs")->get("save_text", ".");
05174        QString fn = CFileDialog( wdir, tr("Save as"), tr("Text Files (*.txt);;All Files(*)"), "", fdShowCodecs);
05175        if (!fn.isEmpty())
05176        {
05177               prefsManager->prefsFile->getContext("dirs")->set("save_text", fn.left(fn.findRev("/")));
05178               const StoryText& story (doc->m_Selection->itemAt(0)->itemText);
05179               Serializer::writeWithEncoding(fn, LoadEnc, story.text(0, story.length()));          
05180        }
05181 }
05182 
05183 void ScribusMainWindow::applyNewMaster(QString name)
05184 {
05185        Apply_MasterPage(name, doc->currentPage()->pageNr(), false);
05186        view->reformPages();
05187        view->DrawNew();
05188        pagePalette->Rebuild();
05189 }
05190 
05191 void ScribusMainWindow::slotNewPageP(int wo, QString templ)
05192 {
05193        NoFrameEdit();
05194        view->Deselect(true);
05195        slotNewPage(wo, templ); //master page is applied now
05196        //applyNewMaster(templ);
05197        doc->addPageToSection(wo, 1, 1);
05198        if (outlinePalette->isVisible())
05199               outlinePalette->BuildTree();
05200        pagePalette->RebuildPage();
05201 }
05202 
05204 void ScribusMainWindow::slotNewPageM()
05205 {
05206        NoFrameEdit();
05207        view->Deselect(true);
05208        QStringList base;
05209        InsPage *dia = new InsPage(this, doc, doc->currentPage()->pageNr(), doc->Pages->count());
05210        if (dia->exec())
05211        {
05212               base = dia->getMasterPages();
05213               addNewPages(dia->getWherePage(),
05214                           dia->getWhere(),
05215                           dia->getCount(),
05216                                    dia->heightMSpinBox->value() / doc->unitRatio(),
05217                                    dia->widthMSpinBox->value() / doc->unitRatio(),
05218                                    dia->orientationQComboBox->currentItem(),
05219                                    dia->prefsPageSizeName,
05220                                    dia->moveObjects->isChecked(),
05221                           &base
05222                           );
05223        }
05224        delete dia;
05225 }
05226 
05227 void ScribusMainWindow::addNewPages(int wo, int where, int numPages, double height, double width, int orient, QString siz, bool mov, QStringList* basedOn)
05228 {
05229        if (UndoManager::undoEnabled())
05230        {
05231               undoManager->beginTransaction(doc->getUName(), Um::IDocument, (numPages == 1) ? Um::AddPage : Um::AddPages, "", Um::ICreate);
05232               SimpleState *ss = new SimpleState(Um::AddPage, "", Um::ICreate);
05233               ss->set("ADD_PAGE", "add_page");
05234               ss->set("PAGE", wo);
05235               ss->set("WHERE", where);
05236               ss->set("COUNT", numPages);
05237               if (basedOn != NULL)
05238                      ss->set("BASED", basedOn->join("|"));
05239               else
05240               {
05241                      int setcol = doc->pageSets[doc->currentPageLayout].Columns;
05242                      if (setcol == 1)
05243                             ss->set("BASED", CommonStrings::trMasterPageNormal);
05244                      else if (setcol == 2)
05245                             ss->set("BASED", CommonStrings::trMasterPageNormalLeft+"|"+ CommonStrings::trMasterPageNormalRight);
05246                      else if ((setcol == 3) || (setcol == 4))
05247                             ss->set("BASED", CommonStrings::trMasterPageNormalLeft+"|"+ CommonStrings::trMasterPageNormalMiddle+"|"+ CommonStrings::trMasterPageNormalRight);
05248               }
05249               ss->set("HEIGHT", height);
05250               ss->set("WIDTH", width);
05251               ss->set("ORIENT", orient);
05252               ss->set("SIZE", siz);
05253               ss->set("MOVED", mov);
05254               undoManager->action(this, ss);
05255        }
05256        // disable recording of undo actions related to new page creating
05257        // and object moving related to that
05258        undoManager->setUndoEnabled(false);
05259 
05260        QStringList base;
05261        if (basedOn == NULL)
05262        {
05263               int setcol = doc->pageSets[doc->currentPageLayout].Columns;
05264               if (setcol == 1)
05265                      base.append( CommonStrings::trMasterPageNormal);
05266               else if (setcol == 2)
05267               {
05268                      base.append( CommonStrings::trMasterPageNormalLeft);
05269                      base.append( CommonStrings::trMasterPageNormalRight);
05270               }
05271               else if (setcol == 3)
05272               {
05273                      base.append( CommonStrings::trMasterPageNormalLeft);
05274                      base.append( CommonStrings::trMasterPageNormalMiddle);
05275                      base.append( CommonStrings::trMasterPageNormalRight);
05276               }
05277               else if (setcol == 4)
05278               {
05279                      base.append( CommonStrings::trMasterPageNormalLeft);
05280                      base.append( CommonStrings::trMasterPageNormalMiddle);
05281                      base.append( CommonStrings::trMasterPageNormalMiddle);
05282                      base.append( CommonStrings::trMasterPageNormalRight);
05283               }
05284        }
05285        else
05286               base = *basedOn;
05287        int cc;
05288        int wot = wo;
05289        if (where==0)
05290               --wot;
05291        else if (where==2)
05292               wot=doc->Pages->count();
05293        for (cc = 0; cc < numPages; ++cc)
05294        {
05295               slotNewPage(wot, base[(wot+doc->pageSets[doc->currentPageLayout].FirstPage) % doc->pageSets[doc->currentPageLayout].Columns], mov); //Avoid the master page application with QString::null
05296 //            slotNewPage(wot, QString::null, mov); //Avoid the master page application with QString::null
05297               doc->currentPage()->setInitialHeight(height);
05298               doc->currentPage()->setInitialWidth(width);
05299               doc->currentPage()->PageOri = orient;
05300               doc->currentPage()->m_pageSize = siz;
05301               //CB If we want to add this master page setting into the slotnewpage call, the pagenumber must be +1 I think
05302        //Apply_MasterPage(base[(doc->currentPage()->pageNr()+doc->pageSets[doc->currentPageLayout].FirstPage) % doc->pageSets[doc->currentPageLayout].Columns],
05303 //                                         doc->currentPage()->pageNr(), false); // this Apply_MasterPage avoids DreawNew and PagePalette->ReBuild, which is much faster for 100 pp :-)
05304               wot ++;
05305        }
05306        //Use wo, the dialog currently returns a page Index +1 due to old numbering scheme, function now does the -1 as required
05307        doc->addPageToSection(wo, where, numPages);
05308        pagePalette->RebuildPage();
05309        view->reformPages(mov);
05310        view->DrawNew();
05311        if (outlinePalette->isVisible())
05312               outlinePalette->BuildTree();
05313 
05314        undoManager->setUndoEnabled(true);
05315 
05316        if (UndoManager::undoEnabled())
05317               undoManager->commit();
05318 }
05319 
05320 void ScribusMainWindow::slotNewMasterPage(int w, const QString& name)
05321 {
05322        if (doc->masterPageMode())
05323        {
05324               doc->addMasterPage(w, name);
05325               view->addPage(w);
05326        }
05327 }
05328 
05329 void ScribusMainWindow::slotNewPage(int w, const QString& masterPageName, bool mov)
05330 {
05331        doc->addPage(w, masterPageName, true);
05332        view->addPage(w, mov);
05333 }
05334 
05335 
05336 void ScribusMainWindow::duplicateToMasterPage()
05337 {
05338        NewTm *dia = new NewTm(this, tr("Name:"), tr("Convert Page to Master Page"), doc, tr("New Master Page %1").arg(doc->MasterNames.count()));
05339        view->Deselect(true);
05340        if (dia->exec())
05341        {
05342               int diaLinksCurrItem=0;
05343               int diaLinksCount=0;
05344               if (doc->currentPageLayout != singlePage)
05345               {
05346                      diaLinksCurrItem=dia->Links->currentItem();
05347                      diaLinksCount=static_cast<int>(dia->Links->count());
05348               }
05349               QString masterPageName = dia->Answer->text();
05350               while (doc->MasterNames.contains(masterPageName) || (masterPageName == CommonStrings::masterPageNormal))
05351               {
05352                      if (!dia->exec())
05353                      {
05354                             delete dia;
05355                             return;
05356                      }
05357                      masterPageName = dia->Answer->text();
05358               }
05359               int currentPageNumber=doc->currentPage()->pageNr();
05360               bool ok=doc->copyPageToMasterPage(currentPageNumber, diaLinksCurrItem, diaLinksCount, masterPageName);
05361               Q_ASSERT(ok); //TODO get a return value in case the copy was not possible
05362               pagePalette->Rebuild();
05363        }
05364        delete dia;
05365 }
05366 
05367 void ScribusMainWindow::slotZoom(double zoomFactor)
05368 {
05369        double finalZoomFactor;
05370        //Zoom to Fit
05371        if (zoomFactor==-100.0)
05372        {
05373               double dx = (view->width()-50) / (doc->currentPage()->width()+30);
05374               double dy = (view->height()-70) / (doc->currentPage()->height()+30);
05375               finalZoomFactor = (dx > dy) ? dy : dx;
05376        }
05377        else if (zoomFactor==-200.0)
05378        {
05379               double dx = (view->width()-50) / (doc->currentPage()->width()+30);
05380               double dy = (view->height()-70) / (doc->currentPage()->height()+30);
05381               finalZoomFactor = (dx < dy) ? dy : dx;
05382        }
05383        //Zoom to %
05384        else
05385               finalZoomFactor = zoomFactor*prefsManager->displayScale()/100.0;
05386        if (finalZoomFactor == view->scale())
05387               return;
05388        int x = qRound(QMAX(view->contentsX() / view->scale(), 0));
05389        int y = qRound(QMAX(view->contentsY() / view->scale(), 0));
05390        int w = qRound(QMIN(view->visibleWidth() / view->scale(), doc->currentPage()->width()));
05391        int h = qRound(QMIN(view->visibleHeight() / view->scale(), doc->currentPage()->height()));
05392        if (zoomFactor==-200.0)
05393               view->rememberOldZoomLocation(qRound(doc->currentPage()->xOffset() + doc->currentPage()->width() / 2.0), qRound(doc->currentPage()->yOffset() + doc->currentPage()->height() / 2.0));
05394        else
05395               view->rememberOldZoomLocation(w / 2 + x,h / 2 + y);
05396        view->setScale(finalZoomFactor);
05397        view->slotDoZoom();
05398 }
05399 
05400 void ScribusMainWindow::ToggleStickyTools()
05401 {
05402        prefsManager->appPrefs.stickyTools = !prefsManager->appPrefs.stickyTools;
05403        scrActions["stickyTools"]->setOn(prefsManager->appPrefs.stickyTools);
05404 }
05405 
05406 void ScribusMainWindow::ToggleAllPalettes()
05407 {
05408        if (palettesStatus[0])
05409        {
05410               palettesStatus[0] = false;
05411               if (palettesStatus[1])
05412                      propertiesPalette->show();
05413               if (palettesStatus[2])
05414                      outlinePalette->show();
05415               if (palettesStatus[3])
05416                      scrapbookPalette->show();
05417               if (palettesStatus[4])
05418                      layerPalette->show();
05419               if (palettesStatus[5])
05420                      pagePalette->show();
05421               if (palettesStatus[6])
05422                      bookmarkPalette->show();
05423               if (palettesStatus[7])
05424                      measurementPalette->show();
05425               if (palettesStatus[9])
05426                      docCheckerPalette->show();
05427               setPagePalette(palettesStatus[5]);
05428               setUndoPalette(palettesStatus[8]);
05429        }
05430        else
05431        {
05432               palettesStatus[1] = propertiesPalette->isVisible();
05433               palettesStatus[2] = outlinePalette->isVisible();
05434               palettesStatus[3] = scrapbookPalette->isVisible();
05435               palettesStatus[4] = layerPalette->isVisible();
05436               palettesStatus[5] = pagePalette->isVisible();
05437               palettesStatus[6] = bookmarkPalette->isVisible();
05438               palettesStatus[7] = measurementPalette->isVisible();
05439               palettesStatus[8] = undoPalette->isVisible();
05440               palettesStatus[9] = docCheckerPalette->isVisible();
05441               propertiesPalette->hide();
05442               outlinePalette->hide();
05443               scrapbookPalette->hide();
05444               bookmarkPalette->hide();
05445               pagePalette->hide();
05446               layerPalette->hide();
05447               measurementPalette->hide();
05448               docCheckerPalette->hide();
05449               setPagePalette(false);
05450               setUndoPalette(false);
05451               palettesStatus[0] = true;
05452        }
05453 }
05454 
05455 void ScribusMainWindow::toggleCheckPal()
05456 {
05457        palettesStatus[0] = false;
05458 }
05459 
05460 void ScribusMainWindow::setUndoPalette(bool visible)
05461 {
05462        undoPalette->setPaletteShown(visible);
05463        scrActions["toolsActionHistory"]->setOn(visible);
05464 }
05465 /*
05466 void ScribusMainWindow::togglePropertiesPalette()
05467 {
05468        palettesStatus[0] = false;
05469 }
05470 
05471 void ScribusMainWindow::toggleOutlinePalette()
05472 {
05473        palettesStatus[0] = false;
05474 }
05475 
05476 void ScribusMainWindow::toggleScrapbookPalette()
05477 {
05478        palettesStatus[0] = false;
05479 }
05480 
05481 void ScribusMainWindow::toggleLayerPalette()
05482 {
05483        palettesStatus[0] = false;
05484 }
05485 */
05486 void ScribusMainWindow::setPagePalette(bool visible)
05487 {
05488        if (!visible)
05489        {
05490               prefsManager->appPrefs.SepalT = pagePalette->getThumb();
05491               prefsManager->appPrefs.SepalN = pagePalette->getNamen();
05492        }
05493 }
05494 
05495 void ScribusMainWindow::togglePagePalette()
05496 {
05497        setPagePalette(!pagePalette->isVisible());
05498        palettesStatus[0] = false;
05499 }
05500 /*
05501 void ScribusMainWindow::toggleBookmarkPalette()
05502 {
05503        palettesStatus[0] = false;
05504 }
05505 */
05506 
05507 void ScribusMainWindow::toggleUndoPalette()
05508 {
05509        setUndoPalette(!undoPalette->isVisible());
05510        palettesStatus[0] = false;
05511 }
05512 
05513 void ScribusMainWindow::TogglePics()
05514 {
05515        if(doc)
05516        {
05517               doc->guidesSettings.showPic = !doc->guidesSettings.showPic;
05518               for (uint b=0; b<doc->Items->count(); ++b)
05519               {
05520                      if (doc->Items->at(b)->asImageFrame())
05521                             doc->Items->at(b)->setImageShown(doc->guidesSettings.showPic);
05522               }
05523               view->DrawNew();
05524        }
05525 }
05526 
05527 void ScribusMainWindow::ToggleAllGuides()
05528 {
05529        if (!doc)
05530               return;
05531        keyrep=false;
05532        if (guidesStatus[0])
05533        {
05534               guidesStatus[0] = false;
05535               doc->guidesSettings.marginsShown = guidesStatus[1];
05536               doc->guidesSettings.framesShown = guidesStatus[2];
05537               doc->guidesSettings.gridShown = guidesStatus[3];
05538               doc->guidesSettings.guidesShown = guidesStatus[4];
05539               doc->guidesSettings.baseShown = guidesStatus[5];
05540               doc->guidesSettings.linkShown = guidesStatus[6];
05541               doc->guidesSettings.showControls = guidesStatus[7];
05542               doc->guidesSettings.rulerMode = guidesStatus[8];
05543               doc->guidesSettings.rulersShown = guidesStatus[9];
05544               doc->guidesSettings.colBordersShown = guidesStatus[10];
05545               doc->guidesSettings.layerMarkersShown = guidesStatus[11] ;
05546               doc->guidesSettings.showBleed = guidesStatus[12] ;
05547               ToggleMarks();
05548               ToggleFrames();
05549               ToggleLayerMarkers();
05550               ToggleRaster();
05551               ToggleGuides();
05552               ToggleColumnBorders();
05553               ToggleBase();
05554               ToggleTextLinks();
05555               ToggleTextControls();
05556               ToggleRulerMode();
05557               ToggleRulers();
05558               ToggleBleeds();
05559        }
05560        else
05561        {
05562               guidesStatus[0] = true;
05563               guidesStatus[1] = !doc->guidesSettings.marginsShown;
05564               guidesStatus[2] = !doc->guidesSettings.framesShown;
05565               guidesStatus[3] = !doc->guidesSettings.gridShown;
05566               guidesStatus[4] = !doc->guidesSettings.guidesShown;
05567               guidesStatus[5] = !doc->guidesSettings.baseShown;
05568               guidesStatus[6] = !doc->guidesSettings.linkShown;
05569               guidesStatus[7] = !doc->guidesSettings.showControls;
05570               guidesStatus[8] = !doc->guidesSettings.rulerMode;
05571               guidesStatus[9] = !doc->guidesSettings.rulersShown;
05572               guidesStatus[10] = !doc->guidesSettings.colBordersShown;
05573               guidesStatus[11] = !doc->guidesSettings.layerMarkersShown;
05574               guidesStatus[12] = !doc->guidesSettings.showBleed;
05575               doc->guidesSettings.marginsShown = false;
05576               doc->guidesSettings.framesShown = false;
05577               doc->guidesSettings.gridShown = false;
05578               doc->guidesSettings.guidesShown = false;
05579               doc->guidesSettings.baseShown = false;
05580               doc->guidesSettings.linkShown = false;
05581               doc->guidesSettings.showControls = false;
05582               doc->guidesSettings.rulerMode = false;
05583               doc->guidesSettings.rulersShown = false;
05584               doc->guidesSettings.colBordersShown = false;
05585               doc->guidesSettings.layerMarkersShown = false;
05586               doc->guidesSettings.showBleed = false;
05587               view->setRulersShown(doc->guidesSettings.rulersShown);
05588        }
05589        scrActions["viewShowMargins"]->setOn(doc->guidesSettings.marginsShown);
05590        scrActions["viewShowBleeds"]->setOn(doc->guidesSettings.showBleed);
05591        scrActions["viewShowFrames"]->setOn(doc->guidesSettings.framesShown);
05592        scrActions["viewShowLayerMarkers"]->setOn(doc->guidesSettings.layerMarkersShown);
05593        scrActions["viewShowGrid"]->setOn(doc->guidesSettings.gridShown);
05594        scrActions["viewShowGuides"]->setOn(doc->guidesSettings.guidesShown);
05595        scrActions["viewShowColumnBorders"]->setOn(doc->guidesSettings.colBordersShown);
05596        scrActions["viewShowBaseline"]->setOn(doc->guidesSettings.baseShown);
05597        scrActions["viewShowTextChain"]->setOn(doc->guidesSettings.linkShown);
05598        scrActions["viewShowTextControls"]->setOn(doc->guidesSettings.showControls);
05599        scrActions["viewShowRulers"]->setOn(doc->guidesSettings.rulersShown);
05600        scrActions["viewRulerMode"]->setOn(doc->guidesSettings.rulerMode);
05601        view->DrawNew();
05602 }
05603 
05604 void ScribusMainWindow::ToggleMarks()
05605 {
05606        if (doc)
05607        {
05608               guidesStatus[0] = false;
05609               doc->guidesSettings.marginsShown = !doc->guidesSettings.marginsShown;
05610               view->DrawNew();
05611        }
05612 }
05613 
05614 void ScribusMainWindow::ToggleBleeds()
05615 {
05616        if (doc)
05617        {
05618               guidesStatus[0] = false;
05619               doc->guidesSettings.showBleed = !doc->guidesSettings.showBleed;
05620               view->DrawNew();
05621        }
05622 }
05623 
05624 void ScribusMainWindow::ToggleFrames()
05625 {
05626        if (doc)
05627        {
05628               guidesStatus[0] = false;
05629               doc->guidesSettings.framesShown = !doc->guidesSettings.framesShown;
05630               view->DrawNew();
05631        }
05632 }
05633 
05634 void ScribusMainWindow::ToggleLayerMarkers()
05635 {
05636        if (doc)
05637        {
05638               guidesStatus[0] = false;
05639               doc->guidesSettings.layerMarkersShown = !doc->guidesSettings.layerMarkersShown;
05640               view->DrawNew();
05641        }
05642 }
05643 
05644 void ScribusMainWindow::ToggleRaster()
05645 {
05646        if (doc)
05647        {
05648               guidesStatus[0] = false;
05649               doc->guidesSettings.gridShown = !doc->guidesSettings.gridShown;
05650               view->DrawNew();
05651        }
05652 }
05653 
05654 void ScribusMainWindow::ToggleGuides()
05655 {
05656        if (doc)
05657        {
05658               guidesStatus[0] = false;
05659               doc->guidesSettings.guidesShown = !doc->guidesSettings.guidesShown;
05660               view->DrawNew();
05661        }
05662 }
05663 
05664 void ScribusMainWindow::ToggleColumnBorders()
05665 {
05666        if (doc)
05667        {
05668               guidesStatus[0] = false;
05669               doc->guidesSettings.colBordersShown = !doc->guidesSettings.colBordersShown;
05670               view->DrawNew();
05671        }
05672 }
05673 
05674 void ScribusMainWindow::ToggleBase()
05675 {
05676        if (doc)
05677        {
05678               guidesStatus[0] = false;
05679               doc->guidesSettings.baseShown = !doc->guidesSettings.baseShown;
05680               view->DrawNew();
05681        }
05682 }
05683 
05684 void ScribusMainWindow::ToggleTextLinks()
05685 {
05686        if (doc)
05687        {
05688               guidesStatus[0] = false;
05689               doc->guidesSettings.linkShown = !doc->guidesSettings.linkShown;
05690               view->DrawNew();
05691        }
05692 }
05693 
05694 void ScribusMainWindow::ToggleTextControls()
05695 {
05696        if (doc)
05697        {
05698               guidesStatus[0] = false;
05699               doc->guidesSettings.showControls = !doc->guidesSettings.showControls;
05700               view->DrawNew();
05701        }
05702 }
05703 
05704 void ScribusMainWindow::ToggleRulers()
05705 {
05706        if (doc)
05707        {
05708               guidesStatus[0] = false;
05709               doc->guidesSettings.rulersShown = !doc->guidesSettings.rulersShown;
05710               view->setRulersShown(doc->guidesSettings.rulersShown);
05711        }
05712 }
05713 
05714 void ScribusMainWindow::ToggleRulerMode()
05715 {
05716        if (doc)
05717        {
05718               guidesStatus[0] = false;
05719               doc->guidesSettings.rulerMode = !doc->guidesSettings.rulerMode;
05720               if (doc->guidesSettings.rulerMode)
05721               {
05722                      doc->rulerXoffset = 0;
05723                      doc->rulerYoffset = 0;
05724               }
05725               else
05726               {
05727                      doc->rulerXoffset += doc->currentPage()->xOffset();
05728                      doc->rulerYoffset += doc->currentPage()->yOffset();
05729               }
05730               if (doc->m_Selection->count()==1)
05731               {
05732                      PageItem* currItem=doc->m_Selection->itemAt(0);
05733                      if (currItem!=NULL)
05734                             currItem->emitAllToGUI();
05735               }
05736               //TODO emit from selection, handle group widths
05737               view->DrawNew();
05738        }
05739 }
05740 
05741 void ScribusMainWindow::ToggleURaster()
05742 {
05743        if (doc)
05744        {
05745               doc->useRaster = !doc->useRaster;
05746               slotDocCh();
05747        }
05748 }
05749 
05750 void ScribusMainWindow::ToggleUGuides()
05751 {
05752        if (doc)
05753        {
05754               doc->SnapGuides = !doc->SnapGuides;
05755               slotDocCh();
05756        }
05757 }
05758 
05759 void ScribusMainWindow::ToggleFrameEdit()
05760 {
05761        if (!doc)
05762               return;
05763        if (doc->EditClip)
05764        {
05765               NoFrameEdit();
05766        }
05767        else
05768        {
05769               //CB Enable/Disable undo in frame edit mode
05770 //            undoManager->setUndoEnabled(false);
05771               scrActions["editUndoAction"]->setEnabled(false);
05772               scrActions["editRedoAction"]->setEnabled(false);
05773               slotSelect();
05774               nodePalette->setDoc(doc, view);
05775               nodePalette->MoveN();
05776               nodePalette->HaveNode(false, false);
05777               nodePalette->MoveNode->setOn(true);
05778               nodePalette->show();
05779               connect(view, SIGNAL(HavePoint(bool, bool)), nodePalette, SLOT(HaveNode(bool, bool)));
05780               doc->EditClipMode = 0;
05781               doc->EditClip = true;
05782               scrActions["toolsSelect"]->setEnabled(false);
05783               scrActions["toolsRotate"]->setEnabled(false);
05784               scrActions["toolsEditContents"]->setEnabled(false);
05785               scrActions["toolsEditWithStoryEditor"]->setEnabled(false);
05786               scrActions["toolsZoom"]->setEnabled(false);
05787               scrActions["toolsInsertTextFrame"]->setEnabled(false);
05788               scrActions["toolsInsertImageFrame"]->setEnabled(false);
05789               scrActions["toolsInsertTableFrame"]->setEnabled(false);
05790               scrActions["toolsInsertShape"]->setEnabled(false);
05791               scrActions["toolsInsertLine"]->setEnabled(false);
05792               scrActions["toolsInsertBezier"]->setEnabled(false);
05793               scrActions["toolsInsertFreehandLine"]->setEnabled(false);
05794               scrActions["toolsInsertPolygon"]->setEnabled(false);
05795               scrActions["toolsLinkTextFrame"]->setEnabled(false);
05796               scrActions["toolsUnlinkTextFrame"]->setEnabled(false);
05797               scrActions["toolsMeasurements"]->setEnabled(false);
05798               scrActions["toolsCopyProperties"]->setEnabled(false);
05799               scrActions["toolsEyeDropper"]->setEnabled(false);
05800               scrActions["toolsPDFPushButton"]->setEnabled(false);
05801               scrActions["toolsPDFTextField"]->setEnabled(false);
05802               scrActions["toolsPDFCheckBox"]->setEnabled(false);
05803               scrActions["toolsPDFComboBox"]->setEnabled(false);
05804               scrActions["toolsPDFListBox"]->setEnabled(false);
05805               scrActions["toolsPDFAnnotText"]->setEnabled(false);
05806               scrActions["toolsPDFAnnotLink"]->setEnabled(false);
05807               scrActions["itemDelete"]->setEnabled(false);
05808               layerPalette->setEnabled(false);
05809               outlinePalette->setEnabled(false);
05810               guidePalette->setEnabled(false);
05811               scrapbookPalette->setEnabled(false);
05812               pagePalette->setEnabled(false);
05813               bookmarkPalette->setEnabled(false);
05814               docCheckerPalette->setEnabled(false);
05815               styleManager->setEnabled(false);
05816               alignDistributePalette->setEnabled(false);
05817               view->pageSelector->setEnabled(false);
05818               view->layerMenu->setEnabled(false);
05819               if (doc->m_Selection->count() != 0)
05820               {
05821                      PageItem *currItem = doc->m_Selection->itemAt(0);
05822                      view->MarkClip(currItem, currItem->PoLine, true);
05823                      nodePalette->EditCont->setEnabled(currItem->ContourLine.size() != 0);
05824                      nodePalette->ResetCont->setEnabled(false);
05825                      nodePalette->ResetContClip->setEnabled(false);
05826                      nodePalette->PolyStatus(currItem->itemType(), currItem->PoLine.size());
05827                      if ((currItem->asImageFrame()) && (currItem->imageClip.size() != 0))
05828                             nodePalette->ResetContClip->show();
05829                      else
05830                             nodePalette->ResetContClip->hide();
05831               }
05832        }
05833        scrActions["itemShapeEdit"]->setOn(doc->EditClip);
05834 }
05835 
05836 void ScribusMainWindow::NoFrameEdit()
05837 {
05838        disconnect(view, SIGNAL(HavePoint(bool, bool)), nodePalette, SLOT(HaveNode(bool, bool)));
05839        actionManager->disconnectModeActions();
05840        nodePalette->setDoc(0,0);
05841        nodePalette->hide();
05842        scrActions["toolsSelect"]->setEnabled(true);
05843        scrActions["toolsSelect"]->setOn(true);
05844        scrActions["toolsRotate"]->setEnabled(true);
05845        scrActions["toolsZoom"]->setEnabled(true);
05846        scrActions["toolsInsertTextFrame"]->setEnabled(true);
05847        scrActions["toolsInsertImageFrame"]->setEnabled(true);
05848        scrActions["toolsInsertTableFrame"]->setEnabled(true);
05849        scrActions["toolsInsertShape"]->setEnabled(true);
05850        scrActions["toolsInsertLine"]->setEnabled(true);
05851        scrActions["toolsInsertBezier"]->setEnabled(true);
05852        scrActions["toolsInsertFreehandLine"]->setEnabled(true);
05853        scrActions["toolsInsertPolygon"]->setEnabled(true);
05854        scrActions["toolsPDFPushButton"]->setEnabled(true);
05855        scrActions["toolsPDFTextField"]->setEnabled(true);
05856        scrActions["toolsPDFCheckBox"]->setEnabled(true);
05857        scrActions["toolsPDFComboBox"]->setEnabled(true);
05858        scrActions["toolsPDFListBox"]->setEnabled(true);
05859        scrActions["toolsPDFAnnotText"]->setEnabled(true);
05860        scrActions["toolsPDFAnnotLink"]->setEnabled(true);
05861        scrActions["toolsEditContents"]->setOn(false);
05862        scrActions["toolsEditWithStoryEditor"]->setOn(false);
05863        scrActions["toolsMeasurements"]->setEnabled(true);
05864        scrActions["toolsCopyProperties"]->setEnabled(true);
05865        scrActions["toolsEyeDropper"]->setEnabled(true);
05866        scrActions["toolsUnlinkTextFrame"]->setEnabled(true);
05867        scrActions["itemDelete"]->setEnabled(true);
05868        scrActions["itemShapeEdit"]->setOn(false);
05869        layerPalette->setEnabled(true);
05870        outlinePalette->setEnabled(true);
05871        guidePalette->setEnabled(true);
05872        scrapbookPalette->setEnabled(true);
05873        pagePalette->setEnabled(true);
05874        bookmarkPalette->setEnabled(true);
05875        docCheckerPalette->setEnabled(true);
05876        styleManager->setEnabled(true);
05877        alignDistributePalette->setEnabled(true);
05878        view->pageSelector->setEnabled(true);
05879        view->layerMenu->setEnabled(true);
05880 //     bool tmpClip = doc->EditClip; // for enabling undo if exiting shape edit mode
05881        if (HaveDoc)
05882        {
05883               doc->EditClip = false;
05884               view->EditContour = false;
05885               if (doc->m_Selection->count() != 0)
05886               {
05887                      HaveNewSel(doc->m_Selection->itemAt(0)->itemType());
05888                      view->DrawNew();
05889               }
05890               else
05891                      HaveNewSel(-1);
05892        }
05893        actionManager->connectModeActions();
05894 //     if (tmpClip)
05895 //            undoManager->setUndoEnabled(true);
05896 }
05897 
05898 void ScribusMainWindow::slotSelect()
05899 {
05900        setAppMode(modeNormal);
05901 }
05902 
05903 void ScribusMainWindow::setAppModeByToggle(bool isOn, int newMode)
05904 {
05905        keyrep=false;
05906        if (isOn)
05907               setAppMode(newMode);
05908        else
05909               setAppMode(modeNormal);
05910 }
05911 
05912 void ScribusMainWindow::setAppMode(int mode)
05913 {
05914        //disconnect the tools actions so we dont fire them off
05915        actionManager->disconnectModeActions();
05916        //set the actions state based on incoming mode
05917        scrActions["toolsSelect"]->setOn(mode==modeNormal);
05918        scrActions["toolsInsertTextFrame"]->setOn(mode==modeDrawText);
05919        scrActions["toolsInsertImageFrame"]->setOn(mode==modeDrawPicture);
05920        scrActions["toolsInsertTableFrame"]->setOn(mode==modeDrawTable);
05921        scrActions["toolsInsertShape"]->setOn(mode==modeDrawShapes);
05922        scrActions["toolsInsertPolygon"]->setOn(mode==modeDrawRegularPolygon);
05923        scrActions["toolsInsertLine"]->setOn(mode==modeDrawLine);
05924        scrActions["toolsInsertBezier"]->setOn(mode==modeDrawBezierLine);
05925        scrActions["toolsInsertFreehandLine"]->setOn(mode==modeDrawFreehandLine);
05926        scrActions["toolsRotate"]->setOn(mode==modeRotation);
05927        scrActions["toolsZoom"]->setOn(mode==modeMagnifier);
05928        scrActions["toolsEditContents"]->setOn(mode==modeEdit);
05929        scrActions["toolsEditWithStoryEditor"]->setOn(mode==modeStoryEditor);
05930        scrActions["toolsLinkTextFrame"]->setOn(mode==modeLinkFrames);
05931        scrActions["toolsUnlinkTextFrame"]->setOn(mode==modeUnlinkFrames);
05932        scrActions["toolsEyeDropper"]->setOn(mode==modeEyeDropper);
05933        scrActions["toolsCopyProperties"]->setOn(mode==modeCopyProperties);
05934        scrActions["toolsPDFPushButton"]->setOn(mode==modeInsertPDFButton);
05935        scrActions["toolsPDFTextField"]->setOn(mode==modeInsertPDFTextfield);
05936        scrActions["toolsPDFCheckBox"]->setOn(mode==modeInsertPDFCheckbox);
05937        scrActions["toolsPDFComboBox"]->setOn(mode==modeInsertPDFCombobox);
05938        scrActions["toolsPDFListBox"]->setOn(mode==modeInsertPDFListbox);
05939        scrActions["toolsPDFAnnotText"]->setOn(mode==modeInsertPDFTextAnnotation);
05940        scrActions["toolsPDFAnnotLink"]->setOn(mode==modeInsertPDFLinkAnnotation);
05941 
05942        if (HaveDoc)
05943        {
05944               PageItem *currItem=0;
05945               if (doc->m_Selection->count() != 0)
05946                      currItem = doc->m_Selection->itemAt(0);
05947               int oldMode = doc->appMode;
05948               doc->appMode = mode;
05949               if (oldMode == modeMeasurementTool)
05950                      disconnect(view, SIGNAL(MVals(double, double, double, double, double, double, int )), measurementPalette, SLOT(setValues(double, double, double, double, double, double, int )));
05951               if (mode != modeEdit && doc->CurTimer!=NULL)
05952               {
05953                      disconnect(doc->CurTimer, SIGNAL(timeout()), view, SLOT(blinkCursor()));
05954                      doc->CurTimer->stop();
05955                      delete doc->CurTimer;
05956                      doc->CurTimer = NULL;
05957               }
05958               if (mode!=modeEdit && oldMode==modeEdit)
05959                      actionManager->restoreActionShortcutsPostEditMode();
05960               else
05961               if (mode==modeEdit && oldMode!=modeEdit)
05962                      actionManager->saveActionShortcutsPreEditMode();
05963               if (oldMode == modeEdit)
05964               {
05965                      view->zoomSpinBox->setFocusPolicy(QWidget::ClickFocus);
05966                      view->pageSelector->focusPolicy(QWidget::ClickFocus);
05967                      scrActions["editClearContents"]->setEnabled(false);
05968                      charPalette->setEnabled(false, 0);
05969                      view->slotDoCurs(false);
05970                      if (currItem != 0)
05971                      {
05972                             view->RefreshItem(currItem);
05973                             scrMenuMgr->setMenuEnabled("Style", true);
05974                             scrMenuMgr->setMenuEnabled("Item", true);
05975                      }
05976                      view->horizRuler->ItemPosValid = false;
05977                      view->horizRuler->repaint();
05978               }
05979               if (mode == modeEdit)
05980               {
05981 //                   view->zoomSpinBox->setFocusPolicy(QWidget::NoFocus);
05982                      view->pageSelector->focusPolicy(QWidget::NoFocus);
05983                      if (currItem != 0)
05984                      {
05985                             if ((currItem->itemType() == PageItem::Polygon) || (currItem->itemType() == PageItem::PolyLine) || (currItem->itemType() == PageItem::PathText))
05986                             {
05987                                    doc->appMode = 1;
05988                                    ToggleFrameEdit();
05989                                    return;
05990                             }
05991                             setTBvals(currItem);
05992                             currItem->CPos = 0;
05993                      }
05994                      scrActions["editPaste"]->setEnabled(false);
05995                      charPalette->setEnabled(true, currItem);
05996                      if (currItem!=NULL && currItem->asTextFrame())
05997                             enableTextActions(&scrActions, true, currItem->currentCharStyle().font().scName());
05998                      if (!Buffer2.isNull())
05999                      {
06000 //                          if (!hasXMLRootElem(Buffer2, "<SCRIBUSELEM"))
06001 //                          {
06002                                    BuFromApp = false;
06003                                    scrActions["editPaste"]->setEnabled(true);
06004 //                          }
06005                      }
06006                      view->slotDoCurs(true);
06007                      scrMenuMgr->setMenuEnabled("Item", false);
06008                      scrMenuMgr->setMenuEnabled("Style", false);
06009                      doc->CurTimer = new QTimer(view);
06010                      if (doc->CurTimer!=NULL)
06011                      {
06012                             connect(doc->CurTimer, SIGNAL(timeout()), view, SLOT(blinkCursor()));
06013                             doc->CurTimer->start(500);
06014                      }
06015                      if (currItem != 0)
06016                      {
06017                             scrActions["editCut"]->setEnabled(currItem->HasSel);
06018                             scrActions["editCopy"]->setEnabled(currItem->HasSel);
06019                             scrActions["editClearContents"]->setEnabled(currItem->HasSel);
06020                             scrActions["editSearchReplace"]->setEnabled(true);
06021 
06022                             view->RefreshItem(currItem);
06023                      }
06024               }
06025               int docSelectionCount=doc->m_Selection->count();
06026               if (mode == modeDrawBezierLine)
06027               {
06028                      if (docSelectionCount != 0)
06029                             view->Deselect(true);
06030                      view->FirstPoly = true;
06031               }
06032               if (mode == modeEditGradientVectors)
06033                      propertiesPalette->setGradientEditMode(true);
06034               if (mode == modeMeasurementTool)
06035               {
06036                      measurementPalette->show();
06037                      connect(view, SIGNAL(MVals(double, double, double, double, double, double, int)), measurementPalette, SLOT(setValues(double, double, double, double, double, double, int )));
06038               }
06039               switch (mode)
06040               {
06041                      case modeDrawShapes:
06042                             if (docSelectionCount!=0)
06043                                    view->Deselect(true);
06044                             qApp->setOverrideCursor(QCursor(loadIcon("DrawFrame.xpm")), true);
06045                             break;
06046                      case modeDrawPicture:
06047                             if (docSelectionCount!=0)
06048                                    view->Deselect(true);
06049                             qApp->setOverrideCursor(QCursor(loadIcon("DrawImageFrame.xpm")), true);
06050                             break;
06051                      case modeDrawText:
06052                             if (docSelectionCount!=0)
06053                                    view->Deselect(true);
06054                             qApp->setOverrideCursor(QCursor(loadIcon("DrawTextFrame.xpm")), true);
06055                             break;
06056                      case modeDrawTable:
06057                             if (docSelectionCount!=0)
06058                                    view->Deselect(true);
06059                             qApp->setOverrideCursor(QCursor(loadIcon("DrawTable.xpm")), true);
06060                             break;
06061                      case modeDrawRegularPolygon:
06062                             if (docSelectionCount!=0)
06063                                    view->Deselect(true);
06064                             qApp->setOverrideCursor(QCursor(loadIcon("DrawPolylineFrame.xpm")), true);
06065                             break;
06066                      case modeMagnifier:
06067                             if (docSelectionCount!=0)
06068                                    view->Deselect(true);
06069                             qApp->setOverrideCursor(QCursor(loadIcon("LupeZ.xpm")), true);
06070                             break;
06071                      case modePanning:
06072                             qApp->setOverrideCursor(QCursor(loadIcon("HandC.xpm")), true);
06073                             break;
06074                      case modeDrawLine:
06075                      case modeDrawBezierLine:
06076                             qApp->setOverrideCursor(QCursor(crossCursor), true);
06077                             break;
06078                      case modeDrawFreehandLine:
06079                             qApp->setOverrideCursor(QCursor(loadIcon("DrawFreeLine.png"), 0, 32), true);
06080                             break;
06081                      case modeEyeDropper:
06082                             qApp->setOverrideCursor(QCursor(loadIcon("colorpickercursor.png"), 0, 32), true);
06083                             break;
06084                      case modeInsertPDFButton:
06085                      case modeInsertPDFTextfield:
06086                      case modeInsertPDFCheckbox:
06087                      case modeInsertPDFCombobox:
06088                      case modeInsertPDFListbox:
06089                      case modeInsertPDFTextAnnotation:
06090                      case modeInsertPDFLinkAnnotation:
06091                             if (docSelectionCount!=0)
06092                                    view->Deselect(true);
06093                             qApp->setOverrideCursor(QCursor(CrossCursor), true);
06094                             break;
06095                      case modeMeasurementTool:
06096                      case modeEditGradientVectors:
06097                             qApp->setOverrideCursor(QCursor(CrossCursor), true);
06098                             break;
06099                      default:
06100                             qApp->setOverrideCursor(QCursor(ArrowCursor), true);
06101                      break;
06102               }
06103               if (mode == modeDrawShapes)
06104               {
06105                      doc->SubMode = mainToolBar->SubMode;
06106                      doc->ShapeValues = mainToolBar->ShapeVals;
06107                      doc->ValCount = mainToolBar->ValCount;
06108                      propertiesPalette->SCustom->setPixmap(propertiesPalette->SCustom->getIconPixmap(doc->SubMode));
06109                      SCustom->setPixmap(SCustom->getIconPixmap(doc->SubMode));
06110               }
06111               else
06112                      doc->SubMode = -1;
06113               if (mode == modeNormal)
06114               {
06115                      propertiesPalette->setGradientEditMode(false);
06116               }
06117               if (mode == modeLinkFrames)
06118                      doc->ElemToLink = doc->m_Selection->itemAt(0);
06119               if ((mode == modeLinkFrames) || (mode == modeUnlinkFrames) || (oldMode == modeLinkFrames) || (oldMode == modeUnlinkFrames))
06120                      view->updateContents();
06121               if (mode == modeStoryEditor)
06122               {
06123                      slotStoryEditor();
06124                      slotSelect();
06125               }
06126               if (mode == modeEyeDropper)
06127                      grabMouse();
06128               else
06129                      releaseMouse();
06130               if (mode == modeCopyProperties)
06131               {
06132                      if (doc->m_Selection->count() != 0)
06133                      {
06134                             doc->ElemToLink = doc->m_Selection->itemAt(0);
06135                             view->Deselect(true);
06136                             scrActions["toolsCopyProperties"]->setEnabled(true);
06137                      }
06138               }
06139               if (mode != modeNormal && mode != modeStoryEditor)
06140                      setActiveWindow();
06141        }
06142        actionManager->connectModeActions();
06143 }
06144 
06145 void ScribusMainWindow::setMainWindowActive()
06146 {
06147        setActiveWindow();
06148        raise();
06149 }
06150 
06151 void ScribusMainWindow::setItemTypeStyle(int id)
06152 {
06153        int b = 0;
06154        if (id == 0)
06155        {
06156               scrActions["typeEffectNormal"]->setOn(true);
06157               scrActions["typeEffectUnderline"]->setOn(false);
06158               scrActions["typeEffectUnderlineWords"]->setOn(false);
06159               scrActions["typeEffectStrikeThrough"]->setOn(false);
06160               scrActions["typeEffectSmallCaps"]->setOn(false);
06161               scrActions["typeEffectAllCaps"]->setOn(false);
06162               scrActions["typeEffectSuperscript"]->setOn(false);
06163               scrActions["typeEffectSubscript"]->setOn(false);
06164               scrActions["typeEffectOutline"]->setOn(false);
06165               scrActions["typeEffectShadow"]->setOn(false);
06166        }
06167        else
06168        {
06169               scrActions["typeEffectNormal"]->setOn(false);
06170               if (id == 4)
06171                      scrActions["typeEffectSubscript"]->setOn(false);
06172               if (id == 5)
06173                      scrActions["typeEffectSuperscript"]->setOn(false);
06174               if (id == 3)
06175                      scrActions["typeEffectAllCaps"]->setOn(false);
06176               if (id == 7)
06177                      scrActions["typeEffectSmallCaps"]->setOn(false);
06178               if (id == 8)
06179                      scrActions["typeEffectUnderline"]->setOn(false);
06180               if (id == 1)
06181                      scrActions["typeEffectUnderlineWords"]->setOn(false);
06182               if (scrActions["typeEffectUnderline"]->isOn())
06183                      b |= 8;
06184               if (scrActions["typeEffectUnderlineWords"]->isOn())
06185                      b |= 512;
06186               if (scrActions["typeEffectShadow"]->isOn())
06187                      b |= 256;
06188               if (scrActions["typeEffectStrikeThrough"]->isOn())
06189                      b |= 16;
06190               if (scrActions["typeEffectAllCaps"]->isOn())
06191                      b |= 32;
06192               if (scrActions["typeEffectSmallCaps"]->isOn())
06193                      b |= 64;
06194               if (scrActions["typeEffectSuperscript"]->isOn())
06195                      b |= 1;
06196               if (scrActions["typeEffectSubscript"]->isOn())
06197                      b |= 2;
06198               if (scrActions["typeEffectOutline"]->isOn())
06199                      b |= 4;
06200        }
06201        setItemHoch(b);
06202 }
06203 
06204 void ScribusMainWindow::setStilvalue(int s)
06205 {
06206        int c = s & 1919;
06207 //     doc->currentStyle.charStyle().setFeatures(static_cast<StyleFlag>(c).featureList());
06208        scrActions["typeEffectNormal"]->setOn(c==0);
06209        scrActions["typeEffectSuperscript"]->setOn(c & 1);
06210        scrActions["typeEffectSubscript"]->setOn(c & 2);
06211        scrActions["typeEffectOutline"]->setOn(c & 4);
06212        scrActions["typeEffectUnderline"]->setOn(c & 8);
06213        scrActions["typeEffectStrikeThrough"]->setOn(c & 16);
06214        scrActions["typeEffectAllCaps"]->setOn(c & 32);
06215        scrActions["typeEffectSmallCaps"]->setOn(c & 64);
06216        scrActions["typeEffectShadow"]->setOn(c & 256);
06217        scrActions["typeEffectUnderlineWords"]->setOn(c & 512);
06218        emit TextStil(s);
06219 }
06220 
06221 void ScribusMainWindow::setItemHoch(int h)
06222 {
06223        if (doc->m_Selection->count() != 0)
06224        {
06225 //            doc->currentStyle.charStyle().setFeatures(static_cast<StyleFlag>(h).featureList());
06226               setStilvalue(h);
06227               doc->itemSelection_SetEffects(h);
06228        }
06229 }
06230 
06231 //CB-->Doc partly
06232 void ScribusMainWindow::DeletePage2(int pg)
06233 {
06234        PageItem* ite;
06235        NoFrameEdit();
06236        if (doc->Pages->count() == 1)
06237               return;
06238        uint oldPg = doc->currentPageNumber();
06239        guidePalette->setDoc(NULL);
06240        if (UndoManager::undoEnabled())
06241               undoManager->beginTransaction(doc->DocName, Um::IDocument, Um::DeletePage, "", Um::IDelete);
06242 /*     if (!doc->masterPageMode)
06243               disconnect(doc->currentPage, SIGNAL(DelObj(uint, uint)), outlinePalette, SLOT(slotRemoveElement(uint, uint))); */
06244        doc->m_Selection->clear();
06245        for (uint d = 0; d < doc->Items->count(); ++d)
06246        {
06247               ite = doc->Items->at(d);
06248               if (ite->OwnPage == pg)
06249               {
06250                      ite->setLocked(false);
06251                      ite->isSingleSel = false;
06252                      if (ite->isBookmark)
06253                             DelBookMark(ite);
06254                      ite->isBookmark = false;
06255                      doc->m_Selection->addItem(ite);
06256               }
06257        }
06258        if (doc->m_Selection->count() != 0)
06259               doc->itemSelection_DeleteItem();
06260        Page *page = doc->Pages->at(pg); // need to remove guides too to get their undo/redo actions working
06261        page->guides.clearHorizontals(GuideManagerCore::Standard);
06262        page->guides.clearHorizontals(GuideManagerCore::Auto);
06263        page->guides.clearVerticals(GuideManagerCore::Standard);
06264        page->guides.clearVerticals(GuideManagerCore::Auto);
06265        if (UndoManager::undoEnabled())
06266        {
06267               SimpleState *ss = new SimpleState(Um::DeletePage, "", Um::ICreate);
06268               ss->set("DELETE_PAGE", "delete_page");
06269               ss->set("PAGENR", pg + 1);
06270               ss->set("MASTERPAGE", doc->Pages->at(pg)->MPageNam);
06271               // replace the deleted page in the undostack by a dummy object that will
06272               // replaced with the "undone" page if user choose to undo the action
06273               DummyUndoObject *duo = new DummyUndoObject();
06274               uint id = static_cast<uint>(duo->getUId());
06275               undoManager->replaceObject(doc->Pages->at(pg)->getUId(), duo);
06276               ss->set("DUMMY_ID", id);
06277               undoManager->action(this, ss);
06278        }
06279        if (doc->masterPageMode())
06280               doc->deleteMasterPage(pg);
06281        else
06282               doc->deletePage(pg);
06283        disconnect(view->pageSelector, SIGNAL(GotoPage(int)), view, SLOT(GotoPa(int)));
06284        view->pageSelector->setMaxValue(doc->Pages->count());
06285        view->pageSelector->GotoPg(0);
06286        connect(view->pageSelector, SIGNAL(GotoPage(int)), view, SLOT(GotoPa(int)));
06287        undoManager->setUndoEnabled(false); // ugly hack to prevent object moving when undoing page deletion
06288        view->reformPages();
06289        undoManager->setUndoEnabled(true); // ugly hack continues
06290        view->GotoPage(QMIN(doc->Pages->count()-1, oldPg));
06291        view->DrawNew();
06292        if (outlinePalette->isVisible())
06293               outlinePalette->BuildTree();
06294        //CB done by doc::reformpages
06295        //slotDocCh();
06296        pagePalette->RebuildPage();
06297        if (UndoManager::undoEnabled())
06298               undoManager->commit();
06299 }
06300 
06301 void ScribusMainWindow::DeletePage()
06302 {
06303        NoFrameEdit();
06304        view->Deselect(true);
06305        DelPages *dia = new DelPages(this, doc->currentPage()->pageNr()+1, doc->Pages->count());
06306        if (dia->exec())
06307               DeletePage(dia->getFromPage(), dia->getToPage());
06308        delete dia;
06309 }
06310 
06311 void ScribusMainWindow::DeletePage(int from, int to)
06312 {
06313        assert( from > 0 );
06314        assert( from <= to );
06315        assert( to <= signed(doc->Pages->count()) );
06316        uint oldPg = doc->currentPageNumber();
06317        guidePalette->setDoc(NULL);
06318        if (UndoManager::undoEnabled())
06319               undoManager->beginTransaction(doc->DocName, Um::IDocument,
06320                                                                  (from - to == 0) ? Um::DeletePage : Um::DeletePages, "",
06321                                                                  Um::IDelete);
06322        PageItem* ite;
06323        doc->m_Selection->clear();
06324        for (int a = to - 1; a >= from - 1; a--)
06325        {
06326               for (uint d = 0; d < doc->Items->count(); ++d)
06327               {
06328                      ite = doc->Items->at(d);
06329                      if (ite->OwnPage == a)
06330                      {
06331                             ite->setLocked(false);
06332                             ite->isSingleSel = false;
06333                             if (ite->isBookmark)
06334                                    DelBookMark(ite);
06335                             ite->isBookmark = false;
06336                             doc->m_Selection->addItem(ite);
06337                      }
06338               }
06339               Page *page = doc->Pages->at(a); // need to remove guides too to get their undo/redo actions working
06340               page->guides.clearHorizontals(GuideManagerCore::Standard);
06341               page->guides.clearHorizontals(GuideManagerCore::Auto);
06342               page->guides.clearVerticals(GuideManagerCore::Standard);
06343               page->guides.clearVerticals(GuideManagerCore::Auto);
06344        }
06345        if (doc->m_Selection->count() != 0)
06346               doc->itemSelection_DeleteItem();
06347        for (int a = to - 1; a >= from - 1; a--)
06348        {
06349               if (UndoManager::undoEnabled())
06350               {
06351                      SimpleState *ss = new SimpleState(Um::DeletePage, "", Um::ICreate);
06352                      ss->set("DELETE_PAGE", "delete_page");
06353                      ss->set("PAGENR", a + 1);
06354                      ss->set("MASTERPAGE", doc->Pages->at(a)->MPageNam);
06355                      // replace the deleted page in the undostack by a dummy object that will
06356                      // replaced with the "undone" page if user choose to undo the action
06357                      DummyUndoObject *duo = new DummyUndoObject();
06358                      uint id = static_cast<uint>(duo->getUId());
06359                      undoManager->replaceObject(doc->Pages->at(a)->getUId(), duo);
06360                      ss->set("DUMMY_ID", id);
06361                      undoManager->action(this, ss);
06362               }
06363               if (doc->masterPageMode())
06364                      doc->deleteMasterPage(a);
06365               else
06366                      doc->deletePage(a);
06367               disconnect(view->pageSelector, SIGNAL(GotoPage(int)), view, SLOT(GotoPa(int)));
06368               view->pageSelector->setMaxValue(doc->Pages->count());
06369               view->pageSelector->GotoPg(0);
06370               connect(view->pageSelector, SIGNAL(GotoPage(int)), view, SLOT(GotoPa(int)));
06371               doc->removePageFromSection(a);
06372        }
06373        undoManager->setUndoEnabled(false); // ugly hack to disable object moving when undoing page deletion
06374        view->reformPages();
06375        undoManager->setUndoEnabled(true); // ugly hack continues
06376        view->GotoPage(QMIN(doc->Pages->count()-1, oldPg));
06377        view->DrawNew();
06378        if (outlinePalette->isVisible())
06379               outlinePalette->BuildTree();
06380        pagePalette->RebuildPage();
06381        if (UndoManager::undoEnabled())
06382               undoManager->commit();
06383 }
06384 
06385 void ScribusMainWindow::MovePage()
06386 {
06387        NoFrameEdit();
06388        MovePages *dia = new MovePages(this, doc->currentPage()->pageNr()+1, doc->Pages->count(), true);
06389        if (dia->exec())
06390        {
06391               int from = dia->getFromPage();
06392               int to = dia->getToPage();
06393               int wie = dia->getWhere();
06394               int wo = dia->getWherePage();
06395               if (from != wo || (wie == 2 && to != signed(doc->Pages->count()) ) )
06396               {
06397                      doc->movePage(from-1, to, wo-1, wie);
06398                      view->reformPages();
06399                      view->DrawNew();
06400                      pagePalette->RebuildPage();
06401                      if (outlinePalette->isVisible())
06402                             outlinePalette->BuildTree();
06403               }
06404        }
06405        delete dia;
06406 }
06407 
06408 void ScribusMainWindow::CopyPage()
06409 {
06410        NoFrameEdit();
06411        MovePages *dia = new MovePages(this, doc->currentPage()->pageNr()+1, doc->Pages->count(), false);
06412        if (dia->exec())
06413        {
06414               int pageNumberToCopy=dia->getFromPage()-1;
06415               int whereToInsert=dia->getWhere();
06416               int copyCount=dia->getCopyCount();
06417               int wo = dia->getWherePage();
06418               doc->copyPage(pageNumberToCopy, wo, whereToInsert, copyCount);
06419               view->Deselect(true);
06420               view->DrawNew();
06421               pagePalette->RebuildPage();
06422               if (outlinePalette->isVisible())
06423                      outlinePalette->BuildTree();
06424        }
06425        delete dia;
06426 }
06427 
06428 void ScribusMainWindow::changePageMargins()
06429 {
06430        NoFrameEdit();
06431        QString Nam = doc->currentPage()->MPageNam;
06432        MarginDialog *dia = new MarginDialog(this, doc);
06433        if (dia->exec())
06434        {
06435               int orientation = dia->getPageOrientation();
06436               double ph = dia->getPageHeight();
06437               double pw = dia->getPageWidth();
06438               QString sizeName = dia->getpPrefsPageSizeName();
06439               if (doc->masterPageMode())
06440               {
06441                      int lp=0;
06442                      if (doc->currentPageLayout != singlePage)
06443                             lp = dia->pageOrder();
06444                      doc->changePageMargins(dia->top(), dia->bottom(),
06445                                                            dia->left(), dia->right(),
06446                                                            ph, pw, ph, pw, orientation,
06447                                                            sizeName, doc->currentPage()->pageNr(), lp);
06448               }
06449               else
06450               {
06451                      doc->changePageMargins(dia->top(), dia->bottom(),
06452                                                            dia->left(), dia->right(),
06453                                                            ph, pw, ph, pw, orientation,
06454                                                            sizeName, doc->currentPage()->pageNr());
06455                      if (dia->masterPage() != Nam)
06456                             Apply_MasterPage(dia->masterPage(), doc->currentPage()->pageNr());
06457               }
06458               view->reformPages(dia->getMoveObjects());
06459               view->DrawNew();
06460        }
06461        delete dia;
06462 }
06463 
06464 void ScribusMainWindow::setItemFont2(int id)
06465 {
06466        disconnect(FontMenu, SIGNAL(activated(int)), this, SLOT(setItemFont(int)));
06467        SetNewFont(FontSub->text(id));
06468        FontMenu->activateItemAt(0);
06469        connect(FontMenu, SIGNAL(activated(int)), this, SLOT(setItemFont(int)));
06470 }
06471 
06472 void ScribusMainWindow::setItemFont(int id)
06473 {
06474        QString nf;
06475        int a = FontMenu->indexOf(id);
06476        if (a == 1)
06477               return;
06478        disconnect(FontMenu, SIGNAL(activated(int)), this, SLOT(setItemFont(int)));
06479        nf = FontID[id];
06480        SetNewFont(nf);
06481        connect(FontMenu, SIGNAL(activated(int)), this, SLOT(setItemFont(int)));
06482 }
06483 
06484 void ScribusMainWindow::SetNewFont(const QString& nf)
06485 {
06486        setMainWindowActive();
06487        QString nf2(nf);
06488        if (!doc->UsedFonts.contains(nf))
06489        {
06490               if (doc->AddFont(nf)) //, prefsManager->appPrefs.AvailFonts[nf]->Font))
06491               {
06492                      int a = FontMenu->insertItem(new FmItem(nf, prefsManager->appPrefs.AvailFonts[nf]));
06493                      FontID.insert(a, prefsManager->appPrefs.AvailFonts[nf].scName());
06494               }
06495               else
06496               {//CB FIXME: to doc?
06497                      if (doc->m_Selection->count() != 0)
06498                      {
06499                             PageItem *currItem = doc->m_Selection->itemAt(0);
06500                             nf2 = currItem->currentCharStyle().font().scName();
06501                      }
06502 //                   propertiesPalette->Fonts->RebuildList(doc);
06503                      buildFontMenu();
06504               }
06505        }
06506        AdjustFontMenu(nf2);
06507        doc->itemSelection_SetFont(nf2);
06508 //     doc->currentStyle.charStyle().setFont((*doc->AllFonts)[nf2]);
06509        view->DrawNew();
06510        slotDocCh();
06511 }
06512 
06513 void ScribusMainWindow::AdjustFontMenu(const QString& nf)
06514 {
06515        currentFontForFontMenu=nf;
06516 /*
06517        QString df;
06518        if (doc->m_Selection->count() != 0)
06519        {
06520               PageItem *currItem = doc->m_Selection->itemAt(0);
06521               FontSub->RebuildList(doc, currItem->isAnnotation());
06522        }
06523        FontSub->setCurrentText(nf);
06524        //propertiesPalette->Fonts->setCurrentFont(nf);
06525        for (uint a = 2; a < FontMenu->count(); ++a)
06526        {
06527               df = FontID[FontMenu->idAt(a)];
06528               FontMenu->setItemChecked(FontMenu->idAt(a), (df == nf));
06529        }
06530 */
06531 }
06532 
06533 void ScribusMainWindow::setItemFSize(int id)
06534 {
06535        int c = id;
06536        if (c != -1)
06537               doc->itemSelection_SetFontSize(c*10);
06538        else
06539        {
06540               bool ok = false;
06541               Query* dia = new Query(this, "New", 1, 0, tr("&Size:"), tr("Size"));
06542               if (dia->exec())
06543               {
06544                      c = qRound(dia->getEditText().toDouble(&ok));
06545                      if ((ok) && (c < 1025) && (c > 0))
06546                             doc->itemSelection_SetFontSize(c*10);
06547               }
06548               delete dia;
06549        }
06550        propertiesPalette->setSize(c*10);
06551        slotDocCh();
06552 }
06553 
06554 void ScribusMainWindow::setFSizeMenu(int size)
06555 {
06556        if (scrActions[QString("fontSize%1").arg(size/10)])
06557               scrActions[QString("fontSize%1").arg(size/10)]->setOn(true);
06558 }
06559 
06560 //CB-->Doc
06561 void ScribusMainWindow::setItemFarbe(int id)
06562 {
06563        if (doc->m_Selection->count() != 0)
06564        {
06565               PageItem *currItem = doc->m_Selection->itemAt(0);
06566               if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText))
06567                      doc->itemSelection_SetFillColor(ColorMenC->text(id));
06568               else
06569                      doc->ItemBrush(ColorMenC->text(id));
06570        }
06571        scrMenuMgr->getLocalPopupMenu("Color")->activateItemAt(0);
06572        slotDocCh();
06573 }
06574 
06575 //CB-->Doc partly
06576 void ScribusMainWindow::setItemShade(int id)
06577 {
06578        int c = id;
06579        bool ok = false;
06580        if (doc->m_Selection->count() != 0)
06581        {
06582               PageItem *currItem = doc->m_Selection->itemAt(0);
06583               if (c != -1)
06584               {
06585                      if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText))
06586                             doc->itemSelection_SetFillShade(c);
06587                      else
06588                             doc->ItemBrushShade(c);
06589               }
06590               else
06591               {
06592                      Query* dia = new Query(this, "New", 1, 0, tr("&Shade:"), tr("Shade"));
06593                      if (dia->exec())
06594                      {
06595                             c = dia->getEditText().toInt(&ok);
06596                             if (ok)
06597                             {
06598                                    if ((currItem->itemType() == PageItem::TextFrame) || (currItem->itemType() == PageItem::PathText))
06599                                           doc->itemSelection_SetFillShade(c);
06600                                    else
06601                                           doc->ItemBrushShade(c);
06602                             }
06603                      }
06604                      delete dia;
06605               }
06606        }
06607        slotDocCh();
06608 }
06609 
06610 void ScribusMainWindow::setCSMenu()
06611 {
06612        QString la = CommonStrings::tr_NoneColor;
06613        int lb = 100;
06614        PageItem *currItem;
06615        if (doc->m_Selection->count() != 0)
06616        {
06617               currItem = doc->m_Selection->itemAt(0);
06618               if ((currItem->asTextFrame()) || (currItem->asPathText()))
06619               {
06620                      if ((doc->appMode == modeEdit) && (currItem->itemText.length() != 0))
06621                      {
06622                             la = currItem->itemText.charStyle(QMIN(currItem->CPos, static_cast<int>(currItem->itemText.length()-1))).fillColor();
06623                             lb = currItem->itemText.charStyle(QMIN(currItem->CPos, static_cast<int>(currItem->itemText.length()-1))).fillShade();
06624                      }
06625                      else
06626                      {
06627                             la = currItem->itemText.defaultStyle().charStyle().fillColor();
06628                             lb = currItem->itemText.defaultStyle().charStyle().fillShade();
06629                      }
06630               }
06631               else
06632               {
06633                      la = currItem->fillColor();
06634                      lb = currItem->fillShade();
06635               }
06636        }
06637        if (la == CommonStrings::None)
06638               la = CommonStrings::tr_NoneColor;
06639        for (uint a = 0; a < static_cast<uint>(ColorMenC->count()); ++a)
06640        {
06641               if (ColorMenC->text(a) == la)
06642                      ColorMenC->setCurrentItem(a);
06643        }
06644        if (scrActions[QString("shade%1").arg(lb)])
06645               scrActions[QString("shade%1").arg(lb)]->setOn(true);
06646 }
06647 
06648 
06649 //CB still called from SE
06650 void ScribusMainWindow::saveStyles(StilFormate *dia)
06651 {
06652        QValueList<uint> ers;
06653        QString nn;
06654 //     PageItem* ite = 0;
06655        bool ff;
06656        uint nr;
06657        ers.clear();
06658        /*FIXME:NLS
06659        ers.append(0);
06660        ers.append(1);
06661        ers.append(2);
06662        ers.append(3);
06663        ers.append(4);
06664        for (uint a=5; a<doc->docParagraphStyles.count(); ++a)
06665 */
06666        for (uint a=0; a<doc->paragraphStyles().count(); ++a)
06667        {
06668               ff = false;
06669               nn = doc->paragraphStyles()[a].name();
06670               for (uint b=0; b<dia->TempVorl.count(); ++b)
06671               {
06672                      if (nn == dia->TempVorl[b].name())
06673                      {
06674                             nr = b;
06675                             ff = true;
06676                             break;
06677                      }
06678               }
06679               if (ff)
06680                      ers.append(nr);
06681               else
06682               {
06683                      for (uint b=0; b<dia->TempVorl.count(); ++b)
06684                      {
06685                             if (doc->paragraphStyles()[a].equiv(dia->TempVorl[b]))
06686                             {
06687                                    nr = b;
06688                                    ff = true;
06689                                    break;
06690                             }
06691                      }
06692                      if (ff)
06693                             ers.append(nr);
06694                      else
06695                      {
06696                             if (dia->ReplaceList.count() != 0)
06697                             {
06698                                    QString ne = dia->ReplaceList[nn];
06699                                    if (ne == tr("No Style"))
06700                                           ers.append(0);
06701                                    else
06702                                    {
06703                                           for (uint b=0; b<dia->TempVorl.count(); ++b)
06704                                           {
06705                                                  if (ne == dia->TempVorl[b].name())
06706                                                  {
06707                                                         nr = b;
06708                                                         ff = true;
06709                                                         break;
06710                                                  }
06711                                           }
06712                                           if (ff)
06713                                                  ers.append(nr);
06714                                           else
06715                                                  ers.append(0);
06716                                    }
06717                             }
06718                             else
06719                                    ers.append(0);
06720                      }
06721               }
06722        }
06723 //     uint counter = 0;
06724 /*
06725        for (uint lc = 0; lc < 3; ++lc)
06726        {
06727               switch (lc)
06728               {
06729                      case 0:
06730                             counter = doc->MasterItems.count();
06731                             break;
06732                      case 1:
06733                             counter = doc->DocItems.count();
06734                             break;
06735                      case 2:
06736                             counter = doc->FrameItems.count();
06737                             break;
06738               }
06739               for (uint d=0; d< counter; ++d)
06740               {
06741                      switch (lc)
06742                      {
06743                             case 0:
06744                                    ite = doc->MasterItems.at(d);
06745                                    break;
06746                             case 1:
06747                                    ite = doc->DocItems.at(d);
06748                                    break;
06749                             case 2:
06750                                    ite = doc->FrameItems.at(d);
06751                                    break;
06752                      }
06753                      if (ite->asTextFrame())
06754                      {
06755                             CharStyle lastStyle;
06756                             int lastStyleStart = 0;
06757                             int lastParaStyle = -1;
06758                             for (int e=0; e<ite->itemText.length(); ++e)
06759                             {
06760                                    const ParagraphStyle origStyle(ite->itemText.paragraphStyle(e));
06761                                    int cabori = findParagraphStyle(doc, origStyle);
06762                                    assert (cabori >= 0 && cabori < doc->docParagraphStyles.count() );
06763                                    int cabneu = ers[cabori];
06764                                    assert (cabneu >= 0 && cabneu < dia->TempVorl.count() );
06765                                    CharStyle newStyle;
06766                                    if (cabori > 4)
06767                                    {
06768                                           if (cabneu > 0)
06769                                           {
06770                                                  if (ite->itemText.charStyle(e).font() == doc->docParagraphStyles[cabori].charStyle().font())
06771                                                         newStyle.setFont(dia->TempVorl[cabneu].charStyle().font());
06772                                                  if (ite->itemText.charStyle(e).fontSize() == doc->docParagraphStyles[cabori].charStyle().fontSize())
06773                                                         newStyle.setFontSize(dia->TempVorl[cabneu].charStyle().fontSize());
06774                                                  if ((ite->itemText.charStyle(e).effects() & 1919 ) == doc->docParagraphStyles[cabori].charStyle().effects())
06775                                                  {
06776                                                         StyleFlag fl = static_cast<StyleFlag>(ite->itemText.charStyle(e).effects() & ~1919);
06777                                                         fl |= dia->TempVorl[cabneu].charStyle().effects();
06778                                                         newStyle.setEffects(fl);
06779                                                  }
06780                                                  if (ite->itemText.charStyle(e).fillColor() == doc->docParagraphStyles[cabori].charStyle().fillColor())
06781                                                         newStyle.setFillColor(dia->TempVorl[cabneu].charStyle().fillColor());
06782                                                  if (ite->itemText.charStyle(e).fillShade() == doc->docParagraphStyles[cabori].charStyle().fillShade())
06783                                                         newStyle.setFillShade(dia->TempVorl[cabneu].charStyle().fillShade());
06784                                                  if (ite->itemText.charStyle(e).strokeColor() == doc->docParagraphStyles[cabori].charStyle().strokeColor())
06785                                                         newStyle.setStrokeColor(dia->TempVorl[cabneu].charStyle().strokeColor());
06786                                                  if (ite->itemText.charStyle(e).strokeShade() == doc->docParagraphStyles[cabori].charStyle().strokeShade())
06787                                                         newStyle.setStrokeShade(dia->TempVorl[cabneu].charStyle().strokeShade());
06788                                                  if (ite->itemText.charStyle(e).shadowXOffset() == doc->docParagraphStyles[cabori].charStyle().shadowXOffset())
06789                                                         newStyle.setShadowXOffset(dia->TempVorl[cabneu].charStyle().shadowXOffset());
06790                                                  if (ite->itemText.charStyle(e).shadowYOffset() == doc->docParagraphStyles[cabori].charStyle().shadowYOffset())
06791                                                         newStyle.setShadowYOffset(dia->TempVorl[cabneu].charStyle().shadowYOffset());
06792                                                  if (ite->itemText.charStyle(e).outlineWidth() == doc->docParagraphStyles[cabori].charStyle().outlineWidth())
06793                                                         newStyle.setOutlineWidth(dia->TempVorl[cabneu].charStyle().outlineWidth());
06794                                                  if (ite->itemText.charStyle(e).underlineOffset() == doc->docParagraphStyles[cabori].charStyle().underlineOffset())
06795                                                         newStyle.setUnderlineOffset(dia->TempVorl[cabneu].charStyle().underlineOffset());
06796                                                  if (ite->itemText.charStyle(e).underlineWidth() == doc->docParagraphStyles[cabori].charStyle().underlineWidth())
06797                                                         newStyle.setUnderlineWidth(dia->TempVorl[cabneu].charStyle().underlineWidth());
06798                                                  if (ite->itemText.charStyle(e).strikethruOffset() == doc->docParagraphStyles[cabori].charStyle().strikethruOffset())
06799                                                         newStyle.setStrikethruOffset(dia->TempVorl[cabneu].charStyle().strikethruOffset());
06800                                                  if (ite->itemText.charStyle(e).strikethruWidth() == doc->docParagraphStyles[cabori].charStyle().strikethruWidth())
06801                                                         newStyle.setStrikethruWidth(dia->TempVorl[cabneu].charStyle().strikethruWidth());
06802                                                  if (ite->itemText.charStyle(e).scaleH() == doc->docParagraphStyles[cabori].charStyle().scaleH())
06803                                                         newStyle.setScaleH(dia->TempVorl[cabneu].charStyle().scaleH());
06804                                                  if (ite->itemText.charStyle(e).scaleV() == doc->docParagraphStyles[cabori].charStyle().scaleV())
06805                                                         newStyle.setScaleV(dia->TempVorl[cabneu].charStyle().scaleV());
06806                                                  if (ite->itemText.charStyle(e).baselineOffset() == doc->docParagraphStyles[cabori].charStyle().baselineOffset())
06807                                                         newStyle.setBaselineOffset(dia->TempVorl[cabneu].charStyle().baselineOffset());
06808                                                  if (ite->itemText.charStyle(e).tracking() == doc->docParagraphStyles[cabori].charStyle().tracking())
06809                                                         newStyle.setTracking(dia->TempVorl[cabneu].charStyle().tracking());
06810                                           }
06811                                           else
06812                                           {
06813                                                  newStyle = ite->itemText.defaultStyle().charStyle();
06814                                                         //.cstyle & static_cast<StyleFlag>(~1919);
06815                                                  //newStyle.cstyle |= static_cast<StyleFlag>(ite->TxTStyle);
06816                                           }
06817                                           if (newStyle != lastStyle || lastParaStyle != cabneu) {
06818                                                  ite->itemText.applyCharStyle(lastStyleStart, e-lastStyleStart, lastStyle);
06819                                                  lastStyle = newStyle;
06820                                                  lastStyleStart = e;
06821                                                  lastParaStyle = cabneu;
06822                                           }
06823                                           if (ite->itemText.text(e) == SpecialChars::PARSEP && cabneu >= 0) {
06824                                                  ite->itemText.applyStyle(e, dia->TempVorl[cabneu]);
06825                                           }
06826                                    }
06827                                    else if (lastParaStyle >= 0) {
06828                                           ite->itemText.applyCharStyle(lastStyleStart, e-lastStyleStart, lastStyle);
06829                                           lastStyle = newStyle;
06830                                           lastStyleStart = e;
06831                                           lastParaStyle = -1;
06832                                    }
06833                             }
06834                             if (ite->itemText.length() > 0) {
06835                                    ite->itemText.applyCharStyle(lastStyleStart, ite->itemText.length()-lastStyleStart, lastStyle);
06836                                    if (lastParaStyle >=0 )
06837                                           ite->itemText.applyStyle(ite->itemText.length()-1, dia->TempVorl[lastParaStyle]);
06838                             }
06839                      }
06840               }
06841        }
06842  */
06843        if (CurrStED != NULL)
06844        {
06845 /*            if (CurrStED->Editor->StyledText.count() != 0)
06846               {
06847                      for (uint pa = 0; pa < CurrStED->Editor->StyledText.count(); ++pa)
06848                      {
06849                             SEditor::ChList *chars;
06850                             chars = CurrStED->Editor->StyledText.at(pa);
06851                             (*CurrStED->Editor->ParagStyles.at(pa)) = ers[CurrStED->Editor->ParagStyles[pa]];
06852 
06853                             int cabneu = 0;
06854                             for (uint e = 0; e < chars->count(); ++e)
06855                             {
06856                                    int cabori = chars->at(e)->cab;
06857                                    assert (cabore >= 0 && cabori < doc->docParagraphStyles.count());
06858                                    cabneu = ers[cabori];
06859                                    assert (cabneu >= 0 && cabneu < dia->TempVorl.count() );
06860                                    if (cabori > 4)
06861                                    {
06862                                           if (cabneu > 0)
06863                                           {
06864                                                  if (chars->at(e)->charStyle.font().scName() == doc->docParagraphStyles[cabori].charStyle().font().scName())
06865                                                         chars->at(e)->charStyle.setFont(dia->TempVorl[cabneu].charStyle().font());
06866                                                  if (chars->at(e)->charStyle.fontSize() == doc->docParagraphStyles[cabori].charStyle().fontSize())
06867                                                         chars->at(e)->charStyle.setFontSize(dia->TempVorl[cabneu].charStyle().fontSize());
06868                                                  if ((chars->at(e)->charStyle.effects() & static_cast<StyleFlag>(1919) ) == doc->docParagraphStyles[cabori].charStyle().effects())
06869                                                  {
06870                                                         StyleFlag fl = chars->at(e)->charStyle.effects();
06871                                                         fl&= static_cast<StyleFlag>(~1919);
06872                                                         fl |= dia->TempVorl[cabneu].charStyle().effects();
06873                                                         chars->at(e)->charStyle.setFeatures(fl.featureList());
06874                                                  }
06875                                                  if (chars->at(e)->charStyle.fillColor() == doc->docParagraphStyles[cabori].charStyle().fillColor())
06876                                                         chars->at(e)->charStyle.setFillColor(dia->TempVorl[cabneu].charStyle().fillColor());
06877                                                  if (chars->at(e)->charStyle.fillShade() == doc->docParagraphStyles[cabori].charStyle().fillShade())
06878                                                         chars->at(e)->charStyle.setFillShade(dia->TempVorl[cabneu].charStyle().fillShade());
06879                                                  if (chars->at(e)->charStyle.strokeColor() == doc->docParagraphStyles[cabori].charStyle().strokeColor())
06880                                                         chars->at(e)->charStyle.setStrokeColor(dia->TempVorl[cabneu].charStyle().strokeColor());
06881                                                  if (chars->at(e)->charStyle.strokeShade() == doc->docParagraphStyles[cabori].charStyle().strokeShade())
06882                                                         chars->at(e)->charStyle.setStrokeShade(dia->TempVorl[cabneu].charStyle().strokeShade());
06883                                                  if (chars->at(e)->charStyle.shadowXOffset() == doc->docParagraphStyles[cabori].charStyle().shadowXOffset())
06884                                                         chars->at(e)->charStyle.setShadowXOffset(dia->TempVorl[cabneu].charStyle().shadowXOffset());
06885                                                  if (chars->at(e)->charStyle.shadowYOffset() == doc->docParagraphStyles[cabori].charStyle().shadowYOffset())
06886                                                         chars->at(e)->charStyle.setShadowYOffset(dia->TempVorl[cabneu].charStyle().shadowYOffset());
06887                                                  if (chars->at(e)->charStyle.outlineWidth() == doc->docParagraphStyles[cabori].charStyle().outlineWidth())
06888                                                         chars->at(e)->charStyle.setOutlineWidth(dia->TempVorl[cabneu].charStyle().outlineWidth());
06889                                                  if (chars->at(e)->charStyle.underlineOffset() == doc->docParagraphStyles[cabori].charStyle().underlineOffset())
06890                                                         chars->at(e)->charStyle.setUnderlineOffset(dia->TempVorl[cabneu].charStyle().underlineOffset());
06891                                                  if (chars->at(e)->charStyle.underlineWidth() == doc->docParagraphStyles[cabori].charStyle().underlineWidth())
06892                                                         chars->at(e)->charStyle.setUnderlineWidth(dia->TempVorl[cabneu].charStyle().underlineWidth());
06893                                                  if (chars->at(e)->charStyle.strikethruOffset() == doc->docParagraphStyles[cabori].charStyle().strikethruOffset())
06894                                                         chars->at(e)->charStyle.setStrikethruOffset(dia->TempVorl[cabneu].charStyle().strikethruOffset());
06895                                                  if (chars->at(e)->charStyle.strikethruWidth() == doc->docParagraphStyles[cabori].charStyle().strikethruWidth())
06896                                                         chars->at(e)->charStyle.setStrikethruWidth(dia->TempVorl[cabneu].charStyle().strikethruWidth());
06897                                                  if (chars->at(e)->charStyle.scaleH() == doc->docParagraphStyles[cabori].charStyle().scaleH())
06898                                                         chars->at(e)->charStyle.setScaleH(dia->TempVorl[cabneu].charStyle().scaleH());
06899                                                  if (chars->at(e)->charStyle.scaleV() == doc->docParagraphStyles[cabori].charStyle().scaleV())
06900                                                         chars->at(e)->charStyle.setScaleV(dia->TempVorl[cabneu].charStyle().scaleV());
06901                                                  if (chars->at(e)->charStyle.baselineOffset() == doc->docParagraphStyles[cabori].charStyle().baselineOffset())
06902                                                         chars->at(e)->charStyle.setBaselineOffset(dia->TempVorl[cabneu].charStyle().baselineOffset());
06903                                                  if (chars->at(e)->charStyle.tracking() == doc->docParagraphStyles[cabori].charStyle().tracking())
06904                                                         chars->at(e)->charStyle.setTracking(dia->TempVorl[cabneu].charStyle().tracking());
06905                                           }
06906                                           else
06907                                           {
06908                                                  chars->at(e)->charStyle = ite->itemText.defaultStyle().charStyle();
06909                                           }
06910                                           chars->at(e)->cab = cabneu;
06911                                    }
06912                             }
06913 
06914                      }
06915                      CurrStED->Editor->currentParaStyle = ers[CurrStED->Editor->currentParaStyle];
06916               }
06917        */
06918        }
06919        doc->redefineStyles(dia->TempVorl);
06920        if (CurrStED != NULL)
06921        {
06922               if (CurrStED->Editor->StyledText.length() != 0)
06923                      CurrStED->Editor->updateAll();
06924        }
06925        for (uint a=0; a<doc->paragraphStyles().count(); ++a)
06926        {
06927               if (!doc->paragraphStyles()[a].charStyle().font().isNone())
06928               {
06929                      QString nf = doc->paragraphStyles()[a].charStyle().font().scName();
06930                      if (!doc->UsedFonts.contains(nf))
06931                      {
06932                             if (doc->AddFont(nf)) //, prefsManager->appPrefs.AvailFonts[nf]->Font))
06933                             {
06934                                    int ff = FontMenu->insertItem(new FmItem(nf, prefsManager->appPrefs.AvailFonts[nf]));
06935                                    FontID.insert(ff, prefsManager->appPrefs.AvailFonts[nf].scName());
06936                             }
06937 //                          else
06938 //FIXME                                   doc->paragraphStyles()[a].charStyle().setFont((prefsManager->appPrefs.AvailFonts[doc->toolSettings.defFont]));
06939                      }
06940               }
06941        }
06942 
06943        propertiesPalette->paraStyleCombo->updateFormatList();
06944        propertiesPalette->charStyleCombo->updateFormatList();
06945        propertiesPalette->updateColorList();
06946        disconnect(ColorMenC, SIGNAL(activated(int)), this, SLOT(setItemFarbe(int)));
06947        ColorList::Iterator it;
06948        updateColorMenu();
06949        view->DrawNew();
06950        slotDocCh();
06951 }
06952 
06953 //CB-->Doc
06954 void ScribusMainWindow::setNewAlignment(int a)
06955 {
06956        if (HaveDoc)
06957        {
06958 //            doc->currentStyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(a));
06959               doc->itemSelection_SetAlignment(a);
06960               propertiesPalette->setAli(a);
06961               PageItem *currItem = doc->m_Selection->itemAt(0);
06962               setTBvals(currItem);
06963        }
06964 }
06965 
06966 void ScribusMainWindow::setNewParStyle(const QString& name)
06967 {
06968        if (HaveDoc)
06969        {
06970 /*            if (name.isEmpty())
06971               {
06972                      doc->itemSelection_SetNamedParagraphStyle(name);
06973                      doc->itemSelection_EraseParagraphStyle();
06974               }
06975               else */              
06976                      doc->itemSelection_SetNamedParagraphStyle(name);
06977               PageItem *currItem = doc->m_Selection->itemAt(0);
06978               setTBvals(currItem);
06979        }
06980 }
06981 
06982 void ScribusMainWindow::setNewCharStyle(const QString& name)
06983 {
06984        if (HaveDoc)
06985        {
06986 /*            if (name.isEmpty())
06987               {
06988                      doc->itemSelection_SetNamedCharStyle(name);                    
06989                      doc->itemSelection_EraseCharStyle();
06990               }
06991               else */
06992                      doc->itemSelection_SetNamedCharStyle(name);
06993               PageItem *currItem = doc->m_Selection->itemAt(0);
06994               setTBvals(currItem);
06995        }
06996 }
06997 
06998 void ScribusMainWindow::setAbsValue(int a)
06999 {
07000 //     doc->currentStyle = doc->docParagraphStyles[a];
07001 //     doc->currentStyle.setAlignment(static_cast<ParagraphStyle::AlignmentType>(a<5 ? a : 0));
07002        propertiesPalette->setAli(a);
07003        QString alignment[] = {"Left", "Center", "Right", "Block", "Forced"};
07004        for (int b=0; b<5; ++b)
07005        {
07006               QString actionName="align"+alignment[b];
07007               if (scrActions[actionName])
07008                      scrActions[actionName]->setOn(a==b);
07009        }
07010 }
07011 
07012 void ScribusMainWindow::slotEditColors()
07013 {
07014        ColorList edc;
07015        if (HaveDoc)
07016               edc = doc->PageColors;
07017        else
07018               edc = prefsManager->colorSet();
07019        ColorManager* dia = new ColorManager(this, edc, doc, prefsManager->colorSetName(), prefsManager->appPrefs.CustomColorSets);
07020        if (dia->exec())
07021        {
07022               if (HaveDoc)
07023               {
07024 //                   uint c;
07025 //                   int d;
07026 //                   PageItem *ite;
07027                      QColor tmpc;
07028                      slotDocCh();
07029                      doc->PageColors = dia->EditColors;
07030                      if (dia->replaceMap.isEmpty())
07031                      {
07032                             // invalidate all charstyles, as replaceNamedResources() wont do it if all maps are empty
07033                             const StyleSet<CharStyle> dummy;
07034                             doc->redefineCharStyles(dummy, false);
07035                      }
07036                      else
07037                      {
07038                             ResourceCollection colorrsc;
07039                             colorrsc.mapColors(dia->replaceMap);
07040                             // Update tools colors
07041                             PrefsManager::replaceToolColors(doc->toolSettings, colorrsc.colors());
07042                             // Update objects and styles colors
07043                             doc->replaceNamedResources(colorrsc);
07044                             // Temporary code until LineStyle is effectively used
07045                             doc->replaceLineStyleColors(dia->replaceMap);
07046                             /*
07047                             // ers == colorrsc.fonts()
07048                             QMap<QString,QString>::Iterator it;
07049                             for (it = ers.begin(); it != ers.end(); ++it)
07050                             {
07051                                    if (it.key() == doc->currentStyle.charStyle().fillColor())
07052                                           doc->currentStyle.charStyle().setFillColor(it.data());
07053                                    if (it.key() == doc->currentStyle.charStyle().strokeColor())
07054                                           doc->currentStyle.charStyle().setStrokeColor(it.data());
07055                                    for (c=0; c<doc->DocItems.count(); ++c)
07056                                    {
07057                                           ite = doc->DocItems.at(c);
07058                                           if ((ite->asTextFrame()) || (ite->asPathText()))
07059                                           {
07060                                                  CharStyle lastStyle;
07061                                                  int lastStyleStart = 0;
07062                                                  for (d=0; d<ite->itemText.length(); ++d)
07063                                                  {
07064                                                         CharStyle newStyle;
07065                                                         if (it.key() == ite->itemText.charStyle(d).fillColor())
07066                                                                newStyle.setFillColor(it.data());
07067                                                         if (it.key() == ite->itemText.charStyle(d).strokeColor())
07068                                                                newStyle.setStrokeColor(it.data());
07069                                                         if (newStyle != lastStyle) {
07070                                                                ite->itemText.applyCharStyle(lastStyleStart, d-lastStyleStart, lastStyle);
07071                                                                lastStyle = newStyle;
07072                                                                lastStyleStart = d;
07073                                                         }
07074                                                  }
07075                                                  ite->itemText.applyCharStyle(lastStyleStart, ite->itemText.length()-lastStyleStart, lastStyle);
07076                                           }
07077                                           if (it.key() == ite->fillColor())
07078                                                  ite->setFillColor(it.data());
07079                                           if (it.key() == ite->lineColor())
07080                                                  ite->setLineColor(it.data());
07081                                           QPtrVector<VColorStop> cstops = ite->fill_gradient.colorStops();
07082                                           for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
07083                                           {
07084                                                  if (it.key() == cstops.at(cst)->name)
07085                                                         cstops.at(cst)->name = it.data();
07086                                           }
07087                                    }
07088                             }
07089                             for (it = ers.begin(); it != ers.end(); ++it)
07090                             {
07091                                    for (c=0; c<doc->FrameItems.count(); ++c)
07092                                    {
07093                                           ite = doc->FrameItems.at(c);
07094                                           if ((ite->asTextFrame()) || (ite->asPathText()))
07095                                           {
07096                                                  CharStyle lastStyle;
07097                                                  int lastStyleStart = 0;
07098                                                  for (d=0; d<ite->itemText.length(); ++d)
07099                                                  {
07100                                                         CharStyle newStyle;
07101                                                         if (it.key() == ite->itemText.charStyle(d).fillColor())
07102                                                                newStyle.setFillColor(it.data());
07103                                                         if (it.key() == ite->itemText.charStyle(d).strokeColor())
07104                                                                newStyle.setStrokeColor(it.data());
07105                                                         if (newStyle != lastStyle) {
07106                                                                ite->itemText.applyCharStyle(lastStyleStart, d-lastStyleStart, lastStyle);
07107                                                                lastStyle = newStyle;
07108                                                                lastStyleStart = d;
07109                                                         }
07110                                                         ite->itemText.applyCharStyle(lastStyleStart, ite->itemText.length()-lastStyleStart, lastStyle);
07111                                                  }
07112                                           }
07113                                           if (it.key() == ite->fillColor())
07114                                                  ite->setFillColor(it.data());
07115                                           if (it.key() == ite->lineColor())
07116                                                  ite->setLineColor(it.data());
07117                                           QPtrVector<VColorStop> cstops = ite->fill_gradient.colorStops();
07118                                           for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
07119                                           {
07120                                                  if (it.key() == cstops.at(cst)->name)
07121                                                         cstops.at(cst)->name = it.data();
07122                                           }
07123                                    }
07124                             }
07125                             for (it = ers.begin(); it != ers.end(); ++it)
07126                             {
07127                                    for (c=0; c<doc->MasterItems.count(); ++c)
07128                                    {
07129                                           ite = doc->MasterItems.at(c);
07130                                           if ((ite->itemType() == PageItem::TextFrame) || (ite->itemType() == PageItem::PathText))
07131                                           {
07132                                                  CharStyle lastStyle;
07133                                                  int lastStyleStart = 0;
07134                                                  for (d=0; d<ite->itemText.length(); ++d)
07135                                                  {
07136                                                         CharStyle newStyle;
07137                                                         if (it.key() == ite->itemText.charStyle(d).fillColor())
07138                                                                newStyle.setFillColor(it.data());
07139                                                         if (it.key() == ite->itemText.charStyle(d).strokeColor())
07140                                                                newStyle.setStrokeColor(it.data());
07141                                                         if (newStyle != lastStyle) {
07142                                                                ite->itemText.applyCharStyle(lastStyleStart, d-lastStyleStart, lastStyle);
07143                                                                lastStyle = newStyle;
07144                                                                lastStyleStart = d;
07145                                                         }
07146                                                  }
07147                                                  ite->itemText.applyCharStyle(lastStyleStart, ite->itemText.length()-lastStyleStart, lastStyle);
07148                                           }
07149                                           if (it.key() == ite->fillColor())
07150                                                  ite->setFillColor(it.data());
07151                                           if (it.key() == ite->lineColor())
07152                                                  ite->setLineColor(it.data());
07153                                           QPtrVector<VColorStop> cstops = ite->fill_gradient.colorStops();
07154                                           for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
07155                                           {
07156                                                  if (it.key() == cstops.at(cst)->name)
07157                                                         cstops.at(cst)->name = it.data();
07158                                           }
07159                                    }
07160                             }
07161                             for (it = ers.begin(); it != ers.end(); ++it)
07162                             {
07163                                    QStringList patterns = doc->docPatterns.keys();
07164                                    for (uint c = 0; c < patterns.count(); ++c)
07165                                    {
07166                                           ScPattern pa = doc->docPatterns[patterns[c]];
07167                                           for (uint o = 0; o < pa.items.count(); o++)
07168                                           {
07169                                                  PageItem *ite = pa.items.at(o);
07170                                                  if ((ite->itemType() == PageItem::TextFrame) || (ite->itemType() == PageItem::PathText))
07171                                                  {
07172                                                         CharStyle lastStyle;
07173                                                         int lastStyleStart = 0;
07174                                                         for (d=0; d<ite->itemText.length(); ++d)
07175                                                         {
07176                                                                CharStyle newStyle;
07177                                                                if (it.key() == ite->itemText.charStyle(d).fillColor())
07178                                                                       newStyle.setFillColor(it.data());
07179                                                                if (it.key() == ite->itemText.charStyle(d).strokeColor())
07180                                                                       newStyle.setStrokeColor(it.data());
07181                                                                if (newStyle != lastStyle) {
07182                                                                       ite->itemText.applyCharStyle(lastStyleStart, d-lastStyleStart, lastStyle);
07183                                                                       lastStyle = newStyle;
07184                                                                       lastStyleStart = d;
07185                                                                }
07186                                                         }
07187                                                         ite->itemText.applyCharStyle(lastStyleStart, ite->itemText.length()-lastStyleStart, lastStyle);
07188                                                  }
07189                                                  if (it.key() == ite->fillColor())
07190                                                         ite->setFillColor(it.data());
07191                                                  if (it.key() == ite->lineColor())
07192                                                         ite->setLineColor(it.data());
07193                                                  QPtrVector<VColorStop> cstops = ite->fill_gradient.colorStops();
07194                                                  for (uint cst = 0; cst < ite->fill_gradient.Stops(); ++cst)
07195                                                  {
07196                                                         if (it.key() == cstops.at(cst)->name)
07197                                                         {
07198                                                                cstops.at(cst)->name = it.data();
07199                                                         }
07200                                                  }
07201                                           }
07202                                    }
07203                             }
07204                              */
07205                      }
07206                      doc->recalculateColors();
07207                      doc->recalcPicturesRes();
07208                      propertiesPalette->updateColorList();
07209                      styleManager->updateColorList();
07210                      updateColorMenu();
07211                      if (doc->m_Selection->count() != 0)
07212                             doc->m_Selection->itemAt(0)->emitAllToGUI();
07213                      view->DrawNew();
07214               }
07215               else
07216               {
07217                      // Update tools colors if needed
07218                      prefsManager->replaceToolColors(dia->replaceMap);
07219                      prefsManager->setColorSet(dia->EditColors);
07220                      prefsManager->setColorSetName(dia->getColorSetName());
07221                      propertiesPalette->Cpal->SetColors(prefsManager->colorSet());
07222               }
07223        }
07224        if (!HaveDoc)
07225               prefsManager->appPrefs.CustomColorSets = dia->customColSet;
07226        delete dia;
07227 }
07228 
07229 // void ScribusMainWindow::slotStyleManager()
07230 // {
07231 //     styleManager->setDoc(HaveDoc ? doc : 0);
07232 //     styleManager->setShown(!styleManager->isVisible());
07233 // }
07234 
07235 void ScribusMainWindow::updtGradFill()
07236 {
07237        if (!HaveDoc)
07238               return;
07239        VGradient vg(propertiesPalette->getFillGradient());
07240        doc->itemSelection_SetFillGradient(vg);
07241 }
07242 /*
07243 //CB-->Doc
07244 void ScribusMainWindow::GetBrushPen()
07245 {
07246        //What? we come back here from mpalette and then go to the view.. someones kidding
07247        if (!HaveDoc)
07248               return;
07249        view->QueryFarben();
07250        //CB We dont need to set the doc changed just to find the colour values...
07251        //slotDocCh();
07252 }
07253 */
07254 //CB-->??
07255 void ScribusMainWindow::MakeFrame(int f, int c, double *vals)
07256 {
07257        PageItem *currItem = doc->m_Selection->itemAt(0);
07258        switch (f)
07259        {
07260        case 0:
07261               currItem->SetRectFrame();
07262               doc->setRedrawBounding(currItem);
07263               break;
07264        case 1:
07265               currItem->SetOvalFrame();
07266               doc->setRedrawBounding(currItem);
07267               break;
07268        default:
07269               currItem->SetFrameShape(c, vals);
07270               doc->setRedrawBounding(currItem);
07271               currItem->FrameType = f+2;
07272               break;
07273        }
07274        //propertiesPalette->SetCurItem(currItem);
07275        view->RefreshItem(currItem);
07276        slotDocCh();
07277 }
07278 
07279 void ScribusMainWindow::ObjektDup()
07280 {
07281        slotSelect();
07282        bool savedAlignGrid = doc->useRaster;
07283        bool savedAlignGuides = doc->SnapGuides;
07284        doc->useRaster = false;
07285        doc->SnapGuides = false;
07286        slotEditCopy();
07287        view->Deselect(true);
07288        slotEditPaste();
07289        for (uint b=0; b<doc->m_Selection->count(); ++b)
07290        {
07291               doc->m_Selection->itemAt(b)->setLocked(false);
07292               doc->MoveItem(doc->toolSettings.dispX, doc->toolSettings.dispY, doc->m_Selection->itemAt(b));
07293        }
07294        doc->useRaster = savedAlignGrid;
07295        doc->SnapGuides = savedAlignGuides;
07296 }
07297 
07298 void ScribusMainWindow::ObjektDupM()
07299 {
07300        if (!HaveDoc)
07301               return;
07302        slotSelect();
07303        NoFrameEdit();
07304        MultipleDuplicate *dia = new MultipleDuplicate(doc->unitIndex(), this);
07305        if (dia->exec())
07306        {
07307               ItemMultipleDuplicateData mdData;
07308               dia->getMultiplyData(mdData);
07309               doc->itemSelection_MultipleDuplicate(mdData);
07310        }
07311        delete dia;
07312 }
07313 
07314 void ScribusMainWindow::selectItemsFromOutlines(PageItem* ite)
07315 {
07316        int d = doc->Items->findRef(ite);
07317        selectItemsFromOutlines(ite->OwnPage, d, true);
07318 }
07319 
07320 void ScribusMainWindow::selectItemsFromOutlines(int Page, int Item, bool single)
07321 {
07322        NoFrameEdit();
07323        setActiveWindow();
07324        view->Deselect(true);
07325        if ((Page != -1) && (Page != static_cast<int>(doc->currentPage()->pageNr())))
07326               view->GotoPage(Page);
07327        view->SelectItemNr(Item, true, single);
07328        if (doc->m_Selection->count() != 0)
07329        {
07330               PageItem *currItem = doc->m_Selection->itemAt(0);
07331         // jjsa 23-05-2004 added for centering of rotated objects
07332               double rotation=currItem->rotation();
07333               if ( rotation != 0.0 )
07334               {
07335                      double MPI180=1.0/(180.0*M_PI);
07336                      double y1 = sin(rotation*MPI180) * currItem->width();
07337                      double x1 = cos(rotation*MPI180) * currItem->width();
07338                      double y2 = sin((rotation+90.0)*MPI180) * currItem->height();
07339                      double x2 = cos((rotation+90.0)*MPI180) * currItem->height();
07340                      double mx = currItem->xPos() + ((x1 + x2)/2.0);
07341                      double my = currItem->yPos() + ((y1 + y2)/2.0);
07342                      double viewScale=view->scale();
07343                      if ((qRound((currItem->xPos() + QMAX(x1, x2)) * viewScale) > view->contentsWidth()) ||
07344                             (qRound((currItem->yPos() + QMAX(y1, y2)) * viewScale) > view->contentsHeight()))
07345                             view->resizeContents(QMAX(qRound((currItem->xPos() + QMAX(x1, x2)) * viewScale),
07346                                                                view->contentsWidth()),
07347                                                                QMAX(qRound((currItem->yPos() + QMAX(y1, y2)) * viewScale), view->contentsHeight()));
07348                      view->SetCCPo(mx, my);
07349               }
07350               else
07351               {
07352                      double viewScale=view->scale();
07353                      if ((qRound((currItem->xPos() + currItem->width()) * viewScale) > view->contentsWidth()) ||
07354                             (qRound((currItem->yPos() + currItem->height()) * viewScale) > view->contentsHeight())
07355                             )
07356                             view->resizeContents(QMAX(qRound((currItem->xPos() + currItem->width()) * viewScale), view->contentsWidth()),
07357                                                                 QMAX(qRound((currItem->yPos() + currItem->height()) * viewScale), view->contentsHeight()));
07358                      view->SetCCPo(currItem->xPos() + currItem->width() / 2.0, currItem->yPos() + currItem->height() / 2.0);
07359               }
07360        }
07361 }
07362 
07363 void ScribusMainWindow::selectPagesFromOutlines(int Page)
07364 {
07365        NoFrameEdit();
07366        setActiveWindow();
07367        view->Deselect(true);
07368        if (Page < 0)
07369               return;
07370        view->GotoPage(Page);
07371 }
07372 
07373 void ScribusMainWindow::buildFontMenu()
07374 {
07375        FontID.clear();
07376        FontMenu->clear();
07377        SCFontsIterator it(prefsManager->appPrefs.AvailFonts);
07378        FontSub = new FontCombo(0);
07379        FontMenu->insertItem(FontSub);
07380        connect(FontSub, SIGNAL(activated(int)), this, SLOT(setItemFont2(int)));
07381        FontMenu->insertSeparator();
07382        int a=0;
07383        if (!HaveDoc)
07384        {
07385               a = FontMenu->insertItem(new FmItem(it.currentKey(), it.current()));
07386               FontMenu->setItemChecked(a, true);
07387               FontID.insert(a, it.current().scName());
07388        }
07389        else
07390        {
07391               QMap<QString,int>::Iterator it3;
07392               for (it3 = doc->UsedFonts.begin(); it3 != doc->UsedFonts.end(); ++it3)
07393               {
07394                      a = FontMenu->insertItem(new FmItem(it3.key(), prefsManager->appPrefs.AvailFonts[it3.key()]));
07395                      if (it3.key() == doc->toolSettings.defFont)
07396                             FontMenu->setItemChecked(a, true);
07397                      FontID.insert(a, it3.key());
07398               }
07399        }
07400        connect(FontMenu, SIGNAL(activated(int)), this, SLOT(setItemFont(int)));
07401 }
07402 
07403 void ScribusMainWindow::prefsOrg(Preferences *dia)
07404 {
07405        //reset the appMode so we restore our tools shortcuts
07406        QString oldGUILanguage = prefsManager->guiLanguage();
07407        QString oldGUIStyle = prefsManager->guiStyle();
07408        int oldGUIFontSize = prefsManager->guiFontSize();
07409        //double oldDisplayScale=prefsManager->displayScale();
07410        dia->updatePreferences();
07411        prefsManager->SavePrefs();
07412        DocDir = prefsManager->documentDir();
07413 //            scrapbookPalette->rebuildView();
07414 //            scrapbookPalette->AdjustMenu();
07415        QString newGUILanguage = prefsManager->guiLanguage();
07416        if (oldGUILanguage != newGUILanguage || ScQApp->currGUILanguage()!=newGUILanguage)
07417               ScQApp->changeGUILanguage(newGUILanguage);
07418        QString newGUIStyle = prefsManager->guiStyle();
07419        if (oldGUIStyle != newGUIStyle)
07420               qApp->setStyle(QStyleFactory::create(newGUIStyle));
07421        int newGUIFontSize = prefsManager->guiFontSize();
07422        if (oldGUIFontSize != newGUIFontSize)
07423        {
07424               QFont apf = qApp->font();
07425               apf.setPointSize(prefsManager->appPrefs.AppFontSize);
07426               qApp->setFont(apf,true);
07427        }
07428        FontSub->RebuildList(0);
07429        propertiesPalette->Fonts->RebuildList(0);
07430        ScCore->getCMSProfiles(false);
07431        ScCore->recheckGS();
07432        SetShortCut();
07433 }
07434 
07435 void ScribusMainWindow::slotPrefsOrg()
07436 {
07437        setAppMode(modeNormal);
07438 
07439        Preferences *dia = new Preferences(this);
07440        if (dia->exec())
07441        {
07442               prefsOrg(dia);
07443        }
07444        delete dia;
07445 }
07446 
07447 void ScribusMainWindow::ShowSubs()
07448 {
07449        QString mess;
07450        if (ScCore->haveGS() != 0)
07451        {
07452               mess = tr("The following programs are missing:")+"\n\n";
07453 #ifndef _WIN32
07454               mess += tr("Ghostscript : You cannot use EPS images or Print Preview")+"\n\n";
07455 #else
07456               mess += tr("Ghostscript : You cannot use EPS images or PostScript Print Preview")+"\n\n";
07457 #endif
07458               QMessageBox::warning(this, CommonStrings::trWarning, mess, 1, 0, 0);
07459        }
07460 
07461        propertiesPalette->startup();
07462        outlinePalette->startup();
07463        scrapbookPalette->startup();
07464        bookmarkPalette->startup();
07465        pagePalette->startup();
07466        layerPalette->startup();
07467        measurementPalette->startup();
07468        docCheckerPalette->startup();
07469        alignDistributePalette->startup();
07470        undoPalette->startup();
07471        guidePalette->startup();
07472        charPalette->startup();
07473        styleManager->startup();
07474 
07475        // init the toolbars
07476        fileToolBar->initVisibility();
07477        editToolBar->initVisibility();
07478        mainToolBar->initVisibility();
07479        pdfToolBar->initVisibility();
07480 
07481        setActiveWindow();
07482        raise();
07483 }
07484 
07485 void ScribusMainWindow::doPrintPreview()
07486 {
07487        if (docCheckerPalette->isIgnoreEnabled())
07488        {
07489               docCheckerPalette->hide();
07490               docCheckerPalette->checkMode = CheckDocument::checkNULL;
07491               docCheckerPalette->setIgnoreEnabled(false);
07492               scrActions["toolsPreflightVerifier"]->setOn(false);
07493               disconnect(docCheckerPalette, SIGNAL(ignoreAllErrors()), this, SLOT(doPrintPreview()));
07494        }
07495        if (HaveDoc)
07496        {
07497               PrefsContext* prefs = PrefsManager::instance()->prefsFile->getContext("print_options");
07498               QString currentPrinter = prefs->get("CurrentPrn");
07499               if ( PPreview::usePostscriptPreview(currentPrinter) && ( ScCore->haveGS() != 0 ) )
07500               {
07501                      QString mess = tr("Ghostscript is missing : Postscript Print Preview is not available")+"\n\n";
07502                      QMessageBox::warning(this, CommonStrings::trWarning, mess, 1, 0, 0);
07503                      return;
07504               }
07505               PPreview *dia = new PPreview(this, view, doc, ScCore->havePNGAlpha(), ScCore->haveTIFFSep(), currentPrinter);
07506               previewDinUse = true;
07507               connect(dia, SIGNAL(doPrint()), this, SLOT(slotReallyPrint()));
07508               dia->exec();
07509               PrefsManager *prefsManager=PrefsManager::instance();
07510               prefsManager->appPrefs.PrPr_Mode = dia->EnableCMYK->isChecked();
07511               prefsManager->appPrefs.PrPr_AntiAliasing = dia->AntiAlias->isChecked();
07512               prefsManager->appPrefs.PrPr_Transparency = dia->AliasTr->isChecked();
07513               if ( ScCore->haveTIFFSep() != 0 || !dia->postscriptPreview )
07514               {
07515                      prefsManager->appPrefs.PrPr_C = dia->EnableCMYK_C->isChecked();
07516                      prefsManager->appPrefs.PrPr_M = dia->EnableCMYK_M->isChecked();
07517                      prefsManager->appPrefs.PrPr_Y = dia->EnableCMYK_Y->isChecked();
07518                      prefsManager->appPrefs.PrPr_K = dia->EnableCMYK_K->isChecked();
07519               }
07520               else
07521               {
07522                      prefsManager->appPrefs.PrPr_C = dia->flagsVisible["Cyan"]->isChecked();
07523                      prefsManager->appPrefs.PrPr_M = dia->flagsVisible["Magenta"]->isChecked();
07524                      prefsManager->appPrefs.PrPr_Y = dia->flagsVisible["Yellow"]->isChecked();
07525                      prefsManager->appPrefs.PrPr_K = dia->flagsVisible["Black"]->isChecked();
07526               }
07527 //            prefsManager->appPrefs.Gcr_Mode = dia->EnableGCR->isChecked();
07528 //            prefsManager->appPrefs.doOverprint = dia->EnableOverprint->isChecked();
07529               disconnect(dia, SIGNAL(doPrint()), this, SLOT(slotReallyPrint()));
07530               previewDinUse = false;
07531               delete dia;
07532               QFile::remove(prefsManager->preferencesLocation()+"/tmp.ps");
07533               QFile::remove(prefsManager->preferencesLocation()+"/sc.png");
07534               QDir d(prefsManager->preferencesLocation()+"/", "sc.*", QDir::Name, QDir::Files | QDir::NoSymLinks);
07535               if ((d.exists()) && (d.count() != 0))
07536               {
07537                      for (uint dc = 0; dc < d.count(); dc++)
07538                      {
07539                             QFile::remove(prefsManager->preferencesLocation() +"/" + d[dc]);
07540                      }
07541               }
07542        }
07543 }
07544 
07545 void ScribusMainWindow::printPreview()
07546 {
07547        if (doc->checkerProfiles[doc->curCheckProfile].autoCheck)
07548        {
07549               if (scanDocument())
07550               {
07551                      if (doc->checkerProfiles[doc->curCheckProfile].ignoreErrors)
07552                      {
07553                             int t = ScMessageBox::warning(this, CommonStrings::trWarning,
07554                                                                              "<qt>"+ tr("Scribus has detected some errors. Consider using the Preflight Verifier to correct them")+"</qt>",
07555                                                                              tr("&Ignore"), tr("&Abort"), 0, 0, 0);
07556                             if (t == 1)
07557                                    return;
07558                      }
07559                      else
07560                      {
07561                             connect(docCheckerPalette, SIGNAL(ignoreAllErrors()), this, SLOT(doPrintPreview()));
07562                             docCheckerPalette->setIgnoreEnabled(true);
07563                             docCheckerPalette->checkMode = CheckDocument::checkPrintPreview;
07564                             docCheckerPalette->buildErrorList(doc);
07565                             docCheckerPalette->show();
07566                             scrActions["toolsPreflightVerifier"]->setOn(true);
07567                             return;
07568                      }
07569               }
07570        }
07571        doPrintPreview();
07572 }
07573 
07574 bool ScribusMainWindow::DoSaveAsEps(QString fn)
07575 {
07576        QStringList spots;
07577        bool return_value = true;
07578        ReOrderText(doc, view);
07579        qApp->setOverrideCursor(QCursor(waitCursor), true);
07580        QMap<QString, QMap<uint, FPointArray> > ReallyUsed;
07581        ReallyUsed.clear();
07582        doc->getUsedFonts(ReallyUsed);
07583        ColorList usedColors;
07584        doc->getUsedColors(usedColors);
07585        ScCore->fileWatcher->forceScan();
07586        ScCore->fileWatcher->stop();
07587        PrintOptions options;
07588        options.pageNumbers.push_back(doc->currentPage()->pageNr()+1);
07589        options.outputSeparations = false;
07590        options.separationName = tr("All");
07591        options.allSeparations = spots;
07592        options.useColor = true;
07593        options.mirrorH = false;
07594        options.mirrorV = false;
07595        options.useICC = true;
07596        options.doGCR = prefsManager->appPrefs.GCRMode;
07597        options.setDevParam = false;
07598        options.doClip = true;
07599        options.doOverprint = false;
07600        options.cropMarks = false;
07601        options.bleedMarks = false;
07602        options.registrationMarks = false;
07603        options.colorMarks = false;
07604        options.markOffset = 0.0;
07605        options.bleeds.Top = 0.0;
07606        options.bleeds.Left = 0.0;
07607        options.bleeds.Right = 0.0;
07608        options.bleeds.Bottom = 0.0;
07609        PSLib *dd = new PSLib(options, false, prefsManager->appPrefs.AvailFonts, ReallyUsed, usedColors, false, true);
07610        if (dd != NULL)
07611        {
07612               if (dd->PS_set_file(fn))
07613               {
07614                      dd->CreatePS(doc, options);
07615               }
07616               else
07617                      return_value = false;
07618               delete dd;
07619               qApp->setOverrideCursor(QCursor(arrowCursor), true);
07620        }
07621        ScCore->fileWatcher->start();
07622        return return_value;
07623 }
07624 
07625 void ScribusMainWindow::SaveAsEps()
07626 {
07627        if (doc->checkerProfiles[doc->curCheckProfile].autoCheck)
07628        {
07629               if (scanDocument())
07630               {
07631                      if (doc->checkerProfiles[doc->curCheckProfile].ignoreErrors)
07632                      {
07633                             int t = ScMessageBox::warning(this, CommonStrings::trWarning,
07634                                                                              tr("Scribus detected some errors.\nConsider using the Preflight Verifier  to correct them."),
07635                                                                              tr("&Abort"), tr("&Ignore"), 0, 0, 0);
07636                             if (t == 0)
07637                                    return;
07638                      }
07639                      else
07640                      {
07641                             connect(docCheckerPalette, SIGNAL(ignoreAllErrors()), this, SLOT(reallySaveAsEps()));
07642                             docCheckerPalette->setIgnoreEnabled(true);
07643                             docCheckerPalette->checkMode = CheckDocument::checkEPS;
07644                             docCheckerPalette->buildErrorList(doc);
07645                             docCheckerPalette->show();
07646                             scrActions["toolsPreflightVerifier"]->setOn(true);
07647                             return;
07648                      }
07649               }
07650        }
07651        reallySaveAsEps();
07652 }
07653 
07654 void ScribusMainWindow::reallySaveAsEps()
07655 {
07656        QString fna;
07657        if (docCheckerPalette->isIgnoreEnabled())
07658        {
07659               docCheckerPalette->hide();
07660               docCheckerPalette->checkMode = CheckDocument::checkNULL;
07661               docCheckerPalette->setIgnoreEnabled(false);
07662               scrActions["toolsPreflightVerifier"]->setOn(false);
07663               disconnect(docCheckerPalette, SIGNAL(ignoreAllErrors()), this, SLOT(reallySaveAsEps()));
07664        }
07665        if (!doc->DocName.startsWith( tr("Document")))
07666        {
07667               QFileInfo fi(doc->DocName);
07668               if (doc->m_Selection->count() != 0)
07669                      fna = fi.dirPath() + "/" + fi.baseName(true) + "_selection.eps";
07670               else
07671                      fna = fi.dirPath() + "/" + getFileNameByPage(doc, doc->currentPage()->pageNr(), "eps");
07672        }
07673        else
07674        {
07675               QDir di = QDir();
07676               if (doc->m_Selection->count() != 0)
07677                      fna = di.currentDirPath() + "/" + doc->DocName + "_selection.eps";
07678               else
07679                      fna = di.currentDirPath() + "/" + getFileNameByPage(doc, doc->currentPage()->pageNr(), "eps");
07680        }
07681        fna = QDir::convertSeparators(fna);
07682        QString wdir = ".";
07683        QString prefsDocDir=prefsManager->documentDir();
07684        if (!prefsDocDir.isEmpty())
07685               wdir = prefsManager->prefsFile->getContext("dirs")->get("eps", prefsDocDir);
07686        else
07687               wdir = prefsManager->prefsFile->getContext("dirs")->get("eps", ".");
07688        QString fn = CFileDialog( wdir, tr("Save as"), tr("EPS Files (*.eps);;All Files (*)"), fna, fdNone);
07689        if (!fn.isEmpty())
07690        {
07691               prefsManager->prefsFile->getContext("dirs")->set("eps", fn.left(fn.findRev("/")));
07692               if (overwrite(this, fn))
07693               {
07694                      if (!DoSaveAsEps(fn))
07695                             QMessageBox::warning(this, CommonStrings::trWarning, tr("Cannot write the file: \n%1").arg(fn), CommonStrings::tr_OK);
07696               }
07697        }
07698 }
07699 
07700 bool ScribusMainWindow::getPDFDriver(const QString & fn, const QString & nam, int Components,
07701                                                                 const std::vector<int> & pageNs, const QMap<int,QPixmap> & thumbs)
07702 {
07703        ScCore->fileWatcher->forceScan();
07704        ScCore->fileWatcher->stop();
07705        bool ret = PDFlib(*doc).doExport(fn, nam, Components, pageNs, thumbs);
07706        ScCore->fileWatcher->start();
07707        return ret;
07708 }
07709 
07710 void ScribusMainWindow::SaveAsPDF()
07711 {
07712        if (doc->checkerProfiles[doc->curCheckProfile].autoCheck)
07713        {
07714               if (scanDocument())
07715               {
07716                      if (doc->checkerProfiles[doc->curCheckProfile].ignoreErrors)
07717                      {
07718                             int t = QMessageBox::warning(this, CommonStrings::trWarning,
07719                                                                              tr("Detected some errors.\nConsider using the Preflight Verifier to correct them"),
07720                                                                              tr("&Abort"), tr("&Ignore"), 0, 0, 0);
07721                             if (t == 0)
07722                                    return;
07723                      }
07724                      else
07725                      {
07726                             connect(docCheckerPalette, SIGNAL(ignoreAllErrors()), this, SLOT(doSaveAsPDF()));
07727                             docCheckerPalette->setIgnoreEnabled(true);
07728                             docCheckerPalette->checkMode = CheckDocument::checkPDF;
07729                             docCheckerPalette->buildErrorList(doc);
07730                             docCheckerPalette->show();
07731                             scrActions["toolsPreflightVerifier"]->setOn(true);
07732                             return;
07733                      }
07734               }
07735        }
07736        doSaveAsPDF();
07737 }
07738 
07739 void ScribusMainWindow::doSaveAsPDF()
07740 {
07741        if (docCheckerPalette->isIgnoreEnabled())
07742        {
07743               docCheckerPalette->hide();
07744               docCheckerPalette->checkMode = CheckDocument::checkNULL;
07745               docCheckerPalette->setIgnoreEnabled(false);
07746               scrActions["toolsPreflightVerifier"]->setOn(false);
07747               disconnect(docCheckerPalette, SIGNAL(ignoreAllErrors()), this, SLOT(doSaveAsPDF()));
07748        }
07749 /*     if (bookmarkPalette->BView->childCount() == 0)
07750               doc->PDF_Options.Bookmarks = false; */
07751        QMap<QString, int> ReallyUsed = doc->UsedFonts;
07752        if (doc->PDF_Options.EmbedList.count() != 0)
07753        {
07754               QValueList<QString> tmpEm;
07755               QValueList<QString>::Iterator itef;
07756               for (itef = doc->PDF_Options.EmbedList.begin(); itef != doc->PDF_Options.EmbedList.end(); ++itef)
07757               {
07758                      if (ReallyUsed.contains((*itef)))
07759                             tmpEm.append((*itef));
07760               }
07761               doc->PDF_Options.EmbedList = tmpEm;
07762        }
07763        if (doc->PDF_Options.SubsetList.count() != 0)
07764        {
07765               QValueList<QString> tmpEm;
07766               QValueList<QString>::Iterator itef;
07767               for (itef = doc->PDF_Options.SubsetList.begin(); itef != doc->PDF_Options.SubsetList.end(); ++itef)
07768               {
07769                      if (ReallyUsed.contains((*itef)))
07770                             tmpEm.append((*itef));
07771               }
07772               doc->PDF_Options.SubsetList = tmpEm;
07773        }
07774        MarginStruct optBleeds = doc->PDF_Options.bleeds;
07775        PDFExportDialog dia(this, doc->DocName, ReallyUsed, view, doc->PDF_Options, doc->PDF_Options.PresentVals, ScCore->PDFXProfiles, prefsManager->appPrefs.AvailFonts, doc->unitRatio(), ScCore->PrinterProfiles);
07776        if (dia.exec())
07777        {
07778               qApp->setOverrideCursor(QCursor(waitCursor), true);
07779               dia.updateDocOptions();
07780               doc->PDF_Options.firstUse = false;
07781               ReOrderText(doc, view);
07782               QString pageString(dia.getPagesString());
07783               std::vector<int> pageNs;
07784               uint pageNumbersSize;
07785               QMap<int,QPixmap> thumbs;
07786               int components=dia.colorSpaceComponents();
07787               QString nam(dia.cmsDescriptor());
07788               QString fileName = doc->PDF_Options.Datei;
07789               parsePagesString(pageString, &pageNs, doc->DocPages.count());
07790               if (doc->PDF_Options.useDocBleeds)
07791                      doc->PDF_Options.bleeds = doc->bleeds;
07792               
07793               if (doc->PDF_Options.doMultiFile)
07794               {
07795                      QFileInfo fi(fileName);
07796                      QString ext = fi.extension( false );
07797                      QString path = fi.dirPath( true );
07798                      QString name = fi.baseName( true );
07799                      uint aa = 0;
07800                      while (aa < pageNs.size())
07801                      {
07802                             thumbs.clear();
07803                             std::vector<int> pageNs2;
07804                             pageNs2.clear();
07805                             pageNs2.push_back(pageNs[aa]);
07806                             pageNumbersSize = pageNs2.size();
07807                             QPixmap pm(10,10);
07808                             if (doc->PDF_Options.Thumbnails)
07809                                    pm.convertFromImage(view->PageToPixmap(pageNs[aa]-1, 100));
07810                             thumbs.insert(1, pm);
07811                             QString realName = QDir::convertSeparators(path+"/"+name+ tr("-Page%1").arg(pageNs[aa])+"."+ext);
07812                             if (!getPDFDriver(realName, nam, components, pageNs2, thumbs))
07813                             {
07814                                    qApp->setOverrideCursor(QCursor(arrowCursor), true);
07815                                    QMessageBox::warning(this, CommonStrings::trWarning, tr("Cannot write the file: \n%1").arg(doc->PDF_Options.Datei), CommonStrings::tr_OK);
07816                                    return;
07817                             }
07818                             aa++;
07819                      }
07820               }
07821               else
07822               {
07823                      pageNumbersSize = pageNs.size();
07824                      for (uint ap = 0; ap < pageNumbersSize; ++ap)
07825                      {
07826                             QPixmap pm(10,10);
07827                             if (doc->PDF_Options.Thumbnails)
07828                                    pm.convertFromImage(view->PageToPixmap(pageNs[ap]-1, 100));
07829                             thumbs.insert(pageNs[ap], pm);
07830                      }
07831                      if (!getPDFDriver(fileName, nam, components, pageNs, thumbs))
07832                      {
07833                             qApp->setOverrideCursor(QCursor(arrowCursor), true);
07834                             QMessageBox::warning(this, CommonStrings::trWarning, tr("Cannot write the file: \n%1").arg(doc->PDF_Options.Datei), CommonStrings::tr_OK);
07835                      }
07836               }
07837               if (doc->PDF_Options.useDocBleeds)
07838                      doc->PDF_Options.bleeds = optBleeds;
07839               qApp->setOverrideCursor(QCursor(arrowCursor), true);
07840        }
07841 }
07842 
07843 //CB-->Doc, stop _storing_ bookmarks in the palette
07844 void ScribusMainWindow::AddBookMark(PageItem *ite)
07845 {
07846        bookmarkPalette->BView->AddPageItem(ite);
07847        StoreBookmarks();
07848 }
07849 
07850 //CB-->Doc, stop _storing_ bookmarks in the palette
07851 void ScribusMainWindow::DelBookMark(PageItem *ite)
07852 {
07853        bookmarkPalette->BView->DeleteItem(ite);
07854        StoreBookmarks();
07855 }
07856 
07857 //CB-->Doc, stop _storing_ bookmarks in the palette
07858 void ScribusMainWindow::BookMarkTxT(PageItem *ite)
07859 {
07860        bookmarkPalette->BView->ChangeText(ite);
07861        StoreBookmarks();
07862 }
07863 
07864 //CB-->Doc, stop _storing_ bookmarks in the palette
07865 void ScribusMainWindow::RestoreBookMarks()
07866 {
07867        QValueList<ScribusDoc::BookMa>::Iterator it2 = doc->BookMarks.begin();
07868        bookmarkPalette->BView->clear();
07869        bookmarkPalette->BView->NrItems = 0;
07870        bookmarkPalette->BView->First = 1;
07871        bookmarkPalette->BView->Last = 0;
07872        if (doc->BookMarks.count() == 0)
07873               return;
07874        BookMItem* ip;
07875        BookMItem* ip2 = NULL;
07876        BookMItem* ip3 = NULL;
07877        BookMItem *ite = new BookMItem(bookmarkPalette->BView, &(*it2));
07878        bookmarkPalette->BView->NrItems++;
07879        ++it2;
07880        for( ; it2 != doc->BookMarks.end(); ++it2 )
07881        {
07882               if ((*it2).Parent == 0)
07883               {
07884                      ite = new BookMItem(bookmarkPalette->BView, ite, &(*it2));
07885                      bookmarkPalette->BView->NrItems++;
07886               }
07887               else
07888               {
07889                      QListViewItemIterator it3(bookmarkPalette->BView);
07890                      for ( ; it3.current(); ++it3)
07891                      {
07892                             ip = (BookMItem*)it3.current();
07893                             if ((*it2).Parent == ip->ItemNr)
07894                             {
07895                                    ip2 = ip;
07896                                    break;
07897                             }
07898                      }
07899                      if ((*it2).Prev == 0)
07900                      {
07901                             (void) new BookMItem(ip2, &(*it2));
07902                             bookmarkPalette->BView->NrItems++;
07903                      }
07904                      else
07905                      {
07906                             QListViewItemIterator it4(bookmarkPalette->BView);
07907                             for ( ; it4.current(); ++it4)
07908                             {
07909                                    ip = (BookMItem*)it4.current();
07910                                    if ((*it2).Prev == ip->ItemNr)
07911                                    {
07912                                           ip3 = ip;
07913                                           break;
07914                                    }
07915                             }
07916                             (void) new BookMItem(ip2, ip3, &(*it2));
07917                             bookmarkPalette->BView->NrItems++;
07918                      }
07919               }
07920        }
07921        bookmarkPalette->BView->Last = bookmarkPalette->BView->NrItems;
07922 }
07923 
07924 //CB-->Doc, stop _storing_ bookmarks in the palette
07925 void ScribusMainWindow::StoreBookmarks()
07926 {
07927        doc->BookMarks.clear();
07928        BookMItem* ip;
07929        QListViewItemIterator it(bookmarkPalette->BView);
07930        struct ScribusDoc::BookMa Boma;
07931        for ( ; it.current(); ++it)
07932        {
07933               ip = (BookMItem*)it.current();
07934               Boma.Title = ip->Titel;
07935               Boma.Text = ip->text(0);
07936               Boma.Aktion = ip->Action;
07937               Boma.ItemNr = ip->ItemNr;
07938               Boma.PageObject = ip->PageObject;
07939 //            Boma.Seite = ip->Seite;
07940 //            Boma.Element = ip->Element;
07941               Boma.Parent = ip->Pare;
07942               Boma.First = ip->First;
07943               Boma.Prev = ip->Prev;
07944               Boma.Next = ip->Next;
07945               Boma.Last = ip->Last;
07946               doc->BookMarks.append(Boma);
07947        }
07948        doc->NrItems = bookmarkPalette->BView->NrItems;
07949        doc->First = bookmarkPalette->BView->First;
07950        doc->Last = bookmarkPalette->BView->Last;
07951 }
07952 
07953 void ScribusMainWindow::slotElemRead(QString xml, double x, double y, bool art, bool loca, ScribusDoc* docc, ScribusView* vie)
07954 {
07955        if (doc == docc)
07956               NoFrameEdit();
07957        
07958        ScriXmlDoc *ss = new ScriXmlDoc();
07959        if(ss->ReadElem(xml, prefsManager->appPrefs.AvailFonts, docc, x, y, art, loca, prefsManager->appPrefs.GFontSub, vie))
07960        {
07961               vie->DrawNew();
07962               if (doc == docc)
07963               {
07964                      buildFontMenu();
07965                      propertiesPalette->updateColorList();
07966                      propertiesPalette->paraStyleCombo->updateFormatList();
07967                      propertiesPalette->charStyleCombo->updateFormatList();
07968                      propertiesPalette->SetLineFormats(docc);
07969                      slotDocCh();
07970               }
07971        }
07972        delete ss;
07973 }
07974 
07975 void ScribusMainWindow::slotChangeUnit(int unitIndex, bool draw)
07976 {
07977        doc->setUnitIndex(unitIndex);
07978        view->unitSwitcher->setCurrentText(unitGetStrFromIndex(doc->unitIndex()));
07979        propertiesPalette->unitChange();
07980        nodePalette->unitChange();
07981        alignDistributePalette->unitChange();
07982        guidePalette->setupPage();
07983        styleManager->unitChange();
07984        if (draw)
07985               view->DrawNew();
07986 }
07987 
07988 void ScribusMainWindow::ManageJava()
07989 {
07990        JavaDocs *dia = new JavaDocs(this, doc, view);
07991        connect(dia, SIGNAL(docChanged(bool)), this, SLOT(slotDocCh(bool )));
07992        dia->exec();
07993        disconnect(dia, SIGNAL(docChanged(bool)), this, SLOT(slotDocCh(bool )));
07994        delete dia;
07995 }
07996 
07997 void ScribusMainWindow::manageMasterPages(QString temp)
07998 {
07999        if (HaveDoc)
08000        {
08001               view->Deselect(true);
08002               if (doc->masterPageMode())
08003               {
08004                      ActWin->masterPagesPalette()->updateMasterPageList(temp);
08005                      ActWin->masterPagesPalette()->selectMasterPage(temp);
08006               }
08007               else
08008               {
08009                      storedPageNum = doc->currentPageNumber();
08010                      storedViewXCoor = view->contentsX();
08011                      storedViewYCoor = view->contentsY();
08012                      storedViewScale = view->scale();
08013                      MasterPagesPalette *dia = new MasterPagesPalette(this, doc, view, temp);
08014                      //connect(dia, SIGNAL(createNew(int)), this, SLOT(slotNewMasterPage(int)));
08015                      connect(dia, SIGNAL(removePage(int )), this, SLOT(DeletePage2(int )));
08016                      //connect(dia, SIGNAL(loadPage(QString, int, bool)), this, SLOT(loadPage(QString, int, bool)));
08017                      connect(dia, SIGNAL(finished()), this, SLOT(manageMasterPagesEnd()));
08018                      scrActions["pageInsert"]->setEnabled(false);
08019                      scrActions["pageImport"]->setEnabled(false);
08020                      scrActions["pageDelete"]->setEnabled(false);
08021                      scrActions["pageCopy"]->setEnabled(false);
08022                      scrActions["pageMove"]->setEnabled(false);
08023                      scrActions["pageApplyMasterPage"]->setEnabled(false);
08024                      scrActions["pageCopyToMasterPage"]->setEnabled(false);
08025                      scrActions["editMasterPages"]->setEnabled(false);
08026                      ActWin->setMenuStatus(0, scrActions["fileSave"]->isEnabled());
08027                      ActWin->setMenuStatus(1, scrActions["fileRevert"]->isEnabled());
08028                      ActWin->setMenuStatus(2, scrActions["fileSave"]->isEnabled());
08029                      ActWin->setMenuStatus(3, scrActions["fileSaveAs"]->isEnabled());
08030                      scrActions["fileNew"]->setEnabled(false);
08031                      scrActions["fileOpen"]->setEnabled(false);
08032                      scrActions["fileClose"]->setEnabled(false);
08033                      scrMenuMgr->setMenuEnabled("FileOpenRecent", false);
08034                      scrActions["fileRevert"]->setEnabled(false);
08035                      scrActions["fileDocSetup"]->setEnabled(false);
08036                      scrActions["filePrint"]->setEnabled(false);
08037                      scrActions["PrintPreview"]->setEnabled(false);
08038                      pagePalette->enablePalette(false);
08039                      dia->show();
08040                      ActWin->setMasterPagesPalette(dia);
08041               }
08042        }
08043 }
08044 
08045 void ScribusMainWindow::manageMasterPagesEnd()
08046 {
08047        view->setScale(storedViewScale);
08048        view->hideMasterPage();
08049        setAppMode(modeNormal);
08050        scrActions["editMasterPages"]->setEnabled(true);
08051        scrActions["fileNew"]->setEnabled(true);
08052        scrActions["fileOpen"]->setEnabled(true);
08053        scrActions["fileClose"]->setEnabled(true);
08054        scrActions["fileSave"]->setEnabled(true);
08055        scrMenuMgr->setMenuEnabled("FileOpenRecent", true);
08056        scrActions["fileRevert"]->setEnabled(true);
08057        scrActions["fileDocSetup"]->setEnabled(true);
08058        scrActions["filePrint"]->setEnabled(true);
08059        if ( ScCore->haveGS()==0 || ScCore->isWinGUI() )
08060               scrActions["PrintPreview"]->setEnabled(true);
08061        scrActions["pageInsert"]->setEnabled(true);
08062        scrActions["pageCopy"]->setEnabled(true);
08063        scrActions["pageImport"]->setEnabled(true);
08064        scrActions["pageApplyMasterPage"]->setEnabled(true);
08065        scrActions["pageCopyToMasterPage"]->setEnabled(true);
08066        bool setter = doc->Pages->count() > 1 ? true : false;
08067        scrActions["pageDelete"]->setEnabled(setter);
08068        scrActions["pageMove"]->setEnabled(setter);
08069        uint pageCount=doc->DocPages.count();
08070        for (uint c=0; c<pageCount; ++c)
08071               Apply_MasterPage(doc->DocPages.at(c)->MPageNam, c, false);
08072 //     doc->setMasterPageMode(false);
08073        pagePalette->enablePalette(true);
08074        pagePalette->RebuildTemp();
08075        ActWin->setMasterPagesPalette(NULL);
08076        doc->setCurrentPage(doc->DocPages.at(storedPageNum));
08077        view->reformPages(false);
08078        view->setContentsPos(static_cast<int>(storedViewXCoor * storedViewScale), static_cast<int>(storedViewYCoor * storedViewScale));
08079        view->DrawNew();
08080        pagePalette->Rebuild();
08081 //     if (outlinePalette->isVisible())
08082 //            outlinePalette->BuildTree();
08083 //     slotDocCh();
08084 }
08085 
08086 void ScribusMainWindow::ApplyMasterPage()
08087 {
08088        Q_ASSERT(!doc->masterPageMode());
08089        ApplyMasterPageDialog *dia = new ApplyMasterPageDialog(this);
08090        dia->setup(doc, doc->currentPage()->MPageNam);
08091        if (dia->exec())
08092        {
08093               QString masterPageName = dia->getMasterPageName();
08094               int pageSelection = dia->getPageSelection(); //0=current, 1=even, 2=odd, 3=all
08095               if (pageSelection==0) //current page only
08096                      Apply_MasterPage(masterPageName, doc->currentPage()->pageNr(), false);
08097               else
08098               {
08099                      int startPage, endPage;
08100                      if (dia->usingRange())
08101                      {
08102                             startPage=dia->getFromPage()-1; //Pages start from 0, not 1
08103                             endPage=dia->getToPage();
08104                      }
08105                      else
08106                      {
08107                             startPage = pageSelection==1 ? 1 : 0; //if even, startPage is 1 (real page 2)
08108                             endPage=doc->DocPages.count();
08109                      }
08110                      for (int pageNum = startPage; pageNum < endPage; ++pageNum)// +=pageStep)
08111                      {
08112                             //Increment by 1 and not 2 even for even/odd application as user
08113                             //can select to eg apply to even pages with a single odd page selected
08114                             if (pageSelection==1 && pageNum%2!=0) //Even, %2!=0 as 1st page is numbered 0
08115                                    Apply_MasterPage(masterPageName, pageNum, false);
08116                             else
08117                             if (pageSelection==2 && pageNum%2==0) //Odd, %2==0 as 1st page is numbered 0
08118                                    Apply_MasterPage(masterPageName, pageNum, false);
08119                             else
08120                             if (pageSelection==3) //All
08121                                    Apply_MasterPage(masterPageName, pageNum, false);
08122                      }
08123               }
08124        }
08125        view->reformPages();
08126        view->DrawNew();
08127        //CB done by doc::reformpages
08128        //slotDocCh();
08129        pagePalette->Rebuild();
08130        guidePalette->setupPage();
08131        delete dia;
08132 }
08133 
08134 void ScribusMainWindow::Apply_MasterPage(QString pageName, int pageNumber, bool reb)
08135 {
08136        if (!HaveDoc)
08137               return;
08138        doc->applyMasterPage(pageName, pageNumber);
08139        if (reb)
08140        {
08141               view->DrawNew();
08142 //            pagePalette->Rebuild();
08143        }
08144 }
08145 
08146 //CB-->Doc
08147 void ScribusMainWindow::GroupObj(bool showLockDia)
08148 {
08149        if (HaveDoc)
08150        {
08151               if (doc->m_Selection->count() < 2)
08152                      return;
08153               PageItem *currItem;
08154               PageItem* bb;
08155               double x, y, w, h;
08156               QString tooltip = Um::ItemsInvolved + "\n";
08157               uint selectedItemCount=doc->m_Selection->count();
08158               if (showLockDia)
08159               {
08160                      uint lockedCount=0;
08161                      for (uint a=0; a<selectedItemCount; ++a)
08162                      {
08163                             if (doc->m_Selection->itemAt(a)->locked())
08164                                    ++lockedCount;
08165                      }
08166                      int t=-1;
08167                      if (lockedCount!=0 && lockedCount!=selectedItemCount)
08168                      {
08169                             t = QMessageBox::warning(this, CommonStrings::trWarning,
08170                                                                              tr("Some objects are locked."),
08171                                                                              CommonStrings::tr_Cancel,
08172                                                                              tr("&Lock All"),
08173                                                                              tr("&Unlock All"), 0, 0);
08174                             if (t == 0)
08175                                    return; // user chose cancel -> do not group but return
08176                             for (uint a=0; a<selectedItemCount; ++a)
08177                             {
08178                                    currItem = doc->m_Selection->itemAt(a);
08179                                    if (currItem->locked())
08180                                    {
08181                                           for (uint c=0; c<selectedItemCount; ++c)
08182                                           {
08183                                                  bb = doc->m_Selection->itemAt(c);
08184                                                  bool t1=(t==1);
08185                                                  bb->setLocked(t1);
08186                                                  scrActions["itemLock"]->setOn(t1);
08187                                                  tooltip += "\t" + currItem->getUName() + "\n";
08188                                           }
08189                                    }
08190                             }
08191                      }
08192               }
08193               doc->m_Selection->getGroupRect(&x, &y, &w, &h);
08194               uint lowestItem = 999999;
08195               uint highestItem = 0;
08196               for (uint a=0; a<selectedItemCount; ++a)
08197               {
08198                      currItem = doc->m_Selection->itemAt(a);
08199                      currItem->gXpos = currItem->xPos() - x;
08200                      currItem->gYpos = currItem->yPos() - y;
08201                      currItem->gWidth = w;
08202                      currItem->gHeight = h;
08203                      lowestItem = QMIN(lowestItem, currItem->ItemNr);
08204                      highestItem = QMAX(highestItem, currItem->ItemNr);
08205               }
08206               double minx = 99999.9;
08207               double miny = 99999.9;
08208               double maxx = -99999.9;
08209               double maxy = -99999.9;
08210               for (uint ep = 0; ep < selectedItemCount; ++ep)
08211               {
08212                      PageItem* currItem = doc->m_Selection->itemAt(ep);
08213                      double lw = currItem->lineWidth() / 2.0;
08214                      if (currItem->rotation() != 0)
08215                      {
08216                             FPointArray pb;
08217                             pb.resize(0);
08218                             pb.addPoint(FPoint(currItem->xPos()-lw, currItem->yPos()-lw));
08219                             pb.addPoint(FPoint(currItem->width()+lw*2.0, -lw, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0));
08220                             pb.addPoint(FPoint(currItem->width()+lw*2.0, currItem->height()+lw*2.0, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0));
08221                             pb.addPoint(FPoint(-lw, currItem->height()+lw*2.0, currItem->xPos()-lw, currItem->yPos()-lw, currItem->rotation(), 1.0, 1.0));
08222                             for (uint pc = 0; pc < 4; ++pc)
08223                             {
08224                                    minx = QMIN(minx, pb.point(pc).x());
08225                                    miny = QMIN(miny, pb.point(pc).y());
08226                                    maxx = QMAX(maxx, pb.point(pc).x());
08227                                    maxy = QMAX(maxy, pb.point(pc).y());
08228                             }
08229                      }
08230                      else
08231                      {
08232                             minx = QMIN(minx, currItem->xPos()-lw);
08233                             miny = QMIN(miny, currItem->yPos()-lw);
08234                             maxx = QMAX(maxx, currItem->xPos()-lw + currItem->width()+lw*2.0);
08235                             maxy = QMAX(maxy, currItem->yPos()-lw + currItem->height()+lw*2.0);
08236                      }
08237               }
08238               double gx = minx;
08239               double gy = miny;
08240               double gw = maxx - minx;
08241               double gh = maxy - miny;
08242               PageItem *high = doc->Items->at(highestItem);
08243               undoManager->setUndoEnabled(false);
08244               int z = doc->itemAdd(PageItem::Polygon, PageItem::Rectangle, gx, gy, gw, gh, 0, doc->toolSettings.dBrush, doc->toolSettings.dPen, true);
08245               PageItem *neu = doc->Items->take(z);
08246               doc->Items->insert(lowestItem, neu);
08247               neu->setItemName( tr("Group%1").arg(doc->GroupCounter));
08248               neu->AutoName = false;
08249               neu->isGroupControl = true;
08250               neu->groupsLastItem = high;
08251               undoManager->setUndoEnabled(true);
08252 
08253               QMap<int, uint> ObjOrder;
08254               for (uint c = 0; c < selectedItemCount; ++c)
08255               {
08256                      currItem = doc->m_Selection->itemAt(c);
08257                      ObjOrder.insert(currItem->ItemNr, c);
08258                      int d = doc->Items->findRef(currItem);
08259                      doc->Items->take(d);
08260               }
08261               QValueList<uint> Oindex = ObjOrder.values();
08262               for (int c = static_cast<int>(Oindex.count()-1); c > -1; c--)
08263               {
08264                      doc->Items->insert(lowestItem+1, doc->m_Selection->itemAt(Oindex[c]));
08265               }
08266 
08267               doc->renumberItemsInListOrder();
08268               doc->m_Selection->prependItem(neu);
08269               selectedItemCount=doc->m_Selection->count();
08270               SimpleState *ss = new SimpleState(Um::Group, tooltip);
08271               ss->set("GROUP", "group");
08272               ss->set("itemcount", selectedItemCount);
08273 
08274               for (uint a=0; a<selectedItemCount; ++a)
08275               {
08276                      currItem = doc->m_Selection->itemAt(a);
08277                      currItem->Groups.push(doc->GroupCounter);
08278                      ss->set(QString("item%1").arg(a), currItem->uniqueNr);
08279               }
08280               doc->GroupCounter++;
08281               view->updateContents(QRect(static_cast<int>(x-5), static_cast<int>(y-5), static_cast<int>(w+10), static_cast<int>(h+10)));
08282               slotDocCh();
08283               scrActions["itemAttachTextToPath"]->setEnabled(false);
08284               scrActions["itemGroup"]->setEnabled(false);
08285               scrActions["itemUngroup"]->setEnabled(true);
08286               undoManager->action(this, ss, Um::SelectionGroup, Um::IGroup);
08287        }
08288 }
08289 
08290 //CB-->Doc
08291 void ScribusMainWindow::UnGroupObj()
08292 {
08293        if (HaveDoc)
08294        {
08295               if (doc->m_Selection->count() != 0)
08296               {
08297                      uint docSelectionCount=doc->m_Selection->count();
08298                      PageItem *currItem;
08299                      uint lowestItem = 999999;
08300                      for (uint a=0; a<docSelectionCount; ++a)
08301                      {
08302                             currItem = doc->m_Selection->itemAt(a);
08303                             if (currItem->Groups.count() != 0)
08304                                    currItem->Groups.pop();
08305                             lowestItem = QMIN(lowestItem, currItem->ItemNr);
08306                      }
08307                      if (doc->Items->at(lowestItem)->isGroupControl)
08308                      {
08309                             doc->m_Selection->removeItem(doc->Items->at(lowestItem));
08310                             doc->Items->remove(lowestItem);
08311                             doc->renumberItemsInListOrder();
08312                      }
08313                      docSelectionCount = doc->m_Selection->count();
08314                      SimpleState *ss = new SimpleState(Um::Ungroup);
08315                      ss->set("UNGROUP", "ungroup");
08316                      ss->set("itemcount", docSelectionCount);
08317                      QString tooltip = Um::ItemsInvolved + "\n";
08318                      slotDocCh();
08319                      HaveNewSel(doc->m_Selection->itemAt(0)->itemType());
08320                      doc->m_Selection->itemAt(0)->emitAllToGUI();
08321                      for (uint a=0; a<docSelectionCount; ++a)
08322                      {
08323                             currItem = doc->m_Selection->itemAt(a);
08324                             ss->set(QString("item%1").arg(a), currItem->uniqueNr);
08325                             ss->set(QString("tableitem%1").arg(a), currItem->isTableItem);
08326                             tooltip += "\t" + currItem->getUName() + "\n";
08327                             currItem->isTableItem = false;
08328                             currItem->setSelected(true);
08329                             currItem->paintObj();
08330                      }
08331                      undoManager->action(this, ss, Um::SelectionGroup, Um::IGroup);
08332               }
08333        }
08334 }
08335 
08336 void ScribusMainWindow::restore(UndoState* state, bool isUndo)
08337 {
08338        SimpleState *ss = dynamic_cast<SimpleState*>(state);
08339        if (ss)
08340        {
08341               if (ss->contains("GROUP"))
08342                      restoreGrouping(ss, isUndo);
08343               else if (ss->contains("UNGROUP"))
08344                      restoreUngrouping(ss, isUndo);
08345               else if (ss->contains("ADD_PAGE"))
08346                      restoreAddPage(ss, isUndo);
08347               else if (ss->contains("DELETE_PAGE"))
08348                      restoreDeletePage(ss, isUndo);
08349        }
08350 }
08351 
08352 void ScribusMainWindow::restoreDeletePage(SimpleState *state, bool isUndo)
08353 {
08354        uint pagenr   = state->getUInt("PAGENR");
08355        QStringList tmpl = state->get("MASTERPAGE");
08356        int where, wo;
08357        if (pagenr == 1)
08358        {
08359               where = 0;
08360               wo = 1;
08361        }
08362        else if (pagenr > doc->Pages->count())
08363        {
08364               where = 2;
08365               wo = doc->Pages->count();
08366        }
08367        else
08368        {
08369               where = 1;
08370               wo = pagenr - 1;
08371        }
08372        if (isUndo)
08373        {
08374               if (doc->masterPageMode())
08375               {
08376                      slotNewMasterPage(wo, tmpl[0]);
08377               }
08378               else
08379               {
08380                      addNewPages(wo, where, 1, doc->pageHeight, doc->pageWidth, doc->PageOri, doc->m_pageSize, true, &tmpl);
08381               }
08382               UndoObject *tmp =
08383                      undoManager->replaceObject(state->getUInt("DUMMY_ID"), doc->Pages->at(pagenr - 1));
08384               delete tmp;
08385        }
08386        else
08387        {
08388               DummyUndoObject *duo = new DummyUndoObject();
08389               uint id = static_cast<uint>(duo->getUId());
08390               undoManager->replaceObject(doc->Pages->at(pagenr - 1)->getUId(), duo);
08391               state->set("DUMMY_ID", id);
08392               DeletePage(pagenr, pagenr);
08393        }
08394 }
08395 
08396 void ScribusMainWindow::restoreAddPage(SimpleState *state, bool isUndo)
08397 {
08398        int wo    = state->getInt("PAGE");
08399        int where = state->getInt("WHERE");
08400        int count = state->getInt("COUNT");
08401        QStringList based = QStringList::split("|", state->get("BASED"));
08402        double height = state->getDouble("HEIGHT");
08403        double width = state->getDouble("WIDTH");
08404        int orient = state->getInt("ORIENT");
08405        QString siz = state->get("SIZE");
08406        bool mov = static_cast<bool>(state->getInt("MOVED"));
08407 
08408        int delFrom = 0;
08409        int delTo = 0;
08410        switch (where)
08411        {
08412               case 0:
08413                      delTo = wo + count - 1;
08414                      delFrom = delTo - count + 1;
08415                      break;
08416               case 1:
08417                      delFrom = wo + 1;
08418                      delTo = wo + count;
08419                      break;
08420               case 2:
08421                      delTo = doc->Pages->count();
08422                      delFrom = doc->Pages->count() - count + 1;
08423                      if (!isUndo)
08424                      {
08425                             delFrom += count;
08426                             delTo   += count;
08427                      }
08428                      break;
08429        }
08430        if (isUndo)
08431        {
08432               for (int i = delFrom - 1; i < delTo; ++i)
08433               {
08434                      DummyUndoObject *duo = new DummyUndoObject();
08435                      ulong did = duo->getUId();
08436                      undoManager->replaceObject(doc->Pages->at(i)->getUId(), duo);
08437                      state->set(QString("Page%1").arg(i), static_cast<uint>(did));
08438               }
08439               NoFrameEdit();
08440               view->Deselect(true);
08441               DeletePage(delFrom, delTo);
08442        }
08443        else
08444        {
08445               if (doc->masterPageMode())
08446               {
08447                      assert (count == 1);
08448                      slotNewMasterPage(wo, based[0]);
08449               }
08450               else
08451               {
08452                      addNewPages(wo, where, count, height, width, orient, siz, mov, &based);
08453               }
08454               for (int i = delFrom - 1; i < delTo; ++i)
08455               {
08456                      UndoObject *tmp = undoManager->replaceObject(
08457                                    state->getUInt(QString("Page%1").arg(i)), doc->Pages->at(i));
08458                      delete tmp;
08459               }
08460        }
08461 }
08462 
08463 void ScribusMainWindow::restoreGrouping(SimpleState *state, bool isUndo)
08464 {
08465        int itemCount = state->getInt("itemcount");
08466        view->Deselect();
08467        for (int i = 0; i < itemCount; ++i)
08468        {
08469               int itemNr = doc->getItemNrfromUniqueID(state->getUInt(QString("item%1").arg(i)));
08470               if (doc->Items->at(itemNr)->uniqueNr == state->getUInt(QString("item%1").arg(i)))
08471                      view->SelectItemNr(itemNr);
08472        }
08473        if (isUndo)
08474        {
08475               uint docSelectionCount=doc->m_Selection->count();
08476               PageItem *currItem;
08477               uint lowestItem = 999999;
08478               for (uint a=0; a<docSelectionCount; ++a)
08479               {
08480                      currItem = doc->m_Selection->itemAt(a);
08481                      lowestItem = QMIN(lowestItem, currItem->ItemNr);
08482               }
08483               if ((lowestItem > 0) && (doc->Items->at(lowestItem-1)->Groups.count() != 0))
08484               {
08485                      if (doc->Items->at(lowestItem-1)->Groups.top() == doc->m_Selection->itemAt(0)->Groups.top())
08486                      {
08487                             view->SelectItemNr(lowestItem-1);
08488                      }
08489               }
08490               UnGroupObj();
08491        }
08492        else
08493               GroupObj(false);
08494 }
08495 
08496 void ScribusMainWindow::restoreUngrouping(SimpleState *state, bool isUndo)
08497 {
08498        int itemCount = state->getInt("itemcount");
08499        view->Deselect();
08500        for (int i = 0; i < itemCount; ++i)
08501        {
08502               int itemNr = doc->getItemNrfromUniqueID(state->getUInt(QString("item%1").arg(i)));
08503               if (doc->Items->at(itemNr)->uniqueNr == state->getUInt(QString("item%1").arg(i)))
08504               {
08505                      if (isUndo)
08506                             doc->Items->at(itemNr)->isTableItem = static_cast<bool>(state->getInt(QString("tableitem%1").arg(i)));
08507                      view->SelectItemNr(itemNr);
08508               }
08509        }
08510        if (isUndo)
08511               GroupObj(false);
08512        else
08513        {
08514               uint docSelectionCount=doc->m_Selection->count();
08515               PageItem *currItem;
08516               uint lowestItem = 999999;
08517               for (uint a=0; a<docSelectionCount; ++a)
08518               {
08519                      currItem = doc->m_Selection->itemAt(a);
08520                      lowestItem = QMIN(lowestItem, currItem->ItemNr);
08521               }
08522               if ((lowestItem > 0) && (doc->Items->at(lowestItem-1)->Groups.count() != 0))
08523               {
08524                      if (doc->Items->at(lowestItem-1)->Groups.top() == doc->m_Selection->itemAt(0)->Groups.top())
08525                      {
08526                             view->SelectItemNr(lowestItem-1);
08527                      }
08528               }
08529               UnGroupObj();
08530        }
08531 }
08532 
08533 void ScribusMainWindow::StatusPic()
08534 {
08535        if (HaveDoc)
08536        {
08537               PicStatus *dia = new PicStatus(this, doc);
08538               connect(dia, SIGNAL(selectPage(int)), this, SLOT(selectPagesFromOutlines(int)));
08539               connect(dia, SIGNAL(selectMasterPage(QString)), this, SLOT(manageMasterPages(QString)));
08540               connect(dia, SIGNAL(selectElement(int, int, bool)), this, SLOT(selectItemsFromOutlines(int, int, bool)));
08541               connect(dia, SIGNAL(refreshItem(PageItem*)), view, SLOT(RefreshItem(PageItem*)));
08542               dia->exec();
08543               delete dia;
08544        }
08545 }
08546 
08547 QString ScribusMainWindow::CFileDialog(QString wDir, QString caption, QString filter, QString defNa,
08548                                 int optionFlags, bool *docom, bool *doFont, bool *doProfiles)
08549 {
08550        QString retval = "";
08551        // changed from "this" to qApp->activeWindow() to be sure it will be opened
08552        // with the current active window as parent. E.g. it won't hide StoryEditor etc. -- PV
08553        CustomFDialog *dia = new CustomFDialog