Rev 556 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
283 | Franz | 1 | #include "export.h" |
2 | #include "dialog.h" |
||
3 | #include "export.moc" |
||
4 | #include <qpixmap.h> |
||
5 | #include <qstring.h> |
||
6 | #include <qdir.h> |
||
7 | #include <qcursor.h> |
||
8 | |||
9 | |||
10 | QString Name() |
||
11 | { |
||
308 | Franz | 12 | return QObject::tr("Save as &Image..."); |
283 | Franz | 13 | } |
14 | |||
15 | |||
16 | int Type() |
||
17 | { |
||
18 | return 3; |
||
19 | } |
||
20 | |||
585 | fschmid | 21 | int ID() |
22 | { |
||
23 | return 4; |
||
24 | } |
||
283 | Franz | 25 | |
585 | fschmid | 26 | |
283 | Franz | 27 | void Run(QWidget *d, ScribusApp *plug) |
28 | { |
||
29 | bool res; |
||
30 | ExportBitmap *ex = new ExportBitmap(plug); |
||
31 | ExportForm *dia = new ExportForm(d, ex->pageSize, ex->quality, ex->bitmapType); |
||
287 | Franz | 32 | |
283 | Franz | 33 | // interval widgets handling |
359 | Franz | 34 | QString tmp; |
35 | dia->RangeVal->setText(tmp.setNum(plug->doc->ActPage->PageNr+1)); |
||
283 | Franz | 36 | // main "loop" |
37 | if (dia->exec()==QDialog::Accepted) |
||
38 | { |
||
39 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||
359 | Franz | 40 | std::vector<int> pageNs; |
549 | subik | 41 | ex->pageSize = dia->DPIBox->value(); |
42 | ex->enlargement = dia->EnlargementBox->value(); |
||
283 | Franz | 43 | ex->quality = dia->QualityBox->value(); |
44 | ex->exportDir = dia->OutputDirectory->text(); |
||
45 | ex->bitmapType = dia->bitmapType; |
||
287 | Franz | 46 | plug->FProg->reset(); |
359 | Franz | 47 | if (dia->OnePageRadio->isChecked()) |
48 | res = ex->exportActual(); |
||
49 | else |
||
283 | Franz | 50 | { |
359 | Franz | 51 | if (dia->AllPagesRadio->isChecked()) |
52 | plug->parsePagesString("*", &pageNs, plug->doc->PageC); |
||
53 | else |
||
54 | plug->parsePagesString(dia->RangeVal->text(), &pageNs, plug->doc->PageC); |
||
55 | res = ex->exportInterval(pageNs); |
||
56 | } |
||
287 | Franz | 57 | plug->FProg->reset(); |
283 | Franz | 58 | QApplication::restoreOverrideCursor(); |
59 | if (!res) |
||
60 | { |
||
359 | Franz | 61 | QMessageBox::warning(plug, QObject::tr("Save as Image"), QObject::tr("Error writting the output file(s).")); |
284 | Franz | 62 | plug->FMess->setText(QObject::tr("Error writing the output file(s).")); |
283 | Franz | 63 | } |
64 | else |
||
65 | { |
||
287 | Franz | 66 | plug->FMess->setText(QObject::tr("Export successful.")); |
283 | Franz | 67 | } |
68 | } // if accepted |
||
69 | // clean the trash |
||
70 | delete ex; |
||
71 | delete dia; |
||
72 | } |
||
73 | |||
74 | |||
75 | ExportBitmap::ExportBitmap(ScribusApp *plug) |
||
76 | { |
||
77 | carrier = plug; |
||
359 | Franz | 78 | pageSize = 72; |
283 | Franz | 79 | quality = 100; |
549 | subik | 80 | enlargement = 100; |
283 | Franz | 81 | exportDir = QDir::currentDirPath(); |
82 | bitmapType = QString("PNG"); |
||
83 | overwrite = FALSE; |
||
84 | } |
||
85 | |||
86 | QString ExportBitmap::getFileName(uint pageNr) |
||
87 | { |
||
88 | QFileInfo path(carrier->doc->DocName); |
||
287 | Franz | 89 | QString name = path.baseName(); // needed tp fix the "/home/user/blah.sla" |
283 | Franz | 90 | QString number; |
293 | Franz | 91 | number = number.setNum(pageNr + carrier->doc->FirstPnum); |
92 | return QDir::convertSeparators(exportDir + "/" + name + "-"+ number + "." + bitmapType.lower()); |
||
283 | Franz | 93 | } |
94 | |||
95 | ExportBitmap::~ExportBitmap() |
||
96 | { |
||
97 | } |
||
98 | |||
287 | Franz | 99 | bool ExportBitmap::exportPage(uint pageNr, bool single = TRUE) |
283 | Franz | 100 | { |
101 | uint over = 0; |
||
287 | Franz | 102 | QString fileName = getFileName(pageNr); |
103 | |||
283 | Franz | 104 | if (!carrier->view->Pages.at(pageNr)) |
105 | return FALSE; |
||
287 | Franz | 106 | |
549 | subik | 107 | QPixmap pixmap = carrier->view->PageToPixmap(pageNr, qRound(carrier->doc->PageH * enlargement / 100)); |
359 | Franz | 108 | QImage im = pixmap.convertToImage(); |
109 | int dpi = qRound(100.0 / 2.54 * pageSize); |
||
110 | im.setDotsPerMeterY(dpi); |
||
111 | im.setDotsPerMeterX(dpi); |
||
283 | Franz | 112 | if (QFile::exists(fileName) && !overwrite) |
113 | { |
||
114 | QApplication::restoreOverrideCursor(); |
||
549 | subik | 115 | /* Changed the following Code from the original QMessageBox::question to |
116 | * QMessageBox::warning to keep the Code compatible to Qt-3.1.x |
||
117 | * f.s 12.05.2004 */ |
||
283 | Franz | 118 | over = QMessageBox::warning(carrier, |
287 | Franz | 119 | QObject::tr("File exists. Overwrite?"), |
120 | fileName +"\n"+ QObject::tr("exists already. Overwrite?"), |
||
121 | QObject::tr("No"), |
||
122 | QObject::tr("Yes"), |
||
123 | // hack for multiple overwritting (petr) |
||
124 | (single==TRUE) ? 0 : QObject::tr("Yes all"), |
||
125 | 0, 0); |
||
283 | Franz | 126 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
127 | if (over == 1) |
||
359 | Franz | 128 | return im.save(fileName, bitmapType, quality); |
283 | Franz | 129 | if (over == 2) |
130 | overwrite = TRUE; |
||
131 | } |
||
359 | Franz | 132 | return im.save(fileName, bitmapType, quality); |
283 | Franz | 133 | } |
134 | |||
135 | bool ExportBitmap::exportActual() |
||
136 | { |
||
287 | Franz | 137 | return exportPage(carrier->doc->ActPage->PageNr, TRUE); |
283 | Franz | 138 | } |
139 | |||
359 | Franz | 140 | bool ExportBitmap::exportInterval(std::vector<int> &pageNs) |
283 | Franz | 141 | { |
142 | bool res; |
||
359 | Franz | 143 | carrier->FProg->setTotalSteps(pageNs.size()); |
144 | for (uint a = 0; a < pageNs.size(); ++a) |
||
283 | Franz | 145 | { |
359 | Franz | 146 | carrier->FProg->setProgress(a); |
147 | res = exportPage(pageNs[a]-1, FALSE); |
||
283 | Franz | 148 | if (!res) |
149 | return FALSE; |
||
150 | } |
||
151 | return TRUE; |
||
152 | } |
||
153 |