Subversion Repositories Scribus

Rev

Rev 14229 | Rev 15021 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13761 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
*/
14214 cbradney 7
#include <QButtonGroup>
13761 cbradney 8
 
14216 cbradney 9
#include "ui/prefs_documentsetup.h"
14205 cbradney 10
#include "commonstrings.h"
14216 cbradney 11
#include "ui/newmarginwidget.h"
14205 cbradney 12
#include "pagesize.h"
14764 cbradney 13
#include "prefsfile.h"
14
#include "prefsmanager.h"
14205 cbradney 15
#include "prefsstructs.h"
14764 cbradney 16
#include "undomanager.h"
14205 cbradney 17
#include "units.h"
18
#include "util.h"
13761 cbradney 19
 
20
Prefs_DocumentSetup::Prefs_DocumentSetup(QWidget* parent)
14205 cbradney 21
        : Prefs_Pane(parent)
13761 cbradney 22
{
23
        setupUi(this);
14229 cbradney 24
 
25
        applySizesToAllPagesCheckBox->hide();
26
        applySizesToAllMasterPagesCheckBox->hide();
27
        applyMarginsToAllPagesCheckBox->hide();
28
        applyMarginsToAllMasterPagesCheckBox->hide();
29
 
14205 cbradney 30
        pageWidthSpinBox->setMaximum(16777215);
31
        pageHeightSpinBox->setMaximum(16777215);
32
        languageChange();
14214 cbradney 33
 
14229 cbradney 34
 
14214 cbradney 35
        pageLayoutButtonGroup->setId(singlePageRadioButton,0);
36
        pageLayoutButtonGroup->setId(doublePageRadioButton,1);
37
        pageLayoutButtonGroup->setId(threeFoldRadioButton,2);
38
        pageLayoutButtonGroup->setId(fourFoldRadioButton,3);
39
 
14216 cbradney 40
        connect(pageSizeComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
41
        connect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setPageOrientation(int)));
42
        connect(pageWidthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
43
        connect(pageHeightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double)));
14214 cbradney 44
        connect(pageLayoutButtonGroup, SIGNAL(buttonReleased(int)), this, SLOT(pageLayoutChanged(int)));
14216 cbradney 45
        connect(pageUnitsComboBox, SIGNAL(activated(int)), this, SLOT(unitChange()));
14764 cbradney 46
        connect(undoCheckBox, SIGNAL(toggled(bool)), this, SLOT(slotUndo(bool)));
13761 cbradney 47
}
48
 
49
Prefs_DocumentSetup::~Prefs_DocumentSetup()
50
{
51
}
52
 
14205 cbradney 53
void Prefs_DocumentSetup::unitChange()
54
{
14216 cbradney 55
        pageWidthSpinBox->blockSignals(true);
56
        pageHeightSpinBox->blockSignals(true);
57
 
14205 cbradney 58
        int docUnitIndex = pageUnitsComboBox->currentIndex();
59
        pageWidthSpinBox->setNewUnit(docUnitIndex);
60
        pageHeightSpinBox->setNewUnit(docUnitIndex);
61
        unitRatio = unitGetRatioFromIndex(docUnitIndex);
62
        pageWidthSpinBox->setValue(pageW * unitRatio);
63
        pageHeightSpinBox->setValue(pageH * unitRatio);
14216 cbradney 64
        marginsWidget->setNewUnitIndex(docUnitIndex);
65
        marginsWidget->setPageHeight(pageH);
66
        marginsWidget->setPageWidth(pageW);
14229 cbradney 67
        bleedsWidget->setNewUnitIndex(docUnitIndex);
68
        bleedsWidget->setPageHeight(pageH);
69
        bleedsWidget->setPageWidth(pageW);
14216 cbradney 70
 
71
        pageWidthSpinBox->blockSignals(false);
72
        pageHeightSpinBox->blockSignals(false);
14205 cbradney 73
}
74
 
