Subversion Repositories Scribus

Rev

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