Back to index

scribus-ng  1.3.4.dfsg+svn20071115
tabdocument.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 <qlabel.h>
00008 #include <qbuttongroup.h>
00009 #include <qcombobox.h>
00010 #include <qtooltip.h>
00011 #include <qspinbox.h>
00012 #include <qstring.h>
00013 #include <qcheckbox.h>
00014 
00015 #include "tabdocument.h"
00016 #include "tabdocument.moc"
00017 
00018 #include "commonstrings.h"
00019 #include "prefsmanager.h"
00020 #include "units.h"
00021 #include "marginWidget.h"
00022 #include "mspinbox.h"
00023 #include "pagelayout.h"
00024 #include "pagesize.h"
00025 #include "undomanager.h"
00026 #include "sccombobox.h"
00027 #include "prefsfile.h"
00028 #include "scribusdoc.h"
00029 
00030 
00031 TabDocument::TabDocument(QWidget* parent, const char* name, const bool reform)
00032        : QWidget(parent, name, 0)
00033 {
00034        ApplicationPrefs* prefsData=&(PrefsManager::instance()->appPrefs);
00035        unitRatio = unitGetRatioFromIndex(prefsData->docUnitIndex);
00036        int decimals = unitGetPrecisionFromIndex(prefsData->docUnitIndex);
00037 
00038        tabLayout_7 = new QHBoxLayout( this, 0, 5, "tabLayout_7");
00039        Layout21 = new QVBoxLayout( 0, 0, 5, "Layout21");
00040        dsLayout4p = new QHBoxLayout;
00041        dsLayout4p->setSpacing( 5 );
00042        dsLayout4p->setMargin( 0 );
00043        dsLayout4p->setAlignment( Qt::AlignLeft );
00044        docLayout = new PageLayouts(this, prefsData->pageSets);
00045        dsLayout4p->addWidget( docLayout );
00046        dsLayout4pv = new QVBoxLayout;
00047        dsLayout4pv->setSpacing( 5 );
00048        dsLayout4pv->setMargin( 0 );
00049 
00050        GroupSize = new QButtonGroup( tr( "Page Size" ), this, "GroupSize" );
00051        GroupSize->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred));
00052        GroupSize->setColumnLayout(0, Qt::Vertical );
00053        GroupSize->layout()->setSpacing( 5 );
00054        GroupSize->layout()->setMargin( 10 );
00055        GroupSizeLayout = new QVBoxLayout( GroupSize->layout() );
00056        GroupSizeLayout->setAlignment( Qt::AlignTop );
00057        Layout6 = new QGridLayout( 0, 1, 1, 0, 5, "Layout6");
00058 
00059        pageSizeComboBox = new QComboBox( true, GroupSize, "pageSizeComboBox" );
00060 
00061        PageSize *ps=new PageSize(prefsData->pageSize);
00062        pageSizeComboBox->insertStringList(ps->sizeTRList());
00063        pageSizeComboBox->insertItem( CommonStrings::trCustomPageSize );
00064        pageSizeComboBox->setEditable(false);
00065 
00066        QStringList pageSizes=ps->sizeList();
00067        int sizeIndex=pageSizes.findIndex(ps->nameTR());
00068        if (sizeIndex!=-1)
00069               pageSizeComboBox->setCurrentItem(sizeIndex);
00070        else
00071               pageSizeComboBox->setCurrentItem(pageSizeComboBox->count()-1);
00072        GZText1 = new QLabel( pageSizeComboBox, tr( "&Size:" ), GroupSize, "GZText1" );
00073        Layout6->addWidget( GZText1, 0, 0 );
00074        Layout6->addWidget( pageSizeComboBox, 0, 1 );
00075 
00076        pageOrientationComboBox = new QComboBox( true, GroupSize, "pageOrientationComboBox" );
00077        pageOrientationComboBox->insertItem( tr( "Portrait" ) );
00078        pageOrientationComboBox->insertItem( tr( "Landscape" ) );
00079        pageOrientationComboBox->setEditable(false);
00080        GZText2 = new QLabel( pageOrientationComboBox, tr( "Orie&ntation:" ), GroupSize, "GZText2" );
00081        Layout6->addWidget( GZText2, 1, 0 );
00082        Layout6->addWidget( pageOrientationComboBox, 1, 1 );
00083        unitCombo = new QComboBox( true, GroupSize, "unitCombo" );
00084        unitCombo->insertStringList(unitGetTextUnitList());
00085        unitCombo->setEditable(false);
00086        unitComboText = new QLabel( unitCombo, tr( "Units:" ), GroupSize, "unitComboText" );
00087        Layout6->addWidget( unitComboText, 2, 0 );
00088        Layout6->addWidget( unitCombo, 2, 1 );
00089        GroupSizeLayout->addLayout( Layout6 );
00090 
00091        Layout5_2 = new QHBoxLayout( 0, 0, 6, "Layout5_2");
00092 
00093        pageWidth = new MSpinBox( 1, 100000, GroupSize, decimals );
00094        pageWidth->setMinimumSize( QSize( 90, 20 ) );
00095        GZText3 = new QLabel( pageWidth, tr( "&Width:" ), GroupSize, "GZText3" );
00096        Layout5_2->addWidget( GZText3 );
00097        Layout5_2->addWidget( pageWidth );
00098 
00099        pageHeight = new MSpinBox( 1, 100000, GroupSize, decimals );
00100        pageHeight->setMinimumSize( QSize( 90, 20 ) );
00101        GZText4 = new QLabel( pageHeight, tr( "&Height:" ), GroupSize, "GZText4" );
00102        Layout5_2->addWidget( GZText4 );
00103        Layout5_2->addWidget( pageHeight );
00104        GroupSizeLayout->addLayout( Layout5_2 );
00105        
00106        QBoxLayout *sizePagesLayout = new QHBoxLayout( 0, 0, 5, "sizePagesLayout");
00107        sizePages = new QLabel( tr( "Apply settings to:" ), GroupSize, "sizePages" );
00108        sizePagesLayout->addWidget(sizePages);
00109        sizeAllPages = new QCheckBox( GroupSize, "sizeAllPages" );
00110        sizeAllPages->setText( tr( "All Document Pages" ) );
00111        sizeAllPages->setChecked( false );
00112        sizePagesLayout->addWidget(sizeAllPages);
00113        sizeAllMasterPages = new QCheckBox( GroupSize, "sizeAllMasterPages" );
00114        sizeAllMasterPages->setText( tr( "All Master Pages" ) );
00115        sizeAllMasterPages->setChecked( false );
00116        sizePagesLayout->addWidget(sizeAllMasterPages);
00117        GroupSizeLayout->addLayout(sizePagesLayout);
00118        sizePages->hide();
00119        sizeAllPages->hide();
00120        sizeAllMasterPages->hide();
00121        
00122        dsLayout4pv->addWidget( GroupSize );
00123 
00124        marginGroup = new MarginWidget(this,  tr( "Margin Guides" ), &(prefsData->margins), prefsData->docUnitIndex, reform);
00125 
00126        dsLayout4pv->addWidget( marginGroup );
00127 
00128        dsLayout4p->addLayout( dsLayout4pv );
00129        Layout21->addLayout( dsLayout4p );
00130        QHBoxLayout *asurLayout = new QHBoxLayout( 0, 0, 5, "asurLayout");
00131 
00132        GroupAS = new QGroupBox( tr( "Autosave" ), this, "GroupAS" );
00133        GroupAS->setCheckable( true );
00134        GroupAS->setColumnLayout(0, Qt::Vertical );
00135        GroupAS->layout()->setSpacing( 5 );
00136        GroupAS->layout()->setMargin( 10 );
00137        GroupASLayout = new QHBoxLayout( GroupAS->layout() );
00138        GroupASLayout->setAlignment( Qt::AlignTop );
00139        ASTime = new QSpinBox( GroupAS, "Time" );
00140        ASTime->setMaxValue( 60 );
00141        ASTime->setMinValue( 1 );
00142        ASTime->setSuffix( " " + tr("min") );
00143        ASText = new QLabel( ASTime, tr( "&Interval:" ), GroupAS, "ASText" );
00144        GroupASLayout->addWidget( ASText);
00145        GroupASLayout->addWidget( ASTime );
00146        asurLayout->addWidget(GroupAS);
00147 
00148        urGroup = new QGroupBox( tr("Undo/Redo"), this, "urGroup");
00149        urGroup->setCheckable(true);
00150        urGroup->setColumnLayout(0, Qt::Vertical);
00151        urGroup->layout()->setSpacing(5);
00152        urGroup->layout()->setMargin(10);
00153        QGridLayout *urGroupLayout = new QGridLayout(urGroup->layout());
00154        urGroupLayout->setAlignment(Qt::AlignTop);
00155        urSpinBox = new QSpinBox(urGroup, "urSpinBox");
00156        urSpinBox->setMinValue(0);
00157        urSpinBox->setMaxValue(1000);
00158        int urSBValue = UndoManager::instance()->getHistoryLength();
00159        if (urSBValue == -1)
00160               urSpinBox->setEnabled(false);
00161        else
00162               urSpinBox->setValue(urSBValue);
00163        urLabel = new QLabel(urSpinBox, tr("Action history length"), urGroup, "urLabel");
00164        urGroupLayout->addWidget(urLabel, 0, 0);
00165        urGroupLayout->addWidget(urSpinBox, 0, 1);
00166        asurLayout->addWidget(urGroup);
00167        Layout21->addLayout(asurLayout);
00168        urGroup->setChecked((PrefsManager::instance()->prefsFile->getContext("undo")->getBool("enabled", true)));
00169 
00170        tabLayout_7->addLayout( Layout21 );
00171 
00172        QToolTip::add( pageWidth, "<qt>" + tr( "Width of document pages, editable if you have chosen a custom page size" ) + "</qt>" );
00173        QToolTip::add( pageHeight, "<qt>" + tr( "Height of document pages, editable if you have chosen a custom page size" ) + "</qt>" );
00174        QToolTip::add( pageSizeComboBox, "<qt>" + tr( "Default page size, either a standard size or a custom size" ) + "</qt>" );
00175        QToolTip::add( pageOrientationComboBox, "<qt>" + tr( "Default orientation of document pages" ) + "</qt>" );
00176        QToolTip::add( unitCombo, "<qt>" + tr( "Default unit of measurement for document editing" ) + "</qt>" );
00177        QToolTip::add( GroupAS, "<qt>" + tr( "When enabled, Scribus saves a backup copy of your file with the .bak extension each time the time period elapses" ) + "</qt>" );
00178        QToolTip::add( ASTime, "<qt>" + tr( "Time period between saving automatically" ) + "</qt>" );
00179        QToolTip::add( urSpinBox, "<qt>" + tr("Set the length of the action history in steps. If set to 0 infinite amount of actions will be stored.") + "</qt>");
00180        QToolTip::add( sizeAllPages, "<qt>" + tr( "Apply the page size changes to all existing pages in the document" ) + "</qt>" );
00181        QToolTip::add( sizeAllMasterPages, "<qt>" + tr( "Apply the page size changes to all existing master pages in the document" ) + "</qt>" );
00182        connect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00183        connect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00184        connect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int)));
00185        connect(pageSizeComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
00186        connect(urGroup, SIGNAL(toggled(bool)), this, SLOT(slotUndo(bool)));
00187 }
00188 
00189 void TabDocument::restoreDefaults(struct ApplicationPrefs *prefsData)
00190 {
00191        disconnect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00192        disconnect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00193        disconnect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int)));
00194        disconnect(pageSizeComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
00195        unitRatio = unitGetRatioFromIndex(prefsData->docUnitIndex);
00196 
00197 //     setSize(prefsData->pageSize);
00198        if (prefsData->pageSize == CommonStrings::customPageSize)
00199               pageSizeComboBox->setCurrentText(CommonStrings::trCustomPageSize);
00200        else
00201               pageSizeComboBox->setCurrentText(prefsData->pageSize);
00202        prefsPageSizeName = prefsData->pageSize;
00203 //     setOrien(prefsData->pageOrientation);
00204 
00205        docLayout->selectItem(prefsData->FacingPages);
00206        docLayout->firstPage->setCurrentItem(prefsData->pageSets[prefsData->FacingPages].FirstPage);
00207        pageOrientationComboBox->setCurrentItem(prefsData->pageOrientation);
00208        unitCombo->setCurrentItem(prefsData->docUnitIndex);
00209        pageWidth->setValue(prefsData->PageWidth * unitRatio);
00210        pageHeight->setValue(prefsData->PageHeight * unitRatio);
00211        pageW = prefsData->PageWidth;
00212        pageH = prefsData->PageHeight;
00213        marginGroup->setNewMargins(prefsData->margins);
00214        marginGroup->setPageWidthHeight(prefsData->PageWidth, prefsData->PageHeight);
00215        marginGroup->setNewBleeds(prefsData->bleeds);
00216        GroupAS->setChecked( prefsData->AutoSave );
00217        ASTime->setValue(prefsData->AutoSaveTime / 1000 / 60);
00218        connect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00219        connect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00220        connect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int)));
00221        connect(pageSizeComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
00222        unitChange();
00223 }
00224 
00225 void TabDocument::restoreDefaults(ScribusDoc *prefsData)
00226 {
00227        disconnect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00228        disconnect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00229        disconnect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int)));
00230        disconnect(pageSizeComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
00231        unitRatio = unitGetRatioFromIndex(prefsData->unitIndex());
00232 
00233 //     setSize(prefsData->m_pageSize);
00234        if (prefsData->m_pageSize == CommonStrings::customPageSize)
00235               pageSizeComboBox->setCurrentText(CommonStrings::trCustomPageSize);
00236        else
00237               pageSizeComboBox->setCurrentText(prefsData->m_pageSize);
00238        prefsPageSizeName = prefsData->m_pageSize;
00239 //     setOrien(prefsData->PageOri);
00240 
00241        docLayout->selectItem(prefsData->currentPageLayout);
00242        docLayout->firstPage->setCurrentItem(prefsData->pageSets[prefsData->currentPageLayout].FirstPage);
00243        pageOrientationComboBox->setCurrentItem(prefsData->PageOri);
00244        unitCombo->setCurrentItem(prefsData->unitIndex());
00245        pageWidth->setValue(prefsData->pageWidth * unitRatio);
00246        pageHeight->setValue(prefsData->pageHeight * unitRatio);
00247        pageW = prefsData->pageWidth;
00248        pageH = prefsData->pageHeight;
00249        marginGroup->setNewBleeds(prefsData->bleeds);
00250        marginGroup->setNewMargins(prefsData->pageMargins);
00251        marginGroup->setPageWidthHeight(prefsData->pageWidth, prefsData->pageHeight);
00252        GroupAS->setChecked( prefsData->AutoSave );
00253        ASTime->setValue(prefsData->AutoSaveTime / 1000 / 60);
00254        connect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00255        connect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00256        connect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setOrien(int)));
00257        connect(pageSizeComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
00258        unitChange();
00259 }
00260 
00261 void TabDocument::unitChange()
00262 {
00263        disconnect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00264        disconnect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00265 
00266        int docUnitIndex = unitCombo->currentItem();
00267        double oldUnitRatio = unitRatio;
00268        double oldB, oldBM, oldH, oldHM, val;
00269        unitRatio = unitGetRatioFromIndex(docUnitIndex);
00270        int decimals = unitGetDecimalsFromIndex(docUnitIndex);
00271        QString suffix = unitGetSuffixFromIndex(docUnitIndex);
00272        
00273        pageWidth->getValues(&oldB, &oldBM, &decimals, &val);
00274        oldB /= oldUnitRatio;
00275        oldBM /= oldUnitRatio;
00276        pageHeight->getValues(&oldH, &oldHM, &decimals, &val);
00277        oldH /= oldUnitRatio;
00278        oldHM /= oldUnitRatio;
00279 
00280        pageWidth->setSuffix(suffix);
00281        pageHeight->setSuffix(suffix);
00282 
00283        pageWidth->setValues(oldB * unitRatio, oldBM * unitRatio, decimals, pageW * unitRatio);
00284        pageHeight->setValues(oldH * unitRatio, oldHM * unitRatio, decimals, pageH * unitRatio);
00285        marginGroup->unitChange(unitRatio, decimals, suffix);
00286        marginGroup->setPageHeight(pageH);
00287        marginGroup->setPageWidth(pageW);
00288 
00289        connect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00290        connect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00291 }
00292 
00293 void TabDocument::setPageWidth(int)
00294 {
00295        pageW = pageWidth->value() / unitRatio;
00296        marginGroup->setPageWidth(pageW);
00297        QString psText=pageSizeComboBox->currentText();
00298        if (psText!=CommonStrings::trCustomPageSize && psText!=CommonStrings::customPageSize)
00299               pageSizeComboBox->setCurrentItem(pageSizeComboBox->count()-1);
00300 }
00301 
00302 void TabDocument::setPageHeight(int)
00303 {
00304        pageH = pageHeight->value() / unitRatio;
00305        marginGroup->setPageHeight(pageH);
00306        QString psText=pageSizeComboBox->currentText();
00307        if (psText!=CommonStrings::trCustomPageSize && psText!=CommonStrings::customPageSize)
00308               pageSizeComboBox->setCurrentItem(pageSizeComboBox->count()-1);
00309 }
00310 
00311 void TabDocument::setSize(const QString & gr)
00312 {
00313        pageW = pageWidth->value() / unitRatio;
00314        pageH = pageHeight->value() / unitRatio;
00315        PageSize *ps2=new PageSize(gr);
00316 
00317        prefsPageSizeName=ps2->name();
00318        if (gr != CommonStrings::trCustomPageSize)
00319        {
00320               pageW = ps2->width();
00321               pageH = ps2->height();
00322        }
00323        else
00324               prefsPageSizeName = CommonStrings::customPageSize;
00325        disconnect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00326        disconnect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00327        pageWidth->setValue(pageW * unitRatio);
00328        pageHeight->setValue(pageH * unitRatio);
00329        marginGroup->setPageHeight(pageH);
00330        marginGroup->setPageWidth(pageW);
00331        marginGroup->setPageSize(gr);
00332        connect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00333        connect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00334        delete ps2;
00335 }
00336 
00337 void TabDocument::setOrien(int ori)
00338 {
00339        double br;
00340        setSize(pageSizeComboBox->currentText());
00341        disconnect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00342        disconnect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00343        if (ori == 0)
00344        {
00345               if (pageSizeComboBox->currentText() == CommonStrings::trCustomPageSize)
00346               {
00347                      br = pageWidth->value();
00348                      pageWidth->setValue(pageHeight->value());
00349                      pageHeight->setValue(br);
00350               }
00351        }
00352        else
00353        {
00354               br = pageWidth->value();
00355               pageWidth->setValue(pageHeight->value());
00356               pageHeight->setValue(br);
00357        }
00358        pageW = pageWidth->value() / unitRatio;
00359        pageH = pageHeight->value() / unitRatio;
00360        connect(pageWidth, SIGNAL(valueChanged(int)), this, SLOT(setPageWidth(int)));
00361        connect(pageHeight, SIGNAL(valueChanged(int)), this, SLOT(setPageHeight(int)));
00362 }
00363 
00364 void TabDocument::setPageSize()
00365 {
00366        setOrien(pageOrientationComboBox->currentItem());
00367 }
00368 
00369 void TabDocument::hideReform()
00370 {
00371        urGroup->hide();
00372        sizePages->show();
00373        sizeAllPages->show();
00374        sizeAllMasterPages->show();
00375 }
00376 
00377 void TabDocument::slotUndo(bool isEnabled)
00378 {
00379        static PrefsContext *undoPrefs = PrefsManager::instance()->prefsFile->getContext("undo");
00380 
00381        if (!isEnabled)
00382               UndoManager::instance()->clearStack();
00383        UndoManager::instance()->setUndoEnabled(isEnabled);
00384        undoPrefs->set("enabled", isEnabled);
00385        UndoManager::instance()->setAllHistoryLengths(urSpinBox->value());
00386 }