Subversion Repositories Scribus

Rev

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

Rev Author Line No. Line
4430 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
*/
638 fschmid 7
/***************************************************************************
8
 *                                                                         *
9
 *   This program is free software; you can redistribute it and/or modify  *
10
 *   it under the terms of the GNU General Public License as published by  *
11
 *   the Free Software Foundation; either version 2 of the License, or     *
12
 *   (at your option) any later version.                                   *
13
 *                                                                         *
14
 ***************************************************************************/
14170 jghali 15
#include "scconfig.h"
19966 craig 16
#include "pdfexportdialog.h"
14170 jghali 17
 
13805 jghali 18
 
10372 cbradney 19
#include <QByteArray>
20
#include <QCheckBox>
19350 craig 21
#include <QFileDialog>
9877 fschmid 22
#include <QGridLayout>
23
#include <QGroupBox>
10372 cbradney 24
#include <QHBoxLayout>
9877 fschmid 25
#include <QLineEdit>
19828 jghali 26
#include <QListWidget>
10372 cbradney 27
#include <QMessageBox>
9877 fschmid 28
#include <QPushButton>
10372 cbradney 29
#include <QRadioButton>
9877 fschmid 30
#include <QSpacerItem>
10372 cbradney 31
#include <QToolButton>
10242 subik 32
#include <QToolTip>
10372 cbradney 33
#include <QVBoxLayout>
6278 subik 34
 
19093 craig 35
#include "commonstrings.h"
20185 craig 36
#include "iconmanager.h"
19093 craig 37
#include "pdfoptions.h"
38
#include "prefsfile.h"
39
#include "prefsmanager.h"
40
#include "scpaths.h"
41
#include "scribusdoc.h"
42
#include "scribusview.h"
20185 craig 43
#include "ui/scmessagebox.h"
19093 craig 44
#include "ui/scrspinbox.h"
45
#include "util.h"
46
 
20185 craig 47
 
4260 craig 48
PDFExportDialog::PDFExportDialog( QWidget* parent, const QString & docFileName,
5387 avox 49
                                                                  const QMap<QString, int > & DocFonts,
4260 craig 50
                                                                  ScribusView *currView, PDFOptions & pdfOptions,
51
                                                                  const ProfilesL & PDFXProfiles, const SCFonts &AllFonts,
18326 jghali 52
                                                                  const ProfilesL & printerProfiles)
9877 fschmid 53
        : QDialog( parent ),
23509 craig 54
        m_doc(currView->m_doc),
18326 jghali 55
        m_opts(pdfOptions),
23509 craig 56
        m_unitRatio(currView->m_doc->unitRatio()),
18326 jghali 57
        m_printerProfiles(printerProfiles)
