Subversion Repositories Scribus

Rev

Rev 7553 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 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
*/
2769 fschmid 7
#include "marginWidget.h"
8
#include "marginWidget.moc"
3795 cbradney 9
 
10
#include <qcheckbox.h>
2769 fschmid 11
#include <qtooltip.h>
12
 
4485 cbradney 13
#include "mspinbox.h"
14
#include "units.h"
15
#include "useprintermarginsdialog.h"
2769 fschmid 16
 
4485 cbradney 17
 
7553 cbradney 18
MarginWidget::MarginWidget( QWidget* parent, QString /*title*/, const MarginStruct* margs, int unitIndex, bool showChangeAll, bool showBleeds) : QTabWidget(parent, "marginWidget")
2769 fschmid 19
{
20
        RandT = margs->Top;
21
        RandB = margs->Bottom;
22
        RandR = margs->Right;
23
        RandL = margs->Left;
4638 subik 24
        facingPages = false;
7136 fschmid 25
        useBleeds = showBleeds;
4729 subik 26
 
4485 cbradney 27
        m_docUnitIndex=unitIndex;
28
        m_unitRatio = unitGetRatioFromIndex(unitIndex);
29
        m_suffix = unitGetSuffixFromIndex(unitIndex);
30
        int decimals = unitGetDecimalsFromIndex(unitIndex);
4729 subik 31
 
7021 fschmid 32
        marginPage = new QWidget(this);
3088 subik 33
 
7021 fschmid 34
        presetCombo = new PresetLayout(marginPage, "presetCombo");
35
        presetLabel = new QLabel(presetCombo, tr("Preset Layouts:"), marginPage, "presetLabel");
36
 
37
        leftR = new MSpinBox( 0, 1000, marginPage, decimals );
4485 cbradney 38
        leftR->setSuffix( m_suffix );
39
        leftR->setValue(RandL * m_unitRatio);
3406 cbradney 40
 
7021 fschmid 41
        rightR = new MSpinBox( 0, 1000, marginPage, decimals );
4485 cbradney 42
        rightR->setSuffix( m_suffix );
43
        rightR->setValue(RandR * m_unitRatio);
3406 cbradney 44
 
7021 fschmid 45
        topR = new MSpinBox( 0, 1000, marginPage, decimals );
4485 cbradney 46
        topR->setSuffix( m_suffix );
47
        topR->setValue(RandT * m_unitRatio);
3088 subik 48
 
7021 fschmid 49
        bottomR = new MSpinBox( 0, 1000, marginPage, decimals );
4485 cbradney 50
        bottomR->setSuffix( m_suffix );
51
        bottomR->setValue(RandB * m_unitRatio);
3088 subik 52
 
7021 fschmid 53
        bText = new QLabel( bottomR, tr( "&Bottom:" ), marginPage, "bText" );
54
        tText = new QLabel( topR, tr( "&Top:" ), marginPage, "tText" );
55
        rText = new QLabel( rightR, tr( "&Right:" ), marginPage, "rText" );
56
        lText = new QLabel( leftR, tr( "&Left:" ), marginPage, "lText" );
3849 subik 57
 
3088 subik 58
        // layout
7021 fschmid 59
        GroupLayout = new QGridLayout( marginPage );
3088 subik 60
        GroupLayout->setAlignment( Qt::AlignTop );
7021 fschmid 61
        GroupLayout->setSpacing( 5 );
62
        GroupLayout->setMargin( 10 );
3088 subik 63
        GroupLayout->addWidget(presetLabel, 0, 0);
64
        GroupLayout->addWidget(presetCombo, 0, 1);
3101 subik 65
        GroupLayout->addWidget( leftR, 1, 1 );
66
        GroupLayout->addWidget( rightR, 2, 1 );
67
        GroupLayout->addWidget( topR, 3, 1 );
68
        GroupLayout->addWidget( bottomR, 4, 1 );
69
        GroupLayout->addWidget( lText, 1, 0 );
70
        GroupLayout->addWidget( rText, 2, 0 );
71
        GroupLayout->addWidget( tText, 3, 0 );
72
        GroupLayout->addWidget( bText, 4, 0 );
3795 cbradney 73
        if (showChangeAll)
3849 subik 74
        {
6332 fschmid 75
                marginsForPagesLayout = new QHBoxLayout( 0, 5, 5, "marginsForPagesLayout");
7021 fschmid 76
                marginsForPages = new QLabel( tr( "Apply settings to:" ), marginPage, "marginsForPages" );
6332 fschmid 77
                marginsForPagesLayout->addWidget(marginsForPages);
7021 fschmid 78
                marginsForAllPages = new QCheckBox( marginPage, "marginsForAllPages" );
6374 cbradney 79
                marginsForAllPages->setText( tr( "All Document Pages" ) );
3795 cbradney 80
                marginsForAllPages->setChecked( false );
6332 fschmid 81
                marginsForPagesLayout->addWidget(marginsForAllPages);
7021 fschmid 82
                marginsForAllMasterPages = new QCheckBox( marginPage, "marginsForAllMasterPages" );
6374 cbradney 83
                marginsForAllMasterPages->setText( tr( "All Master Pages" ) );
6332 fschmid 84
                marginsForAllMasterPages->setChecked( false );
85
                marginsForPagesLayout->addWidget(marginsForAllMasterPages);
86
                GroupLayout->addMultiCellLayout( marginsForPagesLayout, 6, 6, 0, 1 );
3795 cbradney 87
                QToolTip::add( marginsForAllPages, "<qt>" + tr( "Apply the margin changes to all existing pages in the document" ) + "</qt>" );
6374 cbradney 88
                QToolTip::add( marginsForAllMasterPages, "<qt>" + tr( "Apply the margin changes to all existing master pages in the document" ) + "</qt>" );
3795 cbradney 89
        }
90
        else
6332 fschmid 91
        {
92
                marginsForPages=NULL;
3795 cbradney 93
                marginsForAllPages=NULL;
6332 fschmid 94
                marginsForAllMasterPages=NULL;
95
        }
4729 subik 96
 
4485 cbradney 97
        usePrinterMarginsButton=NULL;
4506 cbradney 98
#if defined(HAVE_CUPS) || defined(_WIN32)
7021 fschmid 99
        usePrinterMarginsButton=new QPushButton( tr("Printer Margins..."),marginPage, "usePrinterMarginsButton" );
4485 cbradney 100
        GroupLayout->addWidget( usePrinterMarginsButton, 5, 1 );
7123 fschmid 101
        QToolTip::add( usePrinterMarginsButton, "<qt>" + tr( "Import the margins for the selected page size from the available printers." ) + "</qt>");
7071 fschmid 102
        connect(usePrinterMarginsButton, SIGNAL(clicked()), this, SLOT(setMarginsToPrinterMargins()));
103
#endif
7021 fschmid 104
 
105
        addTab(marginPage, tr("Margin Guides"));
106
 
7136 fschmid 107
        if (useBleeds)
108
        {
109
                bleedPage = new QWidget(this);
110
                BleedGroupLayout = new QGridLayout( bleedPage );
111
                BleedGroupLayout->setSpacing( 5 );
112
                BleedGroupLayout->setMargin( 10 );
113
                BleedGroupLayout->setAlignment( Qt::AlignTop );
114
                BleedTxt3 = new QLabel( bleedPage, "BleedTxt3" );
115
                BleedGroupLayout->addWidget( BleedTxt3, 0, 0 );
116
                BleedLeft = new MSpinBox( bleedPage, decimals );
117
                BleedGroupLayout->addWidget( BleedLeft, 0, 1 );
118
                BleedTxt4 = new QLabel( bleedPage, "BleedTxt4" );
119
                BleedGroupLayout->addWidget( BleedTxt4, 1, 0 );
120
                BleedRight = new MSpinBox( bleedPage, decimals );
121
                BleedGroupLayout->addWidget( BleedRight, 1, 1 );
122
                BleedTxt1 = new QLabel( bleedPage, "BleedTxt1" );
123
                BleedTxt1->setText( tr( "Top:" ) );
124
                BleedGroupLayout->addWidget( BleedTxt1, 2, 0 );
125
                BleedTop = new MSpinBox( bleedPage, decimals );
126
                BleedGroupLayout->addWidget( BleedTop, 2, 1 );
127
                BleedTxt2 = new QLabel( bleedPage, "BleedTxt2" );
128
                BleedTxt2->setText( tr( "Bottom:" ) );
129
                BleedGroupLayout->addWidget( BleedTxt2, 3, 0 );
130
                BleedBottom = new MSpinBox( bleedPage, decimals );
131
                BleedGroupLayout->addWidget( BleedBottom, 3, 1 );
132
                linkBleeds = new LinkButton( bleedPage );
133
                linkBleeds->setToggleButton( true );
134
                linkBleeds->setAutoRaise( true );
135
                linkBleeds->setMaximumSize( QSize( 15, 32767 ) );
136
                BleedGroupLayout->addMultiCellWidget( linkBleeds, 0, 3, 2, 2 );
137
                BleedTop->setSuffix( m_suffix );
138
                BleedTop->setMinValue(0);
139
                BleedTop->setMaxValue(3000*m_unitRatio);
140
                BleedBottom->setSuffix( m_suffix );
141
                BleedBottom->setMinValue(0);
142
                BleedBottom->setMaxValue(3000*m_unitRatio);
143
                BleedRight->setSuffix( m_suffix );
144
                BleedRight->setMinValue(0);
145
                BleedRight->setMaxValue(3000*m_unitRatio);
146
                BleedLeft->setSuffix( m_suffix );
147
                BleedLeft->setMinValue(0);
148
                BleedLeft->setMaxValue(3000*m_unitRatio);
149
                QToolTip::add( BleedTop, "<qt>" + tr( "Distance for bleed from the top of the physical page" ) + "</qt>" );
150
                QToolTip::add( BleedBottom, "<qt>" + tr( "Distance for bleed from the bottom of the physical page" ) + "</qt>" );
151
                QToolTip::add( BleedLeft, "<qt>" + tr( "Distance for bleed from the left of the physical page" ) + "</qt>" );
152
                QToolTip::add( BleedRight, "<qt>" + tr( "Distance for bleed from the right of the physical page" )  + "</qt>");
153
                connect(linkBleeds, SIGNAL(clicked()), this, SLOT(ToggleKette()));
7227 fschmid 154
                connect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
155
                connect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
156
                connect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
157
                connect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
7136 fschmid 158
                addTab(bleedPage, tr("Bleeds"));
159
        }
7021 fschmid 160
 
3088 subik 161
        // hints
162
        QToolTip::add( topR, "<qt>" + tr( "Distance between the top margin guide and the edge of the page" ) + "</qt>");
163
        QToolTip::add( bottomR, "<qt>" + tr( "Distance between the bottom margin guide and the edge of the page" ) + "</qt>");
7553 cbradney 164
        QToolTip::add( leftR, "<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>");
165
        QToolTip::add( rightR, "<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>");
4729 subik 166
 
3795 cbradney 167
                // signals&slots
2769 fschmid 168
        connect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
169
        connect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
170
        connect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
171
        connect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
3088 subik 172
        connect(presetCombo, SIGNAL(activated(int)), this, SLOT(setPreset()));
2769 fschmid 173
}
174
 
