Subversion Repositories Scribus

Rev

Rev 14221 | Rev 14229 | 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)
15
        : QWidget(parent)
16
{
17
        setupUi(this);
18
 
19
}
20
 
21
NewMarginWidget::~NewMarginWidget()
22
{
23
}
24
 
14221 cbradney 25
void NewMarginWidget::setup(const MarginStruct& margs, int unitIndex, bool showPreset)
26
{
14226 cbradney 27
        marginData=savedMarginData=margs;
14221 cbradney 28
        savedPresetItem=PresetLayout::none;//we dont recheck if we are using a layout but always start at none
14226 cbradney 29
        facingPages = false;
30
        m_unitIndex=unitIndex;
31
        m_unitRatio=unitGetRatioFromIndex(unitIndex);
32
        leftMarginSpinBox->setMaximum(1000);
33
        rightMarginSpinBox->setMaximum(1000);
34
        topMarginSpinBox->setMaximum(1000);
35
        bottomMarginSpinBox->setMaximum(1000);
14221 cbradney 36
}
37
 
14226 cbradney 38
void NewMarginWidget::languageChange()
14216 cbradney 39
{
14226 cbradney 40
        leftMarginSpinBox->setToolTip( "<qt>" + tr( "Distance between the top margin guide and the edge of the page" ) + "</qt>");
41
        rightMarginSpinBox->setToolTip( "<qt>" + tr( "Distance between the bottom margin guide and the edge of the page" ) + "</qt>");
42
        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>");
43
        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 44
 
45
}
46
 
14226 cbradney 47
void NewMarginWidget::setPageWidth(double newWidth)
14216 cbradney 48
{
14226 cbradney 49
        leftMarginSpinBox->setMaximum(qMax(0.0, newWidth * m_unitRatio - leftMarginSpinBox->value()));
50
        rightMarginSpinBox->setMaximum(qMax(0.0,newWidth * m_unitRatio - rightMarginSpinBox->value()));
51
        pageWidth = newWidth;
52
        setPreset();
53
}
14216 cbradney 54
 
14226 cbradney 55
void NewMarginWidget::setPageHeight(double newHeight)
56
{
57
        topMarginSpinBox->setMaximum(qMax(0.0, newHeight * m_unitRatio - bottomMarginSpinBox->value()));
58
        bottomMarginSpinBox->setMaximum(qMax(0.0,newHeight * m_unitRatio - topMarginSpinBox->value()));
59
        pageHeight = newHeight;
60
        setPreset();
14216 cbradney 61
}
62
 
14226 cbradney 63
void NewMarginWidget::setTop()
14216 cbradney 64
{
14226 cbradney 65
        double newVal=topMarginSpinBox->value() / m_unitRatio;
66
        bottomMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - topMarginSpinBox->value()));
67
        if (marginLinkCheckBox->isChecked() && savedPresetItem==PresetLayout::none)
68
        {
69
                marginData.set(newVal, newVal, newVal, newVal);
70
                updateMarginSpinValues();
71
        }
72
        else
73
                marginData.Top = newVal;
74
        setPreset();
75
}
14216 cbradney 76
 
14226 cbradney 77
void NewMarginWidget::setBottom()
78
{
79
        double newVal = bottomMarginSpinBox->value() / m_unitRatio;
80
        topMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - bottomMarginSpinBox->value()));
81
        if (marginLinkCheckBox->isChecked() && savedPresetItem==PresetLayout::none)
82
        {
83
                marginData.set(newVal, newVal, newVal, newVal);
84
                updateMarginSpinValues();
85
        }
86
        else
87
                marginData.Bottom = newVal;
88
        setPreset();
14216 cbradney 89
}
90
 
14226 cbradney 91
void NewMarginWidget::setLeft()
14216 cbradney 92
{
14226 cbradney 93
        double newVal = leftMarginSpinBox->value() / m_unitRatio;
94
        rightMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - leftMarginSpinBox->value()));
95
        if (marginLinkCheckBox->isChecked() && savedPresetItem==PresetLayout::none)
96
        {
97
                marginData.set(newVal, newVal, newVal, newVal);
98
                updateMarginSpinValues();
99
        }
100
        else
101
                marginData.Left = newVal;
102
        setPreset();
103
}
14216 cbradney 104
 
14226 cbradney 105
void NewMarginWidget::setRight()
106
{
107
        double newVal = rightMarginSpinBox->value() / m_unitRatio;
108
        leftMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - rightMarginSpinBox->value()));
109
        if (marginLinkCheckBox->isChecked() && savedPresetItem==PresetLayout::none)
110
        {
111
                marginData.set(newVal, newVal, newVal, newVal);
112
                updateMarginSpinValues();
113
        }
114
        else
115
                marginData.Right = newVal;
116
        setPreset();
14216 cbradney 117
}
14226 cbradney 118
 
