Back to index

scribus-ng  1.3.4.dfsg+svn20071115
inspage.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 <qdialog.h>
00008 #include <qcombobox.h>
00009 #include <qlayout.h>
00010 #include <qlabel.h>
00011 #include <qpushbutton.h>
00012 #include <qgroupbox.h>
00013 #include <qcheckbox.h>
00014 #include <qspinbox.h>
00015 #include "scribusdoc.h"
00016 
00017 #include "inspage.h"
00018 #include "inspage.moc"
00019 #include "page.h"
00020 #include "units.h"
00021 #include "mspinbox.h"
00022 #include "pagesize.h"
00023 #include "commonstrings.h"
00024 
00025 extern QPixmap loadIcon(QString nam);
00026 
00027 InsPage::InsPage( QWidget* parent, ScribusDoc* currentDoc, int currentPage, int maxPages)
00028               : QDialog( parent, "InsPage", true, 0 )
00029 {
00030        masterPageCombos.clear();
00031        setCaption( tr( "Insert Page" ) );
00032        setIcon(loadIcon("AppIcon.png"));
00033        dialogLayout = new QVBoxLayout( this, 5, 5 );
00034        whereLayout = new QGridLayout;
00035        whereLayout->setSpacing( 5 );
00036        whereLayout->setMargin( 5 );
00037        insCountData = new QSpinBox( 1, 999, 1, this, "insCountData" );
00038        insCountData->setValue( 1 );
00039        insCountLabel = new QLabel( insCountData, tr( "&Insert" ), this, "insCountLabel" );
00040        whereLayout->addWidget( insCountLabel, 0, 0 );
00041        whereLayout->addWidget( insCountData, 0, 1 );
00042        pagesLabel = new QLabel( tr( "Page(s)" ), this, "pagesLabel" );
00043        whereLayout->addWidget( pagesLabel, 0, 2 );
00044 
00045        insWhereData = new QComboBox( false, this, "insWhereData" );
00046        insWhereData->insertItem( tr("before Page"));
00047        insWhereData->insertItem( tr("after Page"));
00048        insWhereData->insertItem( tr("at End"));
00049        insWhereData->setCurrentItem(2);
00050        whereLayout->addMultiCellWidget( insWhereData, 1, 1, 0, 1 );
00051 
00052        insWherePageData = new QSpinBox( 1, maxPages, 1, this, "insWherePageData" );
00053        insWherePageData->setValue( currentPage+1 );
00054        insWherePageData->setDisabled( true );
00055 
00056        whereLayout->addWidget( insWherePageData, 1, 2 );
00057 
00058        whereLayout->addColSpacing(0, insCountLabel->fontMetrics().width( tr( "&Insert" )));
00059        dialogLayout->addLayout( whereLayout );
00060        
00061        masterPageGroup = new QGroupBox( this, "masterPageGroup" );
00062        masterPageGroup->setTitle( tr( "Master Pages" ) );
00063        masterPageGroup->setColumnLayout(0, Qt::Vertical );
00064        masterPageGroup->layout()->setSpacing( 0 );
00065        masterPageGroup->layout()->setMargin( 0 );
00066        masterPageLayout = new QGridLayout( masterPageGroup->layout() );
00067        masterPageLayout->setAlignment( Qt::AlignTop );
00068        masterPageLayout->setSpacing( 5 );
00069        masterPageLayout->setMargin( 5 );
00070        if (currentDoc->currentPageLayout == 0)
00071        {
00072               QComboBox* pageData = new QComboBox(false, masterPageGroup, "masterPageData");
00073               for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
00074                      pageData->insertItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key());
00075               masterPageLabel = new QLabel(pageData,  tr("&Master Page:"), masterPageGroup, "text");
00076               masterPageLayout->addWidget( masterPageLabel, 0, 0 );
00077               masterPageLayout->addWidget(pageData, 0, 1);
00078               masterPageCombos.append(pageData);
00079        }
00080        else
00081        {
00082               int row = 0;
00083               for (uint mp = 0; mp < currentDoc->pageSets[currentDoc->currentPageLayout].pageNames.count(); ++mp)
00084               {
00085                      QComboBox* pageData = new QComboBox(false, masterPageGroup, "pageData");
00086 //                   for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
00087 //                          pageData->insertItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key());
00088                      if (mp == 0)
00089                      {
00090                             bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalLeft);
00091                             for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
00092                             {
00093                                    if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
00094                                           pageData->insertItem(CommonStrings::trMasterPageNormal);
00095                                    else
00096                                    {
00097                                           if (currentDoc->MasterPages.at(it.data())->LeftPg == 1)
00098                                                  pageData->insertItem(it.key());
00099                                    }
00100                             }
00101                             if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalLeft))
00102                                    pageData->setCurrentText( CommonStrings::trMasterPageNormalLeft);
00103                      }
00104                      else if (mp == 1)
00105                      {
00106                             if (currentDoc->pageSets[currentDoc->currentPageLayout].pageNames.count() > 2)
00107                             {
00108                                    bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle);
00109                                    for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
00110                                    {
00111                                           if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
00112                                                  pageData->insertItem(CommonStrings::trMasterPageNormal);
00113                                           else
00114                                           {
00115                                                  if ((currentDoc->MasterPages.at(it.data())->LeftPg != 0) && (currentDoc->MasterPages.at(it.data())->LeftPg != 1))
00116                                                         pageData->insertItem(it.key());
00117                                           }
00118                                    }
00119                                    if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle))
00120                                           pageData->setCurrentText( CommonStrings::trMasterPageNormalMiddle);
00121                             }
00122                             else
00123                             {
00124                                    bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
00125                                    for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
00126                                    {
00127                                           if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
00128                                                  pageData->insertItem(CommonStrings::trMasterPageNormal);
00129                                           else
00130                                           {
00131                                                  if (currentDoc->MasterPages.at(it.data())->LeftPg == 0)
00132                                                         pageData->insertItem(it.key());
00133                                           }
00134                                    }
00135                                    if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
00136                                           pageData->setCurrentText( CommonStrings::trMasterPageNormalRight);
00137                             }
00138                      }
00139                      else if (mp == 2)
00140                      {
00141                             if (currentDoc->pageSets[currentDoc->currentPageLayout].pageNames.count() > 3)
00142                             {
00143                                    bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle);
00144                                    for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
00145                                    {
00146                                           if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
00147                                                  pageData->insertItem(CommonStrings::trMasterPageNormal);
00148                                           else
00149                                           {
00150                                                  if ((currentDoc->MasterPages.at(it.data())->LeftPg != 0) && (currentDoc->MasterPages.at(it.data())->LeftPg != 1))
00151                                                         pageData->insertItem(it.key());
00152                                           }
00153                                    }
00154                                    if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle))
00155                                           pageData->setCurrentText( CommonStrings::trMasterPageNormalMiddle);
00156                             }
00157                             else
00158                             {
00159                                    bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
00160                                    for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
00161                                    {
00162                                           if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
00163                                                  pageData->insertItem(CommonStrings::trMasterPageNormal);
00164                                           else
00165                                           {
00166                                                  if (currentDoc->MasterPages.at(it.data())->LeftPg == 0)
00167                                                         pageData->insertItem(it.key());
00168                                           }
00169                                    }
00170                                    if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
00171                                           pageData->setCurrentText( CommonStrings::trMasterPageNormalRight);
00172                             }
00173                      }
00174                      else if (mp == 3)
00175                      {
00176                             bool conNam = currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
00177                             for (QMap<QString,int>::Iterator it = currentDoc->MasterNames.begin(); it != currentDoc->MasterNames.end(); ++it)
00178                             {
00179                                    if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
00180                                           pageData->insertItem(CommonStrings::trMasterPageNormal);
00181                                    else
00182                                    {
00183                                           if (currentDoc->MasterPages.at(it.data())->LeftPg == 0)
00184                                                  pageData->insertItem(it.key());
00185                                    }
00186                             }
00187                             if (currentDoc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
00188                                    pageData->setCurrentText( CommonStrings::trMasterPageNormalRight);
00189                      }
00190                      QString transLabel = currentDoc->pageSets[currentDoc->currentPageLayout].pageNames[mp];
00191                      QLabel* pageLabel = new QLabel(pageData,  CommonStrings::translatePageSetLocString(transLabel), masterPageGroup, "text");
00192                      masterPageLayout->addWidget(pageLabel, row, 0 );
00193                      masterPageLayout->addWidget(pageData, row, 1);
00194                      row++;
00195                      masterPageCombos.append(pageData);
00196               }
00197        }
00198        dialogLayout->addWidget(masterPageGroup);
00199 
00200        dsGroupBox7 = new QGroupBox( this, "GroupBox7" );
00201        dsGroupBox7->setTitle( tr( "Page Size" ) );
00202        dsGroupBox7->setColumnLayout(0, Qt::Vertical );
00203        dsGroupBox7->layout()->setSpacing( 0 );
00204        dsGroupBox7->layout()->setMargin( 0 );
00205        dsGroupBox7Layout = new QGridLayout( dsGroupBox7->layout() );
00206        dsGroupBox7Layout->setAlignment( Qt::AlignTop );
00207        dsGroupBox7Layout->setSpacing( 5 );
00208        dsGroupBox7Layout->setMargin( 5 );
00209        TextLabel1 = new QLabel( tr( "&Size:" ), dsGroupBox7, "TextLabel1" );
00210        dsGroupBox7Layout->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 );
00211        PageSize *ps=new PageSize(currentDoc->m_pageSize);
00212        sizeQComboBox = new QComboBox( true, dsGroupBox7, "ComboBox1" );
00213        sizeQComboBox->setEditable(false);
00214        QStringList pageSizes=ps->sizeList();
00215        sizeQComboBox->insertStringList(ps->sizeTRList());
00216        sizeQComboBox->insertItem(CommonStrings::trCustomPageSize);
00217        prefsPageSizeName=ps->name();
00218        int sizeIndex = pageSizes.findIndex(ps->nameTR());
00219        if (sizeIndex != -1)
00220               sizeQComboBox->setCurrentItem(sizeIndex);
00221        else
00222               sizeQComboBox->setCurrentItem(sizeQComboBox->count()-1);
00223        TextLabel1->setBuddy(sizeQComboBox);
00224        dsGroupBox7Layout->addMultiCellWidget(sizeQComboBox, 0, 0, 2, 3);
00225        TextLabel2 = new QLabel( tr( "Orie&ntation:" ), dsGroupBox7, "TextLabel2" );
00226        dsGroupBox7Layout->addMultiCellWidget( TextLabel2, 1, 1, 0, 1 );
00227        orientationQComboBox = new QComboBox( true, dsGroupBox7, "ComboBox2" );
00228        orientationQComboBox->insertItem( tr( "Portrait" ) );
00229        orientationQComboBox->insertItem( tr( "Landscape" ) );
00230        orientationQComboBox->setEditable(false);
00231        orientationQComboBox->setCurrentItem(currentDoc->PageOri );
00232        TextLabel2->setBuddy(orientationQComboBox);
00233        dsGroupBox7Layout->addMultiCellWidget( orientationQComboBox, 1, 1, 2, 3 );
00234        widthMSpinBox = new MSpinBox( 1, 10000, dsGroupBox7, unitGetDecimalsFromIndex(currentDoc->unitIndex()) );
00235        widthQLabel = new QLabel( tr( "&Width:" ), dsGroupBox7, "widthLabel" );
00236        widthMSpinBox->setSuffix(unitGetSuffixFromIndex(currentDoc->unitIndex()));
00237        widthMSpinBox->setValue(currentDoc->pageWidth * currentDoc->unitRatio());
00238        widthQLabel->setBuddy(widthMSpinBox);
00239        dsGroupBox7Layout->addWidget( widthQLabel, 2, 0 );
00240        dsGroupBox7Layout->addWidget( widthMSpinBox, 2, 1 );
00241        heightMSpinBox = new MSpinBox( 1, 10000, dsGroupBox7, unitGetDecimalsFromIndex(currentDoc->unitIndex()) );
00242        heightMSpinBox->setSuffix(unitGetSuffixFromIndex(currentDoc->unitIndex()));
00243        heightMSpinBox->setValue(currentDoc->pageHeight * currentDoc->unitRatio());
00244        heightQLabel = new QLabel(heightMSpinBox,  tr( "&Height:" ), dsGroupBox7, "heightLabel" );
00245        dsGroupBox7Layout->addWidget( heightQLabel, 2, 2 );
00246        dsGroupBox7Layout->addWidget( heightMSpinBox, 2, 3 );
00247        moveObjects = new QCheckBox( dsGroupBox7, "moveObjects" );
00248        moveObjects->setText( tr( "Move Objects with their Page" ) );
00249        moveObjects->setChecked( true );
00250        dsGroupBox7Layout->addMultiCellWidget( moveObjects, 3, 3, 0, 3 );
00251        dialogLayout->addWidget( dsGroupBox7 );
00252        if (sizeQComboBox->currentText() == CommonStrings::trCustomPageSize)
00253        {
00254               heightMSpinBox->setEnabled( true );
00255               widthMSpinBox->setEnabled( true );
00256        }
00257        else
00258        {
00259               heightMSpinBox->setEnabled( false );
00260               widthMSpinBox->setEnabled( false );
00261        }
00262        delete ps;
00263 
00264        okCancelLayout = new QHBoxLayout;
00265        okCancelLayout->setSpacing( 5 );
00266        okCancelLayout->setMargin( 5 );
00267        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00268        okCancelLayout->addItem( spacer );
00269 
00270        okButton = new QPushButton( CommonStrings::tr_OK, this, "okButton" );
00271        okButton->setDefault( true );
00272        okCancelLayout->addWidget( okButton );
00273 
00274        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "cancelButton" );
00275        okCancelLayout->addWidget( cancelButton );
00276        dialogLayout->addLayout( okCancelLayout );
00277        setMaximumSize(sizeHint());
00278        unitRatio = currentDoc->unitRatio();
00279 
00280        // signals and slots connections
00281        connect( insWhereData, SIGNAL( activated(int) ), this, SLOT( insWherePageDataDisable(int) ) );
00282        connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
00283        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
00284        connect(orientationQComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int)));
00285        connect(sizeQComboBox, SIGNAL(activated(const QString &)), this, SLOT(setSize(const QString &)));
00286 }
00287 
00288 void InsPage::setSize(const QString & gr)
00289 {
00290        widthMSpinBox->setEnabled(false);
00291        heightMSpinBox->setEnabled(false);
00292        PageSize *ps2 = new PageSize(gr);
00293        prefsPageSizeName = ps2->name();
00294        if (gr == CommonStrings::trCustomPageSize)
00295        {
00296               widthMSpinBox->setEnabled(true);
00297               heightMSpinBox->setEnabled(true);
00298               prefsPageSizeName = CommonStrings::customPageSize;
00299        }
00300        else
00301        {
00302               widthMSpinBox->setValue(ps2->width() * unitRatio);
00303               heightMSpinBox->setValue(ps2->height() * unitRatio);
00304        }
00305        delete ps2;
00306 }
00307 
00308 void InsPage::setOrien(int ori)
00309 {
00310        double br;
00311        setSize(sizeQComboBox->currentText());
00312        if (ori == 0)
00313        {
00314               if (sizeQComboBox->currentText() == CommonStrings::trCustomPageSize)
00315               {
00316                      br = widthMSpinBox->value();
00317                      widthMSpinBox->setValue(heightMSpinBox->value());
00318                      heightMSpinBox->setValue(br);
00319               }
00320        }
00321        else
00322        {
00323               br = widthMSpinBox->value();
00324               widthMSpinBox->setValue(heightMSpinBox->value());
00325               heightMSpinBox->setValue(br);
00326        }
00327 }
00328 
00329 const QStringList InsPage::getMasterPages()
00330 {
00331        QStringList ret;
00332        for (uint n = 0; n < masterPageCombos.count(); ++n)
00333        {
00334               ret.append(masterPageCombos.at(n)->currentText());
00335        }
00336        return ret;
00337 }
00338 
00339 const QString InsPage::getMasterPageN(uint n)
00340 {
00341        return masterPageCombos.at(n)->currentText();
00342 }
00343 
00344 const int InsPage::getWhere()
00345 {
00346        return insWhereData->currentItem();
00347 }
00348 
00349 const int InsPage::getWherePage()
00350 {
00351        return insWherePageData->value();
00352 }
00353 
00354 const int InsPage::getCount()
00355 {
00356        return insCountData->value();
00357 }
00358 
00359 void InsPage::insWherePageDataDisable(int index)
00360 {
00361        insWherePageData->setDisabled((index==2));
00362 }