7071 fschmid 175
void MarginWidget::ToggleKette()
176
{
7227 fschmid 177
        disconnect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
178
        disconnect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
179
        disconnect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
180
        disconnect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
7071 fschmid 181
        if (linkBleeds->isOn())
182
        {
183
                BleedTop->setValue(BleedLeft->value());
184
                BleedBottom->setValue(BleedLeft->value());
185
                BleedRight->setValue(BleedLeft->value());
186
        }
7227 fschmid 187
        connect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
188
        connect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
189
        connect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
190
        connect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
7071 fschmid 191
}
192
 
7225 cbradney 193
void MarginWidget::changeBleeds()
7071 fschmid 194
{
195
        if (linkBleeds->isOn())
196
        {
197
                double val = 0.0;
198
                if (BleedTop == sender())
199
                        val = BleedTop->value();
200
                else if (BleedBottom == sender())
201
                        val = BleedBottom->value();
202
                else if (BleedLeft == sender())
203
                        val = BleedLeft->value();
204
                else if (BleedRight == sender())
205
                        val = BleedRight->value();
7098 fschmid 206
                val = val / m_unitRatio;
7225 cbradney 207
                MarginStruct v(val,val,val,val);
208
                setNewBleeds(v);
7071 fschmid 209
        }
210
}
211
 