3 paul 58
{
9877 fschmid 59
        setModal(true);
60
        setWindowTitle( tr( "Save as PDF" ) );
23054 craig 61
        setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
9877 fschmid 62
        PDFExportLayout = new QVBoxLayout( this );
24561 craig 63
        PDFExportLayout->setSpacing(6);
64
        PDFExportLayout->setContentsMargins(9, 9, 9, 9);
10553 fschmid 65
        Name = new QGroupBox( this );
3082 fschmid 66
        Name->setTitle( tr( "O&utput to File:" ) );
9905 fschmid 67
        NameLayout = new QGridLayout( Name );
24561 craig 68
        NameLayout->setSpacing(6);
69
        NameLayout->setContentsMargins(9, 9, 9, 9);
3082 fschmid 70
        NameLayout->setAlignment( Qt::AlignTop );
10553 fschmid 71
        fileNameLineEdit = new QLineEdit( Name );
2727 cbradney 72
        fileNameLineEdit->setMinimumSize( QSize( 268, 22 ) );
18326 jghali 73
        if (!m_opts.fileName.isEmpty())
74
                fileNameLineEdit->setText( QDir::toNativeSeparators(m_opts.fileName) );
167 Franz 75
        else
76
        {
6717 fschmid 77
                QFileInfo fi(docFileName);
17720 jghali 78
                QString completeBaseName = fi.completeBaseName();
79
                if (completeBaseName.endsWith(".sla", Qt::CaseInsensitive))
80
                        if (completeBaseName.length() > 4) completeBaseName.chop(4);
81
                if (completeBaseName.endsWith(".gz", Qt::CaseInsensitive))
82
                        if (completeBaseName.length() > 3) completeBaseName.chop(3);
6717 fschmid 83
                if (fi.exists())
7117 jghali 84
                {
17720 jghali 85
                        QString fileName(fi.path() + "/" + completeBaseName + ".pdf");
11949 jghali 86
                        fileNameLineEdit->setText( QDir::toNativeSeparators(fileName) );
7117 jghali 87
                }
6717 fschmid 88
                else
89
                {
23060 craig 90
                        PrefsContext* dirs = PrefsManager::instance().prefsFile->getContext("dirs");
10553 fschmid 91
                        QString pdfdir = dirs->get("pdf", fi.path());
6717 fschmid 92
                        if (pdfdir.right(1) != "/")
93
                                pdfdir += "/";
17720 jghali 94
                        QString fileName(pdfdir + completeBaseName + ".pdf");
11949 jghali 95
                        fileNameLineEdit->setText( QDir::toNativeSeparators(fileName) );
6717 fschmid 96
                }
167 Franz 97
        }
3082 fschmid 98
        NameLayout->addWidget( fileNameLineEdit, 0, 0 );
19351 craig 99
        changeButton = new QPushButton( Name );
100
        changeButton->setText( tr( "Cha&nge..." ) );
101
        changeButton->setMinimumSize( QSize( 88, 24 ) );
102
        NameLayout->addWidget( changeButton, 0, 1 );
10553 fschmid 103
        multiFile = new QCheckBox( tr( "Output one file for eac&h page" ), Name );
18326 jghali 104
        multiFile->setChecked(m_opts.doMultiFile);
3082 fschmid 105
        NameLayout->addWidget( multiFile, 1, 0 );
15130 cbradney 106
        openAfterExportCheckBox = new QCheckBox( tr( "Open PDF after Export" ), Name );
18326 jghali 107
        openAfterExportCheckBox->setChecked(m_opts.openAfterExport);
15130 cbradney 108
        NameLayout->addWidget( openAfterExportCheckBox, 2, 0 );
4259 craig 109
        PDFExportLayout->addWidget( Name );
15130 cbradney 110
 
23509 craig 111
        Options = new TabPDFOptions( this, pdfOptions, AllFonts, PDFXProfiles, DocFonts, currView->m_doc );
4259 craig 112
        PDFExportLayout->addWidget( Options );
9877 fschmid 113
        Layout7 = new QHBoxLayout;
24561 craig 114
        Layout7->setSpacing(6);
24545 craig 115
        Layout7->setContentsMargins(0, 0, 0, 0);
9877 fschmid 116
        QSpacerItem* spacer_2 = new QSpacerItem( 2, 2, QSizePolicy::Expanding, QSizePolicy::Minimum );
245 Franz 117
        Layout7->addItem( spacer_2 );
19351 craig 118
        okButton = new QPushButton( tr( "&Save" ), this );
119
        okButton->setAutoDefault( true );
120
        okButton->setDefault( true );
121
        Layout7->addWidget( okButton );
122
        cancelButton = new QPushButton( CommonStrings::tr_Cancel, this );
123
        Layout7->addWidget( cancelButton );
4259 craig 124
        PDFExportLayout->addLayout( Layout7 );
23548 jghali 125
        if ((m_opts.Version == PDFVersion::PDF_X3) && (Options->InfoString->text().isEmpty()))
19351 craig 126
                okButton->setEnabled(false);
338 Franz 127
        resize(sizeHint());
128
//      setMaximumSize( sizeHint() );
3085 mrdocs 129
//tooltips
10397 cbradney 130
        multiFile->setToolTip( "<qt>" + tr( "This enables exporting one individually named PDF file for each page in the document. Page numbers are added automatically. This is most useful for imposing PDF for commercial printing.") + "</qt>" );
20272 craig 131
        openAfterExportCheckBox->setToolTip( "<qt>" + tr( "Open the exported PDF with the PDF viewer as set in External Tools preferences, when not exporting to a multi-file export destination") + "</qt>" );
132
        okButton->setToolTip( "<qt>" + tr( "The save button will be disabled if you are trying to export PDF/X and the info string is missing from the PDF/X tab") + "</qt>" );
245 Franz 133
        // signals and slots connections
19351 craig 134
        connect( changeButton, SIGNAL( clicked() ), this, SLOT( ChangeFile() ) );
135
        connect( okButton, SIGNAL( clicked() ), this, SLOT( DoExport() ) );
136
        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
11307 cbradney 137
        connect( fileNameLineEdit, SIGNAL( editingFinished() ), this, SLOT( fileNameChanged() ) );
3388 fschmid 138
        connect( Options, SIGNAL(noInfo()), this, SLOT(disableSave()));
139
        connect( Options, SIGNAL(hasInfo()), this, SLOT(enableSave()));
3 paul 140
}
141
 
