Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
13762 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
*/
7
 
8
#include "newmarginwidget.h"
14221 cbradney 9
#include "scrspinbox.h"
10
#include "units.h"
11
#include "ui/marginpresetlayout.h"
12
#include "ui/useprintermarginsdialog.h"
13762 cbradney 13
 
14
NewMarginWidget::NewMarginWidget(QWidget* parent)
14229 cbradney 15
        : QWidget(parent),
16
        savedPresetItem(PresetLayout::none),
17
        facingPages(false),
18
        usingPreset(true)
13762 cbradney 19
{
20
        setupUi(this);
21
 
19355 jghali 22
        pageWidth  = 0;
23
        pageHeight = 0;
13762 cbradney 24
}
25
 
26
NewMarginWidget::~NewMarginWidget()
27
{
28
}
29
 
14229 cbradney 30
void NewMarginWidget::setup(const MarginStruct& margs, int layoutType, int unitIndex, bool showPreset, bool showPrinterMargins)
14221 cbradney 31
{
14226 cbradney 32
        marginData=savedMarginData=margs;
33
        m_unitIndex=unitIndex;
34
        m_unitRatio=unitGetRatioFromIndex(unitIndex);
35
        leftMarginSpinBox->setMaximum(1000);
36
        rightMarginSpinBox->setMaximum(1000);
37
        topMarginSpinBox->setMaximum(1000);
38
        bottomMarginSpinBox->setMaximum(1000);
14229 cbradney 39
        leftMarginSpinBox->init(unitIndex);
40
        rightMarginSpinBox->init(unitIndex);
41
        topMarginSpinBox->init(unitIndex);
42
        bottomMarginSpinBox->init(unitIndex);
43
        updateMarginSpinValues();
44
        usingPreset=showPreset;
45
        if (!showPreset)
46
        {
47
                presetLayoutComboBox->blockSignals(true);
14451 cbradney 48
                presetLayoutComboBox->resize(0,0);
49
                presetLayoutLabel->resize(0,0);
14229 cbradney 50
                presetLayoutComboBox->hide();
51
                presetLayoutLabel->hide();
14451 cbradney 52
                formLayout->removeWidget(presetLayoutComboBox);
53
                formLayout->removeWidget(presetLayoutLabel);
14229 cbradney 54
        }
55
        if (!showPrinterMargins)
56
        {
57
                printerMarginsPushButton->blockSignals(true);
14451 cbradney 58
                printerMarginsPushButton->resize(0,0);
14229 cbradney 59
                printerMarginsPushButton->hide();
14451 cbradney 60
                formLayout->removeWidget(printerMarginsPushButton);
14229 cbradney 61
        }
62
        setFacingPages(!(layoutType == singlePage));
63
 
14451 cbradney 64
        formLayout->invalidate();
65
 
19309 craig 66
        languageChange();
67
 
14229 cbradney 68
        connect(topMarginSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setTop()));
69
        connect(bottomMarginSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setBottom()));
70
        connect(leftMarginSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setLeft()));
71
        connect(rightMarginSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setRight()));
72
        connect(presetLayoutComboBox, SIGNAL(activated(int)), this, SLOT(setPreset()));
73
        connect(marginLinkCheckBox, SIGNAL(clicked()), this, SLOT(slotLinkMargins()));
74
        connect(printerMarginsPushButton, SIGNAL(clicked()), this, SLOT(setMarginsToPrinterMargins()));
14221 cbradney 75
}
76
 
14226 cbradney 77
void NewMarginWidget::languageChange()
14216 cbradney 78
{
19309 craig 79
        topMarginSpinBox->setToolTip( "<qt>" + tr( "Distance between the top margin guide and the edge of the page" ) + "</qt>");
80
        bottomMarginSpinBox->setToolTip( "<qt>" + tr( "Distance between the bottom margin guide and the edge of the page" ) + "</qt>");
81
        leftMarginSpinBox->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>");
82
        rightMarginSpinBox->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>");
83
        printerMarginsPushButton->setToolTip( "<qt>" + tr( "Import the margins for the selected page size from the available printers." ) + "</qt>");
14216 cbradney 84
}
85
 
15081 cbradney 86
void NewMarginWidget::setNewValues(const MarginStruct& margs)
87
{
88
        marginData=savedMarginData=margs;
89
        updateMarginSpinValues();
90
}
91
 