6649 fschmid 212
void MarginWidget::setFacingPages(bool facing, int pagetype)
2769 fschmid 213
{
4638 subik 214
        facingPages = facing;
6649 fschmid 215
        pageType = pagetype;
3101 subik 216
        lText->setText(facing == true ? tr( "&Inside:" ) : tr( "&Left:" ));
217
        rText->setText(facing == true ? tr( "O&utside:" ) : tr( "&Right:" ));
7136 fschmid 218
        if (useBleeds)
7021 fschmid 219
        {
7136 fschmid 220
                if (facing)
221
                {
222
                        BleedTxt3->setText( tr( "Inside:" ) );
223
                        BleedTxt4->setText( tr( "Outside:" ) );
224
                }
225
                else
226
                {
227
                        BleedTxt3->setText( tr( "Left:" ) );
228
                        BleedTxt4->setText( tr( "Right:" ) );
229
                }
7021 fschmid 230
        }
3088 subik 231
        setPreset();
2769 fschmid 232
}
233
 
3411 fschmid 234
void MarginWidget::setPageWidthHeight(double width, double height)
235
{
4485 cbradney 236
        rightR->setMaxValue(width * m_unitRatio - leftR->value());
237
        leftR->setMaxValue(width * m_unitRatio - rightR->value());
3411 fschmid 238
        pageWidth = width;
4485 cbradney 239
        topR->setMaxValue(height * m_unitRatio - bottomR->value());
240
        bottomR->setMaxValue(height * m_unitRatio - topR->value());
3411 fschmid 241
        pageHeight = height;
242
        setPreset();
243
}
244
 
