Subversion Repositories Scribus

Rev

Rev 6663 | Rev 7118 | 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"
6548 subik 20
#include "commonstrings.h"
283 Franz 21
 
3207 craig 22
int scribusexportpixmap_getPluginAPIVersion()
283 Franz 23
{
3207 craig 24
        return PLUGIN_API_VERSION;
283 Franz 25
}
26
 
3207 craig 27
ScPlugin* scribusexportpixmap_getPlugin()
283 Franz 28
{
3207 craig 29
        PixmapExportPlugin* plug = new PixmapExportPlugin();
30
        Q_CHECK_PTR(plug);
31
        return plug;
283 Franz 32
}
33
 
3207 craig 34
void scribusexportpixmap_freePlugin(ScPlugin* plugin)
512 fschmid 35
{
3207 craig 36
        PixmapExportPlugin* plug = dynamic_cast<PixmapExportPlugin*>(plugin);
37
        Q_ASSERT(plug);
38
        delete plug;
512 fschmid 39
}
283 Franz 40
 
3686 craig 41
PixmapExportPlugin::PixmapExportPlugin() : ScActionPlugin()
1208 cbradney 42
{
3207 craig 43
        // Set action info in languageChange, so we only have to do
3686 craig 44
        // it in one place. This includes registering file formats.
3207 craig 45
        languageChange();
1208 cbradney 46
}
512 fschmid 47
 
3686 craig 48
PixmapExportPlugin::~PixmapExportPlugin()
49
{
50
};
3207 craig 51
 
52
void PixmapExportPlugin::languageChange()
1208 cbradney 53
{
3207 craig 54
        // Note that we leave the unused members unset. They'll be initialised
55
        // with their default ctors during construction.
56
        // Action name
57
        m_actionInfo.name = "ExportAsImage";
58
        // Action text for menu, including accel
59
        m_actionInfo.text = tr("Save as &Image...");
60
        // Keyboard shortcut
61
        m_actionInfo.keySequence = "CTRL+SHIFT+E";
62
        // Menu
63
        m_actionInfo.menu = "FileExport";
64
        m_actionInfo.enabledOnStartup = true;
1208 cbradney 65
}
66
 
3207 craig 67
const QString PixmapExportPlugin::fullTrName() const
1208 cbradney 68
{
6665 cbradney 69
        return tr("Export As Image");
1208 cbradney 70
}
71
 
3207 craig 72
const ScActionPlugin::AboutData* PixmapExportPlugin::getAboutData() const
1208 cbradney 73
{
3241 craig 74
        AboutData* about = new AboutData;
75
        Q_CHECK_PTR(about);
3352 subik 76
        about->authors = QString::fromUtf8("Petr Van\xc4\x9bk <petr@scribus.info>");
77
        about->shortDescription = tr("Export As Image");
3355 cbradney 78
        about->description = tr("Exports selected pages as bitmap images.");
3352 subik 79
        // about->version
80
        // about->releaseDate
81
        // about->copyright
82
        about->license = "GPL";
3241 craig 83
        return about;
1208 cbradney 84
}
85
 
3241 craig 86
void PixmapExportPlugin::deleteAboutData(const AboutData* about) const
1208 cbradney 87
{
3241 craig 88
        Q_ASSERT(about);
89
        delete about;
1208 cbradney 90
}
91
 
5781 cbradney 92
bool PixmapExportPlugin::run(ScribusDoc* doc, QString target)
283 Franz 93
{
3207 craig 94
        Q_ASSERT(target.isEmpty());
5781 cbradney 95
        Q_ASSERT(!doc->masterPageMode());
3207 craig 96
        ExportBitmap *ex = new ExportBitmap();
6663 cbradney 97
        ExportForm *dia = new ExportForm(doc->scMW(), ex->pageDPI, ex->quality, ex->bitmapType, doc->pageWidth, doc->pageHeight, doc->DocPages.count());
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();
6665 cbradney 113
                bool res;
359 Franz 114
                if (dia->OnePageRadio->isChecked())
5781 cbradney 115
                        res = ex->exportCurrent(doc);
359 Franz 116
                else
283 Franz 117
                {
359 Franz 118
                        if (dia->AllPagesRadio->isChecked())
5781 cbradney 119
                                parsePagesString("*", &pageNs, doc->DocPages.count());
359 Franz 120
                        else
5781 cbradney 121
                                parsePagesString(dia->RangeVal->text(), &pageNs, doc->DocPages.count());
122
                        res = ex->exportInterval(doc, pageNs);
359 Franz 123
                }
5781 cbradney 124
                doc->scMW()->mainWindowProgressBar->reset();
283 Franz 125
                QApplication::restoreOverrideCursor();
126
                if (!res)
127
                {
6665 cbradney 128
                        QMessageBox::warning(doc->scMW(),  tr("Save as Image"), tr("Error writing the output file(s)."));
129
                        doc->scMW()->setStatusBarInfoText( tr("Error writing the output file(s)."));
283 Franz 130
                }
131
                else
6665 cbradney 132
                        doc->scMW()->setStatusBarInfoText( tr("Export successful"));
133
        }