75
void Prefs_DocumentSetup::languageChange()
76
{
77
        int i=0;
78
 
14206 cbradney 79
        i=pageOrientationComboBox->currentIndex();
14205 cbradney 80
        pageOrientationComboBox->clear();
81
        pageOrientationComboBox->addItem( tr( "Portrait" ) );
82
        pageOrientationComboBox->addItem( tr( "Landscape" ) );
83
        pageOrientationComboBox->setCurrentIndex(i<0?0:i);
84
 
85
        i=pageUnitsComboBox->currentIndex();
86
        pageUnitsComboBox->clear();
87
        pageUnitsComboBox->addItems(unitGetTextUnitList());
88
        pageUnitsComboBox->setCurrentIndex(i<0?0:i);
14214 cbradney 89
 
90
        setupPageSets();
91
 
14205 cbradney 92
}
93
 
94
void Prefs_DocumentSetup::restoreDefaults(struct ApplicationPrefs *prefsData)
95
{
14216 cbradney 96
        pageWidthSpinBox->blockSignals(true);
97
        pageHeightSpinBox->blockSignals(true);
98
        pageOrientationComboBox->blockSignals(true);
99
        pageSizeComboBox->blockSignals(true);
100
 
14205 cbradney 101
        unitRatio = unitGetRatioFromIndex(prefsData->docSetupPrefs.docUnitIndex);
102
        prefsPageSizeName = prefsData->docSetupPrefs.pageSize;
103
        PageSize *ps=new PageSize(prefsPageSizeName);
104
        pageSizeComboBox->addItems(ps->sizeTRList());
105
        pageSizeComboBox->addItem( CommonStrings::trCustomPageSize );
106
        if (prefsData->docSetupPrefs.pageSize == CommonStrings::customPageSize)
107
                setCurrentComboItem(pageSizeComboBox, CommonStrings::trCustomPageSize);
108
        else
109
                setCurrentComboItem(pageSizeComboBox, prefsPageSizeName);
110
 
111
        pageOrientationComboBox->setCurrentIndex(prefsData->docSetupPrefs.pageOrientation);
112
        pageUnitsComboBox->setCurrentIndex(prefsData->docSetupPrefs.docUnitIndex);
113
        pageW = prefsData->docSetupPrefs.pageWidth;
114
        pageH = prefsData->docSetupPrefs.pageHeight;
115
        pageWidthSpinBox->setValue(pageW * unitRatio);
116
        pageHeightSpinBox->setValue(pageH * unitRatio);
117
 
14214 cbradney 118
        pageSets=prefsData->pageSets;
119
        switch (prefsData->docSetupPrefs.pagePositioning)
120
        {
121
                case 0:
122
                        singlePageRadioButton->setChecked(true);
123
                        break;
124
                case 1:
125
                        doublePageRadioButton->setChecked(true);
126
                        break;
127
                case 2:
128
                        threeFoldRadioButton->setChecked(true);
129
                        break;
130
                case 3:
131
                        fourFoldRadioButton->setChecked(true);
132
                        break;
133
        }
134
        setupPageSets();
14205 cbradney 135
 
14214 cbradney 136
        layoutFirstPageIsComboBox->setCurrentIndex(prefsData->pageSets[prefsData->docSetupPrefs.pagePositioning].FirstPage);
14205 cbradney 137
 
14216 cbradney 138
        pageWidthSpinBox->blockSignals(false);
139
        pageHeightSpinBox->blockSignals(false);
140
        pageOrientationComboBox->blockSignals(false);
141
        pageSizeComboBox->blockSignals(false);
142
 
14229 cbradney 143
        marginsWidget->setup(prefsData->docSetupPrefs.margins, prefsData->docSetupPrefs.pagePositioning, prefsData->docSetupPrefs.docUnitIndex, true, true);
144
        marginsWidget->setPageWidth(prefsData->docSetupPrefs.pageWidth);
145
        marginsWidget->setPageHeight(prefsData->docSetupPrefs.pageHeight);
146
        marginsWidget->setPageSize(prefsPageSizeName);
147
        marginsWidget->setMarginPreset(prefsData->docSetupPrefs.marginPreset);
148
        bleedsWidget->setup(prefsData->docSetupPrefs.bleeds, prefsData->docSetupPrefs.pagePositioning, prefsData->docSetupPrefs.docUnitIndex, false, false);
149
        bleedsWidget->setPageWidth(prefsData->docSetupPrefs.pageWidth);
150
        bleedsWidget->setPageHeight(prefsData->docSetupPrefs.pageHeight);
151
        bleedsWidget->setPageSize(prefsPageSizeName);
152
        bleedsWidget->setMarginPreset(prefsData->docSetupPrefs.marginPreset);
14764 cbradney 153
        saveCompressedCheckBox->setChecked(prefsData->docSetupPrefs.saveCompressed);
154
        autosaveCheckBox->setChecked( prefsData->docSetupPrefs.AutoSave );
155
        autosaveIntervalSpinBox->setValue(prefsData->docSetupPrefs.AutoSaveTime / 1000 / 60);
156
        undoCheckBox->setChecked(PrefsManager::instance()->prefsFile->getContext("undo")->getBool("enabled", true));
157
        int undoLength = UndoManager::instance()->getHistoryLength();
158
        if (undoLength == -1)
159
                undoLengthSpinBox->setEnabled(false);
160
        else
161
                undoLengthSpinBox->setValue(undoLength);
14205 cbradney 162
        unitChange();
163
}
164
 
