Subversion Repositories Scribus

Rev

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