283 Franz 134
        // clean the trash
135
        delete ex;
136
        delete dia;
3207 craig 137
        return true;
283 Franz 138
}
139
 
140
 
3207 craig 141
ExportBitmap::ExportBitmap()
283 Franz 142
{
2585 subik 143
        pageDPI = 72;
283 Franz 144
        quality = 100;
5161 fschmid 145
        enlargement = 100.0;
283 Franz 146
        exportDir = QDir::currentDirPath();
147
        bitmapType = QString("PNG");
2680 cbradney 148
        overwrite = false;
283 Franz 149
}
150
 
5781 cbradney 151
QString ExportBitmap::getFileName(ScribusDoc* doc, uint pageNr)
283 Franz 152
{
5781 cbradney 153
        return QDir::cleanDirPath(QDir::convertSeparators(exportDir + "/" + getFileNameByPage(doc, pageNr, bitmapType.lower())));
283 Franz 154
}
155
 
156
ExportBitmap::~ExportBitmap()
157
{
158
}
159
 
5781 cbradney 160
bool ExportBitmap::exportPage(ScribusDoc* doc, uint pageNr, bool single = true)
283 Franz 161
{
162
        uint over = 0;
6665 cbradney 163
        QString fileName(getFileName(doc, pageNr));
287 Franz 164
 
5781 cbradney 165
        if (!doc->Pages->at(pageNr))
2680 cbradney 166
                return false;
287 Franz 167
 
2613 subik 168
        /* a little magic here - I need to compute the "maxGr" value...
169
        * We need to know the right size of the page for landscape,
170
        * portrait and user defined sizes.
171
        */
6665 cbradney 172
        double pixmapSize = (doc->pageHeight > doc->pageWidth) ? doc->pageHeight : doc->pageWidth;
173
        QImage im(doc->view()->PageToPixmap(pageNr, qRound(pixmapSize * enlargement * (pageDPI / 72.0) / 100.0), false));
2585 subik 174
        int dpm = qRound(100.0 / 2.54 * pageDPI);
175
        im.setDotsPerMeterY(dpm);
176
        im.setDotsPerMeterX(dpm);
283 Franz 177
        if (QFile::exists(fileName) && !overwrite)
178
        {
179
                QApplication::restoreOverrideCursor();
6665 cbradney 180
                over = ScMessageBox::question(doc->scMW(), tr("File exists. Overwrite?"),
181
                                fileName +"\n"+ tr("exists already. Overwrite?"),
182
                                CommonStrings::trYes, CommonStrings::trNo,
183
                                // hack for multiple overwritting (petr) 
184
                                (single==true) ? QString::null : tr("All"), 0, 0);
283 Franz 185
                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
3953 cbradney 186
                if (over == 0)
359 Franz 187
                        return im.save(fileName, bitmapType, quality);
283 Franz 188
                if (over == 2)
2680 cbradney 189
                        overwrite = true;
283 Franz 190
        }
359 Franz 191
        return im.save(fileName, bitmapType, quality);
283 Franz 192
}
193
 
5781 cbradney 194
bool ExportBitmap::exportCurrent(ScribusDoc* doc)
283 Franz 195
{
5781 cbradney 196
        return exportPage(doc, doc->currentPageNumber(), true);
283 Franz 197
}
198
 
5781 cbradney 199
bool ExportBitmap::exportInterval(ScribusDoc* doc, std::vector<int> &pageNs)
283 Franz 200
{
5781 cbradney 201
        doc->scMW()->mainWindowProgressBar->setTotalSteps(pageNs.size());
359 Franz 202
        for (uint a = 0; a < pageNs.size(); ++a)
283 Franz 203
        {
5781 cbradney 204
                doc->scMW()->mainWindowProgressBar->setProgress(a);
6665 cbradney 205
                if (!exportPage(doc, pageNs[a]-1, false))
2680 cbradney 206
                        return false;
283 Franz 207
        }
2680 cbradney 208
        return true;
283 Franz 209
}