4259 craig 142
void PDFExportDialog::enableSave()
3388 fschmid 143
{
19351 craig 144
        okButton->setEnabled(true);
3388 fschmid 145
}
146
 
4259 craig 147
void PDFExportDialog::disableSave()
3388 fschmid 148
{
19351 craig 149
        okButton->setEnabled(false);
3388 fschmid 150
}
151
 
4259 craig 152
void PDFExportDialog::DoExport()
248 Franz 153
{
20486 jghali 154
        // Check the page ranges
155
        bool hasInvalidPageRange = false;
156
        QString pageString(this->getPagesString());
157
        std::vector<int> pageNumbers;
158
 
159
        parsePagesString(pageString, &pageNumbers, m_doc->DocPages.count());
160
        for (size_t i = 0; i < pageNumbers.size(); ++i)
161
        {
162
                int pageNumber = pageNumbers[i];
163
                if (pageNumber < 1 || pageNumber > m_doc->DocPages.count())
164
                {
165
                        hasInvalidPageRange = true;
166
                        break;
167
                }
168
        }
169
 
22638 craig 170
        if ((pageNumbers.empty()) || hasInvalidPageRange)
20486 jghali 171
        {
172
                ScMessageBox::warning(this, CommonStrings::trWarning, tr("The range of pages to export is invalid.\nPlease check it and try again."));
173
                return;
174
        }
175
 
176
        // Checking if the path exists
12416 jghali 177
        bool createPath = false;
11639 jghali 178
        QString fn = QDir::fromNativeSeparators(fileNameLineEdit->text());
6280 jghali 179
        QFileInfo fi(fn);
11949 jghali 180
        QString dirPath = QDir::toNativeSeparators(fi.absolutePath());
10553 fschmid 181
        if (!QFile::exists(fi.absolutePath()))
6280 jghali 182
        {
19605 jghali 183
                if (ScMessageBox::question(this, tr( "Save as PDF" ),
6285 jghali 184
                                                                        tr("%1 does not exists and will be created, continue?").arg(dirPath),
19605 jghali 185
                                                                        QMessageBox::Ok | QMessageBox::Cancel,
186
                                                                        QMessageBox::NoButton// GUI default
187
                                                                        QMessageBox::Ok)        // batch default
9422 fschmid 188
                                  == QMessageBox::Cancel)
6282 subik 189
                {
6280 jghali 190
                        return;
6282 subik 191
                }
12416 jghali 192
                createPath = true;
6280 jghali 193
        }
12416 jghali 194
 
6278 subik 195
        // NOTE: Qt4 contains QDir::mkpath()
196
        QDir d(fn);
12416 jghali 197
        if (createPath)
6278 subik 198
        {
12416 jghali 199
                if (!d.mkpath(fi.absolutePath()))
6278 subik 200
                {
19605 jghali 201
                        ScMessageBox::warning(this,
12416 jghali 202
                                                                 CommonStrings::trWarning,
19605 jghali 203
                                                                 tr("Cannot create directory: \n%1").arg(dirPath));
12416 jghali 204
                        return;
6278 subik 205
                }
12416 jghali 206
        }
6278 subik 207
 
5965 fschmid 208
        bool doIt = false;
209
        if (multiFile->isChecked())
210
                doIt = true;
211
        else
212
                doIt = overwrite(this, fn);
20486 jghali 213
        if (!doIt) return;
214
 
215
        int pageIndex = (Options->Pages->currentRow() >= 0) ? Options->Pages->currentRow() : 0;
216
        m_presEffects = Options->EffVal;
217
        m_presEffects[pageIndex].pageViewDuration = Options->PageTime->value();
218
        m_presEffects[pageIndex].pageEffectDuration = Options->EffectTime->value();
219
        m_presEffects[pageIndex].effectType = Options->EffectType->currentIndex();
220
        m_presEffects[pageIndex].Dm = Options->EDirection->currentIndex();
221
        m_presEffects[pageIndex].M = Options->EDirection_2->currentIndex();
222
        m_presEffects[pageIndex].Di = Options->EDirection_2_2->currentIndex();
223
        m_opts.LPISettings[Options->SelLPIcolor].Frequency = Options->LPIfreq->value();
224
        m_opts.LPISettings[Options->SelLPIcolor].Angle = Options->LPIangle->value();
225
        m_opts.LPISettings[Options->SelLPIcolor].SpotFunc = Options->LPIfunc->currentIndex();
226
        accept();
248 Franz 227
}
228
 