14226 cbradney 92
void NewMarginWidget::setPageWidth(double newWidth)
14216 cbradney 93
{
19355 jghali 94
        leftMarginSpinBox->setMaximum(qMax(0.0, newWidth * m_unitRatio - rightMarginSpinBox->value()));
95
        rightMarginSpinBox->setMaximum(qMax(0.0, newWidth * m_unitRatio - leftMarginSpinBox->value()));
14226 cbradney 96
        pageWidth = newWidth;
97
        setPreset();
98
}
14216 cbradney 99
 
14226 cbradney 100
void NewMarginWidget::setPageHeight(double newHeight)
101
{
102
        topMarginSpinBox->setMaximum(qMax(0.0, newHeight * m_unitRatio - bottomMarginSpinBox->value()));
103
        bottomMarginSpinBox->setMaximum(qMax(0.0,newHeight * m_unitRatio - topMarginSpinBox->value()));
104
        pageHeight = newHeight;
105
        setPreset();
14216 cbradney 106
}
107
 
14226 cbradney 108
void NewMarginWidget::setTop()
14216 cbradney 109
{
14226 cbradney 110
        double newVal=topMarginSpinBox->value() / m_unitRatio;
111
        bottomMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - topMarginSpinBox->value()));
112
        if (marginLinkCheckBox->isChecked() && savedPresetItem==PresetLayout::none)
113
        {
114
                marginData.set(newVal, newVal, newVal, newVal);
115
                updateMarginSpinValues();
116
        }
117
        else
118
                marginData.Top = newVal;
119
        setPreset();
120
}
14216 cbradney 121
 
14226 cbradney 122
void NewMarginWidget::setBottom()
123
{
124
        double newVal = bottomMarginSpinBox->value() / m_unitRatio;
125
        topMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - bottomMarginSpinBox->value()));
126
        if (marginLinkCheckBox->isChecked() && savedPresetItem==PresetLayout::none)
127
        {
128
                marginData.set(newVal, newVal, newVal, newVal);
129
                updateMarginSpinValues();
130
        }
131
        else
132
                marginData.Bottom = newVal;
133
        setPreset();
14216 cbradney 134
}
135
 
14226 cbradney 136
void NewMarginWidget::setLeft()
14216 cbradney 137
{
14226 cbradney 138
        double newVal = leftMarginSpinBox->value() / m_unitRatio;
139
        rightMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - leftMarginSpinBox->value()));
140
        if (marginLinkCheckBox->isChecked() && savedPresetItem==PresetLayout::none)
141
        {
142
                marginData.set(newVal, newVal, newVal, newVal);
143
                updateMarginSpinValues();
144
        }
145
        else
146
                marginData.Left = newVal;
147
        setPreset();
148
}
14216 cbradney 149
 
14226 cbradney 150
void NewMarginWidget::setRight()
151
{
152
        double newVal = rightMarginSpinBox->value() / m_unitRatio;
153
        leftMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - rightMarginSpinBox->value()));
154
        if (marginLinkCheckBox->isChecked() && savedPresetItem==PresetLayout::none)
155
        {
156
                marginData.set(newVal, newVal, newVal, newVal);
157
                updateMarginSpinValues();
158
        }
159
        else
160
                marginData.Right = newVal;
161
        setPreset();
14216 cbradney 162
}
14226 cbradney 163
 
164
void NewMarginWidget::setNewUnitIndex(int newUnitIndex)
165
{
166
        leftMarginSpinBox->blockSignals(true);
167
        rightMarginSpinBox->blockSignals(true);
168
        topMarginSpinBox->blockSignals(true);
169
        bottomMarginSpinBox->blockSignals(true);
170
        m_unitIndex=newUnitIndex;
171
        m_unitRatio=unitGetRatioFromIndex(newUnitIndex);
172
        topMarginSpinBox->setNewUnit(newUnitIndex);
173
        bottomMarginSpinBox->setNewUnit(newUnitIndex);
174
        leftMarginSpinBox->setNewUnit(newUnitIndex);
175
        rightMarginSpinBox->setNewUnit(newUnitIndex);
176
        leftMarginSpinBox->blockSignals(false);
177
        rightMarginSpinBox->blockSignals(false);
178
        topMarginSpinBox->blockSignals(false);
179
        bottomMarginSpinBox->blockSignals(false);
180
}
181
 
