Subversion Repositories Scribus

Rev

Rev 5523 | Rev 6548 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4430 cbradney 1
/*
2
For general Scribus (>=1.3.2) copyright and licensing information please refer
3
to the COPYING file provided with the program. Following this notice may exist
4
a copyright and/or license notice that predates the release of Scribus 1.3.2
5
for which a new license (GPL+exception) is in place.
6
*/
283 Franz 7
#include "export.h"
8
#include "dialog.h"
9
#include "export.moc"
10
#include <qpixmap.h>
11
#include <qstring.h>
12
#include <qdir.h>
13
#include <qcursor.h>
14
 
3953 cbradney 15
#include "scmessagebox.h"
3207 craig 16
#include "scribus.h"
1208 cbradney 17
#include "scraction.h"
18
#include "menumanager.h"
2907 subik 19
#include "util.h"
283 Franz 20
 
3207 craig 21
int scribusexportpixmap_getPluginAPIVersion()
283 Franz 22
{
3207 craig 23
        return PLUGIN_API_VERSION;
283 Franz 24
}
25
 
3207 craig 26
ScPlugin* scribusexportpixmap_getPlugin()
283 Franz 27
{
3207 craig 28
        PixmapExportPlugin* plug = new PixmapExportPlugin();
29
        Q_CHECK_PTR(plug);
30
        return plug;
283 Franz 31
}
32
 
3207 craig 33
void scribusexportpixmap_freePlugin(ScPlugin* plugin)
512 fschmid 34
{
3207 craig 35
        PixmapExportPlugin* plug = dynamic_cast<PixmapExportPlugin*>(plugin);
36
        Q_ASSERT(plug);
37
        delete plug;
512 fschmid 38
}
283 Franz 39
 
3686 craig 40
PixmapExportPlugin::PixmapExportPlugin() : ScActionPlugin()
1208 cbradney 41
{
3207 craig 42
        // Set action info in languageChange, so we only have to do
3686 craig 43
        // it in one place. This includes registering file formats.
3207 craig 44
        languageChange();
1208 cbradney 45
}
512 fschmid 46
 
3686 craig 47
PixmapExportPlugin::~PixmapExportPlugin()
48
{
49
};
3207 craig 50
 
51
void PixmapExportPlugin::languageChange()
1208 cbradney 52
{
3207 craig 53
        // Note that we leave the unused members unset. They'll be initialised
54
        // with their default ctors during construction.
55
        // Action name
56
        m_actionInfo.name = "ExportAsImage";
57
        // Action text for menu, including accel
58
        m_actionInfo.text = tr("Save as &Image...");
59
        // Keyboard shortcut
60
        m_actionInfo.keySequence = "CTRL+SHIFT+E";
61
        // Menu
62
        m_actionInfo.menu = "FileExport";
63
        m_actionInfo.enabledOnStartup = true;
1208 cbradney 64
}
65
 
3207 craig 66
const QString PixmapExportPlugin::fullTrName() const
1208 cbradney 67
{
3207 craig 68
        return QObject::tr("Export As Image");
1208 cbradney 69
}
70
 
3207 craig 71
const ScActionPlugin::AboutData* PixmapExportPlugin::getAboutData() const
1208 cbradney 72
{
3241 craig 73
        AboutData* about = new AboutData;
74
        Q_CHECK_PTR(about);
3352 subik 75
        about->authors = QString::fromUtf8("Petr Van\xc4\x9bk <petr@scribus.info>");
76
        about->shortDescription = tr("Export As Image");
3355 cbradney 77
        about->description = tr("Exports selected pages as bitmap images.");
3352 subik 78
        // about->version
79
        // about->releaseDate
80
        // about->copyright
81
        about->license = "GPL";
3241 craig 82
        return about;
1208 cbradney 83
}
84
 
3241 craig 85
void PixmapExportPlugin::deleteAboutData(const AboutData* about) const
1208 cbradney 86
{
3241 craig 87
        Q_ASSERT(about);
88
        delete about;
1208 cbradney 89
}
90
 
5781 cbradney 91
bool PixmapExportPlugin::run(ScribusDoc* doc, QString target)
283 Franz 92
{
3207 craig 93
        Q_ASSERT(target.isEmpty());
5781 cbradney 94
        Q_ASSERT(!doc->masterPageMode());
283 Franz 95
        bool res;
3207 craig 96
        ExportBitmap *ex = new ExportBitmap();
5781 cbradney 97
        ExportForm *dia = new ExportForm(doc->scMW(), ex->pageDPI, ex->quality, ex->bitmapType, doc->pageWidth, doc->pageHeight);
287 Franz 98
 
283 Franz 99
        // interval widgets handling
359 Franz 100
        QString tmp;
5781 cbradney 101
        dia->RangeVal->setText(tmp.setNum(doc->currentPageNumber()+1));
283 Franz 102
        // main "loop"
103
        if (dia->exec()==QDialog::Accepted)
104
        {
105
                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
359 Franz 106
                std::vector<int> pageNs;
2585 subik 107
                ex->pageDPI = dia->DPIBox->value();
552 fschmid 108
                ex->enlargement = dia->EnlargementBox->value();
283 Franz 109
                ex->quality = dia->QualityBox->value();
110
                ex->exportDir = dia->OutputDirectory->text();
111
                ex->bitmapType = dia->bitmapType;
5781 cbradney 112
                doc->scMW()->mainWindowProgressBar->reset();
359 Franz 113
                if (dia->OnePageRadio->isChecked())
5781 cbradney 114
                        res = ex->exportCurrent(doc);
359 Franz 115
                else
283 Franz 116
                {
359 Franz 117
                        if (dia->AllPagesRadio->isChecked())
5781 cbradney 118
                                parsePagesString("*", &pageNs, doc->DocPages.count());
359 Franz 119
                        else
5781 cbradney 120
                                parsePagesString(dia->RangeVal->text(), &pageNs, doc->DocPages.count());
121
                        res = ex->exportInterval(doc, pageNs);
359 Franz 122
                }
5781 cbradney 123
                doc->scMW()->mainWindowProgressBar->reset();
283 Franz 124
                QApplication::restoreOverrideCursor();
125
                if (!res)
126
                {
5781 cbradney 127
                        QMessageBox::warning(doc->scMW(), QObject::tr("Save as Image"), QObject::tr("Error writing the output file(s)."));
128
                        doc->scMW()->setStatusBarInfoText(QObject::tr("Error writing the output file(s)."));
283 Franz 129
                }
130
                else
131
                {
5781 cbradney 132
                        doc->scMW()->setStatusBarInfoText(QObject::tr("Export successful."));
283 Franz 133
                }
134
        } // if accepted
135
        // clean the trash
136
        delete ex;
137
        delete dia;
3207 craig 138
        return true;
283 Franz 139
}
140
 
