Subversion Repositories Scribus

Rev

Rev 6665 | Rev 7152 | 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"
7118 jghali 21
#include "scpaths.h"
283 Franz 22
 
3207 craig 23
int scribusexportpixmap_getPluginAPIVersion()
283 Franz 24
{
3207 craig 25
        return PLUGIN_API_VERSION;
283 Franz 26
}
27
 
3207 craig 28
ScPlugin* scribusexportpixmap_getPlugin()
283 Franz 29
{
3207 craig 30
        PixmapExportPlugin* plug = new PixmapExportPlugin();
31
        Q_CHECK_PTR(plug);
32
        return plug;
283 Franz 33
}
34
 
3207 craig 35
void scribusexportpixmap_freePlugin(ScPlugin* plugin)
512 fschmid 36
{
3207 craig 37
        PixmapExportPlugin* plug = dynamic_cast<PixmapExportPlugin*>(plugin);
38
        Q_ASSERT(plug);
39
        delete plug;
512 fschmid 40
}
283 Franz 41
 
3686 craig 42
PixmapExportPlugin::PixmapExportPlugin() : ScActionPlugin()
1208 cbradney 43
{
3207 craig 44
        // Set action info in languageChange, so we only have to do
3686 craig 45
        // it in one place. This includes registering file formats.
3207 craig 46
        languageChange();
1208 cbradney 47
}
512 fschmid 48
 
3686 craig 49
PixmapExportPlugin::~PixmapExportPlugin()
50
{
51
};
3207 craig 52
 
53
void PixmapExportPlugin::languageChange()
1208 cbradney 54
{
3207 craig 55
        // Note that we leave the unused members unset. They'll be initialised
56
        // with their default ctors during construction.
57
        // Action name
58
        m_actionInfo.name = "ExportAsImage";
59
        // Action text for menu, including accel
60
        m_actionInfo.text = tr("Save as &Image...");
61
        // Keyboard shortcut
62
        m_actionInfo.keySequence = "CTRL+SHIFT+E";
63
        // Menu
64
        m_actionInfo.menu = "FileExport";
65
        m_actionInfo.enabledOnStartup = true;
1208 cbradney 66
}
67
 
3207 craig 68
const QString PixmapExportPlugin::fullTrName() const
1208 cbradney 69
{
6665 cbradney 70
        return tr("Export As Image");
1208 cbradney 71
}
72
 
3207 craig 73
const ScActionPlugin::AboutData* PixmapExportPlugin::getAboutData() const
1208 cbradney 74
{
3241 craig 75
        AboutData* about = new AboutData;
76
        Q_CHECK_PTR(about);
3352 subik 77
        about->authors = QString::fromUtf8("Petr Van\xc4\x9bk <petr@scribus.info>");
78
        about->shortDescription = tr("Export As Image");
3355 cbradney 79
        about->description = tr("Exports selected pages as bitmap images.");
3352 subik 80
        // about->version
81
        // about->releaseDate
82
        // about->copyright
83
        about->license = "GPL";
3241 craig 84
        return about;
1208 cbradney 85
}
86
 
3241 craig 87
void PixmapExportPlugin::deleteAboutData(const AboutData* about) const
1208 cbradney 88
{
3241 craig 89
        Q_ASSERT(about);
90
        delete about;
1208 cbradney 91
}
92
 
