Subversion Repositories Scribus

Rev

Rev 23137 | Details | Compare with Previous | Last modification | View Log | RSS feed

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