182
void NewMarginWidget::setPreset()
183
{
14229 cbradney 184
        if (!usingPreset)
185
                return;
14226 cbradney 186
        leftMarginSpinBox->blockSignals(true);
187
        rightMarginSpinBox->blockSignals(true);
188
        topMarginSpinBox->blockSignals(true);
189
        bottomMarginSpinBox->blockSignals(true);
190
        if (savedPresetItem==PresetLayout::none)
191
                savedMarginData=marginData;
192
        int item = presetLayoutComboBox->currentIndex();
193
 
194
        MarginStruct marg = presetLayoutComboBox->getMargins(item, pageWidth, pageHeight, leftMarginSpinBox->value() / m_unitRatio);
195
        facingPages ? presetLayoutComboBox->setEnabled(true) : presetLayoutComboBox->setEnabled(false);
196
        bool restoringValues=false;
197
        if (item==PresetLayout::none && savedPresetItem!=PresetLayout::none)
198
        {
199
                marg=savedMarginData;
200
                restoringValues=true;
201
        }
202
        if (restoringValues || (presetLayoutComboBox->needUpdate() && facingPages))
203
        {
204
                marginData.set(qMax(0.0, marg.Top), qMax(0.0, marg.Left), qMax(0.0, marg.Bottom), qMax(0.0, marg.Right));
205
                updateMarginSpinValues();
206
 
207
                bottomMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - topMarginSpinBox->value()));
208
                topMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - bottomMarginSpinBox->value()));
209
                rightMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - leftMarginSpinBox->value()));
210
                leftMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - rightMarginSpinBox->value()));
211
                rightMarginSpinBox->setEnabled(restoringValues);
212
                topMarginSpinBox->setEnabled(restoringValues);
213
                bottomMarginSpinBox->setEnabled(restoringValues);
214
        }
215
        else
216
        {
217
                rightMarginSpinBox->setEnabled(true);
218
                topMarginSpinBox->setEnabled(true);
219
                bottomMarginSpinBox->setEnabled(true);
220
        }
221
        if (pageType == 1)
222
                rightMarginSpinBox->setEnabled(false);
223
        leftMarginSpinBox->setEnabled(item != PresetLayout::nineparts);
224
        if (item!=PresetLayout::none)
225
                marginLinkCheckBox->setChecked(false);
14839 cbradney 226
        marginLinkCheckBox->setEnabled(item==PresetLayout::none || !presetLayoutComboBox->isEnabled());
14226 cbradney 227
        leftMarginSpinBox->blockSignals(false);
228
        rightMarginSpinBox->blockSignals(false);
229
        topMarginSpinBox->blockSignals(false);
230
        bottomMarginSpinBox->blockSignals(false);
231
        savedPresetItem=item;
232
}
233
 
234
void NewMarginWidget::setPageSize(const QString& pageSize)
235
{
236
        m_pageSize=pageSize;
237
}
238
 
239
 
240
void NewMarginWidget::updateMarginSpinValues()
241
{
19355 jghali 242
        bool leftBlocked = leftMarginSpinBox->blockSignals(true);
243
        bool rightBlocked = rightMarginSpinBox->blockSignals(true);
244
        bool topBlocked = topMarginSpinBox->blockSignals(true);
245
        bool bottomBlocked = bottomMarginSpinBox->blockSignals(true);
246
 
14226 cbradney 247
        topMarginSpinBox->setValue(marginData.Top * m_unitRatio);
248
        rightMarginSpinBox->setValue(marginData.Right * m_unitRatio);
249
        bottomMarginSpinBox->setValue(marginData.Bottom * m_unitRatio);
250
        leftMarginSpinBox->setValue(marginData.Left * m_unitRatio);
19355 jghali 251
 
252
        leftMarginSpinBox->blockSignals(leftBlocked);
253
        rightMarginSpinBox->blockSignals(rightBlocked);
254
        topMarginSpinBox->blockSignals(topBlocked);
255
        bottomMarginSpinBox->blockSignals(bottomBlocked);
14226 cbradney 256
}
257
 
