Subversion Repositories Scribus

Rev

Rev 24185 | Rev 24744 | Go to most recent revision | 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
*/
10863 cbradney 7
#include "printdialog.h"
128 Franz 8
 
9907 fschmid 9
#include <QDir>
10
#include <QMap>
11
#include <QStringList>
12
#include <QByteArray>
13
 
2688 craig 14
#include "scconfig.h"
23838 jghali 15
 
2952 cbradney 16
#include "commonstrings.h"
23838 jghali 17
#include "customfdialog.h"
18
#include "iconmanager.h"
2856 cbradney 19
#include "prefsmanager.h"
3252 craig 20
#include "prefscontext.h"
415 Franz 21
#include "prefsfile.h"
10947 jghali 22
#include "cupsoptions.h"        
23
#if defined(_WIN32)
9907 fschmid 24
        #include <windows.h>
25
        #include <winspool.h>
21770 jghali 26
#elif defined(HAVE_CUPS) // Haiku doesn't have it
10947 jghali 27
        #include <cups/cups.h>
3 paul 28
#endif
23845 jghali 29
#include "sccolor.h"
23838 jghali 30
#include "scpaths.h"
31
#include "scribuscore.h"
32
#include "scribusdoc.h"
33
#include "scrspinbox.h"
23845 jghali 34
#include "ui/createrange.h"
6954 fschmid 35
#include "units.h"
6663 cbradney 36
#include "usertaskstructs.h"
23838 jghali 37
#include "util.h"
38
#include "util_printer.h"
6663 cbradney 39
 
3234 fschmid 40
extern bool previewDinUse;
3 paul 41
 
23845 jghali 42
PrintDialog::PrintDialog( QWidget* parent, ScribusDoc* doc, const PrintOptions& printOptions)
9907 fschmid 43
                : QDialog( parent )
