Back to index

scribus-ng  1.3.4.dfsg+svn20071115
applytemplatedialog.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 /***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 #include "applytemplatedialog.h"
00016 #include "applytemplatedialog.moc"
00017 
00018 #include <qvariant.h>
00019 #include <qpushbutton.h>
00020 #include <qlabel.h>
00021 #include <qcombobox.h>
00022 #include <qbuttongroup.h>
00023 #include <qradiobutton.h>
00024 #include <qcheckbox.h>
00025 #include <qspinbox.h>
00026 #include <qlayout.h>
00027 #include <qtooltip.h>
00028 #include <qwhatsthis.h>
00029 
00030 #include "commonstrings.h"
00031 #include "scribusdoc.h"
00032 #include "page.h"
00033 
00034 enum {
00035     CurrentPage,
00036     EvenPages,
00037     OddPages,
00038     AllPages
00039 };
00040 
00041 /*
00042  *  Constructs a ApplyMasterPageDialog as a child of 'parent', with the
00043  *  name 'name' and widget flags set to 'f'.
00044  *
00045  *  The dialog will by default be modeless, unless you set 'modal' to
00046  *  true to construct a modal dialog.
00047  */
00048 ApplyMasterPageDialog::ApplyMasterPageDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
00049               : QDialog( parent, name, modal, fl )
00050 {
00051        if ( !name )
00052               setName( "ApplyMasterPageDialog" );
00053        ApplyMasterPageDialogLayout = new QVBoxLayout( this, 11, 6, "ApplyMasterPageDialogLayout");
00054 
00055        templateNameLayout = new QHBoxLayout( 0, 0, 6, "templateNameLayout");
00056 
00057        masterPageLabel = new QLabel( this, "masterPageLabel" );
00058        templateNameLayout->addWidget( masterPageLabel );
00059        spacer2 = new QSpacerItem( 100, 21, QSizePolicy::Expanding, QSizePolicy::Minimum );
00060        templateNameLayout->addItem( spacer2 );
00061 
00062        masterPageComboBox = new QComboBox( false, this, "masterPageComboBox" );
00063        templateNameLayout->addWidget( masterPageComboBox );
00064        ApplyMasterPageDialogLayout->addLayout( templateNameLayout );
00065 
00066        applyToPageButtonGroup = new QButtonGroup( this, "applyToPageButtonGroup" );
00067        applyToPageButtonGroup->setMinimumSize( QSize( 250, 0 ) );
00068        applyToPageButtonGroup->setFrameShape( QButtonGroup::GroupBoxPanel );
00069        applyToPageButtonGroup->setColumnLayout(0, Qt::Vertical );
00070        applyToPageButtonGroup->layout()->setSpacing( 6 );
00071        applyToPageButtonGroup->layout()->setMargin( 11 );
00072        applyToPageButtonGroupLayout = new QVBoxLayout( applyToPageButtonGroup->layout() );
00073        applyToPageButtonGroupLayout->setAlignment( Qt::AlignTop );
00074 
00075        currentPageRadioButton = new QRadioButton( applyToPageButtonGroup, "currentPageRadioButton" );
00076        currentPageRadioButton->setChecked( true );
00077        applyToPageButtonGroupLayout->addWidget( currentPageRadioButton );
00078 
00079        evenPagesRadioButton = new QRadioButton( applyToPageButtonGroup, "evenPagesRadioButton" );
00080        applyToPageButtonGroupLayout->addWidget( evenPagesRadioButton );
00081 
00082        oddPagesRadioButton = new QRadioButton( applyToPageButtonGroup, "oddPagesRadioButton" );
00083        applyToPageButtonGroupLayout->addWidget( oddPagesRadioButton );
00084 
00085        allPagesRadioButton = new QRadioButton( applyToPageButtonGroup, "allPagesRadioButton" );
00086        applyToPageButtonGroupLayout->addWidget( allPagesRadioButton );
00087 
00088        rangeLayout = new QHBoxLayout( 0, 0, 6, "rangeLayout");
00089 
00090        useRangeCheckBox = new QCheckBox( applyToPageButtonGroup, "useRangeCheckBox" );
00091        useRangeCheckBox->setEnabled( false );    
00092        rangeLayout->addWidget( useRangeCheckBox );
00093 
00094        fromPageSpinBox = new QSpinBox( applyToPageButtonGroup, "fromPageSpinBox" );
00095        fromPageSpinBox->setEnabled( false );
00096        fromPageSpinBox->setMinValue( 1 );
00097        rangeLayout->addWidget( fromPageSpinBox );
00098 
00099        toPageLabel = new QLabel( applyToPageButtonGroup, "toPageLabel" );
00100        rangeLayout->addWidget( toPageLabel );
00101 
00102        toPageSpinBox = new QSpinBox( applyToPageButtonGroup, "toPageSpinBox" );
00103        toPageSpinBox->setEnabled( false );
00104        toPageSpinBox->setMinValue( 1 );
00105        rangeLayout->addWidget( toPageSpinBox );
00106        spacer3 = new QSpacerItem( 16, 21, QSizePolicy::Expanding, QSizePolicy::Minimum );
00107        rangeLayout->addItem( spacer3 );
00108        applyToPageButtonGroupLayout->addLayout( rangeLayout );
00109        ApplyMasterPageDialogLayout->addWidget( applyToPageButtonGroup );
00110 
00111        layout8 = new QHBoxLayout( 0, 0, 6, "layout8");
00112        spacer1 = new QSpacerItem( 100, 21, QSizePolicy::Expanding, QSizePolicy::Minimum );
00113        layout8->addItem( spacer1 );
00114 
00115        okButton = new QPushButton( this, "okButton" );
00116        layout8->addWidget( okButton );
00117 
00118        cancelButton = new QPushButton( this, "cancelButton" );
00119        layout8->addWidget( cancelButton );
00120        ApplyMasterPageDialogLayout->addLayout( layout8 );
00121        languageChange();
00122        resize( QSize(272, 230).expandedTo(minimumSizeHint()) );
00123        clearWState( WState_Polished );
00124 
00125        // signals and slots connections
00126        connect( useRangeCheckBox, SIGNAL( toggled(bool) ), this, SLOT( enableRange(bool) ) );
00127        connect( currentPageRadioButton, SIGNAL( clicked() ), this, SLOT( singleSelectable() ) );
00128        connect( evenPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
00129        connect( oddPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
00130        connect( allPagesRadioButton, SIGNAL( clicked() ), this, SLOT( rangeSelectable() ) );
00131        connect( fromPageSpinBox, SIGNAL( valueChanged(const QString&) ), this, SLOT( checkRangeFrom() ) );
00132        connect( toPageSpinBox, SIGNAL( valueChanged(int) ), this, SLOT( checkRangeTo() ) );
00133        connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
00134        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
00135 
00136        // buddies
00137        masterPageLabel->setBuddy( masterPageComboBox );
00138 }
00139 
00140 /*
00141  *  Destroys the object and frees any allocated resources
00142  */
00143 ApplyMasterPageDialog::~ApplyMasterPageDialog()
00144 {
00145        // no need to delete child widgets, Qt does it all for us
00146 }
00147 
00148 void ApplyMasterPageDialog::setup(ScribusDoc *view, QString Nam)
00149 {
00150        QString na = Nam == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : Nam, in;
00151        int cc = 0;
00152        for (QMap<QString,int>::Iterator it = view->MasterNames.begin(); it != view->MasterNames.end(); ++it)
00153        {
00154               in = it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key();
00155               masterPageComboBox->insertItem(in);
00156               if (in == na)
00157                      masterPageComboBox->setCurrentItem(cc);
00158               ++cc;
00159        }
00160        const unsigned int docPagesCount = view->Pages->count();
00161        if (docPagesCount < 2)
00162               evenPagesRadioButton->setEnabled(false);
00163        fromPageSpinBox->setMaxValue(docPagesCount);
00164        fromPageSpinBox->setValue(view->currentPage()->pageNr()+1);
00165        toPageSpinBox->setMaxValue(docPagesCount);
00166        toPageSpinBox->setValue(docPagesCount);
00167 }
00168 
00169 
00170 QString ApplyMasterPageDialog::getMasterPageName()
00171 {
00172        return masterPageComboBox->currentText();
00173 }
00174 
00175 
00176 int ApplyMasterPageDialog::getPageSelection()
00177 {
00178        if (currentPageRadioButton->isChecked())
00179               return CurrentPage;
00180        else if (evenPagesRadioButton->isChecked())
00181               return EvenPages;
00182        else if (oddPagesRadioButton->isChecked())
00183               return OddPages;
00184        else
00185               return AllPages;
00186 }
00187 
00188 void ApplyMasterPageDialog::checkRangeFrom()
00189 {
00190        disconnect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
00191        disconnect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
00192        if (fromPageSpinBox->value() > toPageSpinBox->value())
00193               toPageSpinBox->setValue(fromPageSpinBox->value());
00194        connect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
00195        connect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
00196 }
00197 
00198 void ApplyMasterPageDialog::checkRangeTo()
00199 {
00200        disconnect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
00201        disconnect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
00202        if (toPageSpinBox->value() < fromPageSpinBox->value())
00203               fromPageSpinBox->setValue(toPageSpinBox->value());
00204        connect(fromPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeFrom()));
00205        connect(toPageSpinBox, SIGNAL(valueChanged(int)), this, SLOT(checkRangeTo()));
00206 }
00207 
00208 void ApplyMasterPageDialog::enableRange( bool enabled )
00209 {
00210        fromPageSpinBox->setEnabled(enabled);
00211        toPageSpinBox->setEnabled(enabled);
00212 }
00213 
00214 void ApplyMasterPageDialog::rangeSelectable()
00215 {
00216        useRangeCheckBox->setEnabled(true);
00217        enableRange(useRangeCheckBox->isChecked());
00218 }
00219 
00220 void ApplyMasterPageDialog::singleSelectable()
00221 {
00222        useRangeCheckBox->setEnabled(false);
00223        fromPageSpinBox->setEnabled(false);
00224        toPageSpinBox->setEnabled(false);
00225 }
00226 
00227 
00228 bool ApplyMasterPageDialog::usingRange()
00229 {
00230        return useRangeCheckBox->isChecked();
00231 }
00232 
00233 
00234 int ApplyMasterPageDialog::getFromPage()
00235 {
00236        if (useRangeCheckBox->isChecked())
00237               return fromPageSpinBox->value();
00238        return -1;
00239 }
00240 
00241 
00242 int ApplyMasterPageDialog::getToPage()
00243 {
00244        if (useRangeCheckBox->isChecked())
00245               return toPageSpinBox->value();
00246        return -1;
00247 }
00248 
00249 /*
00250  *  Sets the strings of the subwidgets using the current
00251  *  language.
00252  */
00253 void ApplyMasterPageDialog::languageChange()
00254 {
00255        setCaption( tr( "Apply Master Page" ) );
00256        masterPageLabel->setText( tr( "&Master Page:" ) );
00257        applyToPageButtonGroup->setTitle( tr( "Apply To" ) );
00258        currentPageRadioButton->setText( tr( "Current &page" ) );
00259        currentPageRadioButton->setAccel( QKeySequence( tr( "Alt+P" ) ) );
00260        evenPagesRadioButton->setText( tr( "&Even pages" ) );
00261        evenPagesRadioButton->setAccel( QKeySequence( tr( "Alt+E" ) ) );
00262        oddPagesRadioButton->setText( tr( "O&dd pages" ) );
00263        oddPagesRadioButton->setAccel( QKeySequence( tr( "Alt+D" ) ) );
00264        allPagesRadioButton->setText( tr( "&All pages" ) );
00265        allPagesRadioButton->setAccel( QKeySequence( tr( "Alt+A" ) ) );
00266        useRangeCheckBox->setText( tr( "&Within range" ) );
00267        useRangeCheckBox->setAccel( QKeySequence( tr( "Alt+W" ) ) );
00268        QToolTip::add( useRangeCheckBox, "<qt>" + tr( "Apply the selected master page to even, odd or all pages within the following range") + "</qt>" );
00269        toPageLabel->setText( tr( "to" ) );
00270        okButton->setText( CommonStrings::tr_OK );
00271        okButton->setAccel( QKeySequence( tr( "Alt+O" ) ) );
00272        cancelButton->setText( CommonStrings::tr_Cancel );
00273        cancelButton->setAccel( QKeySequence( tr( "Alt+C" ) ) );
00274 }