Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pdfopts.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 #include "pdfopts.h"
00016 #include "pdfopts.moc"
00017 
00018 #include <qmessagebox.h>
00019 
00020 #include "scconfig.h"
00021 #include "customfdialog.h"
00022 #include "prefsmanager.h"
00023 #include "prefsfile.h"
00024 #include "units.h"
00025 #include "pdfoptions.h"
00026 #include "util.h"
00027 #include "commonstrings.h"
00028 #include "scpaths.h"
00029 
00030 
00031 PDFExportDialog::PDFExportDialog( QWidget* parent, const QString & docFileName,
00032                                                           const QMap<QString, int > & DocFonts,
00033                                                           ScribusView *currView, PDFOptions & pdfOptions,
00034                                                           const QValueList<PDFPresentationData> & Eff,
00035                                                           const ProfilesL & PDFXProfiles, const SCFonts &AllFonts,
00036                                                           double unitRatio, const ProfilesL & printerProfiles)
00037        : QDialog( parent, "pdf", true, 0 ),
00038        doc(currView->Doc),
00039        EffVal(Eff),
00040        Opts(pdfOptions),
00041        docUnitRatio(unitRatio),
00042        cmsDescriptorName(""),
00043        components(3),
00044        appPrinterProfiles(printerProfiles)
00045 {
00046        setCaption( tr( "Save as PDF" ) );
00047        setIcon(loadIcon("AppIcon.png"));
00048        PDFExportLayout = new QVBoxLayout( this );
00049        PDFExportLayout->setSpacing( 5 );
00050        PDFExportLayout->setMargin( 10 );
00051        Name = new QGroupBox( this, "GroupBox" );
00052        Name->setTitle( tr( "O&utput to File:" ) );
00053        Name->setColumnLayout(0, Qt::Vertical );
00054        Name->layout()->setSpacing( 5 );
00055        Name->layout()->setMargin( 10 );
00056        NameLayout = new QGridLayout( Name->layout() );
00057        NameLayout->setAlignment( Qt::AlignTop );
00058        fileNameLineEdit = new QLineEdit( Name, "fileNameLineEdit" );
00059        fileNameLineEdit->setMinimumSize( QSize( 268, 22 ) );
00060        if (!Opts.Datei.isEmpty())
00061               fileNameLineEdit->setText( QDir::convertSeparators(Opts.Datei) );
00062        else
00063        {
00064               QFileInfo fi(docFileName);
00065               if (fi.exists())
00066               {
00067                      QString fileName(fi.dirPath()+"/"+fi.baseName()+".pdf");
00068                      fileNameLineEdit->setText( QDir::convertSeparators(fileName) );
00069               }
00070               else
00071               {
00072                      PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
00073                      QString pdfdir = dirs->get("pdf", fi.dirPath());
00074                      if (pdfdir.right(1) != "/")
00075                             pdfdir += "/";
00076                      QString fileName(pdfdir+fi.baseName()+".pdf");
00077                      fileNameLineEdit->setText( QDir::convertSeparators(fileName) );
00078               }
00079        }
00080        NameLayout->addWidget( fileNameLineEdit, 0, 0 );
00081        FileC = new QToolButton( Name, "FileC" );
00082        FileC->setText( tr( "Cha&nge..." ) );
00083        FileC->setMinimumSize( QSize( 88, 24 ) );
00084        NameLayout->addWidget( FileC, 0, 1 );
00085        multiFile = new QCheckBox( tr( "Output one file for eac&h page" ), Name, "multiFile" );
00086        multiFile->setChecked(Opts.doMultiFile);
00087        NameLayout->addWidget( multiFile, 1, 0 );
00088        PDFExportLayout->addWidget( Name );
00089        Options = new TabPDFOptions( this, pdfOptions, AllFonts, PDFXProfiles, DocFonts,
00090                                                         Eff, currView->Doc->unitIndex(), currView->Doc->pageHeight,
00091                                                         currView->Doc->pageWidth, currView->Doc, true );
00092        PDFExportLayout->addWidget( Options );
00093        Layout7 = new QHBoxLayout;
00094        Layout7->setSpacing( 5 );
00095        Layout7->setMargin( 0 );
00096        QSpacerItem* spacer_2 = new QSpacerItem( 20, 20, QSizePolicy::Expanding, QSizePolicy::Minimum );
00097        Layout7->addItem( spacer_2 );
00098        OK = new QPushButton( tr( "&Save" ), this, "OK" );
00099        OK->setAutoDefault( true );
00100        OK->setDefault( true );
00101        Layout7->addWidget( OK );
00102        Cancel = new QPushButton( CommonStrings::tr_Cancel, this, "Cancel" );
00103        Layout7->addWidget( Cancel );
00104        PDFExportLayout->addLayout( Layout7 );
00105        if ((Opts.Version == PDFOptions::PDFVersion_X3) && (Options->InfoString->text().isEmpty()))
00106               OK->setEnabled(false);
00107        resize(sizeHint());
00108 //     setMaximumSize( sizeHint() );
00109 //tooltips
00110        QToolTip::add( multiFile, "<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>" );
00111        QToolTip::add( OK, "<qt>" + tr( "The save button will be disabled if you are trying to export PDF/X-3 and the info string is missing from the PDF/X-3 tab.") + "</qt>" );
00112        // signals and slots connections
00113        connect( FileC, SIGNAL( clicked() ), this, SLOT( ChangeFile() ) );
00114        connect( OK, SIGNAL( clicked() ), this, SLOT( DoExport() ) );
00115        connect( Cancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
00116        connect( fileNameLineEdit, SIGNAL( lostFocus() ), this, SLOT( fileNameChanged() ) );
00117        connect( fileNameLineEdit, SIGNAL( returnPressed() ), this, SLOT( fileNameChanged() ) );
00118        connect( Options, SIGNAL(noInfo()), this, SLOT(disableSave()));
00119        connect( Options, SIGNAL(hasInfo()), this, SLOT(enableSave()));
00120 }
00121 
00122 void PDFExportDialog::enableSave()
00123 {
00124        OK->setEnabled(true);
00125 }
00126 
00127 void PDFExportDialog::disableSave()
00128 {
00129        OK->setEnabled(false);
00130 }
00131 
00132 void PDFExportDialog::DoExport()
00133 {
00134        QString fn = ScPaths::separatorsToSlashes(fileNameLineEdit->text());
00135        // Checking if the path exists
00136        QFileInfo fi(fn);
00137        QString dirPath = QDir::convertSeparators(fi.dirPath(true));
00138        if (!QFile::exists(fi.dirPath(true)))
00139        {
00140               if (QMessageBox::question(this,
00141                                                                tr( "Save as PDF" ),
00142                                                                tr("%1 does not exists and will be created, continue?").arg(dirPath),
00143                                                                CommonStrings::tr_OK, CommonStrings::tr_Cancel, QString::null, 1, 1)
00144                               != 0)
00145               {
00146                      return;
00147               }
00148        }
00149        // NOTE: Qt4 contains QDir::mkpath()
00150        QDir d(fn);
00151        QStringList dirList = QStringList::split(QDir::separator(), dirPath);
00152        QString existingPath;
00153 #ifndef _WIN32
00154        existingPath = QDir::separator();
00155 #endif
00156        for (QStringList::Iterator it = dirList.begin(); it != dirList.end(); ++it )
00157        {
00158               existingPath += (*it) + QDir::separator();
00159               if (!d.exists(existingPath))
00160               {
00161                      if (!d.mkdir(existingPath))
00162                      {
00163                             QMessageBox::warning(this,
00164                                                                 CommonStrings::trWarning,
00165                                                                 tr("Cannot create directory: \n%1").arg(existingPath),
00166                                                                 CommonStrings::tr_OK);
00167                             return;
00168                      }
00169               }
00170        } // end of Qt4 QDir::mkpath() simulation
00171 
00172        bool doIt = false;
00173        if (multiFile->isChecked())
00174               doIt = true;
00175        else
00176               doIt = overwrite(this, fn);
00177        if (doIt)
00178        {
00179               EffVal = Options->EffVal;
00180               EffVal[Options->PgSel].pageViewDuration = Options->PageTime->value();
00181               EffVal[Options->PgSel].pageEffectDuration = Options->EffectTime->value();
00182               EffVal[Options->PgSel].effectType = Options->EffectType->currentItem();
00183               EffVal[Options->PgSel].Dm = Options->EDirection->currentItem();
00184               EffVal[Options->PgSel].M = Options->EDirection_2->currentItem();
00185               EffVal[Options->PgSel].Di = Options->EDirection_2_2->currentItem();
00186               Opts.LPISettings[Options->SelLPIcolor].Frequency = Options->LPIfreq->value();
00187               Opts.LPISettings[Options->SelLPIcolor].Angle = Options->LPIangle->value();
00188               Opts.LPISettings[Options->SelLPIcolor].SpotFunc = Options->LPIfunc->currentItem();
00189               accept();
00190        }
00191        else
00192               return;
00193 }
00194 
00195 void PDFExportDialog::ChangeFile()
00196 {
00197        QString fn;
00198        PrefsContext* dirs = PrefsManager::instance()->prefsFile->getContext("dirs");
00199        QString wdir = dirs->get("pdf", ".");
00200        CustomFDialog dia(this, wdir, tr("Save as"), tr("PDF Files (*.pdf);;All Files (*)"), fdNone);
00201        if (!fileNameLineEdit->text().isEmpty())
00202               dia.setSelection(fileNameLineEdit->text());
00203        if (dia.exec() == QDialog::Accepted)
00204        {
00205               fn = dia.selectedFile();
00206               dirs->set("pdf", fn.left(fn.findRev("/")));
00207        }
00208        else
00209               return;
00210        fileNameLineEdit->setText( QDir::convertSeparators(fn) );
00211 }
00212 
00213 void PDFExportDialog::fileNameChanged()
00214 {
00215        QString fileName = checkFileExtension(fileNameLineEdit->text(),"pdf");
00216        fileNameLineEdit->setText( QDir::convertSeparators(fileName) );
00217 }
00218 
00219 void PDFExportDialog::updateDocOptions()
00220 {
00221        Opts.Datei = ScPaths::separatorsToSlashes(fileNameLineEdit->text());
00222        Opts.doMultiFile = multiFile->isChecked();
00223        Opts.Thumbnails = Options->CheckBox1->isChecked();
00224        Opts.Compress = Options->Compression->isChecked();
00225        Opts.CompressMethod = Options->CMethod->currentItem();
00226        Opts.Quality = Options->CQuality->currentItem();
00227        Opts.Resolution = Options->Resolution->value();
00228        Opts.EmbedList = Options->FontsToEmbed;
00229        Opts.SubsetList = Options->FontsToOutline;
00230        Opts.RecalcPic = Options->DSColor->isChecked();
00231        Opts.PicRes = Options->ValC->value();
00232        Opts.Bookmarks = Options->CheckBM->isChecked();
00233        Opts.Binding = Options->ComboBind->currentItem();
00234        Opts.MirrorH = Options->MirrorH->isOn();
00235        Opts.MirrorV = Options->MirrorV->isOn();
00236        Opts.doClip = Options->ClipMarg->isChecked();
00237        Opts.RotateDeg = Options->RotateDeg->currentItem() * 90;
00238        Opts.PresentMode = Options->CheckBox10->isChecked();
00239        Opts.PresentVals = EffVal;
00240        Opts.Articles = Options->Article->isChecked();
00241        Opts.Encrypt = Options->Encry->isChecked();
00242        Opts.UseLPI = Options->UseLPI->isChecked();
00243        Opts.useLayers = Options->useLayers->isChecked();
00244        Opts.UseSpotColors = !Options->useSpot->isChecked();
00245        Opts.doOverprint = Options->overprintMode->isChecked();
00246        Opts.displayBookmarks = Options->useBookmarks->isChecked();
00247        Opts.displayFullscreen = Options->useFullScreen->isChecked();
00248        Opts.displayLayers = Options->useLayers2->isChecked();
00249        Opts.displayThumbs = Options->useThumbnails->isChecked();
00250        Opts.hideMenuBar = Options->hideMenuBar->isChecked();
00251        Opts.hideToolBar = Options->hideToolBar->isChecked();
00252        Opts.fitWindow = Options->fitWindow->isChecked();
00253        Opts.useDocBleeds = Options->docBleeds->isChecked();
00254        if (!Options->docBleeds->isChecked())
00255        {
00256               Opts.bleeds.Top = Options->BleedTop->value()/docUnitRatio;
00257               Opts.bleeds.Left = Options->BleedLeft->value()/docUnitRatio;
00258               Opts.bleeds.Right = Options->BleedRight->value()/docUnitRatio;
00259               Opts.bleeds.Bottom = Options->BleedBottom->value()/docUnitRatio;
00260        }
00261        Opts.markOffset = Options->markOffset->value()/docUnitRatio;
00262        Opts.cropMarks = Options->cropMarks->isChecked();
00263        Opts.bleedMarks = Options->bleedMarks->isChecked();
00264        Opts.registrationMarks = Options->registrationMarks->isChecked();
00265        Opts.colorMarks = Options->colorMarks->isChecked();
00266        Opts.docInfoMarks = Options->docInfoMarks->isChecked();
00267        int pgl = PDFOptions::SinglePage;
00268        if (Options->singlePage->isChecked())
00269               pgl = PDFOptions::SinglePage;
00270        else if (Options->continuousPages->isChecked())
00271               pgl = PDFOptions::OneColumn;
00272        else if (Options->doublePageLeft->isChecked())
00273               pgl = PDFOptions::TwoColumnLeft;
00274        else if (Options->doublePageRight->isChecked())
00275               pgl = PDFOptions::TwoColumnRight;
00276        Opts.PageLayout = pgl;
00277        if (Options->actionCombo->currentItem() != 0)
00278               Opts.openAction = Options->actionCombo->currentText();
00279        else
00280               Opts.openAction = "";
00281        if (Options->Encry->isChecked())
00282        {
00283               int Perm = -64;
00284               if (Options->PDFVersionCombo->currentItem() == 1)
00285                      Perm &= ~0x00240000;
00286               if (Options->PrintSec->isChecked())
00287                      Perm += 4;
00288               if (Options->ModifySec->isChecked())
00289                      Perm += 8;
00290               if (Options->CopySec->isChecked())
00291                      Perm += 16;
00292               if (Options->AddSec->isChecked())
00293                      Perm += 32;
00294               Opts.Permissions = Perm;
00295               Opts.PassOwner = Options->PassOwner->text();
00296               Opts.PassUser = Options->PassUser->text();
00297        }
00298        if (Options->PDFVersionCombo->currentItem() == 0)
00299               Opts.Version = PDFOptions::PDFVersion_13;
00300        if (Options->PDFVersionCombo->currentItem() == 1)
00301               Opts.Version = PDFOptions::PDFVersion_14;
00302        if (Options->PDFVersionCombo->currentItem() == 2)
00303               Opts.Version = PDFOptions::PDFVersion_15;
00304        if (Options->PDFVersionCombo->currentItem() == 3)
00305               Opts.Version = PDFOptions::PDFVersion_X3;
00306        if (Options->OutCombo->currentItem() == 0)
00307        {
00308               Opts.UseRGB = true;
00309               Opts.isGrayscale = false;
00310               Opts.UseProfiles = false;
00311               Opts.UseProfiles2 = false;
00312        }
00313        else
00314        {
00315               if (Options->OutCombo->currentItem() == 2)
00316               {
00317                      Opts.isGrayscale = true;
00318                      Opts.UseRGB = false;
00319                      Opts.UseProfiles = false;
00320                      Opts.UseProfiles2 = false;
00321               }
00322               else
00323               {
00324                      Opts.isGrayscale = false;
00325                      Opts.UseRGB = false;
00326                      if (doc->HasCMS)
00327                      {
00328                             Opts.UseProfiles = Options->EmbedProfs->isChecked();
00329                             Opts.UseProfiles2 = Options->EmbedProfs2->isChecked();
00330                             Opts.Intent = Options->IntendS->currentItem();
00331                             Opts.Intent2 = Options->IntendI->currentItem();
00332                             Opts.EmbeddedI = Options->NoEmbedded->isChecked();
00333                             Opts.SolidProf = Options->SolidPr->currentText();
00334                             Opts.ImageProf = Options->ImageP->currentText();
00335                             Opts.PrintProf = Options->PrintProfC->currentText();
00336                             if (Opts.Version == PDFOptions::PDFVersion_X3)
00337                             {
00338                                    cmsHPROFILE hIn;
00339                                    QCString profilePath( appPrinterProfiles[Opts.PrintProf].local8Bit() );
00340                                    hIn = cmsOpenProfileFromFile(profilePath.data(), "r");
00341                                    const char *Descriptor = cmsTakeProductDesc(hIn);
00342                                    cmsDescriptorName = QString(Descriptor);
00343                                    if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigRgbData)
00344                                           components = 3;
00345                                    if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigCmykData)
00346                                           components = 4;
00347                                    if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigCmyData)
00348                                           components = 3;
00349                                    cmsCloseProfile(hIn);
00350                                    Opts.Info = Options->InfoString->text();
00351                                    Opts.Encrypt = false;
00352                                    Opts.MirrorH = false;
00353                                    Opts.MirrorV = false;
00354                                    Opts.RotateDeg = 0;
00355                                    Opts.PresentMode = false;
00356                                    Opts.Encrypt = false;
00357                             }
00358                      }
00359                      else
00360                      {
00361                             Opts.UseProfiles = false;
00362                             Opts.UseProfiles2 = false;
00363                      }
00364               }
00365        }
00366 }
00367 
00368 const QString PDFExportDialog::cmsDescriptor()
00369 {
00370        return cmsDescriptorName;
00371 }
00372 
00373 const int PDFExportDialog::colorSpaceComponents()
00374 {
00375        return components;
00376 }
00377 
00378 const QString PDFExportDialog::getPagesString()
00379 {
00380        if (Options->AllPages->isChecked())
00381               return "*";
00382        return Options->PageNr->text();
00383 }