258
void NewMarginWidget::slotLinkMargins()
259
{
19355 jghali 260
        bool leftBlocked = leftMarginSpinBox->blockSignals(true);
261
        bool rightBlocked = rightMarginSpinBox->blockSignals(true);
262
        bool topBlocked = topMarginSpinBox->blockSignals(true);
263
        bool bottomBlocked = bottomMarginSpinBox->blockSignals(true);
264
 
14226 cbradney 265
        if (marginLinkCheckBox->isChecked())
266
        {
267
                bottomMarginSpinBox->setValue(leftMarginSpinBox->value());
268
                topMarginSpinBox->setValue(leftMarginSpinBox->value());
269
                rightMarginSpinBox->setValue(leftMarginSpinBox->value());
270
                double newVal=leftMarginSpinBox->value() / m_unitRatio;
271
                marginData.set(newVal, newVal, newVal, newVal);
272
        }
19355 jghali 273
 
274
        leftMarginSpinBox->blockSignals(leftBlocked);
275
        rightMarginSpinBox->blockSignals(rightBlocked);
276
        topMarginSpinBox->blockSignals(topBlocked);
277
        bottomMarginSpinBox->blockSignals(bottomBlocked);
14226 cbradney 278
}
14229 cbradney 279
 
280
void NewMarginWidget::setMarginPreset(int p)
281
{
282
        if (!usingPreset)
283
                return;
284
        presetLayoutComboBox->blockSignals(true);
285
        savedPresetItem = p;
286
        presetLayoutComboBox->setCurrentIndex(p);
287
        if (savedPresetItem==PresetLayout::none)
288
                savedMarginData=marginData;
289
        int item = presetLayoutComboBox->currentIndex();
290
        facingPages ? presetLayoutComboBox->setEnabled(true) : presetLayoutComboBox->setEnabled(false);
291
        bool restoringValues=false;
292
        if (item==PresetLayout::none && savedPresetItem!=PresetLayout::none)
293
        {
294
                restoringValues=true;
295
        }
296
        if (restoringValues || (presetLayoutComboBox->needUpdate() && facingPages))
297
        {
298
                rightMarginSpinBox->setEnabled(restoringValues);
299
                topMarginSpinBox->setEnabled(restoringValues);
300
                bottomMarginSpinBox->setEnabled(restoringValues);
301
        }
302
        else
303
        {
304
                rightMarginSpinBox->setEnabled(true);
305
                topMarginSpinBox->setEnabled(true);
306
                bottomMarginSpinBox->setEnabled(true);
307
        }
308
        if (pageType == 1)
309
                rightMarginSpinBox->setEnabled(false);
310
        leftMarginSpinBox->setEnabled(item != PresetLayout::nineparts);
311
        if (item!=PresetLayout::none)
312
                marginLinkCheckBox->setChecked(false);
313
        marginLinkCheckBox->setEnabled(item==PresetLayout::none);
314
        presetLayoutComboBox->blockSignals(false);
315
}
316
 
317
void NewMarginWidget::setFacingPages(bool facing, int pagetype)
318
{
319
        facingPages = facing;
320
        pageType = pagetype;
321
        leftMarginLabel->setText(facing == true ? tr( "&Inside:" ) : tr( "&Left:" ));
322
        rightMarginLabel->setText(facing == true ? tr( "O&utside:" ) : tr( "&Right:" ));
323
        setPreset();
324
}
325
 
326
void NewMarginWidget::setMarginsToPrinterMargins()
327
{
328
        UsePrinterMarginsDialog upm(parentWidget(), m_pageSize, unitGetRatioFromIndex(m_unitIndex), unitGetSuffixFromIndex(m_unitIndex));
329
        if (upm.exec())
330
        {
331
                double t,b,l,r;
332
                upm.getNewPrinterMargins(t,b,l,r);
333
                presetLayoutComboBox->setCurrentIndex(PresetLayout::none);
334
                marginData.set(t,l,b,r);
335
 
336
                updateMarginSpinValues();
337
 
338
                bottomMarginSpinBox->setMaximum((qMax(0.0, pageHeight - t) * m_unitRatio));
339
                topMarginSpinBox->setMaximum((qMax(0.0, pageHeight - b) * m_unitRatio));
340
                rightMarginSpinBox->setMaximum((qMax(0.0, pageWidth - l) * m_unitRatio));
341
                leftMarginSpinBox->setMaximum((qMax(0.0, pageWidth - r) * m_unitRatio));
342
 
343
                rightMarginSpinBox->setEnabled(true);
344
                topMarginSpinBox->setEnabled(true);
345
                bottomMarginSpinBox->setEnabled(true);
346
        }
347
}
348