4259 craig 229
void PDFExportDialog::ChangeFile()
3 paul 230
{
23060 craig 231
        PrefsContext* dirs = PrefsManager::instance().prefsFile->getContext("dirs");
21729 jghali 232
        QString wdir  = dirs->get("pdf", ScPaths::userDocumentDir());
233
 
234
        QString wfile = QDir::fromNativeSeparators(fileNameLineEdit->text());
235
        if (!wfile.isEmpty())
236
        {
237
                QFileInfo fInfo(wfile);
238
                QString absPath = fInfo.absolutePath(); // Yes, we mean the file directory here
239
                if (QDir(absPath).exists())
240
                        wdir = wfile;
241
        }
242
 
22603 craig 243
        QString d = QFileDialog::getSaveFileName(this, tr("Save As"), wdir, tr("PDF Files (*.pdf);;All Files (*)"), nullptr, QFileDialog::DontConfirmOverwrite);
21729 jghali 244
        if (d.length() > 0)
11949 jghali 245
        {
19351 craig 246
                QString fn(QDir::fromNativeSeparators(d));
10427 cbradney 247
                dirs->set("pdf", fn.left(fn.lastIndexOf("/")));
21728 jghali 248
                fileNameLineEdit->setText(QDir::toNativeSeparators(d));
11949 jghali 249
        }      
3 paul 250
}
2725 cbradney 251
 
4259 craig 252
void PDFExportDialog::fileNameChanged()
2725 cbradney 253
{
7117 jghali 254
        QString fileName = checkFileExtension(fileNameLineEdit->text(),"pdf");
11949 jghali 255
        fileNameLineEdit->setText( QDir::toNativeSeparators(fileName) );
2725 cbradney 256
}
3059 cbradney 257
 