5781 cbradney 93
bool PixmapExportPlugin::run(ScribusDoc* doc, QString target)
283 Franz 94
{
3207 craig 95
        Q_ASSERT(target.isEmpty());
5781 cbradney 96
        Q_ASSERT(!doc->masterPageMode());
3207 craig 97
        ExportBitmap *ex = new ExportBitmap();
6663 cbradney 98
        ExportForm *dia = new ExportForm(doc->scMW(), ex->pageDPI, ex->quality, ex->bitmapType, doc->pageWidth, doc->pageHeight, doc->DocPages.count());
287 Franz 99
 
283 Franz 100
        // interval widgets handling
359 Franz 101
        QString tmp;
5781 cbradney 102
        dia->RangeVal->setText(tmp.setNum(doc->currentPageNumber()+1));
283 Franz 103
        // main "loop"
104
        if (dia->exec()==QDialog::Accepted)
105
        {
106
                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
359 Franz 107
                std::vector<int> pageNs;
2585 subik 108
                ex->pageDPI = dia->DPIBox->value();
552 fschmid 109
                ex->enlargement = dia->EnlargementBox->value();
283 Franz 110
                ex->quality = dia->QualityBox->value();
7118 jghali 111
                ex->exportDir = ScPaths::separatorsToSlashes(dia->OutputDirectory->text());
283 Franz 112
                ex->bitmapType = dia->bitmapType;
5781 cbradney 113
                doc->scMW()->mainWindowProgressBar->reset();
6665 cbradney 114
                bool res;
359 Franz 115
                if (dia->OnePageRadio->isChecked())
5781 cbradney 116
                        res = ex->exportCurrent(doc);
359 Franz 117
                else
283 Franz 118
                {
359 Franz 119
                        if (dia->AllPagesRadio->isChecked())
5781 cbradney 120
                                parsePagesString("*", &pageNs, doc->DocPages.count());
359 Franz 121
                        else
5781 cbradney 122
                                parsePagesString(dia->RangeVal->text(), &pageNs, doc->DocPages.count());
123
                        res = ex->exportInterval(doc, pageNs);
359 Franz 124
                }
5781 cbradney 125
                doc->scMW()->mainWindowProgressBar->reset();
283 Franz 126
                QApplication::restoreOverrideCursor();
127
                if (!res)
128
                {
6665 cbradney 129
                        QMessageBox::warning(doc->scMW(),  tr("Save as Image"), tr("Error writing the output file(s)."));
130
                        doc->scMW()->setStatusBarInfoText( tr("Error writing the output file(s)."));
283 Franz 131
                }
132
                else
6665 cbradney 133
                        doc->scMW()->setStatusBarInfoText( tr("Export successful"));
134
        }
283 Franz 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;
6665 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
        */
6665 cbradney 173
        double pixmapSize = (doc->pageHeight > doc->pageWidth) ? doc->pageHeight : doc->pageWidth;
174
        QImage im(doc->view()->PageToPixmap(pageNr, qRound(pixmapSize * enlargement * (pageDPI / 72.0) / 100.0), false));
2585 subik 175
        int dpm = qRound(100.0 / 2.54 * pageDPI);
176
        im.setDotsPerMeterY(dpm);
177
        im.setDotsPerMeterX(dpm);
283 Franz 178
        if (QFile::exists(fileName) && !overwrite)
179
        {
180
                QApplication::restoreOverrideCursor();
6665 cbradney 181
                over = ScMessageBox::question(doc->scMW(), tr("File exists. Overwrite?"),
182
                                fileName +"\n"+ tr("exists already. Overwrite?"),
183
                                CommonStrings::trYes, CommonStrings::trNo,
184
                                // hack for multiple overwritting (petr) 
185
                                (single==true) ? QString::null : tr("All"), 0, 0);
283 Franz 186
                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
3953 cbradney 187
                if (over == 0)
359 Franz 188
                        return im.save(fileName, bitmapType, quality);
283 Franz 189
                if (over == 2)
2680 cbradney 190
                        overwrite = true;
283 Franz 191
        }
359 Franz 192
        return im.save(fileName, bitmapType, quality);
283 Franz 193
}
194
 
5781 cbradney 195
bool ExportBitmap::exportCurrent(ScribusDoc* doc)
283 Franz 196
{
5781 cbradney 197
        return exportPage(doc, doc->currentPageNumber(), true);
283 Franz 198
}
199
 
5781 cbradney 200
bool ExportBitmap::exportInterval(ScribusDoc* doc, std::vector<int> &pageNs)
283 Franz 201
{
5781 cbradney 202
        doc->scMW()->mainWindowProgressBar->setTotalSteps(pageNs.size());
359 Franz 203
        for (uint a = 0; a < pageNs.size(); ++a)
283 Franz 204
        {
5781 cbradney 205
                doc->scMW()->mainWindowProgressBar->setProgress(a);
6665 cbradney 206
                if (!exportPage(doc, pageNs[a]-1, false))
2680 cbradney 207
                        return false;
283 Franz 208
        }
2680 cbradney 209
        return true;
283 Franz 210
}