Subversion Repositories Scribus

Rev

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