Back to index

scribus-ng  1.3.4.dfsg+svn20071115
marginWidget.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 "marginWidget.h"
00008 #include "marginWidget.moc"
00009 
00010 #include <qcheckbox.h>
00011 #include <qtooltip.h>
00012 
00013 #include "mspinbox.h"
00014 #include "units.h"
00015 #include "useprintermarginsdialog.h"
00016 
00017 
00018 MarginWidget::MarginWidget( QWidget* parent, QString /*title*/, const MarginStruct* margs, int unitIndex, bool showChangeAll, bool showBleeds) : QTabWidget(parent, "marginWidget"),
00019 pageType(0)
00020 {
00021        RandT = margs->Top;
00022        RandB = margs->Bottom;
00023        RandR = margs->Right;
00024        RandL = margs->Left;
00025        facingPages = false;
00026        useBleeds = showBleeds;
00027 
00028        m_docUnitIndex=unitIndex;
00029        m_unitRatio = unitGetRatioFromIndex(unitIndex);
00030        m_suffix = unitGetSuffixFromIndex(unitIndex);
00031        int decimals = unitGetDecimalsFromIndex(unitIndex);
00032 
00033        marginPage = new QWidget(this);
00034 
00035        presetCombo = new PresetLayout(marginPage, "presetCombo");
00036        presetLabel = new QLabel(presetCombo, tr("Preset Layouts:"), marginPage, "presetLabel");
00037 
00038        leftR = new MSpinBox( 0, 1000, marginPage, decimals );
00039        leftR->setSuffix( m_suffix );
00040        leftR->setValue(RandL * m_unitRatio);
00041 
00042        rightR = new MSpinBox( 0, 1000, marginPage, decimals );
00043        rightR->setSuffix( m_suffix );
00044        rightR->setValue(RandR * m_unitRatio);
00045 
00046        topR = new MSpinBox( 0, 1000, marginPage, decimals );
00047        topR->setSuffix( m_suffix );
00048        topR->setValue(RandT * m_unitRatio);
00049 
00050        bottomR = new MSpinBox( 0, 1000, marginPage, decimals );
00051        bottomR->setSuffix( m_suffix );
00052        bottomR->setValue(RandB * m_unitRatio);
00053 
00054        bText = new QLabel( bottomR, tr( "&Bottom:" ), marginPage, "bText" );
00055        tText = new QLabel( topR, tr( "&Top:" ), marginPage, "tText" );
00056        rText = new QLabel( rightR, tr( "&Right:" ), marginPage, "rText" );
00057        lText = new QLabel( leftR, tr( "&Left:" ), marginPage, "lText" );
00058 
00059        // layout
00060        GroupLayout = new QGridLayout( marginPage );
00061        GroupLayout->setAlignment( Qt::AlignTop );
00062        GroupLayout->setSpacing( 5 );
00063        GroupLayout->setMargin( 10 );
00064        GroupLayout->addWidget(presetLabel, 0, 0);
00065        GroupLayout->addWidget(presetCombo, 0, 1);
00066        GroupLayout->addWidget( leftR, 1, 1 );
00067        GroupLayout->addWidget( rightR, 2, 1 );
00068        GroupLayout->addWidget( topR, 3, 1 );
00069        GroupLayout->addWidget( bottomR, 4, 1 );
00070        GroupLayout->addWidget( lText, 1, 0 );
00071        GroupLayout->addWidget( rText, 2, 0 );
00072        GroupLayout->addWidget( tText, 3, 0 );
00073        GroupLayout->addWidget( bText, 4, 0 );
00074        if (showChangeAll)
00075        {
00076               marginsForPagesLayout = new QHBoxLayout( 0, 5, 5, "marginsForPagesLayout");
00077               marginsForPages = new QLabel( tr( "Apply settings to:" ), marginPage, "marginsForPages" );
00078               marginsForPagesLayout->addWidget(marginsForPages);
00079               marginsForAllPages = new QCheckBox( marginPage, "marginsForAllPages" );
00080               marginsForAllPages->setText( tr( "All Document Pages" ) );
00081               marginsForAllPages->setChecked( false );
00082               marginsForPagesLayout->addWidget(marginsForAllPages);
00083               marginsForAllMasterPages = new QCheckBox( marginPage, "marginsForAllMasterPages" );
00084               marginsForAllMasterPages->setText( tr( "All Master Pages" ) );
00085               marginsForAllMasterPages->setChecked( false );
00086               marginsForPagesLayout->addWidget(marginsForAllMasterPages);
00087               GroupLayout->addMultiCellLayout( marginsForPagesLayout, 6, 6, 0, 1 );
00088               QToolTip::add( marginsForAllPages, "<qt>" + tr( "Apply the margin changes to all existing pages in the document" ) + "</qt>" );
00089               QToolTip::add( marginsForAllMasterPages, "<qt>" + tr( "Apply the margin changes to all existing master pages in the document" ) + "</qt>" );
00090        }
00091        else
00092        {
00093               marginsForPages=NULL;
00094               marginsForAllPages=NULL;
00095               marginsForAllMasterPages=NULL;
00096        }
00097 
00098        usePrinterMarginsButton=NULL;
00099 #if defined(HAVE_CUPS) || defined(_WIN32)
00100        usePrinterMarginsButton=new QPushButton( tr("Printer Margins..."),marginPage, "usePrinterMarginsButton" );
00101        GroupLayout->addWidget( usePrinterMarginsButton, 5, 1 );
00102        QToolTip::add( usePrinterMarginsButton, "<qt>" + tr( "Import the margins for the selected page size from the available printers." ) + "</qt>");
00103        connect(usePrinterMarginsButton, SIGNAL(clicked()), this, SLOT(setMarginsToPrinterMargins()));
00104 #endif
00105 
00106        addTab(marginPage, tr("Margin Guides"));
00107 
00108        if (useBleeds)
00109        {
00110               bleedPage = new QWidget(this);
00111               BleedGroupLayout = new QGridLayout( bleedPage );
00112               BleedGroupLayout->setSpacing( 5 );
00113               BleedGroupLayout->setMargin( 10 );
00114               BleedGroupLayout->setAlignment( Qt::AlignTop );
00115               BleedTxt3 = new QLabel( bleedPage, "BleedTxt3" );
00116               BleedGroupLayout->addWidget( BleedTxt3, 0, 0 );
00117               BleedLeft = new MSpinBox( bleedPage, decimals );
00118               BleedGroupLayout->addWidget( BleedLeft, 0, 1 );
00119               BleedTxt4 = new QLabel( bleedPage, "BleedTxt4" );
00120               BleedGroupLayout->addWidget( BleedTxt4, 1, 0 );
00121               BleedRight = new MSpinBox( bleedPage, decimals );
00122               BleedGroupLayout->addWidget( BleedRight, 1, 1 );
00123               BleedTxt1 = new QLabel( bleedPage, "BleedTxt1" );
00124               BleedTxt1->setText( tr( "Top:" ) );
00125               BleedGroupLayout->addWidget( BleedTxt1, 2, 0 );
00126               BleedTop = new MSpinBox( bleedPage, decimals );
00127               BleedGroupLayout->addWidget( BleedTop, 2, 1 );
00128               BleedTxt2 = new QLabel( bleedPage, "BleedTxt2" );
00129               BleedTxt2->setText( tr( "Bottom:" ) );
00130               BleedGroupLayout->addWidget( BleedTxt2, 3, 0 );
00131               BleedBottom = new MSpinBox( bleedPage, decimals );
00132               BleedGroupLayout->addWidget( BleedBottom, 3, 1 );
00133               linkBleeds = new LinkButton( bleedPage );
00134               linkBleeds->setToggleButton( true );
00135               linkBleeds->setAutoRaise( true );
00136               linkBleeds->setMaximumSize( QSize( 15, 32767 ) );
00137               BleedGroupLayout->addMultiCellWidget( linkBleeds, 0, 3, 2, 2 );
00138               BleedTop->setSuffix( m_suffix );
00139               BleedTop->setMinValue(0);
00140               BleedTop->setMaxValue(3000*m_unitRatio);
00141               BleedBottom->setSuffix( m_suffix );
00142               BleedBottom->setMinValue(0);
00143               BleedBottom->setMaxValue(3000*m_unitRatio);
00144               BleedRight->setSuffix( m_suffix );
00145               BleedRight->setMinValue(0);
00146               BleedRight->setMaxValue(3000*m_unitRatio);
00147               BleedLeft->setSuffix( m_suffix );
00148               BleedLeft->setMinValue(0);
00149               BleedLeft->setMaxValue(3000*m_unitRatio);
00150               QToolTip::add( BleedTop, "<qt>" + tr( "Distance for bleed from the top of the physical page" ) + "</qt>" );
00151               QToolTip::add( BleedBottom, "<qt>" + tr( "Distance for bleed from the bottom of the physical page" ) + "</qt>" );
00152               QToolTip::add( BleedLeft, "<qt>" + tr( "Distance for bleed from the left of the physical page" ) + "</qt>" );
00153               QToolTip::add( BleedRight, "<qt>" + tr( "Distance for bleed from the right of the physical page" )  + "</qt>");
00154               connect(linkBleeds, SIGNAL(clicked()), this, SLOT(ToggleKette()));
00155               connect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00156               connect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00157               connect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00158               connect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00159               addTab(bleedPage, tr("Bleeds"));
00160        }
00161 
00162        // hints
00163        QToolTip::add( topR, "<qt>" + tr( "Distance between the top margin guide and the edge of the page" ) + "</qt>");
00164        QToolTip::add( bottomR, "<qt>" + tr( "Distance between the bottom margin guide and the edge of the page" ) + "</qt>");
00165        QToolTip::add( leftR, "<qt>" + tr( "Distance between the left margin guide and the edge of the page. If a double-sided, 3 or 4-fold layout is selected, this margin space can be used to achieve the correct margins for binding") + "</qt>");
00166        QToolTip::add( rightR, "<qt>" + tr( "Distance between the right margin guide and the edge of the page. If a double-sided, 3 or 4-fold layout is selected, this margin space can be used to achieve the correct margins for binding") + "</qt>");
00167 
00168               // signals&slots
00169        connect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
00170        connect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
00171        connect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
00172        connect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
00173        connect(presetCombo, SIGNAL(activated(int)), this, SLOT(setPreset()));
00174 }
00175 
00176 void MarginWidget::ToggleKette()
00177 {
00178        disconnect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00179        disconnect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00180        disconnect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00181        disconnect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00182        if (linkBleeds->isOn())
00183        {
00184               BleedTop->setValue(BleedLeft->value());
00185               BleedBottom->setValue(BleedLeft->value());
00186               BleedRight->setValue(BleedLeft->value());
00187        }
00188        connect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00189        connect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00190        connect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00191        connect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00192 }
00193 
00194 void MarginWidget::changeBleeds()
00195 {
00196        if (linkBleeds->isOn())
00197        {
00198               double val = 0.0;
00199               if (BleedTop == sender())
00200                      val = BleedTop->value();
00201               else if (BleedBottom == sender())
00202                      val = BleedBottom->value();
00203               else if (BleedLeft == sender())
00204                      val = BleedLeft->value();
00205               else if (BleedRight == sender())
00206                      val = BleedRight->value();
00207               val = val / m_unitRatio;
00208               MarginStruct v(val,val,val,val);
00209               setNewBleeds(v);
00210        }
00211 }
00212 
00213 void MarginWidget::setFacingPages(bool facing, int pagetype)
00214 {
00215        facingPages = facing;
00216        pageType = pagetype;
00217        lText->setText(facing == true ? tr( "&Inside:" ) : tr( "&Left:" ));
00218        rText->setText(facing == true ? tr( "O&utside:" ) : tr( "&Right:" ));
00219        if (useBleeds)
00220        {
00221               if (facing)
00222               {
00223                      BleedTxt3->setText( tr( "Inside:" ) );
00224                      BleedTxt4->setText( tr( "Outside:" ) );
00225               }
00226               else
00227               {
00228                      BleedTxt3->setText( tr( "Left:" ) );
00229                      BleedTxt4->setText( tr( "Right:" ) );
00230               }
00231        }
00232        setPreset();
00233 }
00234 
00235 void MarginWidget::setPageWidthHeight(double width, double height)
00236 {
00237        rightR->setMaxValue(width * m_unitRatio - leftR->value());
00238        leftR->setMaxValue(width * m_unitRatio - rightR->value());
00239        pageWidth = width;
00240        topR->setMaxValue(height * m_unitRatio - bottomR->value());
00241        bottomR->setMaxValue(height * m_unitRatio - topR->value());
00242        pageHeight = height;
00243        setPreset();
00244 }
00245 
00246 void MarginWidget::setPageWidth(double width)
00247 {
00248        rightR->setMaxValue(QMAX(0.0, width * m_unitRatio - leftR->value()));
00249        leftR->setMaxValue(QMAX(0.0,width * m_unitRatio - rightR->value()));
00250        pageWidth = width;
00251        setPreset();
00252 }
00253 
00254 void MarginWidget::setPageHeight(double height)
00255 {
00256        topR->setMaxValue(QMAX(0.0, height * m_unitRatio - bottomR->value()));
00257        bottomR->setMaxValue(QMAX(0.0,height * m_unitRatio - topR->value()));
00258        pageHeight = height;
00259        setPreset();
00260 }
00261 
00262 void MarginWidget::setTop()
00263 {
00264        RandT = topR->value() / m_unitRatio;
00265        bottomR->setMaxValue(QMAX(0.0, pageHeight * m_unitRatio - topR->value()));
00266        setPreset();
00267 }
00268 
00269 void MarginWidget::setBottom()
00270 {
00271        RandB = bottomR->value() / m_unitRatio;
00272        topR->setMaxValue(QMAX(0.0, pageHeight * m_unitRatio - bottomR->value()));
00273        setPreset();
00274 }
00275 
00276 void MarginWidget::setLeft()
00277 {
00278        RandL = leftR->value() / m_unitRatio;
00279        rightR->setMaxValue(QMAX(0.0, pageWidth * m_unitRatio - leftR->value()));
00280        setPreset();
00281 }
00282 
00283 void MarginWidget::setRight()
00284 {
00285        RandR = rightR->value() / m_unitRatio;
00286        leftR->setMaxValue(QMAX(0.0, pageWidth * m_unitRatio - rightR->value()));
00287        setPreset();
00288 }
00289 
00290 void MarginWidget::unitChange(double newUnit, int newDecimals, QString newSuffix)
00291 {
00292        disconnect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
00293        disconnect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
00294        disconnect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
00295        disconnect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
00296        int decimalsOld;
00297        double oldUnitRatio = m_unitRatio;
00298        double oldMin, oldMax, val;
00299        topR->setSuffix(newSuffix);
00300        bottomR->setSuffix(newSuffix);
00301        leftR->setSuffix(newSuffix);
00302        rightR->setSuffix(newSuffix);
00303        double invUnitConversion = 1.0 / oldUnitRatio * newUnit;
00304        topR->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00305        topR->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
00306        bottomR->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00307        bottomR->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
00308        leftR->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00309        leftR->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
00310        rightR->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00311        rightR->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
00312 
00313        if (useBleeds)
00314        {
00315               disconnect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00316               disconnect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00317               disconnect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00318               disconnect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00319               BleedBottom->setSuffix(newSuffix);
00320               BleedTop->setSuffix(newSuffix);
00321               BleedRight->setSuffix(newSuffix);
00322               BleedLeft->setSuffix(newSuffix);
00323               BleedBottom->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00324               BleedBottom->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
00325               BleedTop->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00326               BleedTop->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
00327               BleedRight->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00328               BleedRight->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
00329               BleedLeft->getValues(&oldMin, &oldMax, &decimalsOld, &val);
00330               BleedLeft->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
00331               connect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00332               connect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00333               connect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00334               connect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00335        }
00336        m_unitRatio = newUnit;
00337        m_suffix=newSuffix;
00338        connect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
00339        connect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
00340        connect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
00341        connect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
00342 }
00343 
00344 void MarginWidget::setPreset()
00345 {
00346        disconnect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
00347        disconnect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
00348        disconnect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
00349        disconnect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
00350        int item = presetCombo->currentItem();
00351        MarginStruct marg = presetCombo->getMargins(item, pageWidth * m_unitRatio, pageHeight * m_unitRatio, leftR->value());
00352        facingPages ? presetCombo->setEnabled(true) : presetCombo->setEnabled(false);
00353        if (presetCombo->needUpdate() && facingPages)
00354        {
00355               leftR->setValue(QMAX(0.0, marg.Left));
00356               rightR->setValue(QMAX(0.0, marg.Right));
00357               topR->setValue(QMAX(0.0, marg.Top));
00358               bottomR->setValue(QMAX(0.0, marg.Bottom));
00359               RandT = topR->value() / m_unitRatio;
00360               RandB = bottomR->value() / m_unitRatio;
00361               RandL = leftR->value() / m_unitRatio;
00362               RandR = rightR->value() / m_unitRatio;
00363               bottomR->setMaxValue(QMAX(0.0, pageHeight * m_unitRatio - topR->value()));
00364               topR->setMaxValue(QMAX(0.0, pageHeight * m_unitRatio - bottomR->value()));
00365               rightR->setMaxValue(QMAX(0.0, pageWidth * m_unitRatio - leftR->value()));
00366               leftR->setMaxValue(QMAX(0.0, pageWidth * m_unitRatio - rightR->value()));
00367               rightR->setEnabled(false);
00368               topR->setEnabled(false);
00369               bottomR->setEnabled(false);
00370        }
00371        else
00372        {
00373               rightR->setEnabled(true);
00374               topR->setEnabled(true);
00375               bottomR->setEnabled(true);
00376        }
00377        if (pageType == 1)
00378               rightR->setEnabled(false);
00379        connect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
00380        connect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
00381        connect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
00382        connect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
00383 }
00384 
00385 void MarginWidget::setPageSize(const QString& pageSize)
00386 {
00387        m_pageSize=pageSize;
00388 }
00389 
00390 void MarginWidget::setMarginsToPrinterMargins()
00391 {
00392        UsePrinterMarginsDialog upm(parentWidget(), m_pageSize, m_unitRatio, m_suffix);
00393        if (upm.exec())
00394        {
00395               double t,b,l,r;
00396               upm.getNewPrinterMargins(t,b,l,r);
00397               presetCombo->setCurrentItem(PresetLayout::none);
00398               topR->setValue(t * m_unitRatio);
00399               bottomR->setValue(b * m_unitRatio);
00400               leftR->setValue(l * m_unitRatio);
00401               rightR->setValue(r * m_unitRatio);
00402 
00403               RandT = t;
00404               RandB = b;
00405               RandL = l;
00406               RandR = r;
00407 
00408               bottomR->setMaxValue((QMAX(0.0, pageHeight - t) * m_unitRatio));
00409               topR->setMaxValue((QMAX(0.0, pageHeight - b) * m_unitRatio));
00410               rightR->setMaxValue((QMAX(0.0, pageWidth - l) * m_unitRatio));
00411               leftR->setMaxValue((QMAX(0.0, pageWidth - r) * m_unitRatio));
00412 
00413               rightR->setEnabled(true);
00414               topR->setEnabled(true);
00415               bottomR->setEnabled(true);
00416        }
00417 }
00418 
00419 double MarginWidget::top()
00420 {
00421        return RandT;
00422 }
00423 
00424 double MarginWidget::bottom()
00425 {
00426        return RandB;
00427 }
00428 
00429 double MarginWidget::left()
00430 {
00431        return RandL;
00432 }
00433 
00434 double MarginWidget::right()
00435 {
00436        return RandR;
00437 }
00438 
00439 void MarginWidget::setNewMargins(MarginStruct &m)
00440 {
00441        disconnect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
00442        disconnect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
00443        disconnect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
00444        disconnect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
00445        topR->setValue(m.Top * m_unitRatio);
00446        RandT = m.Top;
00447        bottomR->setValue(m.Bottom * m_unitRatio);
00448        RandB = m.Bottom;
00449        leftR->setValue(m.Left * m_unitRatio);
00450        RandL = m.Left;
00451        rightR->setValue(m.Right * m_unitRatio);
00452        RandR = m.Right;
00453        connect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
00454        connect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
00455        connect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
00456        connect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
00457 }
00458 
00459 bool MarginWidget::getMarginsForAllPages()
00460 {
00461        return marginsForAllPages->isChecked();
00462 }
00463 
00464 bool MarginWidget::getMarginsForAllMasterPages()
00465 {
00466        return marginsForAllMasterPages->isChecked();
00467 }
00468 
00469 void MarginWidget::setNewBleeds(MarginStruct& b)
00470 {
00471        disconnect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00472        disconnect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00473        disconnect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00474        disconnect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00475        BleedTop->setValue(b.Top * m_unitRatio);
00476        BleedBottom->setValue(b.Bottom * m_unitRatio);
00477        BleedLeft->setValue(b.Left * m_unitRatio);
00478        BleedRight->setValue(b.Right * m_unitRatio);
00479        connect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00480        connect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00481        connect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00482        connect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
00483 }
00484 
00485 double MarginWidget::topBleed()
00486 {
00487        return BleedTop->value() / m_unitRatio;
00488 }
00489 
00490 double MarginWidget::bottomBleed()
00491 {
00492        return BleedBottom->value() / m_unitRatio;
00493 }
00494 
00495 double MarginWidget::leftBleed()
00496 {
00497        return BleedLeft->value() / m_unitRatio;
00498 }
00499 
00500 double MarginWidget::rightBleed()
00501 {
00502        return BleedRight->value() / m_unitRatio;
00503 }
00504 
00505 
00506 /*
00507  * presets
00508  */
00509 PresetLayout::PresetLayout(QWidget *parent, const char * name) : QComboBox(parent, name)
00510 {
00511        insertItem( tr("None", "layout type"), PresetLayout::none);
00512        insertItem( tr("Gutenberg"), PresetLayout::gutenberg);
00513        insertItem( tr("Magazine"), PresetLayout::magazine);
00514        insertItem( tr("Fibonacci"), PresetLayout::fibonacci);
00515        insertItem( tr("Golden Mean"), PresetLayout::goldencut);
00516        insertItem( tr("Nine Parts"), PresetLayout::nineparts);
00517        setCurrentItem(PresetLayout::none);
00518 
00519        QToolTip::add(this, "<qt>" + tr("You can select a predefined page layout here. 'None' leave margins as is, Gutenberg sets margins classically. 'Magazine' sets all margins for same value. Leading is Left/Inside value.") + "</qt>");
00520 }
00521 
00522 MarginStruct PresetLayout::getMargins(int index, double pageWidth, double pageHeight, double leftMargin)
00523 {
00524        MarginStruct ret;
00525 
00526        updateMargins = true;
00527 
00528        switch (index)
00529        {
00530               case PresetLayout::magazine:
00531                      ret.Top = ret.Bottom = ret.Left = ret.Right = leftMargin;
00532                      break;
00533               case PresetLayout::gutenberg:
00534                      {
00535                             double ratio = pageHeight / pageWidth;
00536                             ret.Left = leftMargin;
00537                             ret.Top = leftMargin * ratio;
00538                             ret.Right = leftMargin * 2.0;
00539                             ret.Bottom = ret.Right * ratio;
00540                      }
00541                      break;
00542               case PresetLayout::fibonacci:
00543                      ret.Left = leftMargin;
00544                      ret.Top = leftMargin / 2.0 * 3.0;
00545                      ret.Right = leftMargin / 2.0 * 5.0;
00546                      ret.Bottom = leftMargin / 2.0 * 8.0;
00547                      break;
00548               case PresetLayout::goldencut:
00549                      ret.Left = leftMargin;
00550                      ret.Top = leftMargin / 2.0 * 3.4;
00551                      ret.Right = leftMargin / 2.0 * 4.8;
00552                      ret.Bottom = leftMargin / 2.0 * 6.8;
00553                      break;
00554               case PresetLayout::nineparts:
00555                      ret.Left = pageWidth / 9.0;
00556                      ret.Top = pageHeight / 9.0;
00557                      ret.Right = pageWidth / 9.0 * 2.0;
00558                      ret.Bottom = pageHeight / 9.0 * 2.0;
00559                      break;
00560               default:
00561                      updateMargins = false;
00562                      ret.Top = ret.Bottom = ret.Left = ret.Right = -1.0;
00563        }
00564        return ret;
00565 }
00566 
00567 bool PresetLayout::needUpdate()
00568 {
00569        return updateMargins;
00570 }