Rev 2585 | Rev 2613 | 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 | |||
1208 | cbradney | 9 | #include "scraction.h" |
10 | #include "menumanager.h" |
||
1552 | subik | 11 | #include "pluginmanager.h" |
283 | Franz | 12 | |
1208 | cbradney | 13 | |
1552 | subik | 14 | QString name() |
283 | Franz | 15 | { |
308 | Franz | 16 | return QObject::tr("Save as &Image..."); |
283 | Franz | 17 | } |
18 | |||
19 | |||
1552 | subik | 20 | PluginManager::PluginType type() |
283 | Franz | 21 | { |
1552 | subik | 22 | return PluginManager::Standard; |
283 | Franz | 23 | } |
24 | |||
512 | fschmid | 25 | int ID() |
26 | { |
||
27 | return 4; |
||
28 | } |
||
283 | Franz | 29 | |
1208 | cbradney | 30 | QString actionName() |
31 | { |
||
32 | return "ExportAsImage"; |
||
33 | } |
||
512 | fschmid | 34 | |
1208 | cbradney | 35 | QString actionKeySequence() |
36 | { |
||
1783 | cbradney | 37 | return "CTRL+SHIFT+E"; |
1208 | cbradney | 38 | } |
39 | |||
40 | QString actionMenu() |
||
41 | { |
||
42 | return "FileExport"; |
||
43 | } |
||
44 | |||
45 | QString actionMenuAfterName() |
||
46 | { |
||
47 | return ""; |
||
48 | } |
||
49 | |||
50 | bool actionEnabledOnStartup() |
||
51 | { |
||
52 | return true; |
||
53 | } |
||
54 | |||
1552 | subik | 55 | void run(QWidget *d, ScribusApp *plug) |
283 | Franz | 56 | { |
57 | bool res; |
||
58 | ExportBitmap *ex = new ExportBitmap(plug); |
||
2585 | subik | 59 | ExportForm *dia = new ExportForm(d, ex->pageDPI, ex->quality, ex->bitmapType); |
287 | Franz | 60 | |
283 | Franz | 61 | // interval widgets handling |
359 | Franz | 62 | QString tmp; |
1065 | cbradney | 63 | dia->RangeVal->setText(tmp.setNum(plug->doc->currentPage->PageNr+1)); |
283 | Franz | 64 | // main "loop" |
65 | if (dia->exec()==QDialog::Accepted) |
||
66 | { |
||
67 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
||
359 | Franz | 68 | std::vector<int> pageNs; |
2585 | subik | 69 | ex->pageDPI = dia->DPIBox->value(); |
552 | fschmid | 70 | ex->enlargement = dia->EnlargementBox->value(); |
283 | Franz | 71 | ex->quality = dia->QualityBox->value(); |
72 | ex->exportDir = dia->OutputDirectory->text(); |
||
73 | ex->bitmapType = dia->bitmapType; |
||
2433 | cbradney | 74 | plug->mainWindowProgressBar->reset(); |
359 | Franz | 75 | if (dia->OnePageRadio->isChecked()) |
76 | res = ex->exportActual(); |
||
77 | else |
||
283 | Franz | 78 | { |
359 | Franz | 79 | if (dia->AllPagesRadio->isChecked()) |
2142 | cbradney | 80 | plug->parsePagesString("*", &pageNs, plug->doc->pageCount); |
359 | Franz | 81 | else |
2142 | cbradney | 82 | plug->parsePagesString(dia->RangeVal->text(), &pageNs, plug->doc->pageCount); |
359 | Franz | 83 | res = ex->exportInterval(pageNs); |
84 | } |
||
2433 | cbradney | 85 | plug->mainWindowProgressBar->reset(); |
283 | Franz | 86 | QApplication::restoreOverrideCursor(); |
87 | if (!res) |
||
88 | { |
||
2207 | cbradney | 89 | QMessageBox::warning(plug, QObject::tr("Save as Image"), QObject::tr("Error writing the output file(s).")); |
2433 | cbradney | 90 | plug->mainWindowStatusLabel->setText(QObject::tr("Error writing the output file(s).")); |
283 | Franz | 91 | } |
92 | else |
||
93 | { |
||
2433 | cbradney | 94 | plug->mainWindowStatusLabel->setText(QObject::tr("Export successful.")); |
283 | Franz | 95 | } |
96 | } // if accepted |
||
97 | // clean the trash |
||
98 | delete ex; |
||
99 | delete dia; |
||
100 | } |
||
101 | |||
102 | |||
103 | ExportBitmap::ExportBitmap(ScribusApp *plug) |
||
104 | { |
||
105 | carrier = plug; |
||
2585 | subik | 106 | pageDPI = 72; |
283 | Franz | 107 | quality = 100; |
552 | fschmid | 108 | enlargement = 100; |
283 | Franz | 109 | exportDir = QDir::currentDirPath(); |
110 | bitmapType = QString("PNG"); |
||
111 | overwrite = FALSE; |
||
112 | } |
||
113 | |||
114 | QString ExportBitmap::getFileName(uint pageNr) |
||
115 | { |
||
116 | QFileInfo path(carrier->doc->DocName); |
||
287 | Franz | 117 | QString name = path.baseName(); // needed tp fix the "/home/user/blah.sla" |
283 | Franz | 118 | QString number; |
293 | Franz | 119 | number = number.setNum(pageNr + carrier->doc->FirstPnum); |
120 | return QDir::convertSeparators(exportDir + "/" + name + "-"+ number + "." + bitmapType.lower()); |
||
283 | Franz | 121 | } |
122 | |||
123 | ExportBitmap::~ExportBitmap() |
||
124 | { |
||
125 | } |
||
126 | |||
287 | Franz | 127 | bool ExportBitmap::exportPage(uint pageNr, bool single = TRUE) |
283 | Franz | 128 | { |
129 | uint over = 0; |
||
287 | Franz | 130 | QString fileName = getFileName(pageNr); |
131 | |||
456 | fschmid | 132 | if (!carrier->doc->Pages.at(pageNr)) |
283 | Franz | 133 | return FALSE; |
287 | Franz | 134 | |
2602 | subik | 135 | QImage im = carrier->view->PageToPixmap(pageNr, qRound(carrier->doc->pageHeight * enlargement * (pageDPI / 72.0) / 100.0)); |
2585 | subik | 136 | int dpm = qRound(100.0 / 2.54 * pageDPI); |
137 | im.setDotsPerMeterY(dpm); |
||
138 | im.setDotsPerMeterX(dpm); |
||
283 | Franz | 139 | if (QFile::exists(fileName) && !overwrite) |
140 | { |
||
141 | QApplication::restoreOverrideCursor(); |
||
142 | /* Changed the following Code from the original QMessageBox::question to QMessageBox::warning |
||
287 | Franz | 143 | to keep the Code compatible to Qt-3.1.x |
144 | f.s 12.05.2004 */ |
||
283 | Franz | 145 | over = QMessageBox::warning(carrier, |
287 | Franz | 146 | QObject::tr("File exists. Overwrite?"), |
147 | fileName +"\n"+ QObject::tr("exists already. Overwrite?"), |
||
148 | QObject::tr("No"), |
||
149 | QObject::tr("Yes"), |
||
150 | // hack for multiple overwritting (petr) |
||
151 | (single==TRUE) ? 0 : QObject::tr("Yes all"), |
||
152 | 0, 0); |
||
283 | Franz | 153 | QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); |
154 | if (over == 1) |
||
359 | Franz | 155 | return im.save(fileName, bitmapType, quality); |
283 | Franz | 156 | if (over == 2) |
157 | overwrite = TRUE; |
||
158 | } |
||
359 | Franz | 159 | return im.save(fileName, bitmapType, quality); |
283 | Franz | 160 | } |
161 | |||
162 | bool ExportBitmap::exportActual() |
||
163 | { |
||
1065 | cbradney | 164 | return exportPage(carrier->doc->currentPage->PageNr, TRUE); |
283 | Franz | 165 | } |
166 | |||
359 | Franz | 167 | bool ExportBitmap::exportInterval(std::vector<int> &pageNs) |
283 | Franz | 168 | { |
169 | bool res; |
||
2433 | cbradney | 170 | carrier->mainWindowProgressBar->setTotalSteps(pageNs.size()); |
359 | Franz | 171 | for (uint a = 0; a < pageNs.size(); ++a) |
283 | Franz | 172 | { |
2433 | cbradney | 173 | carrier->mainWindowProgressBar->setProgress(a); |
359 | Franz | 174 | res = exportPage(pageNs[a]-1, FALSE); |
283 | Franz | 175 | if (!res) |
176 | return FALSE; |
||
177 | } |
||
178 | return TRUE; |
||
179 | } |