141
 
3207 craig 142
ExportBitmap::ExportBitmap()
283 Franz 143
{
2585 subik 144
        pageDPI = 72;
283 Franz 145
        quality = 100;
5161 fschmid 146
        enlargement = 100.0;
283 Franz 147
        exportDir = QDir::currentDirPath();
148
        bitmapType = QString("PNG");
2680 cbradney 149
        overwrite = false;
283 Franz 150
}
151
 
5781 cbradney 152
QString ExportBitmap::getFileName(ScribusDoc* doc, uint pageNr)
283 Franz 153
{
5781 cbradney 154
        return QDir::cleanDirPath(QDir::convertSeparators(exportDir + "/" + getFileNameByPage(doc, pageNr, bitmapType.lower())));
283 Franz 155
}
156
 
157
ExportBitmap::~ExportBitmap()
158
{
159
}
160
 
5781 cbradney 161
bool ExportBitmap::exportPage(ScribusDoc* doc, uint pageNr, bool single = true)
283 Franz 162
{
163
        uint over = 0;
5781 cbradney 164
        QString fileName = getFileName(doc, pageNr);
287 Franz 165
 
5781 cbradney 166
        if (!doc->Pages->at(pageNr))
2680 cbradney 167
                return false;
287 Franz 168
 
2613 subik 169
        /* a little magic here - I need to compute the "maxGr" value...
170
        * We need to know the right size of the page for landscape,
171
        * portrait and user defined sizes.
172
        */
173
        double pixmapSize;
5781 cbradney 174
        pixmapSize = (doc->pageHeight > doc->pageWidth) ? doc->pageHeight : doc->pageWidth;
175
        QImage im = doc->view()->PageToPixmap(pageNr, qRound(pixmapSize * enlargement * (pageDPI / 72.0) / 100.0), false);
2585 subik 176
        int dpm = qRound(100.0 / 2.54 * pageDPI);
177
        im.setDotsPerMeterY(dpm);
178
        im.setDotsPerMeterX(dpm);
283 Franz 179
        if (QFile::exists(fileName) && !overwrite)
180
        {
181
                QApplication::restoreOverrideCursor();
182
/* Changed the following Code from the original QMessageBox::question to QMessageBox::warning
287 Franz 183
         to keep the Code compatible to Qt-3.1.x
184
         f.s 12.05.2004 */
5781 cbradney 185
                over = ScMessageBox::warning(doc->scMW(),
287 Franz 186
                                QObject::tr("File exists. Overwrite?"),
187
                                fileName +"\n"+ QObject::tr("exists already. Overwrite?"),
3953 cbradney 188
                                QObject::tr("Yes"),
287 Franz 189
                                QObject::tr("No"),
190
                                // hack for multiple overwritting (petr)
2680 cbradney 191
                                (single==true) ? QString::null : QObject::tr("Yes all"),
287 Franz 192
                                0, 0);
283 Franz 193
                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
3953 cbradney 194
                if (over == 0)
359 Franz 195
                        return im.save(fileName, bitmapType, quality);
283 Franz 196
                if (over == 2)
2680 cbradney 197
                        overwrite = true;
283 Franz 198
        }
359 Franz 199
        return im.save(fileName, bitmapType, quality);
283 Franz 200
}
201
 
5781 cbradney 202
bool ExportBitmap::exportCurrent(ScribusDoc* doc)
283 Franz 203
{
5781 cbradney 204
        return exportPage(doc, doc->currentPageNumber(), true);
283 Franz 205
}
206
 
5781 cbradney 207
bool ExportBitmap::exportInterval(ScribusDoc* doc, std::vector<int> &pageNs)
283 Franz 208
{
209
        bool res;
5781 cbradney 210
        doc->scMW()->mainWindowProgressBar->setTotalSteps(pageNs.size());
359 Franz 211
        for (uint a = 0; a < pageNs.size(); ++a)
283 Franz 212
        {
5781 cbradney 213
                doc->scMW()->mainWindowProgressBar->setProgress(a);
214
                res = exportPage(doc, pageNs[a]-1, false);
283 Franz 215
                if (!res)
2680 cbradney 216
                        return false;
283 Franz 217
        }
2680 cbradney 218
        return true;
283 Franz 219
}