119
void NewMarginWidget::setNewUnitIndex(int newUnitIndex)
120
{
121
        leftMarginSpinBox->blockSignals(true);
122
        rightMarginSpinBox->blockSignals(true);
123
        topMarginSpinBox->blockSignals(true);
124
        bottomMarginSpinBox->blockSignals(true);
125
        m_unitIndex=newUnitIndex;
126
        m_unitRatio=unitGetRatioFromIndex(newUnitIndex);
127
        topMarginSpinBox->setNewUnit(newUnitIndex);
128
        bottomMarginSpinBox->setNewUnit(newUnitIndex);
129
        leftMarginSpinBox->setNewUnit(newUnitIndex);
130
        rightMarginSpinBox->setNewUnit(newUnitIndex);
131
        leftMarginSpinBox->blockSignals(false);
132
        rightMarginSpinBox->blockSignals(false);
133
        topMarginSpinBox->blockSignals(false);
134
        bottomMarginSpinBox->blockSignals(false);
135
}
136
 
137
void NewMarginWidget::setPreset()
138
{
139
        leftMarginSpinBox->blockSignals(true);
140
        rightMarginSpinBox->blockSignals(true);
141
        topMarginSpinBox->blockSignals(true);
142
        bottomMarginSpinBox->blockSignals(true);
143
        if (savedPresetItem==PresetLayout::none)
144
                savedMarginData=marginData;
145
        int item = presetLayoutComboBox->currentIndex();
146
 
147
        MarginStruct marg = presetLayoutComboBox->getMargins(item, pageWidth, pageHeight, leftMarginSpinBox->value() / m_unitRatio);
148
        facingPages ? presetLayoutComboBox->setEnabled(true) : presetLayoutComboBox->setEnabled(false);
149
        bool restoringValues=false;
150
        if (item==PresetLayout::none && savedPresetItem!=PresetLayout::none)
151
        {
152
                marg=savedMarginData;
153
                restoringValues=true;
154
        }
155
        if (restoringValues || (presetLayoutComboBox->needUpdate() && facingPages))
156
        {
157
                marginData.set(qMax(0.0, marg.Top), qMax(0.0, marg.Left), qMax(0.0, marg.Bottom), qMax(0.0, marg.Right));
158
                updateMarginSpinValues();
159
 
160
                bottomMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - topMarginSpinBox->value()));
161
                topMarginSpinBox->setMaximum(qMax(0.0, pageHeight * m_unitRatio - bottomMarginSpinBox->value()));
162
                rightMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - leftMarginSpinBox->value()));
163
                leftMarginSpinBox->setMaximum(qMax(0.0, pageWidth * m_unitRatio - rightMarginSpinBox->value()));
164
                rightMarginSpinBox->setEnabled(restoringValues);
165
                topMarginSpinBox->setEnabled(restoringValues);
166
                bottomMarginSpinBox->setEnabled(restoringValues);
167
        }
168
        else
169
        {
170
                rightMarginSpinBox->setEnabled(true);
171
                topMarginSpinBox->setEnabled(true);
172
                bottomMarginSpinBox->setEnabled(true);
173
        }
174
        if (pageType == 1)
175
                rightMarginSpinBox->setEnabled(false);
176
        leftMarginSpinBox->setEnabled(item != PresetLayout::nineparts);
177
        if (item!=PresetLayout::none)
178
                marginLinkCheckBox->setChecked(false);
179
        marginLinkCheckBox->setEnabled(item==PresetLayout::none);
180
        leftMarginSpinBox->blockSignals(false);
181
        rightMarginSpinBox->blockSignals(false);
182
        topMarginSpinBox->blockSignals(false);
183
        bottomMarginSpinBox->blockSignals(false);
184
        savedPresetItem=item;
185
}
186
 
187
void NewMarginWidget::setPageSize(const QString& pageSize)
188
{
189
        m_pageSize=pageSize;
190
}
191
 
192
 
193
void NewMarginWidget::updateMarginSpinValues()
194
{
195
        topMarginSpinBox->setValue(marginData.Top * m_unitRatio);
196
        rightMarginSpinBox->setValue(marginData.Right * m_unitRatio);
197
        bottomMarginSpinBox->setValue(marginData.Bottom * m_unitRatio);
198
        leftMarginSpinBox->setValue(marginData.Left * m_unitRatio);
199
}
200
 
201
const MarginStruct & NewMarginWidget::margins() const
202
{
203
        return marginData;
204
}
205
 
206
void NewMarginWidget::slotLinkMargins()
207
{
208
        leftMarginSpinBox->blockSignals(true);
209
        rightMarginSpinBox->blockSignals(true);
210
        topMarginSpinBox->blockSignals(true);
211
        bottomMarginSpinBox->blockSignals(true);
212
 
213
        if (marginLinkCheckBox->isChecked())
214
        {
215
                bottomMarginSpinBox->setValue(leftMarginSpinBox->value());
216
                topMarginSpinBox->setValue(leftMarginSpinBox->value());
217
                rightMarginSpinBox->setValue(leftMarginSpinBox->value());
218
                double newVal=leftMarginSpinBox->value() / m_unitRatio;
219
                marginData.set(newVal, newVal, newVal, newVal);
220
        }
221
        leftMarginSpinBox->blockSignals(false);
222
        rightMarginSpinBox->blockSignals(false);
223
        topMarginSpinBox->blockSignals(false);
224
        bottomMarginSpinBox->blockSignals(false);
225
}