2769 fschmid 245
void MarginWidget::setPageWidth(double width)
246
{
4595 fschmid 247
        rightR->setMaxValue(QMAX(0.0, width * m_unitRatio - leftR->value()));
248
        leftR->setMaxValue(QMAX(0.0,width * m_unitRatio - rightR->value()));
2769 fschmid 249
        pageWidth = width;
3088 subik 250
        setPreset();
2769 fschmid 251
}
252
 
253
void MarginWidget::setPageHeight(double height)
254
{
4595 fschmid 255
        topR->setMaxValue(QMAX(0.0, height * m_unitRatio - bottomR->value()));
256
        bottomR->setMaxValue(QMAX(0.0,height * m_unitRatio - topR->value()));
2769 fschmid 257
        pageHeight = height;
3088 subik 258
        setPreset();
2769 fschmid 259
}
260
 
261
void MarginWidget::setTop()
262
{
4485 cbradney 263
        RandT = topR->value() / m_unitRatio;
4595 fschmid 264
        bottomR->setMaxValue(QMAX(0.0, pageHeight * m_unitRatio - topR->value()));
3088 subik 265
        setPreset();
2769 fschmid 266
}
267
 
268
void MarginWidget::setBottom()
269
{
4485 cbradney 270
        RandB = bottomR->value() / m_unitRatio;
4595 fschmid 271
        topR->setMaxValue(QMAX(0.0, pageHeight * m_unitRatio - bottomR->value()));
3088 subik 272
        setPreset();
2769 fschmid 273
}
274
 
275
void MarginWidget::setLeft()
276
{
4485 cbradney 277
        RandL = leftR->value() / m_unitRatio;
4595 fschmid 278
        rightR->setMaxValue(QMAX(0.0, pageWidth * m_unitRatio - leftR->value()));
3088 subik 279
        setPreset();
2769 fschmid 280
}
281
 
282
void MarginWidget::setRight()
283
{
4485 cbradney 284
        RandR = rightR->value() / m_unitRatio;
4595 fschmid 285
        leftR->setMaxValue(QMAX(0.0, pageWidth * m_unitRatio - rightR->value()));
3088 subik 286
        setPreset();
2769 fschmid 287
}
288
 