3 paul 44
{
12243 fschmid 45
        setupUi(this);
9907 fschmid 46
        setModal(true);
23565 jghali 47
 
5880 jghali 48
        m_doc = doc;
23565 jghali 49
        m_unit = doc->unitIndex();
50
        m_unitRatio = unitGetRatioFromIndex(doc->unitIndex());
23060 craig 51
        prefs = PrefsManager::instance().prefsFile->getContext("print_options");
23565 jghali 52
        m_devMode = printOptions.devMode;
53
 
23054 craig 54
        setWindowIcon(IconManager::instance().loadIcon("AppIcon.png"));
55
        pageNrButton->setIcon(IconManager::instance().loadIcon("ellipsis.png"));
23565 jghali 56
        markLength->setNewUnit(m_unit);
57
        markLength->setMinimum(1 * m_unitRatio);
58
        markLength->setMaximum(3000 * m_unitRatio);
59
        markOffset->setNewUnit(m_unit);
12243 fschmid 60
        markOffset->setMinimum(0);
23565 jghali 61
        markOffset->setMaximum(3000 * m_unitRatio);
23839 jghali 62
        bleedBottom->setNewUnit(m_unit);
63
        bleedBottom->setMinimum(0);
64
        bleedBottom->setMaximum(3000 * m_unitRatio);
65
        bleedLeft->setNewUnit(m_unit);
66
        bleedLeft->setMinimum(0);
67
        bleedLeft->setMaximum(3000 * m_unitRatio);
68
        bleedRight->setNewUnit(m_unit);
69
        bleedRight->setMinimum(0);
70
        bleedRight->setMaximum(3000 * m_unitRatio);
71
        bleedTop->setNewUnit(m_unit);
72
        bleedTop->setMinimum(0);
73
        bleedTop->setMaximum(3000 * m_unitRatio);
23777 jghali 74
 
23838 jghali 75
        if (ScCore->haveGS() || ScCore->isWinGUI())
76
                previewButton->setEnabled(!previewDinUse);
77
        else
78
        {
79
                previewButton->setVisible(false);
80
                previewButton->setEnabled(false);
81
        }
82
 
10947 jghali 83
        // Fill printer list
84
        QString printerName;
85
        QStringList printerNames = PrinterUtil::getPrinterNames();
86
        int numPrinters = printerNames.count();
20452 jghali 87
        for (int i = 0; i < numPrinters; i++)
10947 jghali 88
        {
89
                printerName = printerNames[i];
90
                PrintDest->addItem(printerName);
91
        }
24049 jghali 92
        PrintDest->addItem( CommonStrings::trFile );
10947 jghali 93
 
23777 jghali 94
        int prnIndex = PrintDest->findText(printOptions.printer);
95
        if (prnIndex < 0)
96
                prnIndex = PrintDest->findText(PrinterUtil::getDefaultPrinterName());
97
        if (prnIndex >= 0)
98
        {
99
                PrintDest->setCurrentIndex(prnIndex);
100
                prefs->set("CurrentPrn", PrintDest->currentText());
101
        }
102
 
10947 jghali 103
        // Fill Separation list
23845 jghali 104
        ColorList usedSpots;
105
        doc->getUsedColors(usedSpots, true);
106
        m_spotColors = usedSpots.keys();
10947 jghali 107
 
23845 jghali 108
        separationsCombo->addItem( tr("All"), "All" );
109
        separationsCombo->addItem( tr("Cyan"), "Cyan" );
110
        separationsCombo->addItem( tr("Magenta"), "Magenta" );
111
        separationsCombo->addItem( tr("Yellow"), "Yellow" );
24616 jghali 112
        separationsCombo->addItem( tr("Black"), "Black" );
23845 jghali 113
        for (int i = 0; i < m_spotColors.count(); ++i)
114
        {
115
                const QString& spotName = m_spotColors.at(i);
116
                separationsCombo->addItem(spotName, spotName);
117
        }
118
 
15407 craig 119
        if (m_doc->pagePositioning() != 0)
10947 jghali 120
        {
23839 jghali 121
                bleedLeftText->setText( tr( "Inside:" ) );
122
                bleedRightText->setText( tr( "Outside:" ) );
10947 jghali 123
        }
124
 
14327 jghali 125
        QString prnDevice = printOptions.printer;
126
        if (prnDevice.isEmpty())
127
                prnDevice = PrintDest->currentText();
24049 jghali 128
        if ((prnDevice == CommonStrings::trFile) || (PrintDest->count() == 1))
248 Franz 129
        {
9907 fschmid 130
                PrintDest->setCurrentIndex(PrintDest->count()-1);
4361 cbradney 131
                prefs->set("CurrentPrn", PrintDest->currentText());
248 Franz 132
                DateiT->setEnabled(true);
23839 jghali 133
                fileNameEdit->setEnabled(true);
14327 jghali 134
                if (!printOptions.filename.isEmpty())
23839 jghali 135
                        fileNameEdit->setText(QDir::toNativeSeparators(printOptions.filename));
136
                selectFileButton->setEnabled(true);
248 Franz 137
        }
4361 cbradney 138
 
248 Franz 139
        setMaximumSize(sizeHint());
260 Franz 140
        PrintDest->setFocus();
23838 jghali 141
 
248 Franz 142
        // signals and slots connections
23839 jghali 143
        connect( okButton, SIGNAL( clicked() ), this, SLOT( okButtonClicked() ) );
144
        connect( cancelButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
145
        connect( PrintDest, SIGNAL(activated(const QString&)), this, SLOT(selectPrinter(const QString&)));
24049 jghali 146
        connect( printLanguages, SIGNAL(activated(const QString&)), this, SLOT(selectPrintLanguage(const QString&)));
23839 jghali 147
        connect( printAllRadio, SIGNAL(toggled(bool)), this, SLOT(selectRange(bool)));
148
        connect( printCurrentRadio, SIGNAL(toggled(bool)), this, SLOT(selectRange(bool)));
6663 cbradney 149
        connect( pageNrButton, SIGNAL(clicked()), this, SLOT(createPageNumberRange()));
23839 jghali 150
        connect( printSepCombo, SIGNAL(activated(int)), this, SLOT(selectSepMode(int)));
151
        connect( selectFileButton, SIGNAL(clicked()), this, SLOT(selectFile()));
152
        connect( altComCheckBox, SIGNAL(clicked()), this, SLOT(selectCommand()));
6690 fschmid 153
        connect( previewButton, SIGNAL(clicked()), this, SLOT(previewButtonClicked()));
10947 jghali 154
        connect( docBleeds, SIGNAL(clicked()), this, SLOT(doDocBleeds()));
23839 jghali 155
        connect( optionsButton, SIGNAL( clicked() ), this, SLOT( selectOptions() ) );
4361 cbradney 156
 
23845 jghali 157
        setStoredValues(printOptions.filename);
4506 cbradney 158
#if defined(_WIN32)
11987 jghali 159
        if (!outputToFile())
17773 jghali 160
        {
23565 jghali 161
                m_devMode = printOptions.devMode;
162
                PrinterUtil::initDeviceSettings(PrintDest->currentText(), m_devMode);
17773 jghali 163
        }
4506 cbradney 164
#endif
11987 jghali 165
 
24049 jghali 166
        printLanguages->setupLanguages(PrintDest->currentText(), outputToFile());
167
        printLanguages->setEnabled(printLanguages->count() > 1);
3 paul 168
}
169
 
10863 cbradney 170
PrintDialog::~PrintDialog()
6663 cbradney 171
{
9907 fschmid 172
#ifdef HAVE_CUPS
23565 jghali 173
        delete m_cupsOptions;
9907 fschmid 174
#endif
23565 jghali 175
        m_cupsOptions = nullptr;
6663 cbradney 176
}
177
 
23839 jghali 178
void PrintDialog::selectOptions()
3 paul 179
{
4361 cbradney 180
#ifdef HAVE_CUPS
23565 jghali 181
        if (!m_cupsOptions)
182
                m_cupsOptions = new CupsOptions(this, PrintDest->currentText());
183
        if (!m_cupsOptions->exec())
161 Franz 184
        {
23565 jghali 185
                delete m_cupsOptions; // if options was canceled delete dia 
186
                m_cupsOptions = nullptr;    // so that getoptions() in the okButtonClicked() will get
21017 craig 187
                             // the default values from the last successful run
6119 tsoots 188
        }
189
 
190
#elif defined(_WIN32)
191
        bool done;
22517 craig 192
        Qt::HANDLE handle = nullptr;
23565 jghali 193
        DEVMODEW* devMode = (DEVMODEW*) m_devMode.data();
6119 tsoots 194
        // Retrieve the selected printer
10304 jghali 195
        QString printerS = PrintDest->currentText();
6119 tsoots 196
        // Get a printer handle
22517 craig 197
        done = OpenPrinterW((LPWSTR) printerS.utf16(), &handle, nullptr);
20452 jghali 198
        if (!done)
6119 tsoots 199
                return;
200
        // Merge stored settings, prompt user and return user settings
23565 jghali 201
        DocumentPropertiesW((HWND) winId(), handle, (LPWSTR) printerS.utf16(), (DEVMODEW*) m_devMode.data(), (DEVMODEW*) m_devMode.data(),
6119 tsoots 202
                                                DM_IN_BUFFER | DM_IN_PROMPT | DM_OUT_BUFFER);
203
        // Free the printer handle
20452 jghali 204
        ClosePrinter(handle);
20467 jghali 205
 
206
        // With some drivers, one can set the number of copies in print option dialog
207
        // Set it back to Copies widget in this case
208
        devMode->dmCopies = qMax(1, qMin((int) devMode->dmCopies, Copies->maximum()));
209
        if (devMode->dmCopies != numCopies())
210
        {
211
                bool sigBlocked = Copies->blockSignals(true);
212
                Copies->setValue(devMode->dmCopies);
24049 jghali 213
                Copies->blockSignals(sigBlocked);
20467 jghali 214
        }
6119 tsoots 215
#endif
216
}
217
 
23565 jghali 218
QString PrintDialog::getOptions()
6119 tsoots 219
{
220
#ifdef HAVE_CUPS
23565 jghali 221
        QString printerOptions;
222
        if (!m_cupsOptions)
223
                m_cupsOptions = new CupsOptions(this, PrintDest->currentText());
224
 
225
        auto printOptions = m_cupsOptions->options();
226
        for (auto it = printOptions.begin(); it != printOptions.end(); ++it)
6119 tsoots 227
        {
23565 jghali 228
                const QString& optionKey = it.key();
229
                const CupsOptions::OptionData& printOption = it.value();
230
                if (m_cupsOptions->useDefaultValue(optionKey))
16828 jghali 231
                        continue;
232
 
23565 jghali 233
                if (printOption.keyword == "mirror")
234
                        printerOptions += " -o mirror";
235
                else if (printOption.keyword == "page-set")
161 Franz 236
                {
23565 jghali 237
                        int pageSetIndex = m_cupsOptions->optionIndex(optionKey);
238
                        if (pageSetIndex > 0)
239
                        {
240
                                printerOptions += " -o " + printOption.keyword + "=";
241
                                printerOptions += (pageSetIndex == 1) ? "even" : "odd";
242
                        }
16828 jghali 243
                }
23565 jghali 244
                else if (printOption.keyword == "number-up")
16828 jghali 245
                {
23565 jghali 246
                        printerOptions += " -o " + printOption.keyword + "=";
247
                        switch (m_cupsOptions->optionIndex(optionKey))
3 paul 248
                        {
23565 jghali 249
                                case 0:
250
                                        printerOptions += "1";
251
                                        break;
16828 jghali 252
                                case 1:
23565 jghali 253
                                        printerOptions += "2";
16828 jghali 254
                                        break;
255
                                case 2:
23565 jghali 256
                                        printerOptions += "4";
16828 jghali 257
                                        break;
258
                                case 3:
23565 jghali 259
                                        printerOptions += "6";
16828 jghali 260
                                        break;
261
                                case 4:
23565 jghali 262
                                        printerOptions += "9";
16828 jghali 263
                                        break;
264
                                case 5:
23565 jghali 265
                                        printerOptions += "16";
16828 jghali 266
                                        break;
161 Franz 267
                        }
248 Franz 268
                }
23565 jghali 269
                else if (printOption.keyword == "orientation")
270
                        printerOptions += " -o landscape";
16828 jghali 271
                else
272
                {
23565 jghali 273
                        printerOptions += " -o " + printOption.keyword + "=" + m_cupsOptions->optionText(optionKey);
16828 jghali 274
                }
161 Franz 275
        }
23565 jghali 276
        return printerOptions;
23737 jghali 277
#else
278
        return QString();
4361 cbradney 279
#endif
3 paul 280
}
281
 
23839 jghali 282
void PrintDialog::selectCommand()
3 paul 283
{
23839 jghali 284
        bool test = altComCheckBox->isChecked();
223 Franz 285
        OthText->setEnabled(test);
23839 jghali 286
        altCommand->setEnabled(test);
223 Franz 287
        PrintDest->setEnabled(!test);
23839 jghali 288
        if (altComCheckBox->isChecked())
161 Franz 289
        {
248 Franz 290
                DateiT->setEnabled(false);
23839 jghali 291
                fileNameEdit->setEnabled(false);
292
                selectFileButton->setEnabled(false);
293
                optionsButton->setEnabled(false);
248 Franz 294
        }
3 paul 295
        else
161 Franz 296
        {
23839 jghali 297
                selectPrinter(PrintDest->currentText());
24049 jghali 298
                if (PrintDest->currentText() != CommonStrings::trFile)
23839 jghali 299
                        optionsButton->setEnabled(true);
161 Franz 300
        }
3 paul 301
}
302
 
23839 jghali 303
void PrintDialog::selectPrinter(const QString& prn)
3 paul 304
{
24049 jghali 305
        bool toFile = prn == CommonStrings::trFile;
10947 jghali 306
        DateiT->setEnabled(toFile);
23839 jghali 307
        fileNameEdit->setEnabled(toFile);
308
        selectFileButton->setEnabled(toFile);
309
        optionsButton->setEnabled(!toFile);
4506 cbradney 310
#if defined(_WIN32)
11987 jghali 311
        if (!toFile)
10947 jghali 312
        {
23565 jghali 313
                if (!PrinterUtil::getDefaultSettings(PrintDest->currentText(), m_devMode))
18194 fschmid 314
                        qWarning( tr("Failed to retrieve printer settings").toLatin1().data() );
10947 jghali 315
        }
4506 cbradney 316
#endif
23839 jghali 317
        if (toFile && fileNameEdit->text().isEmpty())
14327 jghali 318
        {
22832 craig 319
                QFileInfo fi(m_doc->documentFileName());
24049 jghali 320
                QString fileExt = (printLanguage() == PrintLanguage::PDF) ? ".pdf" : ".ps";
14327 jghali 321
                if (fi.isRelative()) // if (m_doc->DocName.startsWith( tr("Document")))
24049 jghali 322
                        fileNameEdit->setText( QDir::toNativeSeparators(QDir::currentPath() + "/" + m_doc->documentFileName() + fileExt) );
14327 jghali 323
                else
17720 jghali 324
                {
325
                        QString completeBaseName = fi.completeBaseName();
326
                        if (completeBaseName.endsWith(".sla", Qt::CaseInsensitive))
327
                                if (completeBaseName.length() > 4) completeBaseName.chop(4);
328
                        if (completeBaseName.endsWith(".gz", Qt::CaseInsensitive))
329
                                if (completeBaseName.length() > 3) completeBaseName.chop(3);
24049 jghali 330
                        fileNameEdit->setText( QDir::toNativeSeparators(fi.path() + "/" + completeBaseName + fileExt) );
17720 jghali 331
                }
14327 jghali 332
        }
10947 jghali 333
 
334
        // Get page description language supported by the selected printer
24049 jghali 335
        printLanguages->setupLanguages(prn, toFile);
336
        printLanguages->setEnabled(printLanguages->count() > 1);
10947 jghali 337
 
338
        prefs->set("CurrentPrn", prn);
24049 jghali 339
        prefs->set("CurrentPrnEngine", (int) printLanguages->currentLanguage());
340
 
341
        PrintLanguage prnLanguage = printLanguage();
342
 
343
        bool psSupported = false;
344
        psSupported |= (prnLanguage == PrintLanguage::PostScript1);
345
        psSupported |= (prnLanguage == PrintLanguage::PostScript2);
346
        psSupported |= (prnLanguage == PrintLanguage::PostScript3);
347
 
348
        printSepCombo->setEnabled(psSupported);
349
        separationsCombo->setEnabled(psSupported && (printSepCombo->currentIndex() == 1));
350
        if (!psSupported)
4361 cbradney 351
        {
24049 jghali 352
                setCurrentComboItem(printSepCombo, tr("Print Normal"));
353
                setCurrentComboItem(separationsCombo, tr("All"));
4361 cbradney 354
        }
24049 jghali 355
 
356
        bool pdfMarksSupported = (prnLanguage == PrintLanguage::PDF);
357
        pdfMarksSupported |= (prnLanguage == PrintLanguage::PostScript1);
358
        pdfMarksSupported |= (prnLanguage == PrintLanguage::PostScript2);
359
        pdfMarksSupported |= (prnLanguage == PrintLanguage::PostScript3);
360
        usePDFMarks->setEnabled(pdfMarksSupported);
361
 
362
        if (outputToFile())
4361 cbradney 363
        {
24049 jghali 364
                QString newExt = "prn";
365
                if (prnLanguage == PrintLanguage::PDF)
366
                        newExt = "pdf";
367
                if (psSupported)
368
                        newExt = "ps";
369
                QString outputFileName = fileNameEdit->text();
370
                if (!outputFileName.isEmpty())
371
                {
372
                        QFileInfo fileInfo(outputFileName);
373
                        QString currentExt = fileInfo.suffix();
374
                        if (!currentExt.isEmpty())
375
                        {
376
                                int lastIndex = outputFileName.lastIndexOf(currentExt);
377
                                outputFileName.replace(lastIndex, currentExt.length(), newExt);
378
                                fileNameEdit->setText(outputFileName);
379
                        }
380
                }
381
        }
382
}
383
 
384
void PrintDialog::selectPrintLanguage(const QString& prnLanguage)
385
{
386
        prefs->set("CurrentPrnEngine", (int) printLanguages->currentLanguage());
387
 
388
        bool psSupported = false;
389
        psSupported |= (prnLanguage == CommonStrings::trPostScript1);
390
        psSupported |= (prnLanguage == CommonStrings::trPostScript2);
391
        psSupported |= (prnLanguage == CommonStrings::trPostScript3);
392
 
393
        printSepCombo->setEnabled(psSupported);
394
        separationsCombo->setEnabled(psSupported && (printSepCombo->currentIndex() == 1));
395
        if (!psSupported)
396
        {
23839 jghali 397
                setCurrentComboItem(printSepCombo, tr("Print Normal"));
398
                setCurrentComboItem(separationsCombo, tr("All"));
4361 cbradney 399
        }
24049 jghali 400
 
401
        bool pdfMarksSupported = (prnLanguage == CommonStrings::trPDF);
402
        pdfMarksSupported |= (prnLanguage == CommonStrings::trPostScript1);
403
        pdfMarksSupported |= (prnLanguage == CommonStrings::trPostScript2);
404
        pdfMarksSupported |= (prnLanguage == CommonStrings::trPostScript3);
405
        usePDFMarks->setEnabled(pdfMarksSupported);
406
 
407
        if (outputToFile())
408
        {
409
                QString newExt = "prn";
410
                if (prnLanguage == CommonStrings::trPDF)
411
                        newExt = "pdf";
412
                if (psSupported)
413
                        newExt = "ps";
414
                QString outputFileName = fileNameEdit->text();
415
                if (!outputFileName.isEmpty())
416
                {
417
                        QFileInfo fileInfo(outputFileName);
418
                        QString currentExt = fileInfo.suffix();
419
                        if (!currentExt.isEmpty())
420
                        {
421
                                int lastIndex = outputFileName.lastIndexOf(currentExt);
422
                                outputFileName.replace(lastIndex, currentExt.length(), newExt);
423
                                fileNameEdit->setText(outputFileName);
424
                        }
425
                }
426
        }
3 paul 427
}
428
 
23839 jghali 429
void PrintDialog::selectRange(bool e)
3 paul 430
{
6663 cbradney 431
        pageNr->setEnabled(!e);
432
        pageNrButton->setEnabled(!e);
3 paul 433
}
434
 
23839 jghali 435
void PrintDialog::selectSepMode(int e)
3 paul 436
{
23839 jghali 437
        separationsCombo->setEnabled(e != 0);
3 paul 438
}
439
 
23839 jghali 440
void PrintDialog::selectFile()
3 paul 441
{
23060 craig 442
        PrefsContext* dirs = PrefsManager::instance().prefsFile->getContext("dirs");
24049 jghali 443
        QString wdir = dirs->get("printdir", ScPaths::userDocumentDir());
444
 
445
        PrintLanguage prnLanguage = printLanguage();
446
        QString fileFilter = (prnLanguage == PrintLanguage::PDF) ? tr("PDF Files (*.pdf);;All Files (*)") : tr("PostScript Files (*.ps);;All Files (*)");
447
        CustomFDialog dia(this, wdir, tr("Save As"), fileFilter, fdNone | fdHidePreviewCheckBox);
23839 jghali 448
        if (!fileNameEdit->text().isEmpty())
449
                dia.setSelection(fileNameEdit->text());
3 paul 450
        if (dia.exec() == QDialog::Accepted)
415 Franz 451
        {
452
                QString selectedFile = dia.selectedFile();
10863 cbradney 453
                dirs->set("printdir", selectedFile.left(selectedFile.lastIndexOf("/")));
23839 jghali 454
                fileNameEdit->setText( QDir::toNativeSeparators(selectedFile) );
415 Franz 455
        }
3 paul 456
}
457
 
10863 cbradney 458
void PrintDialog::setMinMax(int min, int max, int cur)
3 paul 459
{
329 Franz 460
        QString tmp, tmp2;
24049 jghali 461
        printCurrentRadio->setText( tr( "Print Current Pa&ge" ) + " (" + tmp.setNum(cur) + ")");
462
        pageNr->setText(tmp.setNum(min) + "-" + tmp2.setNum(max));
3 paul 463
}
464
 
10863 cbradney 465
void PrintDialog::storeValues()
451 tsoots 466
{
6119 tsoots 467
        getOptions(); // options were not set get last options with this hack
7104 fschmid 468
 
469
        m_doc->Print_Options.printer = PrintDest->currentText();
23839 jghali 470
        m_doc->Print_Options.filename = QDir::fromNativeSeparators(fileNameEdit->text());
11987 jghali 471
        m_doc->Print_Options.toFile = outputToFile();
7104 fschmid 472
        m_doc->Print_Options.copies = numCopies();
473
        m_doc->Print_Options.outputSeparations = outputSeparations();
474
        m_doc->Print_Options.separationName = separationName();
475
        m_doc->Print_Options.allSeparations = allSeparations();
476
        if (m_doc->Print_Options.outputSeparations)
477
                m_doc->Print_Options.useSpotColors = true;
478
        else
479
                m_doc->Print_Options.useSpotColors = doSpot();
480
        m_doc->Print_Options.useColor = color();
10947 jghali 481
        m_doc->Print_Options.mirrorH  = mirrorHorizontal();
482
        m_doc->Print_Options.mirrorV  = mirrorVertical();
483
        m_doc->Print_Options.doClip   = doClip();
484
        m_doc->Print_Options.doGCR    = doGCR();
24049 jghali 485
        m_doc->Print_Options.prnLanguage = printLanguage();
7104 fschmid 486
        m_doc->Print_Options.setDevParam = doDev();
12247 jghali 487
        m_doc->Print_Options.useDocBleeds  = docBleeds->isChecked();
23839 jghali 488
        m_doc->Print_Options.bleeds.setTop(bleedTop->value() / m_doc->unitRatio());
489
        m_doc->Print_Options.bleeds.setLeft(bleedLeft->value() / m_doc->unitRatio());
490
        m_doc->Print_Options.bleeds.setRight(bleedRight->value() / m_doc->unitRatio());
491
        m_doc->Print_Options.bleeds.setBottom(bleedBottom->value() / m_doc->unitRatio());
17401 jghali 492
        m_doc->Print_Options.markLength = markLength->value() / m_doc->unitRatio();
7104 fschmid 493
        m_doc->Print_Options.markOffset = markOffset->value() / m_doc->unitRatio();
10947 jghali 494
        m_doc->Print_Options.cropMarks  = cropMarks->isChecked();
7104 fschmid 495
        m_doc->Print_Options.bleedMarks = bleedMarks->isChecked();
496
        m_doc->Print_Options.registrationMarks = registrationMarks->isChecked();
497
        m_doc->Print_Options.colorMarks = colorMarks->isChecked();
12589 fschmid 498
        m_doc->Print_Options.includePDFMarks = usePDFMarks->isChecked();
23839 jghali 499
        if (altComCheckBox->isChecked())
7104 fschmid 500
        {
23839 jghali 501
                m_doc->Print_Options.printerCommand = altCommand->text();
7104 fschmid 502
                m_doc->Print_Options.useAltPrintCommand = true;
503
        }
504
        else
505
                m_doc->Print_Options.useAltPrintCommand = false;
23565 jghali 506
        m_doc->Print_Options.printerOptions = getOptions();
507
        m_doc->Print_Options.devMode = m_devMode;
6690 fschmid 508
}
509
 
10863 cbradney 510
void PrintDialog::okButtonClicked()
6690 fschmid 511
{
512
        storeValues();
3234 fschmid 513
        accept();
451 tsoots 514
}
515
 
10863 cbradney 516
void PrintDialog::previewButtonClicked()
6690 fschmid 517
{
518
        storeValues();
519
        emit doPreview();
520
}
521
 
23845 jghali 522
void PrintDialog::setStoredValues(const QString& fileName)
12253 jghali 523
{
7104 fschmid 524
        if (m_doc->Print_Options.firstUse)
23845 jghali 525
                PrinterUtil::getDefaultPrintOptions(m_doc->Print_Options, m_doc->bleedsVal());
12253 jghali 526
 
527
        int selectedDest = PrintDest->findText(m_doc->Print_Options.printer);
528
        if ((selectedDest > -1) && (selectedDest < PrintDest->count()))
451 tsoots 529
        {
12253 jghali 530
                PrintDest->setCurrentIndex(selectedDest);
531
                prefs->set("CurrentPrn", PrintDest->currentText());
24049 jghali 532
                if (PrintDest->currentText() == CommonStrings::trFile)
23839 jghali 533
                        fileNameEdit->setText(fileName);
534
                selectPrinter(PrintDest->currentText());
451 tsoots 535
        }
23839 jghali 536
        altComCheckBox->setChecked(m_doc->Print_Options.useAltPrintCommand);
537
        if (altComCheckBox->isChecked())
12253 jghali 538
        {
23839 jghali 539
                selectCommand();
540
                altCommand->setText(m_doc->Print_Options.printerCommand);
12253 jghali 541
        }
23839 jghali 542
        printAllRadio->setChecked(prefs->getBool("PrintAll", true));
543
        printCurrentRadio->setChecked(prefs->getBool("CurrentPage", false));
544
        bool printRangeChecked = prefs->getBool("PrintRange", false);
545
        printRangeRadio->setChecked(printRangeChecked);
12253 jghali 546
        pageNr->setEnabled(printRangeChecked);
547
        pageNr->setText(prefs->get("PageNr", "1-1"));
548
        Copies->setValue(1);
23839 jghali 549
        printSepCombo->setCurrentIndex(m_doc->Print_Options.outputSeparations);
12253 jghali 550
        colorType->setCurrentIndex(m_doc->Print_Options.useColor ? 0 : 1);
23845 jghali 551
        int selectedSep = separationsCombo->findData(m_doc->Print_Options.separationName);
552
        separationsCombo->setCurrentIndex((selectedSep >= 0) ? selectedSep : 0);
23839 jghali 553
        if (printSepCombo->currentIndex() == 1)
554
                separationsCombo->setEnabled(true);
24049 jghali 555
        setPrintLanguage(m_doc->Print_Options.prnLanguage);
23839 jghali 556
        mirrorHor->setChecked(m_doc->Print_Options.mirrorH);
557
        mirrorVert->setChecked(m_doc->Print_Options.mirrorV);
558
        setMediaSize->setChecked(m_doc->Print_Options.setDevParam);
559
        applyGCR->setChecked(m_doc->Print_Options.doGCR);
560
        clipMargins->setChecked(m_doc->Print_Options.doClip);
561
        convertSpots->setChecked(!m_doc->Print_Options.useSpotColors);
12253 jghali 562
        docBleeds->setChecked(m_doc->Print_Options.useDocBleeds);
563
        if (docBleeds->isChecked())
564
        {
23839 jghali 565
                bleedTop->setValue(m_doc->bleeds()->top() * m_unitRatio);
566
                bleedBottom->setValue(m_doc->bleeds()->bottom() * m_unitRatio);
567
                bleedRight->setValue(m_doc->bleeds()->right() * m_unitRatio);
568
                bleedLeft->setValue(m_doc->bleeds()->left() * m_unitRatio);
12253 jghali 569
        }
7104 fschmid 570
        else
6688 fschmid 571
        {
23839 jghali 572
                bleedTop->setValue(m_doc->Print_Options.bleeds.top() * m_unitRatio);
573
                bleedBottom->setValue(m_doc->Print_Options.bleeds.bottom() * m_unitRatio);
574
                bleedRight->setValue(m_doc->Print_Options.bleeds.right() * m_unitRatio);
575
                bleedLeft->setValue(m_doc->Print_Options.bleeds.left() * m_unitRatio);
6688 fschmid 576
        }
23839 jghali 577
        bleedTop->setEnabled(!docBleeds->isChecked());
578
        bleedBottom->setEnabled(!docBleeds->isChecked());
579
        bleedRight->setEnabled(!docBleeds->isChecked());
580
        bleedLeft->setEnabled(!docBleeds->isChecked());
23565 jghali 581
        markLength->setValue(m_doc->Print_Options.markLength * m_unitRatio);
582
        markOffset->setValue(m_doc->Print_Options.markOffset * m_unitRatio);
12253 jghali 583
        cropMarks->setChecked(m_doc->Print_Options.cropMarks);
584
        bleedMarks->setChecked(m_doc->Print_Options.bleedMarks);
585
        registrationMarks->setChecked(m_doc->Print_Options.registrationMarks);
586
        colorMarks->setChecked(m_doc->Print_Options.colorMarks);
12589 fschmid 587
        usePDFMarks->setChecked(m_doc->Print_Options.includePDFMarks);
451 tsoots 588
}
589
 
10863 cbradney 590
QString PrintDialog::printerName()
3 paul 591
{
11987 jghali 592
        return PrintDest->currentText();
3 paul 593
}
594
 
10863 cbradney 595
QString PrintDialog::outputFileName()
3 paul 596
{
23839 jghali 597
        return QDir::fromNativeSeparators(fileNameEdit->text());
3 paul 598
}
599
 
10863 cbradney 600
bool PrintDialog::outputToFile()
3 paul 601
{
24049 jghali 602
        return (PrintDest->currentText() == CommonStrings::trFile);
3 paul 603
}
604
 
10863 cbradney 605
int PrintDialog::numCopies()
3 paul 606
{
607
        return Copies->value();
608
}
609
 
10863 cbradney 610
bool PrintDialog::outputSeparations()
3 paul 611
{
23839 jghali 612
        return separationsCombo->isEnabled();
3 paul 613
}
614
 
10863 cbradney 615
QString PrintDialog::separationName()
3 paul 616
{
23839 jghali 617
        if (separationsCombo->currentIndex() == 0)
22557 jghali 618
                return QString("All");
23839 jghali 619
        if (separationsCombo->currentIndex() == 1)
22557 jghali 620
                return QString("Cyan");
23839 jghali 621
        if (separationsCombo->currentIndex() == 2)
22557 jghali 622
                return QString("Magenta");
23839 jghali 623
        if (separationsCombo->currentIndex() == 3)
22557 jghali 624
                return QString("Yellow");
23839 jghali 625
        if (separationsCombo->currentIndex() == 4)
22557 jghali 626
                return QString("Black");
23839 jghali 627
        return separationsCombo->currentText();
3 paul 628
}
629
 
10863 cbradney 630
QStringList PrintDialog::allSeparations()
3068 fschmid 631
{
632
        QStringList ret;
24185 craig 633
        for (int i = 1; i < separationsCombo->count(); ++i)
634
                ret.append(separationsCombo->itemText(i));
3068 fschmid 635
        return ret;
636
}
3234 fschmid 637
 
10863 cbradney 638
bool PrintDialog::color()
3 paul 639
{
22601 craig 640
        return colorType->currentIndex() == 0;
3 paul 641
}
3234 fschmid 642
 
10863 cbradney 643
bool PrintDialog::mirrorHorizontal()
3234 fschmid 644
{
23839 jghali 645
        return mirrorHor->isChecked();
3234 fschmid 646
}
647
 
10863 cbradney 648
bool PrintDialog::mirrorVertical()
3234 fschmid 649
{
23839 jghali 650
        return mirrorVert->isChecked();
3234 fschmid 651
}
652
 
10863 cbradney 653
bool PrintDialog::doGCR()
3234 fschmid 654
{
23839 jghali 655
        return applyGCR->isChecked();
3234 fschmid 656
}
657
 
10863 cbradney 658
bool PrintDialog::doClip()
4649 fschmid 659
{
23839 jghali 660
        return clipMargins->isChecked();
4649 fschmid 661
}
662
 
24049 jghali 663
PrintLanguage PrintDialog::printLanguage()
3234 fschmid 664
{
24049 jghali 665
        return printLanguages->currentLanguage();
3234 fschmid 666
}
667
 
10863 cbradney 668
bool PrintDialog::doDev()
3234 fschmid 669
{
23839 jghali 670
        return setMediaSize->isChecked();
3234 fschmid 671
}
672
 
10863 cbradney 673
bool PrintDialog::doSpot()
3234 fschmid 674
{
23839 jghali 675
        return !convertSpots->isChecked();
3234 fschmid 676
}
677
 
12243 fschmid 678
bool PrintDialog::doPrintAll()
679
{
23839 jghali 680
        return printAllRadio->isChecked();
12243 fschmid 681
}
682
 
683
bool PrintDialog::doPrintCurrentPage()
684
{
23839 jghali 685
        return printCurrentRadio->isChecked();
12243 fschmid 686
}
687
 
688
QString PrintDialog::getPageString()
689
{
690
        return pageNr->text();
691
}
692
 
10863 cbradney 693
void PrintDialog::doDocBleeds()
6954 fschmid 694
{
695
        if (docBleeds->isChecked())
696
        {
23839 jghali 697
                prefs->set("BleedTop", bleedTop->value() / m_unitRatio);
698
                prefs->set("BleedBottom", bleedBottom->value() / m_unitRatio);
699
                prefs->set("BleedRight", bleedRight->value() / m_unitRatio);
700
                prefs->set("BleedLeft", bleedLeft->value() / m_unitRatio);
701
                bleedTop->setValue(m_doc->bleeds()->top() * m_unitRatio);
702
                bleedBottom->setValue(m_doc->bleeds()->bottom() * m_unitRatio);
703
                bleedRight->setValue(m_doc->bleeds()->right() * m_unitRatio);
704
                bleedLeft->setValue(m_doc->bleeds()->left() * m_unitRatio);
6954 fschmid 705
        }
706
        else
707
        {
23839 jghali 708
                bleedTop->setValue(prefs->getDouble("BleedTop",0.0) * m_unitRatio);
709
                bleedBottom->setValue(prefs->getDouble("BleedBottom",0.0) * m_unitRatio);
710
                bleedRight->setValue(prefs->getDouble("BleedRight",0.0) * m_unitRatio);
711
                bleedLeft->setValue(prefs->getDouble("BleedLeft",0.0) * m_unitRatio);
6954 fschmid 712
        }
12247 jghali 713
        bool isChecked = docBleeds->isChecked();
714
        prefs->set("UseDocBleeds", isChecked);
23839 jghali 715
        bleedTop->setEnabled(!isChecked);
716
        bleedBottom->setEnabled(!isChecked);
717
        bleedRight->setEnabled(!isChecked);
718
        bleedLeft->setEnabled(!isChecked);
6954 fschmid 719
}
6663 cbradney 720
 
10863 cbradney 721
void PrintDialog::createPageNumberRange( )
6119 tsoots 722
{
22601 craig 723
        if (m_doc!=nullptr)
6663 cbradney 724
        {
6775 cbradney 725
                CreateRange cr(pageNr->text(), m_doc->DocPages.count(), this);
6663 cbradney 726
                if (cr.exec())
727
                {
728
                        CreateRangeData crData;
729
                        cr.getCreateRangeData(crData);
730
                        pageNr->setText(crData.pageRange);
731
                        return;
732
                }
733
        }
23049 craig 734
        pageNr->setText(QString());
6119 tsoots 735
}
10947 jghali 736
 
24049 jghali 737
void PrintDialog::setPrintLanguage(PrintLanguage prnLanguage)
10947 jghali 738
{
24049 jghali 739
        int itemIndex = printLanguages->findLanguage(prnLanguage);
10947 jghali 740
        if (itemIndex >= 0)
24049 jghali 741
                printLanguages->setCurrentIndex(itemIndex);
742
        else if (printLanguages->count() > 0)
10947 jghali 743
        {
24049 jghali 744
                itemIndex = printLanguages->findLanguage(PrintLanguage::PostScript3);
10947 jghali 745
                if (itemIndex >= 0)
24049 jghali 746
                        printLanguages->setCurrentIndex(itemIndex);
10947 jghali 747
                else
24049 jghali 748
                        printLanguages->setCurrentIndex(printLanguages->count() - 1);
10947 jghali 749
        }
10950 subik 750
}