165
void Prefs_DocumentSetup::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
166
{
14214 cbradney 167
        prefsData->docSetupPrefs.pageSize=prefsPageSizeName;
168
        prefsData->docSetupPrefs.pageOrientation=pageOrientationComboBox->currentIndex();
169
        prefsData->docSetupPrefs.pageWidth=pageW;
170
        prefsData->docSetupPrefs.pageHeight=pageH;
171
        prefsData->docSetupPrefs.pagePositioning=pageLayoutButtonGroup->checkedId();
172
        prefsData->pageSets[prefsData->docSetupPrefs.pagePositioning].FirstPage=layoutFirstPageIsComboBox->currentIndex();
14229 cbradney 173
        prefsData->docSetupPrefs.margins=marginsWidget->margins();
174
        prefsData->docSetupPrefs.bleeds=bleedsWidget->margins();
14764 cbradney 175
        prefsData->docSetupPrefs.saveCompressed=saveCompressedCheckBox->isChecked();
176
        prefsData->docSetupPrefs.AutoSave=autosaveCheckBox->isChecked();
177
        prefsData->docSetupPrefs.AutoSaveTime = autosaveIntervalSpinBox->value() * 1000 * 60;
178
        bool undoActive=undoCheckBox->isChecked();
179
        if (!undoActive)
180
                UndoManager::instance()->clearStack();
181
        UndoManager::instance()->setUndoEnabled(undoActive);
182
        UndoManager::instance()->setAllHistoryLengths(undoLengthSpinBox->value());
183
        static PrefsContext *undoPrefs = PrefsManager::instance()->prefsFile->getContext("undo");
184
        undoPrefs->set("enabled", undoActive);
14205 cbradney 185
}
186
 
14214 cbradney 187
void Prefs_DocumentSetup::setupPageSets()
188
{
189
        int i=layoutFirstPageIsComboBox->currentIndex();
190
        layoutFirstPageIsComboBox->clear();
191
        int currIndex=pageLayoutButtonGroup->checkedId()<0?0:pageLayoutButtonGroup->checkedId();
192
        if (currIndex>=0 && currIndex<pageSets.count())
193
                for(QStringList::Iterator pNames = pageSets[currIndex].pageNames.begin(); pNames != pageSets[currIndex].pageNames.end(); ++pNames )
194
                        layoutFirstPageIsComboBox->addItem(CommonStrings::translatePageSetLocString(*pNames));
195
        layoutFirstPageIsComboBox->setCurrentIndex(i<0?0:i);
196
}
14205 cbradney 197
 
14229 cbradney 198
void Prefs_DocumentSetup::pageLayoutChanged(int i)
14214 cbradney 199
{
200
        setupPageSets();
14229 cbradney 201
        marginsWidget->setFacingPages(!(i == singlePage));
14214 cbradney 202
        layoutFirstPageIsComboBox->setCurrentIndex(pageSets[pageLayoutButtonGroup->checkedId()].FirstPage);
203
}
204
 