289
void MarginWidget::unitChange(double newUnit, int newDecimals, QString newSuffix)
290
{
291
        disconnect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
292
        disconnect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
293
        disconnect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
294
        disconnect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
295
        int decimalsOld;
4485 cbradney 296
        double oldUnitRatio = m_unitRatio;
2769 fschmid 297
        double oldMin, oldMax, val;
298
        topR->setSuffix(newSuffix);
299
        bottomR->setSuffix(newSuffix);
300
        leftR->setSuffix(newSuffix);
301
        rightR->setSuffix(newSuffix);
302
        double invUnitConversion = 1.0 / oldUnitRatio * newUnit;
303
        topR->getValues(&oldMin, &oldMax, &decimalsOld, &val);
304
        topR->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
305
        bottomR->getValues(&oldMin, &oldMax, &decimalsOld, &val);
306
        bottomR->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
307
        leftR->getValues(&oldMin, &oldMax, &decimalsOld, &val);
308
        leftR->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
309
        rightR->getValues(&oldMin, &oldMax, &decimalsOld, &val);
310
        rightR->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
7136 fschmid 311
 
312
        if (useBleeds)
313
        {
7227 fschmid 314
                disconnect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
315
                disconnect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
316
                disconnect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
317
                disconnect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
7136 fschmid 318
                BleedBottom->setSuffix(newSuffix);
319
                BleedTop->setSuffix(newSuffix);
320
                BleedRight->setSuffix(newSuffix);
321
                BleedLeft->setSuffix(newSuffix);
322
                BleedBottom->getValues(&oldMin, &oldMax, &decimalsOld, &val);
323
                BleedBottom->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
324
                BleedTop->getValues(&oldMin, &oldMax, &decimalsOld, &val);
325
                BleedTop->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
326
                BleedRight->getValues(&oldMin, &oldMax, &decimalsOld, &val);
327
                BleedRight->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
328
                BleedLeft->getValues(&oldMin, &oldMax, &decimalsOld, &val);
329
                BleedLeft->setValues(0, oldMax * invUnitConversion, newDecimals, val * invUnitConversion);
7227 fschmid 330
                connect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
331
                connect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
332
                connect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
333
                connect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
7136 fschmid 334
        }
4485 cbradney 335
        m_unitRatio = newUnit;
336
        m_suffix=newSuffix;
2769 fschmid 337
        connect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
338
        connect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
339
        connect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
340
        connect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
341
}
3088 subik 342
 
343
void MarginWidget::setPreset()
344
{
3411 fschmid 345
        disconnect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
346
        disconnect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
347
        disconnect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
348
        disconnect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
3088 subik 349
        int item = presetCombo->currentItem();
4485 cbradney 350
        MarginStruct marg = presetCombo->getMargins(item, pageWidth * m_unitRatio, pageHeight * m_unitRatio, leftR->value());
4638 subik 351
        facingPages ? presetCombo->setEnabled(true) : presetCombo->setEnabled(false);
352
        if (presetCombo->needUpdate() && facingPages)
3101 subik 353
        {
4595 fschmid 354
                leftR->setValue(QMAX(0.0, marg.Left));
355
                rightR->setValue(QMAX(0.0, marg.Right));
356
                topR->setValue(QMAX(0.0, marg.Top));
357
                bottomR->setValue(QMAX(0.0, marg.Bottom));
4485 cbradney 358
                RandT = topR->value() / m_unitRatio;
359
                RandB = bottomR->value() / m_unitRatio;
360
                RandL = leftR->value() / m_unitRatio;
361
                RandR = rightR->value() / m_unitRatio;
4595 fschmid 362
                bottomR->setMaxValue(QMAX(0.0, pageHeight * m_unitRatio - topR->value()));
363
                topR->setMaxValue(QMAX(0.0, pageHeight * m_unitRatio - bottomR->value()));
364
                rightR->setMaxValue(QMAX(0.0, pageWidth * m_unitRatio - leftR->value()));
365
                leftR->setMaxValue(QMAX(0.0, pageWidth * m_unitRatio - rightR->value()));
3411 fschmid 366
                rightR->setEnabled(false);
367
                topR->setEnabled(false);
368
                bottomR->setEnabled(false);
369
        }
370
        else
371
        {
3101 subik 372
                rightR->setEnabled(true);
373
                topR->setEnabled(true);
374
                bottomR->setEnabled(true);
375
        }
6649 fschmid 376
        if (pageType == 1)
377
                rightR->setEnabled(false);
3411 fschmid 378
        connect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
379
        connect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
380
        connect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
381
        connect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
3088 subik 382
}
383
 
