Subversion Repositories Scribus

Rev

Rev 19248 | Rev 19885 | 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
 
15021 cbradney 20
Prefs_DocumentSetup::Prefs_DocumentSetup(QWidget* parent, ScribusDoc* doc)
15096 cbradney 21
        : Prefs_Pane(parent),
22
        m_doc(doc)
13761 cbradney 23
{
24
        setupUi(this);
14229 cbradney 25
 
15096 cbradney 26
        if (!m_doc)
27
        {
28
                applySizesToAllPagesCheckBox->hide();
29
                applySizesToAllMasterPagesCheckBox->hide();
30
                applyMarginsToAllPagesCheckBox->hide();
31
                applyMarginsToAllMasterPagesCheckBox->hide();
15105 cbradney 32
                pageSizeLinkToolButton->hide(); //temp
33
//              connect(pageSizeLinkToolButton, SIGNAL(clicked()), this, SLOT(emitSectionChange()));
15096 cbradney 34
        }
15105 cbradney 35
        else
36
        {
37
                pageSizeLinkToolButton->hide();
38
        }
14229 cbradney 39
 
14214 cbradney 40
        pageLayoutButtonGroup->setId(singlePageRadioButton,0);
41
        pageLayoutButtonGroup->setId(doublePageRadioButton,1);
42
        pageLayoutButtonGroup->setId(threeFoldRadioButton,2);
43
        pageLayoutButtonGroup->setId(fourFoldRadioButton,3);
15407 craig 44
        singlePageRadioButton->setChecked(true);
45
        layoutFirstPageIsComboBox->clear();
46
        layoutFirstPageIsComboBox->addItem(" ");
47
        layoutFirstPageIsComboBox->setCurrentIndex(0);
48
        layoutFirstPageIsComboBox->setEnabled(false);
14214 cbradney 49
 
15407 craig 50
        pageWidthSpinBox->setMaximum(16777215);
51
        pageHeightSpinBox->setMaximum(16777215);
52
        languageChange();
53
 
14216 cbradney 54
        connect(pageSizeComboBox, SIGNAL(activated(const QString &)), this, SLOT(setPageSize()));
55
        connect(pageOrientationComboBox, SIGNAL(activated(int)), this, SLOT(setPageOrientation(int)));
56
        connect(pageWidthSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageWidth(double)));
57
        connect(pageHeightSpinBox, SIGNAL(valueChanged(double)), this, SLOT(setPageHeight(double)));
15407 craig 58
        connect(pageLayoutButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(pageLayoutChanged(int)));
14216 cbradney 59
        connect(pageUnitsComboBox, SIGNAL(activated(int)), this, SLOT(unitChange()));
14764 cbradney 60
        connect(undoCheckBox, SIGNAL(toggled(bool)), this, SLOT(slotUndo(bool)));
13761 cbradney 61
}
62
 
63
Prefs_DocumentSetup::~Prefs_DocumentSetup()
64
{
65
}
66
 
14205 cbradney 67
void Prefs_DocumentSetup::unitChange()
68
{
14216 cbradney 69
        pageWidthSpinBox->blockSignals(true);
70
        pageHeightSpinBox->blockSignals(true);
71
 
14205 cbradney 72
        int docUnitIndex = pageUnitsComboBox->currentIndex();
73
        pageWidthSpinBox->setNewUnit(docUnitIndex);
74
        pageHeightSpinBox->setNewUnit(docUnitIndex);
75
        unitRatio = unitGetRatioFromIndex(docUnitIndex);
76
        pageWidthSpinBox->setValue(pageW * unitRatio);
77
        pageHeightSpinBox->setValue(pageH * unitRatio);
19371 jghali 78
        marginsWidget->setNewUnit(docUnitIndex);
14216 cbradney 79
        marginsWidget->setPageHeight(pageH);
80
        marginsWidget->setPageWidth(pageW);
19371 jghali 81
        bleedsWidget->setNewUnit(docUnitIndex);
14229 cbradney 82
        bleedsWidget->setPageHeight(pageH);
83
        bleedsWidget->setPageWidth(pageW);
14216 cbradney 84
 
85
        pageWidthSpinBox->blockSignals(false);
86
        pageHeightSpinBox->blockSignals(false);
19248 craig 87
 
88
        emit prefsChangeUnits(docUnitIndex);
14205 cbradney 89
}
90
 
