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