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 <QPixmap>
8 #include <QGridLayout>
9 #include <QHBoxLayout>
10 #include <QVBoxLayout>
11 #include <QLabel>
12 #include <QPushButton>
13 #include <QGroupBox>
14 #include <QComboBox>
15 #include <QCheckBox>
16 #include <QColorDialog>
17
18 #include "commonstrings.h"
19 #include "iconmanager.h"
20 #include "marginwidget.h"
21 #include "pagepropertiesdialog.h"
22 #include "pagesize.h"
23 #include "pagestructs.h"
24 #include "scpage.h"
25 #include "scribusdoc.h"
26 #include "scrspinbox.h"
27 #include "units.h"
28
PagePropertiesDialog(QWidget * parent,ScribusDoc * doc)29 PagePropertiesDialog::PagePropertiesDialog( QWidget* parent, ScribusDoc* doc ) : QDialog( parent)
30 {
31 setModal(true);
32 setWindowTitle( tr( "Manage Page Properties" ) );
33 setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
34 unitRatio = doc->unitRatio();
35 dialogLayout = new QVBoxLayout(this);
36 dialogLayout->setContentsMargins(9, 9, 9, 9);
37 dialogLayout->setSpacing(6);
38
39 dsGroupBox7 = new QGroupBox(this);
40 dsGroupBox7->setTitle( tr( "Page Size" ) );
41 dsGroupBox7Layout = new QGridLayout(dsGroupBox7);
42 dsGroupBox7Layout->setAlignment( Qt::AlignTop );
43 dsGroupBox7Layout->setSpacing(6);
44 dsGroupBox7Layout->setContentsMargins(9, 9, 9, 9);
45 TextLabel1 = new QLabel( tr( "&Size:" ), dsGroupBox7 );
46 dsGroupBox7Layout->addWidget( TextLabel1, 0, 0, 1, 2 );
47
48 PageSize ps(doc->currentPage()->size());
49 prefsPageSizeName=ps.name();
50 sizeQComboBox = new QComboBox(dsGroupBox7);
51 QStringList insertList(ps.activeSizeTRList());
52 if (insertList.indexOf(prefsPageSizeName)==-1 && prefsPageSizeName!=CommonStrings::customPageSize)
53 insertList<<prefsPageSizeName;
54 insertList.sort();
55 insertList<<CommonStrings::trCustomPageSize;
56 sizeQComboBox->addItems(insertList);
57 int sizeIndex = insertList.indexOf(ps.nameTR());
58 if (sizeIndex != -1)
59 sizeQComboBox->setCurrentIndex(sizeIndex);
60 else
61 sizeQComboBox->setCurrentIndex(sizeQComboBox->count()-1);
62
63 TextLabel1->setBuddy(sizeQComboBox);
64 dsGroupBox7Layout->addWidget(sizeQComboBox, 0, 2, 1, 2);
65 TextLabel2 = new QLabel( tr( "Orie&ntation:" ), dsGroupBox7 );
66 dsGroupBox7Layout->addWidget( TextLabel2, 1, 0, 1, 2 );
67 orientationQComboBox = new QComboBox( dsGroupBox7 );
68 orientationQComboBox->addItem( tr( "Portrait" ) );
69 orientationQComboBox->addItem( tr( "Landscape" ) );
70 orientationQComboBox->setEditable(false);
71 orientationQComboBox->setCurrentIndex(doc->currentPage()->orientation() );
72 oldOri = doc->currentPage()->orientation();
73 TextLabel2->setBuddy(orientationQComboBox);
74 dsGroupBox7Layout->addWidget( orientationQComboBox, 1, 2, 1, 2 );
75 widthSpinBox = new ScrSpinBox(pts2value(1.0, doc->unitIndex()), 16777215, dsGroupBox7, doc->unitIndex());
76 widthQLabel = new QLabel( tr( "&Width:" ), dsGroupBox7 );
77 widthSpinBox->setValue(doc->currentPage()->width() * doc->unitRatio());
78 widthQLabel->setBuddy(widthSpinBox);
79 dsGroupBox7Layout->addWidget( widthQLabel, 2, 0 );
80 dsGroupBox7Layout->addWidget( widthSpinBox, 2, 1 );
81 heightSpinBox = new ScrSpinBox(pts2value(1.0, doc->unitIndex()), 16777215, dsGroupBox7, doc->unitIndex());
82 heightSpinBox->setValue(doc->currentPage()->height() * doc->unitRatio());
83 heightQLabel = new QLabel( tr( "&Height:" ), dsGroupBox7 );
84 heightQLabel->setBuddy(heightSpinBox);
85 dsGroupBox7Layout->addWidget( heightQLabel, 2, 2 );
86 dsGroupBox7Layout->addWidget( heightSpinBox, 2, 3 );
87 moveObjects = new QCheckBox( dsGroupBox7 );
88 moveObjects->setText( tr( "Move Objects with their Page" ) );
89 moveObjects->setChecked( true );
90 dsGroupBox7Layout->addWidget( moveObjects, 3, 0, 1, 4 );
91 Links=nullptr;
92 if ((doc->pagePositioning() != singlePage) && (doc->masterPageMode()))
93 {
94 TextLabel3 = new QLabel( tr( "Type:" ), dsGroupBox7 );
95 dsGroupBox7Layout->addWidget( TextLabel3, 4, 0, 1, 2 );
96 Links = new QComboBox( dsGroupBox7 );
97 QStringList::Iterator pNames;
98 QList<PageSet> pageSet(doc->pageSets());
99 for(pNames = pageSet[doc->pagePositioning()].pageNames.begin(); pNames != pageSet[doc->pagePositioning()].pageNames.end(); ++pNames )
100 {
101 //Links->insertItem((*pNames));
102 Links->addItem(CommonStrings::translatePageSetLocString((*pNames)));
103 }
104 Links->setEditable(false);
105 dsGroupBox7Layout->addWidget( Links, 4, 2, 1, 2 );
106 if (doc->currentPage()->LeftPg == 0)
107 Links->setCurrentIndex(Links->count()-1);
108 else if (doc->currentPage()->LeftPg == 1)
109 Links->setCurrentIndex(0);
110 else
111 Links->setCurrentIndex(doc->currentPage()->LeftPg-1);
112 }
113 dialogLayout->addWidget( dsGroupBox7 );
114
115 marginWidget = new MarginWidget(this, tr( "Margin Guides" ), &doc->currentPage()->initialMargins, doc->unitIndex(), false, false);
116 marginWidget->setPageWidthHeight(doc->currentPage()->width(), doc->currentPage()->height());
117 marginWidget->setFacingPages(!(doc->pagePositioning() == singlePage), doc->locationOfPage(doc->currentPage()->pageNr()));
118 marginWidget->setMarginPreset(doc->currentPage()->marginPreset);
119 dialogLayout->addWidget( marginWidget );
120
121 groupMaster = new QGroupBox( this );
122 groupMaster->setTitle( tr( "Other Settings" ) );
123 masterLayout = new QHBoxLayout( groupMaster );
124 masterLayout->setSpacing(6);
125 masterLayout->setContentsMargins(9, 9, 9, 9);
126 masterPageLabel = new QLabel( groupMaster );
127 masterLayout->addWidget( masterPageLabel );
128 if (!doc->masterPageMode())
129 {
130 masterPageLabel->setText( tr( "Master Page:" ) );
131 masterPageComboBox = new QComboBox( groupMaster );
132 QString Nam = doc->currentPage()->masterPageName();
133 QString na = Nam == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : Nam, in;
134 int cc = 0;
135 for (QMap<QString,int>::Iterator it = doc->MasterNames.begin(); it != doc->MasterNames.end(); ++it)
136 {
137 in = it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key();
138 masterPageComboBox->addItem(in);
139 if (in == na)
140 masterPageComboBox->setCurrentIndex(cc);
141 ++cc;
142 }
143 masterLayout->addWidget( masterPageComboBox );
144 }
145 dialogLayout->addWidget( groupMaster );
146 if (doc->masterPageMode())
147 groupMaster->hide();
148
149 okCancelLayout = new QHBoxLayout;
150 okCancelLayout->setSpacing(6);
151 okCancelLayout->setContentsMargins(0, 0, 0, 0);
152 QSpacerItem* spacer = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum );
153 okCancelLayout->addItem( spacer );
154 okButton = new QPushButton( CommonStrings::tr_OK, this );
155 okButton->setDefault( true );
156 okCancelLayout->addWidget(okButton);
157 cancelButton = new QPushButton( CommonStrings::tr_Cancel, this );
158 cancelButton->setDefault( false );
159 okCancelLayout->addWidget(cancelButton);
160 dialogLayout->addLayout( okCancelLayout );
161 setMaximumSize(sizeHint());
162 pageWidth = widthSpinBox->value() / unitRatio;
163 pageHeight = heightSpinBox->value() / unitRatio;
164 bool isCustom = (sizeQComboBox->currentText() == CommonStrings::trCustomPageSize);
165 heightSpinBox->setEnabled(isCustom);
166 widthSpinBox->setEnabled(isCustom);
167 // signals and slots connections
168 connect( okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
169 connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
170 connect(orientationQComboBox, SIGNAL(activated(int)), this, SLOT(setOrientation(int)));
171 connect(sizeQComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
172 connect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
173 connect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double)));
174
175 //tooltips
176 sizeQComboBox->setToolTip( tr( "Size of the inserted pages, either a standard or custom size" ) );
177 orientationQComboBox->setToolTip( tr( "Orientation of the page(s) to be inserted" ) );
178 widthSpinBox->setToolTip( tr( "Width of the page(s) to be inserted" ) );
179 heightSpinBox->setToolTip( tr( "Height of the page(s) to be inserted" ) );
180 moveObjects->setToolTip( tr( "When inserting a new page between others, move objects with their current pages. This is the default action." ) );
181
182 setPageSize();
183 setMinimumSize(minimumSizeHint());
184 setMaximumSize(minimumSizeHint());
185 resize(minimumSizeHint());
186 }
187
setPageWidth(double)188 void PagePropertiesDialog::setPageWidth(double)
189 {
190 pageWidth = widthSpinBox->value() / unitRatio;
191 marginWidget->setPageWidth(pageWidth);
192 int newOrientation = (widthSpinBox->value() > heightSpinBox->value()) ? landscapePage : portraitPage;
193 if (newOrientation != orientationQComboBox->currentIndex())
194 {
195 orientationQComboBox->blockSignals(true);
196 orientationQComboBox->setCurrentIndex(newOrientation);
197 orientationQComboBox->blockSignals(false);
198 oldOri = newOrientation;
199 }
200 }
201
setPageHeight(double)202 void PagePropertiesDialog::setPageHeight(double)
203 {
204 pageHeight = heightSpinBox->value() / unitRatio;
205 marginWidget->setPageHeight(pageHeight);
206 int newOrientation = (widthSpinBox->value() > heightSpinBox->value()) ? landscapePage : portraitPage;
207 if (newOrientation != orientationQComboBox->currentIndex())
208 {
209 orientationQComboBox->blockSignals(true);
210 orientationQComboBox->setCurrentIndex(newOrientation);
211 orientationQComboBox->blockSignals(false);
212 oldOri = newOrientation;
213 }
214 }
215
setPageSize()216 void PagePropertiesDialog::setPageSize()
217 {
218 if (sizeQComboBox->currentText() != CommonStrings::trCustomPageSize)
219 oldOri++;
220 setOrientation(orientationQComboBox->currentIndex());
221 }
222
setSize(const QString & gr)223 void PagePropertiesDialog::setSize(const QString & gr)
224 {
225 pageWidth = widthSpinBox->value() / unitRatio;
226 pageHeight = heightSpinBox->value() / unitRatio;
227 widthSpinBox->setEnabled(false);
228 heightSpinBox->setEnabled(false);
229 PageSize *ps2 = new PageSize(gr);
230 prefsPageSizeName = ps2->name();
231 if (gr == CommonStrings::trCustomPageSize)
232 {
233 widthSpinBox->setEnabled(true);
234 heightSpinBox->setEnabled(true);
235 prefsPageSizeName = CommonStrings::customPageSize;
236 }
237 else
238 {
239 pageWidth = ps2->width();
240 pageHeight = ps2->height();
241 }
242 disconnect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
243 disconnect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double)));
244 widthSpinBox->setValue(pageWidth * unitRatio);
245 heightSpinBox->setValue(pageHeight * unitRatio);
246 marginWidget->setPageHeight(pageHeight);
247 marginWidget->setPageWidth(pageWidth);
248 marginWidget->setPageSize(gr);
249 connect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
250 connect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double)));
251 delete ps2;
252 }
253
setOrientation(int ori)254 void PagePropertiesDialog::setOrientation(int ori)
255 {
256 setSize(sizeQComboBox->currentText());
257 disconnect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
258 disconnect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double)));
259 if ((sizeQComboBox->currentText() == CommonStrings::trCustomPageSize) && (ori != oldOri))
260 {
261 double w = widthSpinBox->value(), h = heightSpinBox->value();
262 widthSpinBox->setValue((ori == portraitPage) ? qMin(w, h) : qMax(w, h));
263 heightSpinBox->setValue((ori == portraitPage) ? qMax(w, h) : qMin(w, h));
264 }
265 else
266 {
267 if ((ori != portraitPage) && (ori != oldOri))
268 {
269 double w = widthSpinBox->value(), h = heightSpinBox->value();
270 widthSpinBox->setValue(qMax(w, h));
271 heightSpinBox->setValue(qMin(w, h));
272 }
273 }
274 oldOri = ori;
275 pageWidth = widthSpinBox->value() / unitRatio;
276 pageHeight = heightSpinBox->value() / unitRatio;
277 connect(widthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
278 connect(heightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double)));
279 }
280
pageOrder()281 int PagePropertiesDialog::pageOrder()
282 {
283 int lp=0;
284 if (Links!=nullptr)
285 lp = Links->currentIndex();
286 if (lp == 0)
287 lp = 1;
288 else if (lp == static_cast<int>(Links->count()-1))
289 lp = 0;
290 else
291 lp++;
292 return lp;
293 }
294
getPageWidth()295 double PagePropertiesDialog::getPageWidth()
296 {
297 return pageWidth;
298 }
299
getPageHeight()300 double PagePropertiesDialog::getPageHeight()
301 {
302 return pageHeight;
303 }
304
getPageOrientation()305 int PagePropertiesDialog::getPageOrientation()
306 {
307 return orientationQComboBox->currentIndex();
308 }
309
getPrefsPageSizeName()310 QString PagePropertiesDialog::getPrefsPageSizeName()
311 {
312 return prefsPageSizeName;
313 }
314
getMoveObjects()315 bool PagePropertiesDialog::getMoveObjects()
316 {
317 return moveObjects->isChecked();
318 }
319
top()320 double PagePropertiesDialog::top()
321 {
322 return marginWidget->top();
323 }
324
bottom()325 double PagePropertiesDialog::bottom()
326 {
327 return marginWidget->bottom();
328 }
329
left()330 double PagePropertiesDialog::left()
331 {
332 return marginWidget->left();
333 }
334
right()335 double PagePropertiesDialog::right()
336 {
337 return marginWidget->right();
338 }
339
masterPage()340 QString PagePropertiesDialog::masterPage()
341 {
342 if (masterPageComboBox != nullptr)
343 return masterPageComboBox->currentText();
344 return "";
345 }
346
getMarginPreset()347 int PagePropertiesDialog::getMarginPreset()
348 {
349 return marginWidget->getMarginPreset();
350 }
351