91
void Prefs_DocumentSetup::languageChange()
92
{
93
        int i=0;
94
 
14206 cbradney 95
        i=pageOrientationComboBox->currentIndex();
14205 cbradney 96
        pageOrientationComboBox->clear();
97
        pageOrientationComboBox->addItem( tr( "Portrait" ) );
98
        pageOrientationComboBox->addItem( tr( "Landscape" ) );
99
        pageOrientationComboBox->setCurrentIndex(i<0?0:i);
100
 
101
        i=pageUnitsComboBox->currentIndex();
102
        pageUnitsComboBox->clear();
103
        pageUnitsComboBox->addItems(unitGetTextUnitList());
104
        pageUnitsComboBox->setCurrentIndex(i<0?0:i);
14214 cbradney 105
 
106
        setupPageSets();
107
 
15096 cbradney 108
        pageWidthSpinBox->setToolTip( "<qt>" + tr( "Width of document pages, editable if you have chosen a custom page size" ) + "</qt>" );
109
        pageHeightSpinBox->setToolTip( "<qt>" + tr( "Height of document pages, editable if you have chosen a custom page size" ) + "</qt>" );
15108 cbradney 110
        pageSizeComboBox->setToolTip( "<qt>" + tr( "Default page size, either a standard size or a custom size. More page sizes can be made visible by activating them in Preferences." ) + "</qt>" );
15105 cbradney 111
        pageSizeLinkToolButton->setToolTip( "<qt>" + tr( "Enable or disable more page sizes by jumping to Page Size preferences" ) + "</qt>" );
15096 cbradney 112
        pageOrientationComboBox->setToolTip( "<qt>" + tr( "Default orientation of document pages" ) + "</qt>" );
113
        pageUnitsComboBox->setToolTip( "<qt>" + tr( "Default unit of measurement for document editing" ) + "</qt>" );
114
        autosaveCheckBox->setToolTip( "<qt>" + tr( "When enabled, Scribus saves a backup copy of your file with the .bak extension each time the time period elapses" ) + "</qt>" );
115
        autosaveIntervalSpinBox->setToolTip( "<qt>" + tr( "Time period between saving automatically" ) + "</qt>" );
116
        undoLengthSpinBox->setToolTip( "<qt>" + tr("Set the length of the action history in steps. If set to 0 infinite amount of actions will be stored.") + "</qt>");
117
        applySizesToAllPagesCheckBox->setToolTip( "<qt>" + tr( "Apply the page size changes to all existing pages in the document" ) + "</qt>" );
118
        applyMarginsToAllPagesCheckBox->setToolTip( "<qt>" + tr( "Apply the page size changes to all existing master pages in the document" ) + "</qt>" );
14205 cbradney 119
}
120
 
