Back to index

scribus-ng  1.3.4.dfsg+svn20071115
margindialog.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 <qlayout.h>
00009 #include <qpushbutton.h>
00010 #include <qgroupbox.h>
00011 #include <qlabel.h>
00012 #include <qcombobox.h>
00013 #include <qcheckbox.h>
00014 
00015 #include "margindialog.h"
00016 #include "margindialog.moc"
00017 #include "marginWidget.h"
00018 #include "pagestructs.h"
00019 #include "page.h"
00020 #include "scribusdoc.h"
00021 #include "units.h"
00022 #include "mspinbox.h"
00023 #include "pagesize.h"
00024 #include "commonstrings.h"
00025 
00026 extern QPixmap loadIcon(QString nam);
00027 
00028 MarginDialog::MarginDialog( QWidget* parent, ScribusDoc* doc ) : QDialog( parent, "MarginDialog", true, 0 )
00029 {
00030        setCaption( tr( "Manage Page Properties" ) );
00031        setIcon(loadIcon("AppIcon.png"));
00032        unitRatio = doc->unitRatio();
00033        dialogLayout = new QVBoxLayout( this, 10, 5);
00034        
00035        dsGroupBox7 = new QGroupBox( this, "GroupBox7" );
00036        dsGroupBox7->setTitle( tr( "Page Size" ) );
00037        dsGroupBox7->setColumnLayout(0, Qt::Vertical );
00038        dsGroupBox7->layout()->setSpacing( 0 );
00039        dsGroupBox7->layout()->setMargin( 0 );
00040        dsGroupBox7Layout = new QGridLayout( dsGroupBox7->layout() );
00041        dsGroupBox7Layout->setAlignment( Qt::AlignTop );
00042        dsGroupBox7Layout->setSpacing( 5 );
00043        dsGroupBox7Layout->setMargin( 10 );
00044        TextLabel1 = new QLabel( tr( "&Size:" ), dsGroupBox7, "TextLabel1" );
00045        dsGroupBox7Layout->addMultiCellWidget( TextLabel1, 0, 0, 0, 1 );
00046        PageSize *ps=new PageSize(doc->currentPage()->m_pageSize);
00047        sizeQComboBox = new QComboBox( true, dsGroupBox7, "ComboBox1" );
00048        sizeQComboBox->setEditable(false);
00049        QStringList pageSizes=ps->sizeList();
00050        sizeQComboBox->insertStringList(ps->sizeTRList());
00051        sizeQComboBox->insertItem( CommonStrings::trCustomPageSize );
00052        prefsPageSizeName=ps->name();
00053        int sizeIndex = pageSizes.findIndex(ps->nameTR());
00054        if (sizeIndex != -1)
00055               sizeQComboBox->setCurrentItem(sizeIndex);
00056        else
00057               sizeQComboBox->setCurrentItem(sizeQComboBox->count()-1);
00058        TextLabel1->setBuddy(sizeQComboBox);
00059        dsGroupBox7Layout->addMultiCellWidget(sizeQComboBox, 0, 0, 2, 3);
00060        TextLabel2 = new QLabel( tr( "Orie&ntation:" ), dsGroupBox7, "TextLabel2" );
00061        dsGroupBox7Layout->addMultiCellWidget( TextLabel2, 1, 1, 0, 1 );
00062        orientationQComboBox = new QComboBox( true, dsGroupBox7, "ComboBox2" );
00063        orientationQComboBox->insertItem( tr( "Portrait" ) );
00064        orientationQComboBox->insertItem( tr( "Landscape" ) );
00065        orientationQComboBox->setEditable(false);
00066        orientationQComboBox->setCurrentItem(doc->currentPage()->PageOri );
00067        oldOri = doc->currentPage()->PageOri;
00068        TextLabel2->setBuddy(orientationQComboBox);
00069        dsGroupBox7Layout->addMultiCellWidget( orientationQComboBox, 1, 1, 2, 3 );
00070        widthMSpinBox = new MSpinBox( 1, 100000, dsGroupBox7, unitGetDecimalsFromIndex(doc->unitIndex()) );
00071        widthQLabel = new QLabel( tr( "&Width:" ), dsGroupBox7, "widthLabel" );
00072        widthMSpinBox->setSuffix(unitGetSuffixFromIndex(doc->unitIndex()));
00073        widthMSpinBox->setValue(doc->currentPage()->width() * doc->unitRatio());
00074        widthQLabel->setBuddy(widthMSpinBox);
00075        dsGroupBox7Layout->addWidget( widthQLabel, 2, 0 );
00076        dsGroupBox7Layout->addWidget( widthMSpinBox, 2, 1 );
00077        heightMSpinBox = new MSpinBox( 1, 100000, dsGroupBox7, unitGetDecimalsFromIndex(doc->unitIndex()) );
00078        heightMSpinBox->setSuffix(unitGetSuffixFromIndex(doc->unitIndex()));
00079        heightMSpinBox->setValue(doc->currentPage()->height() * doc->unitRatio());
00080        heightQLabel = new QLabel(heightMSpinBox,  tr( "&Height:" ), dsGroupBox7, "heightLabel" );
00081        dsGroupBox7Layout->addWidget( heightQLabel, 2, 2 );
00082        dsGroupBox7Layout->addWidget( heightMSpinBox, 2, 3 );
00083        moveObjects = new QCheckBox( dsGroupBox7, "moveObjects" );
00084        moveObjects->setText( tr( "Move Objects with their Page" ) );
00085        moveObjects->setChecked( true );
00086        dsGroupBox7Layout->addMultiCellWidget( moveObjects, 3, 3, 0, 3 );
00087        Links=0;
00088        if ((doc->currentPageLayout != singlePage) && (doc->masterPageMode()))
00089        {
00090               TextLabel3 = new QLabel( tr( "Type:" ), dsGroupBox7, "TextLabel3" );
00091               dsGroupBox7Layout->addMultiCellWidget( TextLabel3, 4, 4, 0, 1 );
00092               Links = new QComboBox( true, dsGroupBox7, "links" );
00093               QStringList::Iterator pNames;
00094               for(pNames = doc->pageSets[doc->currentPageLayout].pageNames.begin(); pNames != doc->pageSets[doc->currentPageLayout].pageNames.end(); ++pNames )
00095               {
00096                      //Links->insertItem((*pNames));
00097                      Links->insertItem(CommonStrings::translatePageSetLocString((*pNames)));
00098               }
00099               Links->setEditable(false);
00100               dsGroupBox7Layout->addMultiCellWidget( Links, 4, 4, 2, 3 );
00101               if (doc->currentPage()->LeftPg == 0)
00102                      Links->setCurrentItem(Links->count()-1);
00103               else if (doc->currentPage()->LeftPg == 1)
00104                      Links->setCurrentItem(0);
00105               else
00106                      Links->setCurrentItem(doc->currentPage()->LeftPg-1);
00107        }
00108        dialogLayout->addWidget( dsGroupBox7 );
00109        
00110        GroupRand = new MarginWidget(this,  tr( "Margin Guides" ), &doc->currentPage()->initialMargins, doc->unitIndex(), false, false);
00111        GroupRand->setPageWidthHeight(doc->currentPage()->width(), doc->currentPage()->height());
00112        GroupRand->setFacingPages(!(doc->currentPageLayout == singlePage), doc->locationOfPage(doc->currentPage()->pageNr()));
00113        dialogLayout->addWidget( GroupRand );
00114 
00115        groupMaster = new QGroupBox( this, "groupMaster" );
00116        groupMaster->setTitle( tr( "Other Settings" ) );
00117        groupMaster->setColumnLayout(0, Qt::Vertical );
00118        groupMaster->layout()->setSpacing( 0 );
00119        groupMaster->layout()->setMargin( 0 );
00120        masterLayout = new QHBoxLayout( groupMaster->layout() );
00121        masterLayout->setAlignment( Qt::AlignTop );
00122        masterLayout->setSpacing( 5 );
00123        masterLayout->setMargin( 10 );
00124        masterPageLabel = new QLabel( groupMaster, "masterPageLabel" );
00125        masterPageLabel->setText( tr( "Master Page:" ) );
00126        masterLayout->addWidget( masterPageLabel );
00127        masterPageComboBox = new QComboBox( false, groupMaster, "masterPageComboBox" );
00128        QString Nam = doc->currentPage()->MPageNam;
00129        QString na = Nam == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : Nam, in;
00130        int cc = 0;
00131        for (QMap<QString,int>::Iterator it = doc->MasterNames.begin(); it != doc->MasterNames.end(); ++it)
00132        {
00133               in = it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key();
00134               masterPageComboBox->insertItem(in);
00135               if (in == na)
00136                      masterPageComboBox->setCurrentItem(cc);
00137               ++cc;
00138        }
00139        masterLayout->addWidget( masterPageComboBox );
00140        dialogLayout->addWidget( groupMaster );
00141        if (doc->masterPageMode())
00142               groupMaster->hide();
00143 
00144        okCancelLayout = new QHBoxLayout;
00145        okCancelLayout->setSpacing( 6 );
00146        okCancelLayout->setMargin( 0 );
00147        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00148        okCancelLayout->addItem( spacer );
00149        okButton = new QPushButton( CommonStrings::tr_OK, this, "okButton" );
00150        okButton->setDefault( true );
00151        okCancelLayout->addWidget(okButton);
00152        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "cancelButton" );
00153        cancelButton->setDefault( false );
00154        okCancelLayout->addWidget(cancelButton);
00155        dialogLayout->addLayout( okCancelLayout );
00156        setMaximumSize(sizeHint());
00157        pageWidth = widthMSpinBox->value() / unitRatio;
00158        pageHeight = heightMSpinBox->value() / unitRatio;
00159        if (sizeQComboBox->currentText() == CommonStrings::trCustomPageSize)
00160        {
00161               heightMSpinBox->setEnabled( true );
00162               widthMSpinBox->setEnabled( true );
00163        }
00164        else
00165        {
00166               heightMSpinBox->setEnabled( false );
00167               widthMSpinBox->setEnabled( false );
00168        }
00169        delete ps;
00170        // signals and slots connections
00171        connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
00172        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
00173        connect(orientationQComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int)));
00174        connect(sizeQComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
00175        connect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00176        connect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00177        
00178        setPageSize();
00179        setMinimumSize(minimumSizeHint());
00180        setMaximumSize(minimumSizeHint());
00181        resize(minimumSizeHint());
00182 }
00183 
00184 void MarginDialog::setPageWidth(int)
00185 {
00186        pageWidth = widthMSpinBox->value() / unitRatio;
00187        GroupRand->setPageWidth(pageWidth);
00188 }
00189 
00190 void MarginDialog::setPageHeight(int)
00191 {
00192        pageHeight = heightMSpinBox->value() / unitRatio;
00193        GroupRand->setPageHeight(pageHeight);
00194 }
00195 
00196 void MarginDialog::setPageSize()
00197 {
00198        if (sizeQComboBox->currentText() != CommonStrings::trCustomPageSize)
00199               oldOri++;
00200        setOrien(orientationQComboBox->currentItem());
00201 }
00202 
00203 void MarginDialog::setSize(const QString & gr)
00204 {
00205        pageWidth = widthMSpinBox->value() / unitRatio;
00206        pageHeight = heightMSpinBox->value() / unitRatio;
00207        widthMSpinBox->setEnabled(false);
00208        heightMSpinBox->setEnabled(false);
00209        PageSize *ps2 = new PageSize(gr);
00210        prefsPageSizeName = ps2->name();
00211        if (gr == CommonStrings::trCustomPageSize)
00212        {
00213               widthMSpinBox->setEnabled(true);
00214               heightMSpinBox->setEnabled(true);
00215               prefsPageSizeName = CommonStrings::customPageSize;
00216        }
00217        else
00218        {
00219               pageWidth = ps2->width();
00220               pageHeight = ps2->height();
00221        }
00222        disconnect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00223        disconnect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00224        widthMSpinBox->setValue(pageWidth * unitRatio);
00225        heightMSpinBox->setValue(pageHeight * unitRatio);
00226        GroupRand->setPageHeight(pageHeight);
00227        GroupRand->setPageWidth(pageWidth);
00228        GroupRand->setPageSize(gr);
00229        connect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00230        connect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00231        delete ps2;
00232 }
00233 
00234 void MarginDialog::setOrien(int ori)
00235 {
00236        double br;
00237        setSize(sizeQComboBox->currentText());
00238        disconnect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00239        disconnect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00240        if ((sizeQComboBox->currentText() == CommonStrings::trCustomPageSize) && (ori != oldOri))
00241        {
00242               br = widthMSpinBox->value();
00243               widthMSpinBox->setValue(heightMSpinBox->value());
00244               heightMSpinBox->setValue(br);
00245        }
00246        else
00247        {
00248               if ((ori != 0) && (ori != oldOri))
00249               {
00250                      br = widthMSpinBox->value();
00251                      widthMSpinBox->setValue(heightMSpinBox->value());
00252                      heightMSpinBox->setValue(br);
00253               }
00254        }
00255        oldOri = ori;
00256        pageWidth = widthMSpinBox->value() / unitRatio;
00257        pageHeight = heightMSpinBox->value() / unitRatio;
00258        connect(widthMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00259        connect(heightMSpinBox, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00260 }
00261 
00262 int MarginDialog::pageOrder()
00263 {
00264        int lp=0;
00265        if (Links!=0)
00266               lp = Links->currentItem();
00267        if (lp == 0)
00268               lp = 1;
00269        else if (lp == static_cast<int>(Links->count()-1))
00270               lp = 0;
00271        else
00272               lp++;
00273        return lp;
00274 }
00275 
00276 double MarginDialog::getPageWidth()
00277 {
00278        return pageWidth;
00279 }
00280 
00281 double MarginDialog::getPageHeight()
00282 {
00283        return pageHeight;
00284 }
00285 
00286 int MarginDialog::getPageOrientation()
00287 {
00288        return orientationQComboBox->currentItem();
00289 }
00290 
00291 QString MarginDialog::getpPrefsPageSizeName()
00292 {
00293        return prefsPageSizeName;
00294 }
00295 
00296 bool MarginDialog::getMoveObjects()
00297 {
00298        return moveObjects->isChecked();
00299 }
00300 
00301 double MarginDialog::top()
00302 {
00303        return GroupRand->top();
00304 }
00305 
00306 double MarginDialog::bottom()
00307 {
00308        return GroupRand->bottom();
00309 }
00310 
00311 double MarginDialog::left()
00312 {
00313        return GroupRand->left();
00314 }
00315 
00316 double MarginDialog::right()
00317 {
00318        return GroupRand->right();
00319 }
00320 
00321 QString MarginDialog::masterPage()
00322 {
00323        return masterPageComboBox->currentText();
00324 }