1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 #include <QLabel>
8 #include <QPushButton>
9 
10 #include "delpages.h"
11 #include "iconmanager.h"
12 #include "commonstrings.h"
13 #include "ui/scrspinbox.h"
14 
DelPages(QWidget * parent,int currentPage,int maxPage)15 DelPages::DelPages( QWidget* parent, int currentPage, int maxPage ) : QDialog( parent )
16 {
17 	setWindowTitle( tr( "Delete Pages" ) );
18 	setModal(true);
19 	setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
20 	dialogLayout = new QVBoxLayout( this );
21 	dialogLayout->setSpacing(6);
22 	dialogLayout->setContentsMargins(9, 9, 9, 9);
23 	fromToLayout = new QHBoxLayout;
24 	fromToLayout->setSpacing(6);
25 	fromToLayout->setContentsMargins(0, 0, 0, 0);
26 	fromLabel = new QLabel( tr( "Delete From:" ), this );
27 	fromToLayout->addWidget( fromLabel );
28 	fromPageData = new ScrSpinBox(this);
29 	fromPageData->setDecimals(0);
30 	fromPageData->setSuffix("");
31 	fromPageData->setMinimum(1);
32 	fromPageData->setMaximum(maxPage);
33 	fromPageData->setSuffix("");
34 	fromPageData->setValue( currentPage );
35 	fromToLayout->addWidget( fromPageData );
36 	toLabel = new QLabel( this );
37 	toLabel->setText( tr( "to:" ) );
38 	fromToLayout->addWidget( toLabel );
39 	toPageData = new ScrSpinBox(this);
40 	toPageData->setDecimals(0);
41 	toPageData->setMinimum(1);
42 	toPageData->setMaximum(maxPage);
43 	toPageData->setSuffix("");
44 	toPageData->setValue( currentPage );
45 	toPageData->setSuffix("");
46 	fromToLayout->addWidget( toPageData );
47 	dialogLayout->addLayout( fromToLayout );
48 
49 	okCancelLayout = new QHBoxLayout;
50 	okCancelLayout->setSpacing(6);
51 	okCancelLayout->setContentsMargins(0, 0, 0, 0);
52 	QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
53 	okCancelLayout->addItem( spacer );
54 	okButton = new QPushButton( CommonStrings::tr_OK, this );
55 	okButton->setDefault( true );
56 	okCancelLayout->addWidget(okButton);
57 	cancelButton = new QPushButton( CommonStrings::tr_Cancel, this );
58 	cancelButton->setDefault( false );
59 	okCancelLayout->addWidget(cancelButton);
60 	dialogLayout->addLayout( okCancelLayout );
61 	setMaximumSize(sizeHint());
62 
63 	// signals and slots connections
64 	connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
65 	connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
66 	connect( fromPageData, SIGNAL( valueChanged(double) ), this, SLOT( fromChanged() ) );
67 	connect( toPageData, SIGNAL( valueChanged(double) ), this, SLOT( toChanged() ) );
68 }
69 
fromChanged()70 void DelPages::fromChanged()
71 {
72 	int pageNumber=static_cast<int>(fromPageData->value());
73 	if (pageNumber > toPageData->value())
74 		toPageData->setValue(pageNumber);
75 	if ((pageNumber == 1) && (toPageData->value() == toPageData->maximum()))
76 		toPageData->setValue(toPageData->maximum()-1);
77 }
78 
toChanged()79 void DelPages::toChanged()
80 {
81 	int pageNumber=toPageData->value();
82 	if (pageNumber < fromPageData->value())
83 		fromPageData->setValue(pageNumber);
84 	if ((fromPageData->value() == 1) && (pageNumber == toPageData->maximum()))
85 		fromPageData->setValue(2);
86 }
87 
getFromPage() const88 int DelPages::getFromPage() const
89 {
90 	return static_cast<int>(fromPageData->value());
91 }
92 
getToPage() const93 int DelPages::getToPage() const
94 {
95 	return toPageData->value();
96 }
97 
98