121
void Prefs_DocumentSetup::restoreDefaults(struct ApplicationPrefs *prefsData)
122
{
14216 cbradney 123
        pageWidthSpinBox->blockSignals(true);
124
        pageHeightSpinBox->blockSignals(true);
125
        pageOrientationComboBox->blockSignals(true);
126
        pageSizeComboBox->blockSignals(true);
127
 
14205 cbradney 128
        unitRatio = unitGetRatioFromIndex(prefsData->docSetupPrefs.docUnitIndex);
15105 cbradney 129
        setupPageSizes(prefsData);
14205 cbradney 130
 
131
        pageOrientationComboBox->setCurrentIndex(prefsData->docSetupPrefs.pageOrientation);
132
        pageUnitsComboBox->setCurrentIndex(prefsData->docSetupPrefs.docUnitIndex);
133
        pageW = prefsData->docSetupPrefs.pageWidth;
134
        pageH = prefsData->docSetupPrefs.pageHeight;
135
        pageWidthSpinBox->setValue(pageW * unitRatio);
136
        pageHeightSpinBox->setValue(pageH * unitRatio);
14214 cbradney 137
        pageSets=prefsData->pageSets;
138
        switch (prefsData->docSetupPrefs.pagePositioning)
139
        {
140
                case 0:
141
                        singlePageRadioButton->setChecked(true);
142
                        break;
143
                case 1:
144
                        doublePageRadioButton->setChecked(true);
145
                        break;
146
                case 2:
147
                        threeFoldRadioButton->setChecked(true);
148
                        break;
149
                case 3:
150
                        fourFoldRadioButton->setChecked(true);
151
                        break;
152
        }
153
        setupPageSets();
14205 cbradney 154
 
14214 cbradney 155
        layoutFirstPageIsComboBox->setCurrentIndex(prefsData->pageSets[prefsData->docSetupPrefs.pagePositioning].FirstPage);
14205 cbradney 156
 
14216 cbradney 157
        pageWidthSpinBox->blockSignals(false);
158
        pageHeightSpinBox->blockSignals(false);
159
        pageOrientationComboBox->blockSignals(false);
160
        pageSizeComboBox->blockSignals(false);
161
 
14229 cbradney 162
        marginsWidget->setup(prefsData->docSetupPrefs.margins, prefsData->docSetupPrefs.pagePositioning, prefsData->docSetupPrefs.docUnitIndex, true, true);
163
        marginsWidget->setPageWidth(prefsData->docSetupPrefs.pageWidth);
164
        marginsWidget->setPageHeight(prefsData->docSetupPrefs.pageHeight);
15105 cbradney 165
//      marginsWidget->setPageSize(prefsPageSizeName);
14229 cbradney 166
        marginsWidget->setMarginPreset(prefsData->docSetupPrefs.marginPreset);
167
        bleedsWidget->setup(prefsData->docSetupPrefs.bleeds, prefsData->docSetupPrefs.pagePositioning, prefsData->docSetupPrefs.docUnitIndex, false, false);
168
        bleedsWidget->setPageWidth(prefsData->docSetupPrefs.pageWidth);
169
        bleedsWidget->setPageHeight(prefsData->docSetupPrefs.pageHeight);
15105 cbradney 170
//      bleedsWidget->setPageSize(prefsPageSizeName);
14229 cbradney 171
        bleedsWidget->setMarginPreset(prefsData->docSetupPrefs.marginPreset);
14764 cbradney 172
        saveCompressedCheckBox->setChecked(prefsData->docSetupPrefs.saveCompressed);
173
        autosaveCheckBox->setChecked( prefsData->docSetupPrefs.AutoSave );
174
        autosaveIntervalSpinBox->setValue(prefsData->docSetupPrefs.AutoSaveTime / 1000 / 60);
175
        undoCheckBox->setChecked(PrefsManager::instance()->prefsFile->getContext("undo")->getBool("enabled", true));
176
        int undoLength = UndoManager::instance()->getHistoryLength();
177
        if (undoLength == -1)
178
                undoLengthSpinBox->setEnabled(false);
179
        else
180
                undoLengthSpinBox->setValue(undoLength);
14205 cbradney 181
        unitChange();
182
}
183
 
184
void Prefs_DocumentSetup::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
185
{
18318 jghali 186
        prefsData->docSetupPrefs.pageSize = prefsPageSizeName;
14214 cbradney 187
        prefsData->docSetupPrefs.pageOrientation=pageOrientationComboBox->currentIndex();
15407 craig 188
        prefsData->docSetupPrefs.docUnitIndex=pageUnitsComboBox->currentIndex();
14214 cbradney 189
        prefsData->docSetupPrefs.pageWidth=pageW;
190
        prefsData->docSetupPrefs.pageHeight=pageH;
191
        prefsData->docSetupPrefs.pagePositioning=pageLayoutButtonGroup->checkedId();
192
        prefsData->pageSets[prefsData->docSetupPrefs.pagePositioning].FirstPage=layoutFirstPageIsComboBox->currentIndex();
15407 craig 193
 
14229 cbradney 194
        prefsData->docSetupPrefs.margins=marginsWidget->margins();
195
        prefsData->docSetupPrefs.bleeds=bleedsWidget->margins();
14764 cbradney 196
        prefsData->docSetupPrefs.saveCompressed=saveCompressedCheckBox->isChecked();
197
        prefsData->docSetupPrefs.AutoSave=autosaveCheckBox->isChecked();
198
        prefsData->docSetupPrefs.AutoSaveTime = autosaveIntervalSpinBox->value() * 1000 * 60;
199
        bool undoActive=undoCheckBox->isChecked();
200
        if (!undoActive)
201
                UndoManager::instance()->clearStack();
202
        UndoManager::instance()->setUndoEnabled(undoActive);
203
        UndoManager::instance()->setAllHistoryLengths(undoLengthSpinBox->value());
204
        static PrefsContext *undoPrefs = PrefsManager::instance()->prefsFile->getContext("undo");
205
        undoPrefs->set("enabled", undoActive);
14205 cbradney 206
}
207
 