4485 cbradney 384
void MarginWidget::setPageSize(const QString& pageSize)
385
{
386
        m_pageSize=pageSize;
387
}
388
 
389
void MarginWidget::setMarginsToPrinterMargins()
390
{
391
        UsePrinterMarginsDialog upm(parentWidget(), m_pageSize, m_unitRatio, m_suffix);
392
        if (upm.exec())
393
        {
394
                double t,b,l,r;
395
                upm.getNewPrinterMargins(t,b,l,r);
396
                presetCombo->setCurrentItem(PresetLayout::none);
397
                topR->setValue(t * m_unitRatio);
398
                bottomR->setValue(b * m_unitRatio);
399
                leftR->setValue(l * m_unitRatio);
400
                rightR->setValue(r * m_unitRatio);
4729 subik 401
 
4485 cbradney 402
                RandT = t;
403
                RandB = b;
404
                RandL = l;
405
                RandR = r;
4729 subik 406
 
4595 fschmid 407
                bottomR->setMaxValue((QMAX(0.0, pageHeight - t) * m_unitRatio));
408
                topR->setMaxValue((QMAX(0.0, pageHeight - b) * m_unitRatio));
409
                rightR->setMaxValue((QMAX(0.0, pageWidth - l) * m_unitRatio));
410
                leftR->setMaxValue((QMAX(0.0, pageWidth - r) * m_unitRatio));
4729 subik 411
 
4485 cbradney 412
                rightR->setEnabled(true);
413
                topR->setEnabled(true);
414
                bottomR->setEnabled(true);
415
        }
416
}
417
 
4638 subik 418
double MarginWidget::top()
419
{
420
        return RandT;
421
}
4485 cbradney 422
 
4638 subik 423
double MarginWidget::bottom()
424
{
425
        return RandB;
426
}
427
 
428
double MarginWidget::left()
429
{
430
        return RandL;
431
}
432
 
433
double MarginWidget::right()
434
{
435
        return RandR;
436
}
437
 
7225 cbradney 438
void MarginWidget::setNewMargins(MarginStruct &m)
4638 subik 439
{
7548 fschmid 440
        disconnect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
441
        disconnect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
442
        disconnect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
443
        disconnect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
7225 cbradney 444
        topR->setValue(m.Top * m_unitRatio);
7559 cbradney 445
        RandT = m.Top;
7225 cbradney 446
        bottomR->setValue(m.Bottom * m_unitRatio);
7559 cbradney 447
        RandB = m.Bottom;
7225 cbradney 448
        leftR->setValue(m.Left * m_unitRatio);
7559 cbradney 449
        RandL = m.Left;
7225 cbradney 450
        rightR->setValue(m.Right * m_unitRatio);
7559 cbradney 451
        RandR = m.Right;
7550 fschmid 452
        connect(topR, SIGNAL(valueChanged(int)), this, SLOT(setTop()));
453
        connect(bottomR, SIGNAL(valueChanged(int)), this, SLOT(setBottom()));
454
        connect(leftR, SIGNAL(valueChanged(int)), this, SLOT(setLeft()));
455
        connect(rightR, SIGNAL(valueChanged(int)), this, SLOT(setRight()));
4638 subik 456
}
457
 
458
bool MarginWidget::getMarginsForAllPages()
459
{
460
        return marginsForAllPages->isChecked();
461
}
462
 
6332 fschmid 463
bool MarginWidget::getMarginsForAllMasterPages()
464
{
465
        return marginsForAllMasterPages->isChecked();
466
}
4638 subik 467
 
