Rev 283 | Rev 287 | 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); |
||
27 | // interval widgets handling |
||
28 | dia->ToBox->setMaxValue(plug->doc->PageC); |
||
29 | dia->FromBox->setMaxValue(plug->doc->PageC - 1); |
||
30 | dia->ToBox->setValue(plug->doc->PageC); |
||
31 | // main "loop" |
||
32 | if (dia->exec()==QDialog::Accepted) |
||
33 | { |
||
34 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||
35 | ex->pageSize = dia->SizeBox->value(); |
||
36 | ex->quality = dia->QualityBox->value(); |
||
37 | ex->exportDir = dia->OutputDirectory->text(); |
||
38 | ex->bitmapType = dia->bitmapType; |
||
39 | switch (dia->ButtonGroup1->id(dia->ButtonGroup1->selected())) |
||
40 | { |
||
41 | case 0: res = ex->exportActual(); |
||
42 | break; |
||
43 | case 1: res = ex->exportAll(); |
||
44 | break; |
||
45 | case 2: res = ex->exportInterval( |
||
46 | dia->FromBox->value(), |
||
47 | dia->ToBox->value() |
||
48 | ); |
||
49 | break; |
||
50 | } // switch |
||
51 | QApplication::restoreOverrideCursor(); |
||
52 | if (!res) |
||
53 | { |
||
284 | Franz | 54 | QMessageBox::warning(plug, QObject::tr("Export to image"), |
55 | QObject::tr("Error writing the output file(s).")); |
||
56 | plug->FMess->setText(QObject::tr("Error writing the output file(s).")); |
||
283 | Franz | 57 | } |
58 | else |
||
59 | { |
||
284 | Franz | 60 | plug->FMess->setText(QObject::tr("Export to Image 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; |
||
72 | pageSize = static_cast<int>(carrier->doc->PageH); |
||
73 | quality = 100; |
||
74 | exportDir = QDir::currentDirPath(); |
||
75 | bitmapType = QString("PNG"); |
||
76 | overwrite = FALSE; |
||
77 | } |
||
78 | |||
79 | |||
80 | QString ExportBitmap::getFileName(uint pageNr) |
||
81 | { |
||
82 | QFileInfo path(carrier->doc->DocName); |
||
83 | QString name = path.baseName(); |
||
84 | QString number; |
||
85 | uint turn; |
||
86 | // create the 00x counter |
||
87 | number = number.setNum(carrier->view->Pages.count()); |
||
88 | turn = number.length(); |
||
89 | // number of the page |
||
90 | number = number.setNum(pageNr); |
||
91 | number = number.rightJustify(turn, '0'); |
||
92 | return QDir::convertSeparators( |
||
93 | exportDir+ "/" + name + "-"+ number + "." + bitmapType.lower() |
||
94 | ); |
||
95 | } |
||
96 | |||
97 | |||
98 | ExportBitmap::~ExportBitmap() |
||
99 | { |
||
100 | } |
||
101 | |||
102 | bool ExportBitmap::exportPage(uint pageNr, QString fileName) |
||
103 | { |
||
104 | uint over = 0; |
||
105 | if (!carrier->view->Pages.at(pageNr)) |
||
106 | return FALSE; |
||
107 | QPixmap pixmap = carrier->view->PageToPixmap(pageNr, pageSize); |
||
108 | if (QFile::exists(fileName) && !overwrite) |
||
109 | { |
||
110 | QApplication::restoreOverrideCursor(); |
||
111 | /* Changed the following Code from the original QMessageBox::question to QMessageBox::warning |
||
112 | to keep the Code compatible to Qt-3.1.x |
||
113 | f.s 12.05.2004 */ |
||
114 | over = QMessageBox::warning(carrier, |
||
115 | QObject::tr("File exists. Overwrite?"), |
||
116 | fileName +"\n"+ QObject::tr("exists already. Overwrite?"), |
||
117 | QObject::tr("No"), |
||
118 | QObject::tr("Yes"), |
||
119 | QObject::tr("Yes all"), |
||
120 | 0, 0); |
||
121 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||
122 | if (over == 1) |
||
123 | return pixmap.save(fileName, bitmapType); |
||
124 | if (over == 2) |
||
125 | overwrite = TRUE; |
||
126 | } |
||
127 | return pixmap.save(fileName, bitmapType); |
||
128 | } |
||
129 | |||
130 | |||
131 | bool ExportBitmap::exportActual() |
||
132 | { |
||
133 | uint pageNo = carrier->doc->ActPage->PageNr; |
||
134 | return exportPage(pageNo, getFileName(pageNo)); |
||
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; |
||
147 | for (uint pageNo = from; pageNo<to; pageNo++) |
||
148 | { |
||
149 | res = exportPage(pageNo, getFileName(pageNo)); |
||
150 | if (!res) |
||
151 | return FALSE; |
||
152 | } |
||
153 | return TRUE; |
||
154 | } |
||
155 |