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