Back to index

scribus-ng  1.3.4.dfsg+svn20071115
movepage.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 <qlabel.h>
00010 #include <qpushbutton.h>
00011 #include <qspinbox.h>
00012 #include <qlayout.h>
00013 
00014 #include "movepage.h"
00015 #include "movepage.moc"
00016 
00017 #include "commonstrings.h"
00018 
00019 extern QPixmap loadIcon(QString nam);
00020 
00021 /*
00022  *  Constructs a MovePages which is a child of 'parent', with the 
00023  *  name 'name' and widget flags set to 'f' 
00024  *
00025  *  The dialog will by default be modeless, unless you set 'modal' to
00026  *  true to construct a modal dialog.
00027  */
00028 MovePages::MovePages( QWidget* parent, int currentPage, int maxPages, bool moving )
00029               : QDialog( parent, "MovePages", true, 0 )
00030 {
00031        move = moving;       
00032        setCaption (move ? tr("Move Pages") : tr("Copy Page"));
00033        setIcon(loadIcon("AppIcon.png"));
00034        dialogLayout = new QVBoxLayout( this, 10, 5 );
00035        fromToLayout = new QGridLayout;
00036        fromToLayout->setSpacing( 6 );
00037        fromToLayout->setMargin( 5 );
00038        moveLabel = new QLabel( (move ? tr("Move Page(s)") : tr("Copy Page")) + ":", this, "moveLabel" );
00039        fromPageData = new QSpinBox( 1, maxPages, 1, this, "fromPageData" );
00040        fromPageData->setValue( currentPage );
00041        uint currentRow=0;
00042        fromToLayout->addWidget( moveLabel, currentRow, 0);
00043        fromToLayout->addWidget( fromPageData, currentRow, 1);
00044 
00045        if (move)
00046        {
00047               toLabel = new QLabel( tr("To:"), this, "toLabel" );
00048               toPageData = new QSpinBox( 1, maxPages, 1, this, "toPageData" );
00049               toPageData->setValue( currentPage );
00050               fromToLayout->addWidget( toLabel, currentRow, 2);
00051               fromToLayout->addWidget( toPageData, currentRow, 3);
00052        }
00053        else
00054        {
00055               numberOfCopiesLabel = new QLabel( tr("Number of copies:"), this, "numberOfCopiesLabel" );
00056               numberOfCopiesData = new QSpinBox(this, "numberOfCopiesData" );
00057               numberOfCopiesData->setMinValue(1);
00058               numberOfCopiesData->setMaxValue(100);
00059               ++currentRow;
00060               fromToLayout->addWidget(numberOfCopiesLabel, currentRow, 0);
00061               fromToLayout->addWidget(numberOfCopiesData, currentRow, 1);
00062        }
00063        ++currentRow;
00064        mvWhereData = new QComboBox( false, this, "mvWhereData" );
00065        mvWhereData->insertItem( tr("Before Page"));
00066        mvWhereData->insertItem( tr("After Page"));
00067        mvWhereData->insertItem( tr("At End"));
00068        mvWhereData->setCurrentItem(2);
00069        mvWherePageData = new QSpinBox( 1, maxPages, 1, this, "mvWherePageData" );
00070        mvWherePageData->setValue( currentPage );
00071        mvWherePageData->setDisabled( true );
00072        fromToLayout->addWidget( mvWhereData, currentRow, 0 );  
00073        fromToLayout->addWidget( mvWherePageData, currentRow, 1 );
00074        fromToLayout->addColSpacing(0, moveLabel->fontMetrics().width( tr( "Move Page(s):" )));
00075        dialogLayout->addLayout( fromToLayout );
00076 
00077        okCancelLayout = new QHBoxLayout;
00078        okCancelLayout->setSpacing( 6 );
00079        okCancelLayout->setMargin( 0 );
00080        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00081        okCancelLayout->addItem( spacer );
00082        okButton = new QPushButton( CommonStrings::tr_OK, this, "okButton" );
00083        okButton->setDefault( true );
00084        okCancelLayout->addWidget(okButton);
00085        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "cancelButton" );
00086        okCancelLayout->addWidget(cancelButton);
00087        dialogLayout->addLayout( okCancelLayout );
00088        setMaximumSize(sizeHint());
00089 
00090        // signals and slots connections
00091        if (move)
00092               connect( toPageData, SIGNAL( valueChanged(int) ), this, SLOT( toChanged(int) ) );
00093        connect( mvWhereData, SIGNAL( activated(int) ), this, SLOT( mvWherePageDataDisable(int) ) );
00094        connect( fromPageData, SIGNAL( valueChanged(int) ), this, SLOT( fromChanged(int) ) );
00095        connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
00096        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
00097 }
00098 
00099 void MovePages::fromChanged(int pageNumber)
00100 {
00101        if (move)
00102        {
00103               if (pageNumber > toPageData->value())
00104                      toPageData->setValue(pageNumber);
00105               if ((pageNumber == 1) && (toPageData->value() == toPageData->maxValue()))
00106                      toPageData->setValue(toPageData->maxValue()-1);
00107        }
00108 }
00109 
00110 void MovePages::toChanged(int pageNumber)
00111 {
00112        if (pageNumber < fromPageData->value())
00113               fromPageData->setValue(pageNumber);
00114        if ((fromPageData->value() == 1) && (pageNumber == toPageData->maxValue()))
00115               fromPageData->setValue(2);
00116 }
00117 
00118 void MovePages::mvWherePageDataDisable(int index)
00119 {
00120     mvWherePageData->setDisabled((index==2));
00121 }
00122 
00123 
00124 const int MovePages::getFromPage()
00125 {
00126        return fromPageData->value();
00127 }
00128 
00129 const int MovePages::getToPage()
00130 {
00131        return toPageData->value();
00132 }
00133 
00134 const int MovePages::getWhere()
00135 {
00136        return mvWhereData->currentItem();
00137 }
00138 
00139 const int MovePages::getWherePage()
00140 {
00141        return mvWherePageData->value();
00142 }
00143 
00144 const int MovePages::getCopyCount()
00145 {
00146        return numberOfCopiesData->value();
00147 }