14216 cbradney 205
void Prefs_DocumentSetup::setPageWidth(double w)
206
{
207
        pageW = pageWidthSpinBox->value() / unitRatio;
208
        marginsWidget->setPageWidth(pageW);
209
        QString psText=pageSizeComboBox->currentText();
210
        if (psText!=CommonStrings::trCustomPageSize && psText!=CommonStrings::customPageSize)
211
                pageSizeComboBox->setCurrentIndex(pageSizeComboBox->count()-1);
212
        int newOrientation = (pageWidthSpinBox->value() > pageHeightSpinBox->value()) ? landscapePage : portraitPage;
213
        if (newOrientation != pageOrientationComboBox->currentIndex())
214
        {
215
                pageOrientationComboBox->blockSignals(true);
216
                pageOrientationComboBox->setCurrentIndex(newOrientation);
217
                pageOrientationComboBox->blockSignals(false);
218
        }
219
}
220
 
221
void Prefs_DocumentSetup::setPageHeight(double h)
222
{
223
        pageH = pageHeightSpinBox->value() / unitRatio;
224
        marginsWidget->setPageHeight(pageH);
225
        QString psText=pageSizeComboBox->currentText();
226
        if (psText!=CommonStrings::trCustomPageSize && psText!=CommonStrings::customPageSize)
227
                pageSizeComboBox->setCurrentIndex(pageSizeComboBox->count()-1);
228
        int newOrientation = (pageWidthSpinBox->value() > pageHeightSpinBox->value()) ? landscapePage : portraitPage;
229
        if (newOrientation != pageOrientationComboBox->currentIndex())
230
        {
231
                pageOrientationComboBox->blockSignals(true);
232
                pageOrientationComboBox->setCurrentIndex(newOrientation);
233
                pageOrientationComboBox->blockSignals(false);
234
        }
235
}
236
 
237
void Prefs_DocumentSetup::setPageOrientation(int orientation)
238
{
239
        setSize(pageSizeComboBox->currentText());
240
        pageWidthSpinBox->blockSignals(true);
241
        pageHeightSpinBox->blockSignals(true);
14221 cbradney 242
        if ((orientation==0 && pageSizeComboBox->currentText() == CommonStrings::trCustomPageSize) || orientation!=0)
14216 cbradney 243
        {
244
                double w = pageWidthSpinBox->value(), h = pageHeightSpinBox->value();
245
                pageWidthSpinBox->setValue((orientation == portraitPage) ? qMin(w, h) : qMax(w, h));
246
                pageHeightSpinBox->setValue((orientation == portraitPage) ? qMax(w, h) : qMin(w, h));
247
        }
248
        pageW = pageWidthSpinBox->value() / unitRatio;
249
        pageH = pageHeightSpinBox->value() / unitRatio;
250
        pageWidthSpinBox->blockSignals(false);
251
        pageHeightSpinBox->blockSignals(false);
252
}
253
 
254
void Prefs_DocumentSetup::setPageSize()
255
{
256
        setPageOrientation(pageOrientationComboBox->currentIndex());
257
}
258
 
259
void Prefs_DocumentSetup::setSize(const QString &newSize)
260
{
261
        pageW = pageWidthSpinBox->value() / unitRatio;
262
        pageH = pageHeightSpinBox->value() / unitRatio;
263
        PageSize *ps2=new PageSize(newSize);
264
 
265
        prefsPageSizeName=ps2->name();
266
        if (newSize != CommonStrings::trCustomPageSize)
267
        {
268
                pageW = ps2->width();
269
                pageH = ps2->height();
270
        }
271
        else
272
                prefsPageSizeName = CommonStrings::customPageSize;
273
        pageWidthSpinBox->blockSignals(true);
274
        pageHeightSpinBox->blockSignals(true);
275
        pageWidthSpinBox->setValue(pageW * unitRatio);
276
        pageHeightSpinBox->setValue(pageH * unitRatio);
277
        marginsWidget->setPageHeight(pageH);
278
        marginsWidget->setPageWidth(pageW);
279
        marginsWidget->setPageSize(newSize);
280
        pageWidthSpinBox->blockSignals(false);
281
        pageHeightSpinBox->blockSignals(false);
282
        delete ps2;
283
}
14764 cbradney 284
 
285
void Prefs_DocumentSetup::slotUndo(bool isEnabled)
286
{
287
        undoLengthSpinBox->setEnabled(isEnabled);
288
}