Back to index

scribus-ng  1.3.4.dfsg+svn20071115
delpages.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 <qlabel.h>
00009 #include <qlayout.h>
00010 #include <qpushbutton.h>
00011 #include <qspinbox.h>
00012 
00013 #include "delpages.h"
00014 #include "delpages.moc"
00015 
00016 #include "commonstrings.h"
00017 
00018 extern QPixmap loadIcon(QString nam);
00019 
00020 /*
00021  *  Constructs a DelPages which is a child of 'parent', with the 
00022  *  name 'name' and widget flags set to 'f' 
00023  *
00024  *  The dialog will by default be modeless, unless you set 'modal' to
00025  *  true to construct a modal dialog.
00026  */
00027 DelPages::DelPages( QWidget* parent, int currentPage, int maxPage )
00028               : QDialog( parent, "DelPages", true, 0 )
00029 {
00030        setCaption( tr( "Delete Pages" ) );
00031        setIcon(loadIcon("AppIcon.png"));
00032        dialogLayout = new QVBoxLayout( this, 10, 5);
00033        fromToLayout = new QHBoxLayout;
00034        fromToLayout->setSpacing( 6 );
00035        fromToLayout->setMargin( 5 );
00036        fromLabel = new QLabel( tr( "Delete From:" ), this, "fromLabel" );
00037        fromToLayout->addWidget( fromLabel );
00038        fromPageData = new QSpinBox( 1, maxPage, 1, this, "fromPageData" );
00039        fromPageData->setValue( currentPage );
00040        fromToLayout->addWidget( fromPageData );
00041        toLabel = new QLabel( this, "toLabel" );
00042        toLabel->setText( tr( "to:" ) );
00043        fromToLayout->addWidget( toLabel );
00044        toPageData = new QSpinBox( 1, maxPage, 1, this, "toPageData" );
00045        toPageData->setValue( currentPage );
00046        fromToLayout->addWidget( toPageData );
00047        dialogLayout->addLayout( fromToLayout );
00048 
00049        okCancelLayout = new QHBoxLayout;
00050        okCancelLayout->setSpacing( 6 );
00051        okCancelLayout->setMargin( 0 );
00052        QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00053        okCancelLayout->addItem( spacer );
00054        okButton = new QPushButton( CommonStrings::tr_OK, this, "okButton" );
00055        okButton->setDefault( true );
00056        okCancelLayout->addWidget(okButton);
00057        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this, "cancelButton" );
00058        cancelButton->setDefault( false );
00059        okCancelLayout->addWidget(cancelButton);
00060        dialogLayout->addLayout( okCancelLayout );
00061        setMaximumSize(sizeHint());
00062 
00063        // signals and slots connections
00064        connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
00065        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
00066        connect( fromPageData, SIGNAL( valueChanged(int) ), this, SLOT( fromChanged(int) ) );
00067        connect( toPageData, SIGNAL( valueChanged(int) ), this, SLOT( toChanged(int) ) );
00068 }
00069 
00070 void DelPages::fromChanged(int pageNumber)
00071 {
00072        if (pageNumber > toPageData->value())
00073               toPageData->setValue(pageNumber);
00074        if ((pageNumber == 1) && (toPageData->value() == toPageData->maxValue()))
00075               toPageData->setValue(toPageData->maxValue()-1);
00076 }
00077 
00078 void DelPages::toChanged(int pageNumber)
00079 {
00080        if (pageNumber < fromPageData->value())
00081               fromPageData->setValue(pageNumber);
00082        if ((fromPageData->value() == 1) && (pageNumber == toPageData->maxValue()))
00083               fromPageData->setValue(2);
00084 }
00085 
00086 const int DelPages::getFromPage()
00087 {
00088     return fromPageData->value();
00089 }
00090 
00091 const int DelPages::getToPage()
00092 {
00093     return toPageData->value();
00094 }
00095