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
8 #include "inspage.h"
9
10 #include <QLabel>
11 #include <QDialog>
12 #include <QComboBox>
13 #include <QGroupBox>
14 #include <QCheckBox>
15 #include <QPushButton>
16 #include <QScopedPointer>
17
18 #include "commonstrings.h"
19 #include "iconmanager.h"
20 #include "pagesize.h"
21 #include "scpage.h"
22 #include "scribusdoc.h"
23 #include "scrspinbox.h"
24 #include "units.h"
25 #include "util.h"
26
InsPage(QWidget * parent,ScribusDoc * currentDoc,int currentPage,int maxPages)27 InsPage::InsPage( QWidget* parent, ScribusDoc* currentDoc, int currentPage, int maxPages)
28 : QDialog(parent, Qt::WindowFlags())
29 {
30 m_doc = currentDoc;
31 masterPageCombos.clear();
32
33 setModal(true);
34 setWindowTitle( tr( "Insert Page" ) );
35 setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
36
37 dialogLayout = new QVBoxLayout(this);
38 dialogLayout->setSpacing(6);
39 dialogLayout->setContentsMargins(9, 9, 9, 9);
40
41 whereLayout = new QGridLayout();
42 whereLayout->setSpacing(6);
43 whereLayout->setContentsMargins(0, 0, 0, 0);
44
45 insCountData = new QSpinBox(this);
46 insCountData->setMinimum(1);
47 insCountData->setMaximum(999);
48 insCountData->setValue(1);
49 insCountLabel = new QLabel(tr( "&Insert" ), this );
50 insCountLabel->setBuddy(insCountData);
51 whereLayout->addWidget(insCountLabel, 0, 0);
52 whereLayout->addWidget(insCountData, 0, 1);
53
54 pagesLabel = new QLabel( tr( "Page(s)" ), this);
55 whereLayout->addWidget(pagesLabel, 0, 2);
56
57 insWhereData = new QComboBox( this );
58 insWhereData->addItem( tr("before Page"));
59 insWhereData->addItem( tr("after Page"));
60 insWhereData->addItem( tr("at End"));
61 insWhereData->setCurrentIndex(2);
62 whereLayout->addWidget(insWhereData, 1, 0, 1, 2);
63
64 insWherePageData = new QSpinBox(this);
65 insWherePageData->setMinimum(1);
66 insWherePageData->setMaximum(maxPages);
67 insWherePageData->setValue(currentPage + 1);
68 insWherePageData->setDisabled(true);
69
70 whereLayout->addWidget(insWherePageData, 1, 2);
71 whereLayout->addItem(new QSpacerItem(insCountLabel->fontMetrics().horizontalAdvance( tr( "&Insert" )), 0), 0, 0);
72 dialogLayout->addLayout(whereLayout);
73
74 masterPageLabel = nullptr;
75 masterPageGroup = new QGroupBox( this);
76 masterPageGroup->setTitle( tr( "Master Pages" ) );
77 masterPageLayout = new QGridLayout( masterPageGroup );
78 masterPageLayout->setAlignment(Qt::AlignTop);
79 masterPageLayout->setSpacing(6);
80 masterPageLayout->setContentsMargins(9, 9, 9, 9);
81 if (m_doc->pagePositioning() == 0)
82 {
83 QComboBox* pageData = new QComboBox(masterPageGroup);
84 for (QMap<QString, int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
85 {
86 pageData->addItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key(), it.key());
87 }
88 if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormal))
89 setCurrentComboItem(pageData, CommonStrings::trMasterPageNormal);
90 masterPageLabel = new QLabel(tr("&Master Page:"), masterPageGroup);
91 masterPageLabel->setBuddy(pageData);
92 masterPageLayout->addWidget(masterPageLabel, 0, 0);
93 masterPageLayout->addWidget(pageData, 0, 1);
94 masterPageCombos.append(pageData);
95 }
96 else
97 {
98 int row = 0;
99 const PageSet& currentPageSet = m_doc->pageSets()[m_doc->pagePositioning()];
100 for (int mp = 0; mp < currentPageSet.pageNames.count(); ++mp)
101 {
102 QComboBox* pageData = new QComboBox(masterPageGroup);
103 // for (QMap<QString, int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
104 // pageData->insertItem(it.key() == CommonStrings::masterPageNormal ? CommonStrings::trMasterPageNormal : it.key());
105 if (mp == 0)
106 {
107 bool conNam = m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalLeft);
108 for (QMap<QString, int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
109 {
110 if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
111 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
112 else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam))
113 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
114 else
115 {
116 if (m_doc->MasterPages.at(it.value())->LeftPg == 1)
117 pageData->addItem(it.key(), it.key());
118 }
119 }
120 if (m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalLeft))
121 setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalLeft);
122 }
123 else if (mp == 1)
124 {
125 if (currentPageSet.pageNames.count() > 2)
126 {
127 bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalMiddle);
128 for (QMap<QString, int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
129 {
130 if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
131 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
132 else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam))
133 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
134 else
135 {
136 if ((m_doc->MasterPages.at(it.value())->LeftPg != 0) && (m_doc->MasterPages.at(it.value())->LeftPg != 1))
137 pageData->addItem(it.key(), it.key());
138 }
139 }
140 if (m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalMiddle))
141 setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalMiddle);
142 }
143 else
144 {
145 bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
146 for (QMap<QString, int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
147 {
148 if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
149 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
150 else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam))
151 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
152 else
153 {
154 if (m_doc->MasterPages.at(it.value())->LeftPg == 0)
155 pageData->addItem(it.key(), it.key());
156 }
157 }
158 if (m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalRight))
159 setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight);
160 }
161 }
162 else if (mp == 2)
163 {
164 if (currentPageSet.pageNames.count() > 3)
165 {
166 bool conNam = m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalMiddle);
167 for (QMap<QString, int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
168 {
169 if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
170 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
171 else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam))
172 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
173 else
174 {
175 if ((m_doc->MasterPages.at(it.value())->LeftPg != 0) && (m_doc->MasterPages.at(it.value())->LeftPg != 1))
176 pageData->addItem(it.key(), it.key());
177 }
178 }
179 if (m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalMiddle))
180 setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalMiddle);
181 }
182 else
183 {
184 bool conNam = m_doc->MasterNames.contains(CommonStrings::trMasterPageNormalRight);
185 for (QMap<QString, int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
186 {
187 if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
188 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
189 else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam))
190 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
191 else
192 {
193 if (m_doc->MasterPages.at(it.value())->LeftPg == 0)
194 pageData->addItem(it.key(), it.key());
195 }
196 }
197 if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
198 setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight);
199 }
200 }
201 else if (mp == 3)
202 {
203 bool conNam = m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight);
204 for (QMap<QString, int>::Iterator it = m_doc->MasterNames.begin(); it != m_doc->MasterNames.end(); ++it)
205 {
206 if ((it.key() == CommonStrings::masterPageNormal) && (!conNam))
207 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
208 else if ((it.key() == CommonStrings::trMasterPageNormal) && (!conNam))
209 pageData->addItem(CommonStrings::trMasterPageNormal, it.key());
210 else
211 {
212 if (m_doc->MasterPages.at(it.value())->LeftPg == 0)
213 pageData->addItem(it.key(), it.key());
214 }
215 }
216 if (m_doc->MasterNames.contains( CommonStrings::trMasterPageNormalRight))
217 setCurrentComboItem(pageData, CommonStrings::trMasterPageNormalRight);
218 }
219 QString transLabel = currentPageSet.pageNames[mp];
220 QLabel* pageLabel = new QLabel(CommonStrings::translatePageSetLocString(transLabel), masterPageGroup);
221 pageLabel->setBuddy(pageData);
222 masterPageLayout->addWidget(pageLabel, row, 0 );
223 masterPageLayout->addWidget(pageData, row, 1);
224 row++;
225 masterPageCombos.append(pageData);
226 }
227 }
228 dialogLayout->addWidget(masterPageGroup);
229 overrideMPSizingCheckBox = new QCheckBox( tr("Override Master Page Sizing"));
230 dialogLayout->addWidget(overrideMPSizingCheckBox);
231 dsGroupBox7 = new QGroupBox( this );
232 dsGroupBox7->setTitle( tr( "Page Size" ) );
233 dsGroupBox7Layout = new QGridLayout(dsGroupBox7);
234 dsGroupBox7Layout->setSpacing(6);
235 dsGroupBox7Layout->setContentsMargins(9, 9, 9, 9);
236 textLabel1 = new QLabel( tr( "&Size:" ), dsGroupBox7);
237 dsGroupBox7Layout->addWidget(textLabel1, 0, 0);
238
239 QScopedPointer<PageSize> ps(new PageSize(m_doc->pageSize()));
240 prefsPageSizeName = ps->name();
241 sizeQComboBox = new QComboBox(dsGroupBox7);
242 QStringList insertList(ps->activeSizeTRList());
243 if (insertList.indexOf(prefsPageSizeName) == -1)
244 insertList << prefsPageSizeName;
245 insertList.sort();
246 insertList << CommonStrings::trCustomPageSize;
247 sizeQComboBox->addItems(insertList);
248 int sizeIndex = insertList.indexOf(ps->nameTR());
249 if (sizeIndex != -1)
250 sizeQComboBox->setCurrentIndex(sizeIndex);
251 else
252 sizeQComboBox->setCurrentIndex(sizeQComboBox->count() - 1);
253
254 textLabel1->setBuddy(sizeQComboBox);
255 dsGroupBox7Layout->addWidget(sizeQComboBox, 0, 1, 1, 3);
256
257 textLabel2 = new QLabel( tr( "Orie&ntation:" ), dsGroupBox7);
258 dsGroupBox7Layout->addWidget(textLabel2, 1, 0);
259
260 orientationQComboBox = new QComboBox(dsGroupBox7);
261 orientationQComboBox->addItem( tr( "Portrait" ) );
262 orientationQComboBox->addItem( tr( "Landscape" ) );
263 orientationQComboBox->setCurrentIndex(m_doc->pageOrientation() );
264 textLabel2->setBuddy(orientationQComboBox);
265 dsGroupBox7Layout->addWidget(orientationQComboBox, 1, 1, 1, 3);
266
267 widthSpinBox = new ScrSpinBox(1, 10000, dsGroupBox7, m_doc->unitIndex());
268 widthQLabel = new QLabel( tr( "&Width:" ), dsGroupBox7);
269 widthSpinBox->setValue(m_doc->pageWidth() * m_doc->unitRatio());
270 widthQLabel->setBuddy(widthSpinBox);
271 dsGroupBox7Layout->addWidget(widthQLabel, 2, 0);
272 dsGroupBox7Layout->addWidget(widthSpinBox, 2, 1);
273
274 heightSpinBox = new ScrSpinBox(1, 10000, dsGroupBox7, m_doc->unitIndex());
275 heightSpinBox->setValue(m_doc->pageHeight() * m_doc->unitRatio());
276 heightQLabel = new QLabel( tr( "&Height:" ), dsGroupBox7);
277 heightQLabel->setBuddy(heightSpinBox);
278 dsGroupBox7Layout->addWidget(heightQLabel, 3, 0);
279 dsGroupBox7Layout->addWidget(heightSpinBox, 3, 1);
280
281 moveObjectsCheckBox = new QCheckBox( dsGroupBox7);
282 moveObjectsCheckBox->setText( tr( "Move Objects with their Page" ) );
283 moveObjectsCheckBox->setChecked(true);
284 dsGroupBox7Layout->addWidget(moveObjectsCheckBox, 4, 0, 1, 4);
285 dialogLayout->addWidget(dsGroupBox7);
286
287 dsGroupBox7->setEnabled(false);
288 bool b = (sizeQComboBox->currentText() == CommonStrings::trCustomPageSize);
289 heightSpinBox->setEnabled(b);
290 widthSpinBox->setEnabled(b);
291
292 okCancelLayout = new QHBoxLayout;
293 okCancelLayout->setSpacing(6);
294 okCancelLayout->setContentsMargins(0, 0, 0, 0);
295 QSpacerItem* spacer = new QSpacerItem(20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
296 okCancelLayout->addItem(spacer);
297
298 okButton = new QPushButton(CommonStrings::tr_OK, this);
299 okButton->setDefault(true);
300 okCancelLayout->addWidget(okButton);
301
302 cancelButton = new QPushButton(CommonStrings::tr_Cancel, this);
303 okCancelLayout->addWidget(cancelButton);
304 dialogLayout->addLayout(okCancelLayout);
305 setMaximumSize(sizeHint());
306 m_unitRatio = m_doc->unitRatio();
307
308 // signals and slots connections
309 connect(insWhereData, SIGNAL( activated(int) ), this, SLOT( insWherePageDataDisable(int) ) );
310 connect(okButton, SIGNAL( clicked() ), this, SLOT( accept() ) );
311 connect(cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
312 connect(orientationQComboBox, SIGNAL(activated(int)), this, SLOT(setOrientation(int)));
313 connect(sizeQComboBox, SIGNAL(activated(const QString &)), this, SLOT(setSize(const QString &)));
314 connect(overrideMPSizingCheckBox, SIGNAL(stateChanged(int)), this, SLOT(enableSizingControls(int)));
315 }
316
setSize(const QString & gr)317 void InsPage::setSize(const QString & gr)
318 {
319 widthSpinBox->setEnabled(false);
320 heightSpinBox->setEnabled(false);
321 PageSize *ps2 = new PageSize(gr);
322 prefsPageSizeName = ps2->name();
323 if (gr == CommonStrings::trCustomPageSize)
324 {
325 widthSpinBox->setEnabled(true);
326 heightSpinBox->setEnabled(true);
327 prefsPageSizeName = CommonStrings::customPageSize;
328 }
329 else
330 {
331 widthSpinBox->setValue(ps2->width() * m_unitRatio);
332 heightSpinBox->setValue(ps2->height() * m_unitRatio);
333 }
334 delete ps2;
335 }
336
setOrientation(int ori)337 void InsPage::setOrientation(int ori)
338 {
339 double br;
340 setSize(sizeQComboBox->currentText());
341 if (ori == 0)
342 {
343 if (sizeQComboBox->currentText() == CommonStrings::trCustomPageSize)
344 {
345 br = widthSpinBox->value();
346 widthSpinBox->setValue(heightSpinBox->value());
347 heightSpinBox->setValue(br);
348 }
349 }
350 else
351 {
352 br = widthSpinBox->value();
353 widthSpinBox->setValue(heightSpinBox->value());
354 heightSpinBox->setValue(br);
355 }
356 }
357
getMasterPages() const358 QStringList InsPage::getMasterPages() const
359 {
360 QStringList ret;
361 for (int i = 0; i < masterPageCombos.count(); ++i)
362 {
363 int currentIndex = masterPageCombos.at(i)->currentIndex();
364 QVariant pageVar = masterPageCombos.at(i)->itemData(currentIndex);
365 ret.append(pageVar.toString());
366 }
367 return ret;
368 }
369
getMasterPageN(uint n) const370 QString InsPage::getMasterPageN(uint n) const
371 {
372 QComboBox* comboBox = masterPageCombos.at(n);
373 int currentIndex = comboBox->currentIndex();
374 return comboBox->itemData(currentIndex).toString();
375 }
376
getWhere() const377 int InsPage::getWhere() const
378 {
379 return insWhereData->currentIndex();
380 }
381
getWherePage() const382 int InsPage::getWherePage() const
383 {
384 if (insWhereData->currentIndex() == 2)
385 return m_doc->Pages->count();
386 return insWherePageData->value();
387 }
388
getCount() const389 int InsPage::getCount() const
390 {
391 return insCountData->value();
392 }
393
pageWidth() const394 double InsPage::pageWidth() const
395 {
396 return widthSpinBox->value() / m_unitRatio;
397 }
398
pageHeight() const399 double InsPage::pageHeight() const
400 {
401 return heightSpinBox->value() / m_unitRatio;
402 }
403
orientation() const404 int InsPage::orientation() const
405 {
406 return orientationQComboBox->currentIndex();
407 }
408
overrideMasterPageSizing() const409 bool InsPage::overrideMasterPageSizing() const
410 {
411 return (overrideMPSizingCheckBox->checkState() == Qt::Checked);
412 }
413
moveObjects() const414 bool InsPage::moveObjects() const
415 {
416 return moveObjectsCheckBox->isChecked();
417 }
418
insWherePageDataDisable(int index)419 void InsPage::insWherePageDataDisable(int index)
420 {
421 insWherePageData->setDisabled((index == 2));
422 }
423
enableSizingControls(int state)424 void InsPage::enableSizingControls(int state)
425 {
426 dsGroupBox7->setEnabled(state == Qt::Checked);
427 }
428