14214 cbradney 208
void Prefs_DocumentSetup::setupPageSets()
209
{
210
        int i=layoutFirstPageIsComboBox->currentIndex();
15407 craig 211
        int currIndex=pageLayoutButtonGroup->checkedId()<0?0:pageLayoutButtonGroup->checkedId();
14214 cbradney 212
        layoutFirstPageIsComboBox->clear();
15407 craig 213
        if (currIndex>0 && currIndex<pageSets.count())
214
        {
215
                layoutFirstPageIsComboBox->setEnabled(true);
14214 cbradney 216
                for(QStringList::Iterator pNames = pageSets[currIndex].pageNames.begin(); pNames != pageSets[currIndex].pageNames.end(); ++pNames )
217
                        layoutFirstPageIsComboBox->addItem(CommonStrings::translatePageSetLocString(*pNames));
15407 craig 218
                layoutFirstPageIsComboBox->setCurrentIndex(i<0?0:i);
219
        }
220
        else
221
        {
222
                layoutFirstPageIsComboBox->addItem(" ");
223
                layoutFirstPageIsComboBox->setCurrentIndex(0);
224
                layoutFirstPageIsComboBox->setEnabled(false);
225
        }
14214 cbradney 226
}
14205 cbradney 227
 
15105 cbradney 228
void Prefs_DocumentSetup::setupPageSizes(struct ApplicationPrefs *prefsData)
229
{
18318 jghali 230
        PageSize ps(prefsData->docSetupPrefs.pageSize);
231
        QStringList insertList(ps.activeSizeList());
232
        QStringList insertTrList(ps.activeSizeTRList());
233
 
15105 cbradney 234
        prefsPageSizeName = prefsData->docSetupPrefs.pageSize;
18318 jghali 235
        if (insertList.indexOf(prefsPageSizeName) ==-1)
236
        {
237
                insertList << prefsPageSizeName;
238
                insertTrList << prefsPageSizeName;
239
        }
240
 
241
        QMap<QString, QString> insertMap;
242
        for (int i = 0; i < insertTrList.count(); ++i)
243
        {
244
                QString key = insertTrList.at(i);
245
                insertMap[key] = insertList.at(i);
246
        }
247
        insertTrList.sort();
248
 
15105 cbradney 249
        pageSizeComboBox->clear();
18318 jghali 250
        for (int i = 0; i < insertList.count(); ++i)
251
        {
252
                QString key = insertTrList.at(i);
253
                pageSizeComboBox->addItem(key, insertMap[key]);
254
        }
255
        pageSizeComboBox->addItem(CommonStrings::trCustomPageSize, CommonStrings::customPageSize);
15107 cbradney 256
 
18318 jghali 257
        QString pageSizeName = CommonStrings::trCustomPageSize;
258
        int index = pageSizeComboBox->findData(prefsPageSizeName);
259
        if (index >= 0)
260
                pageSizeName = pageSizeComboBox->itemText(index);
261
        setCurrentComboItem(pageSizeComboBox, pageSizeName);
15105 cbradney 262
        marginsWidget->setPageSize(prefsPageSizeName);
263
        bleedsWidget->setPageSize(prefsPageSizeName);
264
}
265
 
14229 cbradney 266
void Prefs_DocumentSetup::pageLayoutChanged(int i)
14214 cbradney 267
{
268
        setupPageSets();
14229 cbradney 269
        marginsWidget->setFacingPages(!(i == singlePage));
15407 craig 270
        //layoutFirstPageIsComboBox->setCurrentIndex(pageSets[pageLayoutButtonGroup->checkedId()].FirstPage);
14214 cbradney 271
}
272
 
14216 cbradney 273
void Prefs_DocumentSetup::setPageWidth(double w)
274
{
275
        pageW = pageWidthSpinBox->value() / unitRatio;
276
        marginsWidget->setPageWidth(pageW);
277
        QString psText=pageSizeComboBox->currentText();
278
        if (psText!=CommonStrings::trCustomPageSize && psText!=CommonStrings::customPageSize)
279
                pageSizeComboBox->setCurrentIndex(pageSizeComboBox->count()-1);
280
        int newOrientation = (pageWidthSpinBox->value() > pageHeightSpinBox->value()) ? landscapePage : portraitPage;
281
        if (newOrientation != pageOrientationComboBox->currentIndex())
282
        {
283
                pageOrientationComboBox->blockSignals(true);
284
                pageOrientationComboBox->setCurrentIndex(newOrientation);
285
                pageOrientationComboBox->blockSignals(false);
286
        }
287
}
288
 
