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 "marginwidget.h"
8
9 #include <QHBoxLayout>
10 #include <QGridLayout>
11 #include <QLabel>
12 #include <QToolTip>
13 #include <QCheckBox>
14 #include <QLabel>
15 #include <QPushButton>
16
17 #include "scrspinbox.h"
18 #include "units.h"
19 #include "ui/useprintermarginsdialog.h"
20
21
MarginWidget(QWidget * parent,const QString &,const MarginStruct * margs,int unitIndex,bool showChangeAll,bool showBleeds)22 MarginWidget::MarginWidget( QWidget* parent, const QString& /*title*/, const MarginStruct* margs, int unitIndex, bool showChangeAll, bool showBleeds) : QTabWidget(parent),
23 m_useBleeds(showBleeds)
24 {
25 marginData = *margs;
26 m_savedMargins = *margs;
27 m_savedPresetItem = PresetLayout::none; //we don't recheck if we are using a layout but always start at none
28 marginPage = new QWidget(this);
29
30 presetCombo = new PresetLayout(marginPage);
31 presetLabel = new QLabel( tr("Preset Layouts:"), marginPage);
32 presetLabel->setBuddy(presetCombo);
33 m_unitIndex = unitIndex;
34 m_unitRatio = unitGetRatioFromIndex(unitIndex);
35 leftR = new ScrSpinBox( 0, 1000, marginPage, unitIndex );
36 rightR = new ScrSpinBox( 0, 1000, marginPage, unitIndex );
37 topR = new ScrSpinBox( 0, 1000, marginPage, unitIndex );
38 bottomR = new ScrSpinBox( 0, 1000, marginPage, unitIndex );
39 updateMarginSpinValues();
40
41 bText = new QLabel( tr( "&Bottom:" ), marginPage);
42 bText->setBuddy(bottomR);
43 tText = new QLabel( tr( "&Top:" ), marginPage);
44 tText->setBuddy(topR);
45 rText = new QLabel( tr( "&Right:" ), marginPage);
46 rText->setBuddy(rightR);
47 lText = new QLabel( tr( "&Left:" ), marginPage);
48 lText->setBuddy(leftR);
49
50 linkMargins = new LinkButton( marginPage );
51 linkMargins->setCheckable( true );
52 linkMargins->setChecked(false);
53 linkMargins->setAutoRaise( true );
54 linkMargins->setMinimumSize( QSize( 15, 0 ) );
55 linkMargins->setMaximumSize( QSize( 15, 32767 ) );
56
57 // layout
58 GroupLayout = new QGridLayout( marginPage );
59 GroupLayout->setSpacing(6);
60 GroupLayout->setContentsMargins(9, 9, 9, 9);
61 GroupLayout->addWidget(presetLabel, 0, 0);
62 GroupLayout->addWidget(presetCombo, 0, 1);
63 GroupLayout->addWidget( leftR, 1, 1 );
64 GroupLayout->addWidget( rightR, 2, 1 );
65 GroupLayout->addWidget( topR, 3, 1 );
66 GroupLayout->addWidget( bottomR, 4, 1 );
67 GroupLayout->addWidget( lText, 1, 0 );
68 GroupLayout->addWidget( rText, 2, 0 );
69 GroupLayout->addWidget( tText, 3, 0 );
70 GroupLayout->addWidget( bText, 4, 0 );
71 GroupLayout->addWidget( linkMargins, 1, 2, 4, 1 );
72 if (showChangeAll)
73 {
74 marginsForPagesLayout = new QHBoxLayout;
75 marginsForPagesLayout->setContentsMargins(9, 9, 9, 9);
76 marginsForPagesLayout->setSpacing(6);
77 marginsForPages = new QLabel( tr( "Apply settings to:" ), marginPage );
78 marginsForPagesLayout->addWidget(marginsForPages);
79 marginsForAllPages = new QCheckBox( marginPage );
80 marginsForAllPages->setText( tr( "All Document Pages" ) );
81 marginsForAllPages->setChecked( false );
82 marginsForPagesLayout->addWidget(marginsForAllPages);
83 marginsForAllMasterPages = new QCheckBox( marginPage );
84 marginsForAllMasterPages->setText( tr( "All Master Pages" ) );
85 marginsForAllMasterPages->setChecked( false );
86 marginsForPagesLayout->addWidget(marginsForAllMasterPages);
87 GroupLayout->addLayout( marginsForPagesLayout, 6, 0, 1, 2 );
88 marginsForAllPages->setToolTip( "<qt>" + tr( "Apply the margin changes to all existing pages in the document" ) + "</qt>" );
89 marginsForAllMasterPages->setToolTip( "<qt>" + tr( "Apply the margin changes to all existing master pages in the document" ) + "</qt>" );
90 }
91
92 usePrinterMarginsButton = nullptr;
93 usePrinterMarginsButton = new QPushButton( tr("Printer Margins..."),marginPage );
94 GroupLayout->addWidget( usePrinterMarginsButton, 5, 1 );
95 usePrinterMarginsButton->setToolTip( "<qt>" + tr( "Import the margins for the selected page size from the available printers" ) + "</qt>");
96 connect(usePrinterMarginsButton, SIGNAL(clicked()), this, SLOT(setMarginsToPrinterMargins()));
97
98 addTab(marginPage, tr("Margin Guides"));
99
100 if (m_useBleeds)
101 {
102 bleedPage = new QWidget(this);
103 BleedGroupLayout = new QGridLayout( bleedPage );
104 BleedGroupLayout->setSpacing(6);
105 BleedGroupLayout->setContentsMargins(9, 9, 9, 9);
106 BleedGroupLayout->setAlignment( Qt::AlignTop );
107 BleedTxt3 = new QLabel( bleedPage );
108 BleedGroupLayout->addWidget( BleedTxt3, 0, 0 );
109 BleedLeft = new ScrSpinBox( 0, 3000*m_unitRatio, bleedPage, unitIndex );
110 BleedGroupLayout->addWidget( BleedLeft, 0, 1 );
111 BleedTxt4 = new QLabel( bleedPage );
112 BleedGroupLayout->addWidget( BleedTxt4, 1, 0 );
113 BleedRight = new ScrSpinBox( 0, 3000*m_unitRatio, bleedPage, unitIndex );
114 BleedGroupLayout->addWidget( BleedRight, 1, 1 );
115 BleedTxt1 = new QLabel( bleedPage );
116 BleedTxt1->setText( tr( "Top:" ) );
117 BleedGroupLayout->addWidget( BleedTxt1, 2, 0 );
118 BleedTop = new ScrSpinBox( 0, 3000*m_unitRatio, bleedPage, unitIndex );
119 BleedGroupLayout->addWidget( BleedTop, 2, 1 );
120 BleedTxt2 = new QLabel( bleedPage );
121 BleedTxt2->setText( tr( "Bottom:" ) );
122 BleedGroupLayout->addWidget( BleedTxt2, 3, 0 );
123 BleedBottom = new ScrSpinBox( 0, 3000*m_unitRatio, bleedPage, unitIndex );
124 BleedGroupLayout->addWidget( BleedBottom, 3, 1 );
125 linkBleeds = new LinkButton( bleedPage );
126 /** Fix Me to move this to the prefsmanager.cpp someday */
127 linkBleeds->setCheckable( true );
128 linkBleeds->setChecked(true);
129 linkBleeds->setAutoRaise( true );
130 linkBleeds->setMinimumSize( QSize( 15, 0 ) );
131 linkBleeds->setMaximumSize( QSize( 15, 32767 ) );
132 BleedGroupLayout->addWidget( linkBleeds, 0, 2, 4, 1 );
133 BleedTop->setToolTip( "<qt>" + tr( "Distance for bleed from the top of the physical page" ) + "</qt>" );
134 BleedBottom->setToolTip( "<qt>" + tr( "Distance for bleed from the bottom of the physical page" ) + "</qt>" );
135 BleedLeft->setToolTip( "<qt>" + tr( "Distance for bleed from the left of the physical page" ) + "</qt>" );
136 BleedRight->setToolTip( "<qt>" + tr( "Distance for bleed from the right of the physical page" ) + "</qt>");
137 linkBleeds->setToolTip( "<qt>" + tr( "Ensure all bleeds have the same value" ) + "</qt>");
138 connect(BleedLeft, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
139 connect(BleedRight, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
140 connect(BleedTop, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
141 connect(BleedBottom, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
142 connect(linkBleeds, SIGNAL(clicked()), this, SLOT(slotLinkBleeds()));
143 addTab(bleedPage, tr("Bleeds"));
144 }
145
146 // hints
147 topR->setToolTip( "<qt>" + tr( "Distance between the top margin guide and the edge of the page" ) + "</qt>");
148 bottomR->setToolTip( "<qt>" + tr( "Distance between the bottom margin guide and the edge of the page" ) + "</qt>");
149 leftR->setToolTip( "<qt>" + tr( "Distance between the left margin guide and the edge of the page. If a double-sided, 3 or 4-fold layout is selected, this margin space can be used to achieve the correct margins for binding.") + "</qt>");
150 rightR->setToolTip( "<qt>" + tr( "Distance between the right margin guide and the edge of the page. If a double-sided, 3 or 4-fold layout is selected, this margin space can be used to achieve the correct margins for binding.") + "</qt>");
151 linkMargins->setToolTip( "<qt>" + tr( "Ensure all margins have the same value") + "</qt>");
152
153 // signals&slots
154 connect(topR, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
155 connect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
156 connect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
157 connect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
158 connect(presetCombo, SIGNAL(activated(int)), this, SLOT(setPreset()));
159 connect(linkMargins, SIGNAL(clicked()), this, SLOT(slotLinkMargins()));
160 }
161
slotLinkBleeds()162 void MarginWidget::slotLinkBleeds()
163 {
164 disconnect(BleedLeft, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
165 disconnect(BleedRight, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
166 disconnect(BleedTop, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
167 disconnect(BleedBottom, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
168
169 double bleedValue = BleedLeft->value();
170 if (BleedLeft->hasFocus())
171 {
172 BleedLeft->clearFocus();
173 bleedValue = BleedLeft->value();
174 }
175 if (BleedRight->hasFocus())
176 {
177 BleedRight->clearFocus();
178 bleedValue = BleedRight->value();
179 }
180 if (BleedTop->hasFocus())
181 {
182 BleedTop->clearFocus();
183 bleedValue = BleedTop->value();
184 }
185 if (BleedBottom->hasFocus())
186 {
187 BleedBottom->clearFocus();
188 bleedValue = BleedBottom->value();
189 }
190
191 if (linkBleeds->isChecked())
192 {
193 BleedLeft->setValue(bleedValue);
194 BleedTop->setValue(bleedValue);
195 BleedBottom->setValue(bleedValue);
196 BleedRight->setValue(bleedValue);
197 }
198
199 connect(BleedLeft, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
200 connect(BleedRight, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
201 connect(BleedTop, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
202 connect(BleedBottom, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
203 }
204
changeBleeds()205 void MarginWidget::changeBleeds()
206 {
207 if (linkBleeds->isChecked())
208 {
209 double val = 0.0;
210 if (BleedTop == sender())
211 val = BleedTop->value();
212 else if (BleedBottom == sender())
213 val = BleedBottom->value();
214 else if (BleedLeft == sender())
215 val = BleedLeft->value();
216 else if (BleedRight == sender())
217 val = BleedRight->value();
218 val = val / m_unitRatio;
219 MarginStruct v(val,val,val,val);
220 setNewBleeds(v);
221 }
222 }
223
setFacingPages(bool facing,int pagetype)224 void MarginWidget::setFacingPages(bool facing, int pagetype)
225 {
226 m_facingPages = facing;
227 m_pageType = pagetype;
228 lText->setText(facing ? tr( "&Inside:" ) : tr( "&Left:" ));
229 rText->setText(facing ? tr( "O&utside:" ) : tr( "&Right:" ));
230 if (m_useBleeds)
231 {
232 if (facing)
233 {
234 BleedTxt3->setText( tr( "Inside:" ) );
235 BleedTxt4->setText( tr( "Outside:" ) );
236 }
237 else
238 {
239 BleedTxt3->setText( tr( "Left:" ) );
240 BleedTxt4->setText( tr( "Right:" ) );
241 }
242 }
243 setPreset();
244 }
245
setPageWidthHeight(double width,double height)246 void MarginWidget::setPageWidthHeight(double width, double height)
247 {
248 rightR->setMaximum(qMax(0.0, width * m_unitRatio - leftR->value()));
249 leftR->setMaximum(qMax(0.0, width * m_unitRatio - rightR->value()));
250 m_pageWidth = width;
251 topR->setMaximum(qMax(0.0, height * m_unitRatio - bottomR->value()));
252 bottomR->setMaximum(qMax(0.0, height * m_unitRatio - topR->value()));
253 m_pageHeight = height;
254 setPreset();
255 }
256
setPageWidth(double width)257 void MarginWidget::setPageWidth(double width)
258 {
259 rightR->setMaximum(qMax(0.0, width * m_unitRatio - leftR->value()));
260 leftR->setMaximum(qMax(0.0,width * m_unitRatio - rightR->value()));
261 m_pageWidth = width;
262 setPreset();
263 }
264
setPageHeight(double height)265 void MarginWidget::setPageHeight(double height)
266 {
267 topR->setMaximum(qMax(0.0, height * m_unitRatio - bottomR->value()));
268 bottomR->setMaximum(qMax(0.0,height * m_unitRatio - topR->value()));
269 m_pageHeight = height;
270 setPreset();
271 }
272
setTop()273 void MarginWidget::setTop()
274 {
275 double newVal=topR->value() / m_unitRatio;
276 bottomR->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - topR->value()));
277 if (linkMargins->isChecked() && m_savedPresetItem == PresetLayout::none)
278 {
279 marginData.set(newVal, newVal, newVal, newVal);
280 updateMarginSpinValues();
281 }
282 else
283 marginData.setTop(newVal);
284 setPreset();
285 }
286
setBottom()287 void MarginWidget::setBottom()
288 {
289 double newVal = bottomR->value() / m_unitRatio;
290 topR->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - bottomR->value()));
291 if (linkMargins->isChecked() && m_savedPresetItem == PresetLayout::none)
292 {
293 marginData.set(newVal, newVal, newVal, newVal);
294 updateMarginSpinValues();
295 }
296 else
297 marginData.setBottom(newVal);
298 setPreset();
299 }
300
setLeft()301 void MarginWidget::setLeft()
302 {
303 double newVal = leftR->value() / m_unitRatio;
304 rightR->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - leftR->value()));
305 if (linkMargins->isChecked() && m_savedPresetItem == PresetLayout::none)
306 {
307 marginData.set(newVal, newVal, newVal, newVal);
308 updateMarginSpinValues();
309 }
310 else
311 marginData.setLeft(newVal);
312 setPreset();
313 }
314
setRight()315 void MarginWidget::setRight()
316 {
317 double newVal = rightR->value() / m_unitRatio;
318 leftR->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - rightR->value()));
319 if (linkMargins->isChecked() && m_savedPresetItem == PresetLayout::none)
320 {
321 marginData.set(newVal, newVal, newVal, newVal);
322 updateMarginSpinValues();
323 }
324 else
325 marginData.setRight(newVal);
326 setPreset();
327 }
328
setNewUnit(int newUnitIndex)329 void MarginWidget::setNewUnit(int newUnitIndex)
330 {
331 disconnect(topR, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
332 disconnect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
333 disconnect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
334 disconnect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
335 m_unitIndex = newUnitIndex;
336 m_unitRatio = unitGetRatioFromIndex(newUnitIndex);
337 topR->setNewUnit(newUnitIndex);
338 bottomR->setNewUnit(newUnitIndex);
339 leftR->setNewUnit(newUnitIndex);
340 rightR->setNewUnit(newUnitIndex);
341
342 if (m_useBleeds)
343 {
344 disconnect(BleedLeft, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
345 disconnect(BleedRight, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
346 disconnect(BleedTop, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
347 disconnect(BleedBottom, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
348 BleedBottom->setNewUnit(newUnitIndex);
349 BleedTop->setNewUnit(newUnitIndex);
350 BleedRight->setNewUnit(newUnitIndex);
351 BleedLeft->setNewUnit(newUnitIndex);
352 connect(BleedLeft, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
353 connect(BleedRight, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
354 connect(BleedTop, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
355 connect(BleedBottom, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
356 }
357 connect(topR, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
358 connect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
359 connect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
360 connect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
361 }
362
setPreset()363 void MarginWidget::setPreset()
364 {
365 disconnect(topR, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
366 disconnect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
367 disconnect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
368 disconnect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
369 if (m_savedPresetItem == PresetLayout::none)
370 m_savedMargins = marginData;
371 int item = presetCombo->currentIndex();
372
373 MarginStruct marg = presetCombo->getMargins(item, m_pageWidth, m_pageHeight, leftR->value() / m_unitRatio);
374 presetCombo->setEnabled(m_facingPages);
375
376 bool restoringValues = false;
377 if ((item == PresetLayout::none) && (m_savedPresetItem != PresetLayout::none))
378 {
379 marg = m_savedMargins;
380 restoringValues = true;
381 }
382 if (restoringValues || (presetCombo->needUpdate() && m_facingPages))
383 {
384 marginData.set(qMax(0.0, marg.top()), qMax(0.0, marg.left()), qMax(0.0, marg.bottom()), qMax(0.0, marg.right()));
385 updateMarginSpinValues();
386
387 bottomR->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - topR->value()));
388 topR->setMaximum(qMax(0.0, m_pageHeight * m_unitRatio - bottomR->value()));
389 rightR->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - leftR->value()));
390 leftR->setMaximum(qMax(0.0, m_pageWidth * m_unitRatio - rightR->value()));
391 rightR->setEnabled(restoringValues);
392 topR->setEnabled(restoringValues);
393 bottomR->setEnabled(restoringValues);
394 }
395 else
396 {
397 rightR->setEnabled(true);
398 topR->setEnabled(true);
399 bottomR->setEnabled(true);
400 }
401 if (m_pageType == 1)
402 rightR->setEnabled(false);
403 leftR->setEnabled(item != PresetLayout::nineparts);
404 if (item != PresetLayout::none)
405 linkMargins->setChecked(false);
406 linkMargins->setEnabled(item == PresetLayout::none || !presetCombo->isEnabled());
407 connect(topR, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
408 connect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
409 connect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
410 connect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
411 m_savedPresetItem=item;
412 }
413
setPageSize(const QString & pageSize)414 void MarginWidget::setPageSize(const QString& pageSize)
415 {
416 m_pageSize = pageSize;
417 }
418
setMarginsToPrinterMargins()419 void MarginWidget::setMarginsToPrinterMargins()
420 {
421 QSizeF pageDimensions(m_pageWidth, m_pageHeight);
422 UsePrinterMarginsDialog upm(parentWidget(), pageDimensions, m_pageSize, unitGetRatioFromIndex(m_unitIndex), unitGetSuffixFromIndex(m_unitIndex));
423 if (upm.exec() != QDialog::Accepted)
424 return;
425
426 double t, b, l, r;
427 upm.getNewPrinterMargins(t, b, l, r);
428 presetCombo->setCurrentIndex(PresetLayout::none);
429
430 marginData.setTop(t);
431 marginData.setBottom(b);
432 marginData.setLeft(l);
433 marginData.setRight(r);
434 updateMarginSpinValues();
435
436 bottomR->setMaximum((qMax(0.0, m_pageHeight - t) * m_unitRatio));
437 topR->setMaximum((qMax(0.0, m_pageHeight - b) * m_unitRatio));
438 rightR->setMaximum((qMax(0.0, m_pageWidth - l) * m_unitRatio));
439 leftR->setMaximum((qMax(0.0, m_pageWidth - r) * m_unitRatio));
440
441 rightR->setEnabled(true);
442 topR->setEnabled(true);
443 bottomR->setEnabled(true);
444 }
445
top() const446 double MarginWidget::top() const
447 {
448 return marginData.top();
449 }
450
bottom() const451 double MarginWidget::bottom() const
452 {
453 return marginData.bottom();
454 }
455
left() const456 double MarginWidget::left() const
457 {
458 return marginData.left();
459 }
460
right() const461 double MarginWidget::right() const
462 {
463 return marginData.right();
464 }
465
setNewMargins(MarginStruct & m)466 void MarginWidget::setNewMargins(MarginStruct &m)
467 {
468 disconnect(topR, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
469 disconnect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
470 disconnect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
471 disconnect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
472 marginData=m;
473 updateMarginSpinValues();
474 connect(topR, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
475 connect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
476 connect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
477 connect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
478 }
479
setMarginPreset(int p)480 void MarginWidget::setMarginPreset(int p)
481 {
482 disconnect(presetCombo, SIGNAL(activated(int)), this, SLOT(setPreset()));
483 m_savedPresetItem = p;
484 presetCombo->setCurrentIndex(p);
485 if (m_savedPresetItem == PresetLayout::none)
486 m_savedMargins=marginData;
487 int item = presetCombo->currentIndex();
488 presetCombo->setEnabled(m_facingPages);
489 bool restoringValues=false;
490 if ((item == PresetLayout::none) && (m_savedPresetItem != PresetLayout::none))
491 {
492 restoringValues=true;
493 }
494 if (restoringValues || (presetCombo->needUpdate() && m_facingPages))
495 {
496 rightR->setEnabled(restoringValues);
497 topR->setEnabled(restoringValues);
498 bottomR->setEnabled(restoringValues);
499 }
500 else
501 {
502 rightR->setEnabled(true);
503 topR->setEnabled(true);
504 bottomR->setEnabled(true);
505 }
506 if (m_pageType == 1)
507 rightR->setEnabled(false);
508 leftR->setEnabled(item != PresetLayout::nineparts);
509 if (item!=PresetLayout::none)
510 linkMargins->setChecked(false);
511 linkMargins->setEnabled(item==PresetLayout::none);
512 connect(presetCombo, SIGNAL(activated(int)), this, SLOT(setPreset()));
513 }
514
getMarginPreset()515 int MarginWidget::getMarginPreset()
516 {
517 return presetCombo->currentIndex();
518 }
519
getMarginsForAllPages() const520 bool MarginWidget::getMarginsForAllPages() const
521 {
522 return marginsForAllPages->isChecked();
523 }
524
getMarginsForAllMasterPages() const525 bool MarginWidget::getMarginsForAllMasterPages() const
526 {
527 return marginsForAllMasterPages->isChecked();
528 }
529
setNewBleeds(MarginStruct & b)530 void MarginWidget::setNewBleeds(MarginStruct& b)
531 {
532 disconnect(BleedLeft, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
533 disconnect(BleedRight, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
534 disconnect(BleedTop, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
535 disconnect(BleedBottom, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
536 BleedTop->setValue(b.top() * m_unitRatio);
537 BleedBottom->setValue(b.bottom() * m_unitRatio);
538 BleedLeft->setValue(b.left() * m_unitRatio);
539 BleedRight->setValue(b.right() * m_unitRatio);
540 connect(BleedLeft, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
541 connect(BleedRight, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
542 connect(BleedTop, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
543 connect(BleedBottom, SIGNAL(valueChanged(double)), this, SLOT(changeBleeds()));
544 }
545
topBleed() const546 double MarginWidget::topBleed() const
547 {
548 return BleedTop->value() / m_unitRatio;
549 }
550
bottomBleed() const551 double MarginWidget::bottomBleed() const
552 {
553 return BleedBottom->value() / m_unitRatio;
554 }
555
leftBleed() const556 double MarginWidget::leftBleed() const
557 {
558 return BleedLeft->value() / m_unitRatio;
559 }
560
rightBleed() const561 double MarginWidget::rightBleed() const
562 {
563 return BleedRight->value() / m_unitRatio;
564 }
565
margins() const566 const MarginStruct & MarginWidget::margins() const
567 {
568 return marginData;
569 }
570
slotLinkMargins()571 void MarginWidget::slotLinkMargins()
572 {
573 disconnect(topR, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
574 disconnect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
575 disconnect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
576 disconnect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
577
578 double marginValue = leftR->value();
579 if (leftR->hasFocus())
580 {
581 leftR->clearFocus();
582 marginValue = leftR->value();
583 }
584 if (rightR->hasFocus())
585 {
586 rightR->clearFocus();
587 marginValue = rightR->value();
588 }
589 if (topR->hasFocus())
590 {
591 topR->clearFocus();
592 marginValue = topR->value();
593 }
594 if (bottomR->hasFocus())
595 {
596 bottomR->clearFocus();
597 marginValue = bottomR->value();
598 }
599
600 if (linkMargins->isChecked())
601 {
602 leftR->setValue(marginValue);
603 bottomR->setValue(marginValue);
604 topR->setValue(marginValue);
605 rightR->setValue(marginValue);
606 double newVal = marginValue / m_unitRatio;
607 marginData.set(newVal, newVal, newVal, newVal);
608 }
609
610 connect(topR, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
611 connect(bottomR, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
612 connect(leftR, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
613 connect(rightR, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
614
615 }
616
updateMarginSpinValues()617 void MarginWidget::updateMarginSpinValues()
618 {
619 topR->setValue(marginData.top() * m_unitRatio);
620 rightR->setValue(marginData.right() * m_unitRatio);
621 bottomR->setValue(marginData.bottom() * m_unitRatio);
622 leftR->setValue(marginData.left() * m_unitRatio);
623 }
624