Rev 284 | Rev 293 | 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 | { |
||
284 | 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 |
29 | dia->ToBox->setMaxValue(plug->doc->PageC); |
||
30 | dia->FromBox->setMaxValue(plug->doc->PageC - 1); |
||
31 | dia->ToBox->setValue(plug->doc->PageC); |
||
32 | // main "loop" |
||
33 | if (dia->exec()==QDialog::Accepted) |
||
34 | { |
||
35 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||
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(); |
283 | Franz | 41 | switch (dia->ButtonGroup1->id(dia->ButtonGroup1->selected())) |
42 | { |
||
43 | case 0: res = ex->exportActual(); |
||
44 | break; |
||
45 | case 1: res = ex->exportAll(); |
||
46 | break; |
||
47 | case 2: res = ex->exportInterval( |
||
48 | dia->FromBox->value(), |
||
49 | dia->ToBox->value() |
||
50 | ); |
||
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; |
88 | uint turn; |
||
89 | // create the 00x counter |
||
90 | number = number.setNum(carrier->view->Pages.count()); |
||
91 | turn = number.length(); |
||
92 | // number of the page |
||
93 | number = number.setNum(pageNr); |
||
94 | number = number.rightJustify(turn, '0'); |
||
95 | return QDir::convertSeparators( |
||
96 | exportDir+ "/" + name + "-"+ number + "." + bitmapType.lower() |
||
97 | ); |
||
98 | } |
||
99 | |||
100 | |||
101 | ExportBitmap::~ExportBitmap() |
||
102 | { |
||
103 | } |
||
104 | |||
287 | Franz | 105 | |
106 | bool ExportBitmap::exportPage(uint pageNr, bool single = TRUE) |
||
283 | Franz | 107 | { |
108 | uint over = 0; |
||
287 | Franz | 109 | QString fileName = getFileName(pageNr); |
110 | |||
283 | Franz | 111 | if (!carrier->view->Pages.at(pageNr)) |
112 | return FALSE; |
||
287 | Franz | 113 | |
283 | Franz | 114 | QPixmap pixmap = carrier->view->PageToPixmap(pageNr, pageSize); |
115 | if (QFile::exists(fileName) && !overwrite) |
||
116 | { |
||
117 | QApplication::restoreOverrideCursor(); |
||
118 | /* Changed the following Code from the original QMessageBox::question to QMessageBox::warning |
||
287 | Franz | 119 | to keep the Code compatible to Qt-3.1.x |
120 | f.s 12.05.2004 */ |
||
283 | Franz | 121 | over = QMessageBox::warning(carrier, |
287 | Franz | 122 | QObject::tr("File exists. Overwrite?"), |
123 | fileName +"\n"+ QObject::tr("exists already. Overwrite?"), |
||
124 | QObject::tr("No"), |
||
125 | QObject::tr("Yes"), |
||
126 | // hack for multiple overwritting (petr) |
||
127 | (single==TRUE) ? 0 : QObject::tr("Yes all"), |
||
128 | 0, 0); |
||
283 | Franz | 129 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
130 | if (over == 1) |
||
131 | return pixmap.save(fileName, bitmapType); |
||
132 | if (over == 2) |
||
133 | overwrite = TRUE; |
||
134 | } |
||
287 | Franz | 135 | |
283 | Franz | 136 | return pixmap.save(fileName, bitmapType); |
137 | } |
||
138 | |||
139 | |||
140 | bool ExportBitmap::exportActual() |
||
141 | { |
||
287 | Franz | 142 | return exportPage(carrier->doc->ActPage->PageNr, TRUE); |
283 | Franz | 143 | } |
144 | |||
145 | |||
146 | bool ExportBitmap::exportAll() |
||
147 | { |
||
148 | return exportInterval(0, carrier->view->Pages.count()); |
||
149 | } |
||
150 | |||
151 | |||
152 | bool ExportBitmap::exportInterval(uint from, uint to) |
||
153 | { |
||
154 | bool res; |
||
287 | Franz | 155 | |
156 | carrier->FProg->setTotalSteps(to - from); |
||
157 | for (uint pageNo = from; pageNo < to; pageNo++) |
||
283 | Franz | 158 | { |
287 | Franz | 159 | carrier->FProg->setProgress(pageNo - from); |
160 | res = exportPage(pageNo, FALSE); |
||
283 | Franz | 161 | if (!res) |
162 | return FALSE; |
||
163 | } |
||
164 | return TRUE; |
||
165 | } |
||
166 |