289
void Prefs_DocumentSetup::setPageHeight(double h)
290
{
291
        pageH = pageHeightSpinBox->value() / unitRatio;
292
        marginsWidget->setPageHeight(pageH);
293
        QString psText=pageSizeComboBox->currentText();
294
        if (psText!=CommonStrings::trCustomPageSize && psText!=CommonStrings::customPageSize)
295
                pageSizeComboBox->setCurrentIndex(pageSizeComboBox->count()-1);
296
        int newOrientation = (pageWidthSpinBox->value() > pageHeightSpinBox->value()) ? landscapePage : portraitPage;
297
        if (newOrientation != pageOrientationComboBox->currentIndex())
298
        {
299
                pageOrientationComboBox->blockSignals(true);
300
                pageOrientationComboBox->setCurrentIndex(newOrientation);
301
                pageOrientationComboBox->blockSignals(false);
302
        }
303
}
304
 
305
void Prefs_DocumentSetup::setPageOrientation(int orientation)
306
{
307
        setSize(pageSizeComboBox->currentText());
308
        pageWidthSpinBox->blockSignals(true);
309
        pageHeightSpinBox->blockSignals(true);
14221 cbradney 310
        if ((orientation==0 && pageSizeComboBox->currentText() == CommonStrings::trCustomPageSize) || orientation!=0)
14216 cbradney 311
        {
312
                double w = pageWidthSpinBox->value(), h = pageHeightSpinBox->value();
313
                pageWidthSpinBox->setValue((orientation == portraitPage) ? qMin(w, h) : qMax(w, h));
314
                pageHeightSpinBox->setValue((orientation == portraitPage) ? qMax(w, h) : qMin(w, h));
315
        }
316
        pageW = pageWidthSpinBox->value() / unitRatio;
317
        pageH = pageHeightSpinBox->value() / unitRatio;
318
        pageWidthSpinBox->blockSignals(false);
319
        pageHeightSpinBox->blockSignals(false);
320
}
321
 
322
void Prefs_DocumentSetup::setPageSize()
323
{
324
        setPageOrientation(pageOrientationComboBox->currentIndex());
325
}
326
 
327
void Prefs_DocumentSetup::setSize(const QString &newSize)
328
{
329
        pageW = pageWidthSpinBox->value() / unitRatio;
330
        pageH = pageHeightSpinBox->value() / unitRatio;
331
        PageSize *ps2=new PageSize(newSize);
332
 
333
        prefsPageSizeName=ps2->name();
334
        if (newSize != CommonStrings::trCustomPageSize)
335
        {
336
                pageW = ps2->width();
337
                pageH = ps2->height();
338
        }
339
        else
340
                prefsPageSizeName = CommonStrings::customPageSize;
341
        pageWidthSpinBox->blockSignals(true);
342
        pageHeightSpinBox->blockSignals(true);
343
        pageWidthSpinBox->setValue(pageW * unitRatio);
344
        pageHeightSpinBox->setValue(pageH * unitRatio);
345
        marginsWidget->setPageHeight(pageH);
346
        marginsWidget->setPageWidth(pageW);
347
        marginsWidget->setPageSize(newSize);
348
        pageWidthSpinBox->blockSignals(false);
349
        pageHeightSpinBox->blockSignals(false);
350
        delete ps2;
351
}
14764 cbradney 352
 
353
void Prefs_DocumentSetup::slotUndo(bool isEnabled)
354
{
355
        undoLengthSpinBox->setEnabled(isEnabled);
356
}
15096 cbradney 357
 
358
void Prefs_DocumentSetup::getResizeDocumentPages(bool &resizePages, bool &resizeMasterPages, bool &resizePageMargins, bool &resizeMasterPageMargins)
359
{
360
        resizePages=applySizesToAllPagesCheckBox->isChecked();
361
        resizeMasterPages=applySizesToAllMasterPagesCheckBox->isChecked();
362
        resizePageMargins=applyMarginsToAllPagesCheckBox->isChecked();
363
        resizeMasterPageMargins=applyMarginsToAllMasterPagesCheckBox->isChecked();
364
}
365
 
15105 cbradney 366
void Prefs_DocumentSetup::emitSectionChange()
367
{
368
        emit changeToOtherSection("Prefs_PageSizes");
369
}