Back to index

scribus-ng  1.3.4.dfsg+svn20071115
newfile.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 #include "newfile.h"
00008 #include "newfile.moc"
00009 
00010 #include <qdir.h>
00011 #include <qtooltip.h>
00012 #include <qobjectlist.h>
00013 #include <qpoint.h>
00014 #include <qiconview.h>
00015 
00016 #include "fileloader.h"
00017 #include "prefsfile.h"
00018 #include "units.h"
00019 #include "pagesize.h"
00020 #include "marginWidget.h"
00021 #include "scconfig.h"
00022 #include "scribuscore.h"
00023 #include "prefsmanager.h"
00024 #include "pagelayout.h"
00025 #include "pagestructs.h"
00026 #include "commonstrings.h"
00027 #include "mspinbox.h"
00028 #include "customfdialog.h"
00029 #include "sccombobox.h"
00030 
00031 
00032 extern QPixmap loadIcon(QString nam);
00033 
00034 
00035 NewDoc::NewDoc( QWidget* parent, const QStringList& recentDocs, bool startUp ) : QDialog( parent, "newDoc", true, 0 )
00036 {
00037        prefsManager=PrefsManager::instance();
00038        tabSelected = 0;
00039        onStartup = startUp;
00040        unitIndex = prefsManager->appPrefs.docUnitIndex;
00041        unitSuffix = unitGetSuffixFromIndex(unitIndex);
00042        unitRatio = unitGetRatioFromIndex(unitIndex);
00043        precision = unitGetPrecisionFromIndex(unitIndex);
00044        Orient = 0;
00045        setCaption( tr( "New Document" ) );
00046        setIcon(loadIcon("AppIcon.png"));
00047        TabbedNewDocLayout = new QVBoxLayout( this, 10, 5, "Form1Layout");
00048        if (startUp)
00049               tabWidget = new QTabWidget( this, "tabWidget2" );
00050        createNewDocPage();
00051        if (startUp)
00052        {
00053               tabWidget->addTab(newDocFrame, tr("&New Document"));
00054               createOpenDocPage();
00055               tabWidget->addTab(openDocFrame, tr("Open &Existing Document"));
00056               recentDocList=recentDocs;
00057               createRecentDocPage();
00058               tabWidget->addTab(recentDocFrame, tr("Open Recent &Document"));
00059               TabbedNewDocLayout->addWidget(tabWidget);
00060        }
00061        else
00062               TabbedNewDocLayout->addWidget(newDocFrame);
00063 
00064        Layout1 = new QHBoxLayout;
00065        Layout1->setSpacing( 6 );
00066        Layout1->setMargin( 0 );
00067        if (startUp)
00068        {
00069               startUpDialog = new QCheckBox( tr( "Do not show this dialog again" ), this, "startUpDialog" );
00070               startUpDialog->setChecked(!prefsManager->appPrefs.showStartupDialog);
00071               Layout1->addWidget( startUpDialog );
00072        }
00073        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00074        Layout1->addItem( spacer );
00075        OKButton = new QPushButton( CommonStrings::tr_OK, this, "OKButton" );
00076        OKButton->setDefault( true );
00077        Layout1->addWidget( OKButton );
00078        CancelB = new QPushButton( CommonStrings::tr_Cancel, this, "CancelB" );
00079        CancelB->setAutoDefault( false );
00080        Layout1->addWidget( CancelB );
00081        TabbedNewDocLayout->addLayout( Layout1 );
00082        //tooltips
00083        QToolTip::add( pageSizeComboBox, tr( "Document page size, either a standard size or a custom size" ) );
00084        QToolTip::add( pageOrientationComboBox, tr( "Orientation of the document's pages" ) );
00085        QToolTip::add( widthMSpinBox, tr( "Width of the document's pages, editable if you have chosen a custom page size" ) );
00086        QToolTip::add( heightMSpinBox, tr( "Height of the document's pages, editable if you have chosen a custom page size" ) );
00087        QToolTip::add( pageCountSpinBox, tr( "Initial number of pages of the document" ) );
00088        QToolTip::add( unitOfMeasureComboBox, tr( "Default unit of measurement for document editing" ) );
00089        QToolTip::add( autoTextFrame, tr( "Create text frames automatically when new pages are added" ) );
00090        QToolTip::add( numberOfCols, tr( "Number of columns to create in automatically created text frames" ) );
00091        QToolTip::add( Distance, tr( "Distance between automatically created columns" ) );
00092 
00093        // signals and slots connections
00094        connect( OKButton, SIGNAL( clicked() ), this, SLOT( ExitOK() ) );
00095        connect( CancelB, SIGNAL( clicked() ), this, SLOT( reject() ) );
00096        connect(pageSizeComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPGsize(const QString &)));
00097        connect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int)));
00098        connect(unitOfMeasureComboBox, SIGNAL(activated(int)), this, SLOT(setUnit(int)));
00099        connect(Distance, SIGNAL(valueChanged(int)), this, SLOT(setDist(int)));
00100        connect(autoTextFrame, SIGNAL(clicked()), this, SLOT(handleAutoFrame()));
00101        connect(layoutsView, SIGNAL(clicked(QIconViewItem *)), this, SLOT(itemSelected(QIconViewItem* )));
00102        if (startUp)
00103               connect(recentDocListBox, SIGNAL(selected(int)), this, SLOT(recentDocListBox_doubleClicked(int)));
00104 
00105        setMinimumSize(minimumSizeHint());
00106        setMaximumSize(minimumSizeHint());
00107        resize(minimumSizeHint());
00108        clearWState( WState_Polished );
00109 }
00110 
00111 void NewDoc::createNewDocPage()
00112 {
00113        newDocFrame = new QFrame(this, "newDocFrame");
00114 
00115        pageSizeGroupBox = new QGroupBox(newDocFrame, "pageSizeGroupBox" );
00116        pageSizeGroupBox->setTitle( tr( "Document Layout" ) );
00117        pageSizeGroupBox->setColumnLayout(0, Qt::Vertical );
00118        pageSizeGroupBox->layout()->setSpacing( 5 );
00119        pageSizeGroupBox->layout()->setMargin( 10 );
00120        pageSizeGroupBoxLayout = new QGridLayout( pageSizeGroupBox->layout() );
00121        pageSizeGroupBoxLayout->setAlignment( Qt::AlignTop );
00122 
00123        layoutsView = new QIconView( pageSizeGroupBox, "layoutsView" );
00124        layoutsView->setHScrollBarMode( QIconView::Auto );
00125        layoutsView->setVScrollBarMode( QIconView::Auto );
00126        layoutsView->setArrangement(QIconView::LeftToRight);
00127        layoutsView->setItemsMovable(false);
00128        layoutsView->setSorting( false );
00129        layoutsView->setFocusPolicy(QWidget::NoFocus);
00130        layoutsView->setSelectionMode(QIconView::Single);
00131        layoutsView->clear();
00132        for (uint pg = 0; pg < prefsManager->appPrefs.pageSets.count(); ++pg)
00133        {
00134               QIconViewItem *ic;
00135               QString psname=CommonStrings::translatePageSetString(prefsManager->appPrefs.pageSets[pg].Name);
00136               if (pg == 0)
00137               {
00138                      ic = new QIconViewItem( layoutsView, psname, loadIcon("32/page-simple.png") );
00139                      ic->setDragEnabled(false);
00140               }
00141               else if (pg == 1)
00142               {
00143                      ic = new QIconViewItem( layoutsView, psname, loadIcon("32/page-doublesided.png") );
00144                      ic->setDragEnabled(false);
00145               }
00146               else if (pg == 2)
00147               {
00148                      ic = new QIconViewItem( layoutsView, psname, loadIcon("32/page-3fold.png") );
00149                      ic->setDragEnabled(false);
00150               }
00151               else if (pg == 3)
00152               {
00153                      ic = new QIconViewItem( layoutsView, psname, loadIcon("32/page-4fold.png") );
00154                      ic->setDragEnabled(false);
00155               }
00156               else
00157               {
00158                      ic = new QIconViewItem( layoutsView, psname, loadIcon("32/page-simple.png") );
00159                      ic->setDragEnabled(false);
00160               }
00161        }
00162        pageSizeGroupBoxLayout->addMultiCellWidget( layoutsView, 0, 4, 0, 0 );
00163 
00164 
00165        TextLabel1 = new QLabel( tr( "&Size:" ), pageSizeGroupBox, "TextLabel1" );
00166        pageSizeGroupBoxLayout->addWidget( TextLabel1, 0, 1 );
00167        PageSize ps(prefsManager->appPrefs.pageSize);
00168        pageSizeComboBox = new QComboBox( true, pageSizeGroupBox, "pageSizeComboBox" );
00169        pageSizeComboBox->insertStringList(ps.sizeTRList());
00170        pageSizeComboBox->insertItem( CommonStrings::trCustomPageSize );
00171        pageSizeComboBox->setEditable(false);
00172        TextLabel1->setBuddy(pageSizeComboBox);
00173        pageSizeGroupBoxLayout->addWidget(pageSizeComboBox, 0, 2 );
00174        TextLabel2 = new QLabel( tr( "Orie&ntation:" ), pageSizeGroupBox, "TextLabel2" );
00175        pageSizeGroupBoxLayout->addWidget( TextLabel2, 1, 1 );
00176        pageOrientationComboBox = new QComboBox( true, pageSizeGroupBox, "pageOrientationComboBox" );
00177        pageOrientationComboBox->insertItem( tr( "Portrait" ) );
00178        pageOrientationComboBox->insertItem( tr( "Landscape" ) );
00179        pageOrientationComboBox->setEditable(false);
00180        pageOrientationComboBox->setCurrentItem(prefsManager->appPrefs.pageOrientation);
00181        TextLabel2->setBuddy(pageOrientationComboBox);
00182        pageSizeGroupBoxLayout->addWidget( pageOrientationComboBox, 1, 2 );
00183 
00184        TextLabel1_2 = new QLabel( tr( "&Width:" ), pageSizeGroupBox, "TextLabel1_2" );
00185        pageSizeGroupBoxLayout->addWidget(TextLabel1_2, 2, 1 );
00186        widthMSpinBox = new MSpinBox( 1, 10000, pageSizeGroupBox, precision );
00187        widthMSpinBox->setSuffix(unitSuffix);
00188        TextLabel1_2->setBuddy(widthMSpinBox);
00189        pageSizeGroupBoxLayout->addWidget(widthMSpinBox, 2, 2 );
00190        TextLabel2_2 = new QLabel( tr( "&Height:" ), pageSizeGroupBox, "TextLabel2_2" );
00191        pageSizeGroupBoxLayout->addWidget(TextLabel2_2, 3, 1 );
00192        heightMSpinBox = new MSpinBox( 1, 10000, pageSizeGroupBox, precision );
00193        heightMSpinBox->setSuffix(unitSuffix);
00194        TextLabel2_2->setBuddy(heightMSpinBox);
00195        pageSizeGroupBoxLayout->addWidget(heightMSpinBox, 3, 2 );
00196        layoutLabel1 = new QLabel( pageSizeGroupBox, "layoutLabel1" );
00197        layoutLabel1->setText( tr( "First Page is:" ) );
00198        pageSizeGroupBoxLayout->addWidget( layoutLabel1, 4, 1 );
00199        firstPage = new ScComboBox( false, pageSizeGroupBox, "firstPage" );
00200        firstPage->clear();
00201        pageSizeGroupBoxLayout->addWidget( firstPage, 4, 2 );
00202        selectItem(prefsManager->appPrefs.FacingPages);
00203        firstPage->setCurrentItem(prefsManager->appPrefs.pageSets[prefsManager->appPrefs.FacingPages].FirstPage);
00204 
00205        MarginStruct marg(prefsManager->appPrefs.margins);
00206        marginGroup = new MarginWidget(newDocFrame,  tr( "Margin Guides" ), &marg, unitIndex );
00207        marginGroup->setPageWidthHeight(prefsManager->appPrefs.PageWidth, prefsManager->appPrefs.PageHeight);
00208        marginGroup->setFacingPages(!(prefsManager->appPrefs.FacingPages == singlePage));
00209        widthMSpinBox->setValue(prefsManager->appPrefs.PageWidth * unitRatio);
00210        heightMSpinBox->setValue(prefsManager->appPrefs.PageHeight * unitRatio);
00211        QStringList pageSizes=ps.sizeList();
00212        int sizeIndex=pageSizes.findIndex(ps.nameTR());
00213        if (sizeIndex!=-1)
00214               pageSizeComboBox->setCurrentItem(sizeIndex);
00215        else
00216               pageSizeComboBox->setCurrentItem(pageSizeComboBox->count()-1);
00217        marginGroup->setPageSize(pageSizeComboBox->currentText());
00218        setDS(prefsManager->appPrefs.FacingPages);
00219        setSize(prefsManager->appPrefs.pageSize);
00220        setOrien(prefsManager->appPrefs.pageOrientation);
00221        widthMSpinBox->setValue(prefsManager->appPrefs.PageWidth * unitRatio);
00222        heightMSpinBox->setValue(prefsManager->appPrefs.PageHeight * unitRatio);
00223        marginGroup->setNewBleeds(prefsManager->appPrefs.bleeds);
00224 
00225        optionsGroupBox = new QGroupBox( newDocFrame, "optionsGroupBox" );
00226        optionsGroupBox->setTitle( tr( "Options" ) );
00227        optionsGroupBox->setColumnLayout(0, Qt::Vertical );
00228        optionsGroupBox->layout()->setSpacing( 5 );
00229        optionsGroupBox->layout()->setMargin( 10 );
00230        optionsGroupBoxLayout = new QGridLayout( optionsGroupBox->layout() );
00231        optionsGroupBoxLayout->setAlignment( Qt::AlignTop );
00232        pageCountLabel = new QLabel( tr( "N&umber of Pages:" ), optionsGroupBox, "pageCountLabel" );
00233 
00234        pageCountSpinBox = new QSpinBox( optionsGroupBox, "pageCountSpinBox" );
00235        pageCountSpinBox->setMaxValue( 10000 );
00236        pageCountSpinBox->setMinValue( 1 );
00237        pageCountLabel->setBuddy(pageCountSpinBox);
00238        unitOfMeasureLabel = new QLabel( tr( "&Default Unit:" ), optionsGroupBox, "unitOfMeasureLabel" );
00239        unitOfMeasureComboBox = new QComboBox( true, optionsGroupBox, "unitOfMeasureComboBox" );
00240        unitOfMeasureComboBox->insertStringList(unitGetTextUnitList());
00241        unitOfMeasureComboBox->setCurrentItem(unitIndex);
00242        unitOfMeasureComboBox->setEditable(false);
00243        unitOfMeasureLabel->setBuddy(unitOfMeasureComboBox);
00244        optionsGroupBoxLayout->addWidget( pageCountLabel, 0, 0 );
00245        optionsGroupBoxLayout->addWidget( pageCountSpinBox, 0, 1 );
00246        optionsGroupBoxLayout->addWidget( unitOfMeasureLabel, 1, 0 );
00247        optionsGroupBoxLayout->addWidget( unitOfMeasureComboBox, 1, 1 );
00248 
00249        autoTextFrame = new QCheckBox( optionsGroupBox, "autoTextFrame" );
00250        autoTextFrame->setText( tr( "&Automatic Text Frames" ) );
00251        optionsGroupBoxLayout->addMultiCellWidget( autoTextFrame, 2, 2, 0, 1 );
00252        TextLabel3 = new QLabel( tr( "Colu&mns:" ), optionsGroupBox, "TextLabel3" );
00253        optionsGroupBoxLayout->addWidget( TextLabel3, 3, 0 );
00254        numberOfCols = new QSpinBox( optionsGroupBox, "numberOfCols" );
00255        numberOfCols->setButtonSymbols( QSpinBox::UpDownArrows );
00256        numberOfCols->setMinValue( 1 );
00257        numberOfCols->setValue( 1 );
00258        TextLabel3->setBuddy(numberOfCols);
00259        optionsGroupBoxLayout->addWidget( numberOfCols, 3, 1);
00260 
00261        TextLabel4 = new QLabel( tr( "&Gap:" ), optionsGroupBox, "TextLabel4" );
00262        optionsGroupBoxLayout->addWidget( TextLabel4, 4, 0 );
00263        Distance = new MSpinBox( 0, 1000, optionsGroupBox, precision );
00264        Distance->setSuffix( unitSuffix );
00265        Distance->setValue(11 * unitRatio);
00266        Dist = 11;
00267        optionsGroupBoxLayout->addWidget( Distance, 4, 1);
00268        TextLabel4->setBuddy(Distance);
00269 
00270        TextLabel3->setEnabled(false);
00271        TextLabel4->setEnabled(false);
00272        Distance->setEnabled(false);
00273        numberOfCols->setEnabled(false);
00274        startDocSetup = new QCheckBox( optionsGroupBox, "startDocSetup" );
00275        startDocSetup->setText( tr( "Show Document Settings After Creation" ) );
00276        startDocSetup->setChecked(false);
00277        optionsGroupBoxLayout->addMultiCellWidget( startDocSetup, 5, 5, 0, 1 );
00278 
00279        NewDocLayout = new QGridLayout( newDocFrame, 2, 2, 10, 5, "NewDocLayout");
00280        NewDocLayout->addWidget( marginGroup, 1, 0 );
00281        NewDocLayout->addWidget( optionsGroupBox, 1, 1 );
00282        NewDocLayout->addMultiCellWidget( pageSizeGroupBox, 0, 0, 0, 1);
00283 }
00284 
00285 void NewDoc::createOpenDocPage()
00286 {
00287        PrefsContext* docContext = prefsManager->prefsFile->getContext("docdirs", false);
00288        QString docDir = ".";
00289        QString prefsDocDir=prefsManager->documentDir();
00290        if (!prefsDocDir.isEmpty())
00291               docDir = docContext->get("docsopen", prefsDocDir);
00292        else
00293               docDir = docContext->get("docsopen", ".");
00294        QString formats(FileLoader::getLoadFilterString());
00295        openDocFrame = new QFrame(this, "openDocFrame");
00296        QVBoxLayout* openDocLayout = new QVBoxLayout(openDocFrame, 5,5, "openDocLayout");
00297        fileDialog = new CustomFDialog(openDocFrame, docDir, tr("Open"), formats, fdNone);
00298        fileDialog->setSizeGripEnabled(false);
00299        fileDialog->setModal(false);
00300        QObjectList *l = fileDialog->queryList("QPushButton");
00301        QObjectListIt it(*l);
00302        QObject *obj;
00303        while ((obj = it.current()) != 0)
00304        {
00305               ++it;
00306               ((QPushButton*)obj)->hide();
00307        }
00308        delete l;
00309        QPoint point = QPoint(0,0);
00310        fileDialog->reparent(openDocFrame, point);
00311        openDocLayout->addWidget(fileDialog);
00312        connect(fileDialog, SIGNAL(fileSelected ( const QString & )), this, SLOT(openFile(const QString& )));
00313 }
00314 
00315 void NewDoc::openFile(const QString &)
00316 {
00317        ExitOK();
00318 }
00319 
00320 void NewDoc::createRecentDocPage()
00321 {
00322        recentDocFrame = new QFrame(this, "recentDocFrame");
00323        recentDocLayout = new QVBoxLayout(recentDocFrame, 5, 5, "recentDocLayout");
00324        recentDocListBox = new QListBox(recentDocFrame, "recentDocListBox");
00325        recentDocLayout->addWidget(recentDocListBox);
00326        uint max = QMIN(prefsManager->appPrefs.RecentDCount, recentDocList.count());
00327        for (uint m = 0; m < max; ++m)
00328               recentDocListBox->insertItem( QDir::convertSeparators(recentDocList[m]) );
00329 }
00330 
00331 void NewDoc::setWidth(int)
00332 {
00333        pageWidth = widthMSpinBox->value() / unitRatio;
00334        marginGroup->setPageWidth(pageWidth);
00335        QString psText=pageSizeComboBox->currentText();
00336        if (psText!=CommonStrings::trCustomPageSize && psText!=CommonStrings::customPageSize)
00337               pageSizeComboBox->setCurrentItem(pageSizeComboBox->count()-1);
00338 }
00339 
00340 void NewDoc::setHeight(int)
00341 {
00342        pageHeight = heightMSpinBox->value() / unitRatio;
00343        marginGroup->setPageHeight(pageHeight);
00344        QString psText=pageSizeComboBox->currentText();
00345        if (psText!=CommonStrings::trCustomPageSize && psText!=CommonStrings::customPageSize)
00346               pageSizeComboBox->setCurrentItem(pageSizeComboBox->count()-1);
00347 }
00348 
00349 void NewDoc::selectItem(uint nr)
00350 {
00351        QIconViewItem* ic=0;
00352        uint cce;
00353        disconnect(layoutsView, SIGNAL(clicked(QIconViewItem *)), this, SLOT(itemSelected(QIconViewItem* )));
00354        ic = layoutsView->firstItem();
00355        cce = layoutsView->count();
00356        for (uint cc = 0; cc < cce; ++cc)
00357        {
00358               if (cc == nr)
00359               {
00360                      if (cc > 0)
00361                      {
00362                             firstPage->setEnabled(true);
00363                             firstPage->clear();
00364                             QStringList::Iterator pNames;
00365                             for(pNames = prefsManager->appPrefs.pageSets[cc].pageNames.begin(); pNames != prefsManager->appPrefs.pageSets[cc].pageNames.end(); ++pNames )
00366                             {
00367                                    firstPage->insertItem(CommonStrings::translatePageSetLocString((*pNames)));
00368                             }
00369                      }
00370                      else
00371                      {
00372                             firstPage->clear();
00373                             firstPage->insertItem(" ");
00374                             firstPage->setEnabled(false);
00375                      }
00376                      layoutsView->setSelected(ic, true);
00377                      break;
00378               }
00379               ic = ic->nextItem();
00380        }
00381        connect(layoutsView, SIGNAL(clicked(QIconViewItem *)), this, SLOT(itemSelected(QIconViewItem* )));
00382 }
00383 
00384 void NewDoc::itemSelected(QIconViewItem* ic)
00385 {
00386        if (ic == 0)
00387               return;
00388        selectItem(layoutsView->index(ic));
00389        setDS(layoutsView->index(ic));
00390 }
00391 
00392 void NewDoc::handleAutoFrame()
00393 {
00394        if (autoTextFrame->isChecked())
00395        {
00396               TextLabel3->setEnabled(true);
00397               TextLabel4->setEnabled(true);
00398               Distance->setEnabled(true);
00399               numberOfCols->setEnabled(true);
00400        }
00401        else
00402        {
00403               TextLabel3->setEnabled(false);
00404               TextLabel4->setEnabled(false);
00405               Distance->setEnabled(false);
00406               numberOfCols->setEnabled(false);
00407        }
00408 }
00409 
00410 void NewDoc::setDist(int)
00411 {
00412        Dist = Distance->value() / unitRatio;
00413 }
00414 
00415 void NewDoc::setUnit(int newUnitIndex)
00416 {
00417        disconnect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setWidth(int)));
00418        disconnect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int)));
00419 
00420        double oldUnitRatio = unitRatio;
00421        double val, oldB, oldBM, oldH, oldHM;
00422        int decimals;
00423        widthMSpinBox->getValues(&oldB, &oldBM, &decimals, &val);
00424        oldB /= oldUnitRatio;
00425        oldBM /= oldUnitRatio;
00426        heightMSpinBox->getValues(&oldH, &oldHM, &decimals, &val);
00427        oldH /= oldUnitRatio;
00428        oldHM /= oldUnitRatio;
00429 
00430        unitIndex = newUnitIndex;
00431        unitRatio = unitGetRatioFromIndex(newUnitIndex);
00432        decimals = unitGetDecimalsFromIndex(newUnitIndex);
00433        if (pageOrientationComboBox->currentItem() == portraitPage)
00434        {
00435               widthMSpinBox->setValues(oldB * unitRatio, oldBM * unitRatio, decimals, pageWidth * unitRatio);
00436               heightMSpinBox->setValues(oldH * unitRatio, oldHM * unitRatio, decimals, pageHeight * unitRatio);
00437        }
00438        else
00439        {
00440               widthMSpinBox->setValues(oldB * unitRatio, oldBM * unitRatio, decimals, pageHeight * unitRatio);
00441               heightMSpinBox->setValues(oldH * unitRatio, oldHM * unitRatio, decimals, pageWidth * unitRatio);
00442        }
00443        Distance->setValue(Dist * unitRatio);
00444        unitSuffix = unitGetSuffixFromIndex(newUnitIndex);
00445        widthMSpinBox->setSuffix(unitSuffix);
00446        heightMSpinBox->setSuffix(unitSuffix);
00447        Distance->setSuffix( unitSuffix );
00448        marginGroup->unitChange(unitRatio, decimals, unitSuffix);
00449        marginGroup->setPageHeight(pageHeight);
00450        marginGroup->setPageWidth(pageWidth);
00451        connect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setWidth(int)));
00452        connect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int)));
00453 
00454 }
00455 
00456 void NewDoc::ExitOK()
00457 {
00458        pageWidth = widthMSpinBox->value() / unitRatio;
00459        pageHeight = heightMSpinBox->value() / unitRatio;
00460        bleedBottom = marginGroup->bottomBleed();
00461        bleedTop = marginGroup->topBleed();
00462        bleedLeft = marginGroup->leftBleed();
00463        bleedRight = marginGroup->rightBleed();
00464        if (onStartup)
00465               tabSelected = tabWidget->currentPageIndex();
00466        else
00467               tabSelected = 0;
00468        accept();
00469 }
00470 
00471 void NewDoc::setOrien(int ori)
00472 {
00473        double br;
00474        disconnect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setWidth(int)));
00475        disconnect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int)));
00476        if (ori != Orient)
00477        {
00478               br = widthMSpinBox->value();
00479               widthMSpinBox->setValue(heightMSpinBox->value());
00480               heightMSpinBox->setValue(br);
00481        }
00482        // #869 pv - defined constants added + code repeat (check w/h)
00483        (ori == portraitPage) ? Orient = portraitPage : Orient = landscapePage;
00484        if (pageSizeComboBox->currentText() == CommonStrings::trCustomPageSize)
00485        {
00486               if (widthMSpinBox->value() > heightMSpinBox->value())
00487                      pageOrientationComboBox->setCurrentItem(landscapePage);
00488               else
00489                      pageOrientationComboBox->setCurrentItem(portraitPage);
00490        }
00491        // end of #869
00492        marginGroup->setPageHeight(pageHeight);
00493        marginGroup->setPageWidth(pageWidth);
00494        connect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setWidth(int)));
00495        connect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int)));
00496 }
00497 
00498 void NewDoc::setPGsize(const QString &size)
00499 {
00500        if (size == CommonStrings::trCustomPageSize)
00501               setSize(size);
00502        else
00503        {
00504               setSize(size);
00505               setOrien(pageOrientationComboBox->currentItem());
00506        }
00507        marginGroup->setPageSize(size);
00508 }
00509 
00510 void NewDoc::setSize(QString gr)
00511 {
00512        pageWidth = widthMSpinBox->value() / unitRatio;
00513        pageHeight = heightMSpinBox->value() / unitRatio;
00514 
00515        disconnect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setWidth(int)));
00516        disconnect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int)));
00517        if (gr==CommonStrings::trCustomPageSize || gr==CommonStrings::customPageSize)
00518        {
00519               //widthMSpinBox->setEnabled(true);
00520               //heightMSpinBox->setEnabled(true);
00521        }
00522        else
00523        {
00524               PageSize *ps2=new PageSize(gr);
00525               if (pageOrientationComboBox->currentItem() == portraitPage)
00526               {
00527                      pageWidth = ps2->width();
00528                      pageHeight = ps2->height();
00529               } else {
00530                      pageWidth = ps2->height();
00531                      pageHeight = ps2->width();
00532               }
00533               delete ps2;
00534        }
00535        widthMSpinBox->setValue(pageWidth * unitRatio);
00536        heightMSpinBox->setValue(pageHeight * unitRatio);
00537        marginGroup->setPageHeight(pageHeight);
00538        marginGroup->setPageWidth(pageWidth);
00539        connect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setWidth(int)));
00540        connect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setHeight(int)));
00541 }
00542 
00543 void NewDoc::setDS(int layout)
00544 {
00545        marginGroup->setFacingPages(!(layout == singlePage));
00546        choosenLayout = layout;
00547        firstPage->setCurrentItem(prefsManager->appPrefs.pageSets[choosenLayout].FirstPage);
00548 }
00549 
00550 void NewDoc::recentDocListBox_doubleClicked(int /*item*/)
00551 {
00552        /* Yep. There is nothing to solve. ScribusMainWindow handles all
00553        openings etc. It's Franz's programming style ;) */
00554        ExitOK();
00555 }