4259 craig 258
void PDFExportDialog::updateDocOptions()
3059 cbradney 259
{
18326 jghali 260
        m_opts.fileName = QDir::fromNativeSeparators(fileNameLineEdit->text());
261
        m_opts.doMultiFile = multiFile->isChecked();
262
        m_opts.openAfterExport = openAfterExportCheckBox->isChecked();
263
        m_opts.Thumbnails = Options->CheckBox1->isChecked();
264
        m_opts.Compress = Options->Compression->isChecked();
265
        m_opts.CompressMethod = (PDFOptions::PDFCompression) Options->CMethod->currentIndex();
266
        m_opts.Quality = Options->CQuality->currentIndex();
267
        m_opts.Resolution = Options->Resolution->value();
20122 jghali 268
        m_opts.FontEmbedding = Options->fontEmbeddingMode();
19828 jghali 269
        m_opts.EmbedList = Options->fontsToEmbed();
20103 avox 270
        m_opts.SubsetList = Options->fontsToSubset();
20122 jghali 271
        m_opts.OutlineList = Options->fontsToOutline();
18326 jghali 272
        m_opts.RecalcPic = Options->DSColor->isChecked();
273
        m_opts.PicRes = Options->ValC->value();
274
        m_opts.embedPDF = Options->EmbedPDF->isChecked();
275
        m_opts.Bookmarks = Options->CheckBM->isChecked();
276
        m_opts.Binding = Options->ComboBind->currentIndex();
277
        m_opts.MirrorH = Options->MirrorH->isChecked();
278
        m_opts.MirrorV = Options->MirrorV->isChecked();
279
        m_opts.doClip = Options->ClipMarg->isChecked();
280
        m_opts.RotateDeg = Options->RotateDeg->currentIndex() * 90;
281
        m_opts.pageRangeSelection = Options->AllPages->isChecked() ? 0 : 1;
282
        m_opts.pageRangeString = Options->PageNr->text();
283
        m_opts.PresentMode = Options->CheckBox10->isChecked();
18394 fschmid 284
        if (m_opts.PresentMode)
285
        {
286
                for (int pg = 0; pg < m_doc->Pages->count(); ++pg)
287
                {
288
                        m_doc->Pages->at(pg)->PresentVals = m_presEffects[pg];
289
                }
290
        }
18326 jghali 291
        m_opts.Articles = Options->Article->isChecked();
292
        m_opts.Encrypt = Options->Encry->isChecked();
293
        m_opts.UseLPI = Options->UseLPI->isChecked();
294
        m_opts.useLayers = Options->useLayers->isChecked();
295
        m_opts.UseSpotColors = !Options->useSpot->isChecked();
296
        m_opts.displayBookmarks = Options->useBookmarks->isChecked();
297
        m_opts.displayFullscreen = Options->useFullScreen->isChecked();
298
        m_opts.displayLayers = Options->useLayers2->isChecked();
299
        m_opts.displayThumbs = Options->useThumbnails->isChecked();
300
        m_opts.hideMenuBar = Options->hideMenuBar->isChecked();
301
        m_opts.hideToolBar = Options->hideToolBar->isChecked();
302
        m_opts.fitWindow = Options->fitWindow->isChecked();
303
        m_opts.useDocBleeds = Options->docBleeds->isChecked();
7076 fschmid 304
        if (!Options->docBleeds->isChecked())
305
        {
19831 craig 306
                m_opts.bleeds.setTop(Options->BleedTop->value() / m_unitRatio);
307
                m_opts.bleeds.setLeft(Options->BleedLeft->value() / m_unitRatio);
308
                m_opts.bleeds.setRight(Options->BleedRight->value() / m_unitRatio);
309
                m_opts.bleeds.setBottom(Options->BleedBottom->value()/ m_unitRatio);
7076 fschmid 310
        }
18326 jghali 311
        m_opts.markLength = Options->markLength->value() / m_unitRatio;
312
        m_opts.markOffset = Options->markOffset->value() / m_unitRatio;
313
        m_opts.cropMarks = Options->cropMarks->isChecked();
314
        m_opts.bleedMarks = Options->bleedMarks->isChecked();
315
        m_opts.registrationMarks = Options->registrationMarks->isChecked();
316
        m_opts.colorMarks = Options->colorMarks->isChecked();
317
        m_opts.docInfoMarks = Options->docInfoMarks->isChecked();
4197 fschmid 318
        int pgl = PDFOptions::SinglePage;
319
        if (Options->singlePage->isChecked())
320
                pgl = PDFOptions::SinglePage;
321
        else if (Options->continuousPages->isChecked())
322
                pgl = PDFOptions::OneColumn;
21491 craig 323
        else if (Options->facingPagesLeft->isChecked())
4197 fschmid 324
                pgl = PDFOptions::TwoColumnLeft;
21491 craig 325
        else if (Options->facingPagesRight->isChecked())
4197 fschmid 326
                pgl = PDFOptions::TwoColumnRight;
18326 jghali 327
        m_opts.PageLayout = pgl;
10553 fschmid 328
        if (Options->actionCombo->currentIndex() != 0)
18326 jghali 329
                m_opts.openAction = Options->actionCombo->currentText();
4197 fschmid 330
        else
18326 jghali 331
                m_opts.openAction = "";
3059 cbradney 332
        if (Options->Encry->isChecked())
333
        {
334
                int Perm = -64;
23548 jghali 335
                if (Options->PDFVersionCombo->version() == PDFVersion::PDF_14)
3059 cbradney 336
                        Perm &= ~0x00240000;
337
                if (Options->PrintSec->isChecked())
338
                        Perm += 4;
339
                if (Options->ModifySec->isChecked())
340
                        Perm += 8;
341
                if (Options->CopySec->isChecked())
342
                        Perm += 16;
343
                if (Options->AddSec->isChecked())
344
                        Perm += 32;
18326 jghali 345
                m_opts.Permissions = Perm;
346
                m_opts.PassOwner = Options->PassOwner->text();
347
                m_opts.PassUser = Options->PassUser->text();
3059 cbradney 348
        }
23548 jghali 349
        m_opts.Version = Options->PDFVersionCombo->version();
10553 fschmid 350
        if (Options->OutCombo->currentIndex() == 0)
3059 cbradney 351
        {
18326 jghali 352
                m_opts.UseRGB = true;
353
                m_opts.isGrayscale = false;
354
                m_opts.UseProfiles = false;
355
                m_opts.UseProfiles2 = false;
3059 cbradney 356
        }
357
        else
358
        {
10553 fschmid 359
                if (Options->OutCombo->currentIndex() == 2)
3059 cbradney 360
                {
18326 jghali 361
                        m_opts.isGrayscale = true;
362
                        m_opts.UseRGB = false;
363
                        m_opts.UseProfiles = false;
364
                        m_opts.UseProfiles2 = false;
3059 cbradney 365
                }
366
                else
367
                {
18326 jghali 368
                        m_opts.isGrayscale = false;
369
                        m_opts.UseRGB = false;
370
                        if (m_doc->HasCMS)
3059 cbradney 371
                        {
18326 jghali 372
                                m_opts.UseProfiles = Options->EmbedProfs->isChecked();
373
                                m_opts.UseProfiles2 = Options->EmbedProfs2->isChecked();
23548 jghali 374
                                if (m_opts.Version != PDFVersion::PDF_X1a)
14043 jghali 375
                                {
18326 jghali 376
                                        m_opts.Intent = Options->IntendS->currentIndex();
377
                                        m_opts.Intent2 = Options->IntendI->currentIndex();
378
                                        m_opts.EmbeddedI = Options->NoEmbedded->isChecked();
379
                                        m_opts.SolidProf = Options->SolidPr->currentText();
380
                                        m_opts.ImageProf = Options->ImageP->currentText();
14043 jghali 381
                                }
18326 jghali 382
                                m_opts.PrintProf = Options->PrintProfC->currentText();
23548 jghali 383
                                if ((m_opts.Version == PDFVersion::PDF_X3) || (m_opts.Version == PDFVersion::PDF_X1a) || (m_opts.Version == PDFVersion::PDF_X4))
3059 cbradney 384
                                {
18326 jghali 385
                                        m_opts.Info = Options->InfoString->text();
386
                                        m_opts.Encrypt = false;
387
                                        m_opts.MirrorH = false;
388
                                        m_opts.MirrorV = false;
13804 jghali 389
                                        //#8306 : PDF/X-3 export ignores rotation setting
18326 jghali 390
                                        //m_opts.RotateDeg = 0;
391
                                        m_opts.PresentMode = false;
3059 cbradney 392
                                }
393
                        }
394
                        else
395
                        {
18326 jghali 396
                                m_opts.UseProfiles = false;
397
                                m_opts.UseProfiles2 = false;
3059 cbradney 398
                        }
399
                }
400
        }
401
}
402
 
23670 craig 403
QString PDFExportDialog::getPagesString()
3062 cbradney 404
{
405
        if (Options->AllPages->isChecked())
406
                return "*";
407
        return Options->PageNr->text();
408
}