7225 cbradney 468
void MarginWidget::setNewBleeds(MarginStruct& b)
7021 fschmid 469
{
7227 fschmid 470
        disconnect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
471
        disconnect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
472
        disconnect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
473
        disconnect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
7225 cbradney 474
        BleedTop->setValue(b.Top * m_unitRatio);
475
        BleedBottom->setValue(b.Bottom * m_unitRatio);
476
        BleedLeft->setValue(b.Left * m_unitRatio);
477
        BleedRight->setValue(b.Right * m_unitRatio);
7227 fschmid 478
        connect(BleedLeft, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
479
        connect(BleedRight, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
480
        connect(BleedTop, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
481
        connect(BleedBottom, SIGNAL(valueChanged(int)), this, SLOT(changeBleeds()));
7021 fschmid 482
}
6332 fschmid 483
 
7021 fschmid 484
double MarginWidget::topBleed()
485
{
486
        return BleedTop->value() / m_unitRatio;
487
}
488
 
489
double MarginWidget::bottomBleed()
490
{
491
        return BleedBottom->value() / m_unitRatio;
492
}
493
 
494
double MarginWidget::leftBleed()
495
{
496
        return BleedLeft->value() / m_unitRatio;
497
}
498
 
499
double MarginWidget::rightBleed()
500
{
501
        return BleedRight->value() / m_unitRatio;
502
}
503
 
504
 
3088 subik 505
/*
506
 * presets
507
 */
508
PresetLayout::PresetLayout(QWidget *parent, const char * name) : QComboBox(parent, name)
509
{
6260 fschmid 510
        insertItem( tr("None", "layout type"), PresetLayout::none);
511
        insertItem( tr("Gutenberg"), PresetLayout::gutenberg);
512
        insertItem( tr("Magazine"), PresetLayout::magazine);
513
        insertItem( tr("Fibonacci"), PresetLayout::fibonacci);
514
        insertItem( tr("Golden Mean"), PresetLayout::goldencut);
515
        insertItem( tr("Nine Parts"), PresetLayout::nineparts);
3088 subik 516
        setCurrentItem(PresetLayout::none);
517
 
7123 fschmid 518
        QToolTip::add(this, "<qt>" + tr("You can select a predefined page layout here. 'None' leave margins as is, Gutenberg sets margins classically. 'Magazine' sets all margins for same value. Leading is Left/Inside value.") + "</qt>");
3088 subik 519
}
520
 
521
MarginStruct PresetLayout::getMargins(int index, double pageWidth, double pageHeight, double leftMargin)
522
{
523
        MarginStruct ret;
524
 
3101 subik 525
        updateMargins = true;
526
 
3088 subik 527
        switch (index)
528
        {
529
                case PresetLayout::magazine:
3091 cbradney 530
                        ret.Top = ret.Bottom = ret.Left = ret.Right = leftMargin;
531
                        break;
3900 cbradney 532
                case PresetLayout::gutenberg:
3091 cbradney 533
                        {
3088 subik 534
                                double ratio = pageHeight / pageWidth;
535
                                ret.Left = leftMargin;
536
                                ret.Top = leftMargin * ratio;
537
                                ret.Right = leftMargin * 2.0;
538
                                ret.Bottom = ret.Right * ratio;
3091 cbradney 539
                        }
540
                        break;
3562 fschmid 541
                case PresetLayout::fibonacci:
542
                        ret.Left = leftMargin;
543
                        ret.Top = leftMargin / 2.0 * 3.0;
544
                        ret.Right = leftMargin / 2.0 * 5.0;
545
                        ret.Bottom = leftMargin / 2.0 * 8.0;
546
                        break;
547
                case PresetLayout::goldencut:
548
                        ret.Left = leftMargin;
549
                        ret.Top = leftMargin / 2.0 * 3.4;
550
                        ret.Right = leftMargin / 2.0 * 4.8;
551
                        ret.Bottom = leftMargin / 2.0 * 6.8;
552
                        break;
553
                case PresetLayout::nineparts:
554
                        ret.Left = pageWidth / 9.0;
555
                        ret.Top = pageHeight / 9.0;
556
                        ret.Right = pageWidth / 9.0 * 2.0;
557
                        ret.Bottom = pageHeight / 9.0 * 2.0;
558
                        break;
3088 subik 559
                default:
3101 subik 560
                        updateMargins = false;
3091 cbradney 561
                        ret.Top = ret.Bottom = ret.Left = ret.Right = -1.0;
3088 subik 562
        }
563
        return ret;
564
}
3101 subik 565
 
566
bool PresetLayout::needUpdate()
567
{
568
        return updateMargins;
569
}