Rev 293 | Rev 359 | 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 |
293 | Franz | 29 | dia->ToBox->setMinValue(1); |
283 | Franz | 30 | dia->ToBox->setMaxValue(plug->doc->PageC); |
31 | dia->ToBox->setValue(plug->doc->PageC); |
||
293 | Franz | 32 | dia->FromBox->setMinValue(1); |
33 | dia->FromBox->setMaxValue(plug->doc->PageC); |
||
34 | dia->FromBox->setValue(plug->doc->ActPage->PageNr+1); |
||
283 | Franz | 35 | // main "loop" |
36 | if (dia->exec()==QDialog::Accepted) |
||
37 | { |
||
38 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||
39 | ex->pageSize = dia->SizeBox->value(); |
||
40 | ex->quality = dia->QualityBox->value(); |
||
41 | ex->exportDir = dia->OutputDirectory->text(); |
||
42 | ex->bitmapType = dia->bitmapType; |
||
287 | Franz | 43 | plug->FProg->reset(); |
283 | Franz | 44 | switch (dia->ButtonGroup1->id(dia->ButtonGroup1->selected())) |
45 | { |
||
46 | case 0: res = ex->exportActual(); |
||
47 | break; |
||
48 | case 1: res = ex->exportAll(); |
||
49 | break; |
||
293 | Franz | 50 | case 2: res = ex->exportInterval(dia->FromBox->value(), dia->ToBox->value()); |
283 | Franz | 51 | break; |
52 | } // switch |
||
287 | Franz | 53 | plug->FProg->reset(); |
283 | Franz | 54 | QApplication::restoreOverrideCursor(); |
55 | if (!res) |
||
56 | { |
||
287 | Franz | 57 | QMessageBox::warning(plug, QObject::tr("Save as Image"), |
58 | QObject::tr("Error writting the output file(s).")); |
||
284 | Franz | 59 | plug->FMess->setText(QObject::tr("Error writing the output file(s).")); |
283 | Franz | 60 | } |
61 | else |
||
62 | { |
||
287 | Franz | 63 | plug->FMess->setText(QObject::tr("Export successful.")); |
283 | Franz | 64 | } |
65 | } // if accepted |
||
66 | // clean the trash |
||
67 | delete ex; |
||
68 | delete dia; |
||
69 | } |
||
70 | |||
71 | |||
72 | ExportBitmap::ExportBitmap(ScribusApp *plug) |
||
73 | { |
||
74 | carrier = plug; |
||
75 | pageSize = static_cast<int>(carrier->doc->PageH); |
||
76 | quality = 100; |
||
77 | exportDir = QDir::currentDirPath(); |
||
78 | bitmapType = QString("PNG"); |
||
79 | overwrite = FALSE; |
||
80 | } |
||
81 | |||
82 | |||
83 | QString ExportBitmap::getFileName(uint pageNr) |
||
84 | { |
||
85 | QFileInfo path(carrier->doc->DocName); |
||
287 | Franz | 86 | QString name = path.baseName(); // needed tp fix the "/home/user/blah.sla" |
283 | Franz | 87 | QString number; |
293 | Franz | 88 | number = number.setNum(pageNr + carrier->doc->FirstPnum); |
89 | return QDir::convertSeparators(exportDir + "/" + name + "-"+ number + "." + bitmapType.lower()); |
||
283 | Franz | 90 | } |
91 | |||
92 | |||
93 | ExportBitmap::~ExportBitmap() |
||
94 | { |
||
95 | } |
||
96 | |||
287 | Franz | 97 | |
98 | bool ExportBitmap::exportPage(uint pageNr, bool single = TRUE) |
||
283 | Franz | 99 | { |
100 | uint over = 0; |
||
287 | Franz | 101 | QString fileName = getFileName(pageNr); |
102 | |||
283 | Franz | 103 | if (!carrier->view->Pages.at(pageNr)) |
104 | return FALSE; |
||
287 | Franz | 105 | |
283 | Franz | 106 | QPixmap pixmap = carrier->view->PageToPixmap(pageNr, pageSize); |
107 | if (QFile::exists(fileName) && !overwrite) |
||
108 | { |
||
109 | QApplication::restoreOverrideCursor(); |
||
110 | /* Changed the following Code from the original QMessageBox::question to QMessageBox::warning |
||
287 | Franz | 111 | 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) |
||
123 | return pixmap.save(fileName, bitmapType); |
||
124 | if (over == 2) |
||
125 | overwrite = TRUE; |
||
126 | } |
||
287 | Franz | 127 | |
283 | Franz | 128 | return pixmap.save(fileName, bitmapType); |
129 | } |
||
130 | |||
131 | |||
132 | bool ExportBitmap::exportActual() |
||
133 | { |
||
287 | Franz | 134 | return exportPage(carrier->doc->ActPage->PageNr, TRUE); |
283 | Franz | 135 | } |
136 | |||
137 | |||
138 | bool ExportBitmap::exportAll() |
||
139 | { |
||
140 | return exportInterval(0, carrier->view->Pages.count()); |
||
141 | } |
||
142 | |||
143 | |||
144 | bool ExportBitmap::exportInterval(uint from, uint to) |
||
145 | { |
||
146 | bool res; |
||
287 | Franz | 147 | |
293 | Franz | 148 | carrier->FProg->setTotalSteps(to - from+1); |
149 | for (uint pageNo = from-1; pageNo < to; pageNo++) |
||
283 | Franz | 150 | { |
293 | Franz | 151 | carrier->FProg->setProgress(pageNo - from+1); |
287 | Franz | 152 | res = exportPage(pageNo, FALSE); |
283 | Franz | 153 | if (!res) |
154 | return FALSE; |
||
155 | } |
||
156 | return TRUE; |
||
157 | } |
||
158 |