Subversion Repositories Scribus

Rev

Rev 5781 | Rev 6663 | 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
 
6548 subik 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
{
3207 craig 70
        return QObject::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());
283 Franz 97
        bool res;
3207 craig 98
        ExportBitmap *ex = new ExportBitmap();
5781 cbradney 99
        ExportForm *dia = new ExportForm(doc->scMW(), ex->pageDPI, ex->quality, ex->bitmapType, doc->pageWidth, doc->pageHeight);
287 Franz 100
 
283 Franz 101
        // interval widgets handling
359 Franz 102
        QString tmp;
5781 cbradney 103
        dia->RangeVal->setText(tmp.setNum(doc->currentPageNumber()+1));
283 Franz 104
        // main "loop"
105
        if (dia->exec()==QDialog::Accepted)
106
        {
107
                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
359 Franz 108
                std::vector<int> pageNs;
2585 subik 109
                ex->pageDPI = dia->DPIBox->value();
552 fschmid 110
                ex->enlargement = dia->EnlargementBox->value();
283 Franz 111
                ex->quality = dia->QualityBox->value();
112
                ex->exportDir = dia->OutputDirectory->text();
113
                ex->bitmapType = dia->bitmapType;
5781 cbradney 114
                doc->scMW()->mainWindowProgressBar->reset();
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
                {
5781 cbradney 129
                        QMessageBox::warning(doc->scMW(), QObject::tr("Save as Image"), QObject::tr("Error writing the output file(s)."));
130
                        doc->scMW()->setStatusBarInfoText(QObject::tr("Error writing the output file(s)."));
283 Franz 131
                }
132
                else
133
                {
5781 cbradney 134
                        doc->scMW()->setStatusBarInfoText(QObject::tr("Export successful."));
283 Franz 135
                }
136
        } // if accepted
137
        // clean the trash
138
        delete ex;
139
        delete dia;
3207 craig 140
        return true;
283 Franz 141
}
142
 
143
 
3207 craig 144
ExportBitmap::ExportBitmap()
283 Franz 145
{
2585 subik 146
        pageDPI = 72;
283 Franz 147
        quality = 100;
5161 fschmid 148
        enlargement = 100.0;
283 Franz 149
        exportDir = QDir::currentDirPath();
150
        bitmapType = QString("PNG");
2680 cbradney 151
        overwrite = false;
283 Franz 152
}
153
 
5781 cbradney 154
QString ExportBitmap::getFileName(ScribusDoc* doc, uint pageNr)
283 Franz 155
{
5781 cbradney 156
        return QDir::cleanDirPath(QDir::convertSeparators(exportDir + "/" + getFileNameByPage(doc, pageNr, bitmapType.lower())));
283 Franz 157
}
158
 
159
ExportBitmap::~ExportBitmap()
160
{
161
}
162
 
5781 cbradney 163
bool ExportBitmap::exportPage(ScribusDoc* doc, uint pageNr, bool single = true)
283 Franz 164
{
165
        uint over = 0;
5781 cbradney 166
        QString fileName = getFileName(doc, pageNr);
287 Franz 167
 
5781 cbradney 168
        if (!doc->Pages->at(pageNr))
2680 cbradney 169
                return false;
287 Franz 170
 
2613 subik 171
        /* a little magic here - I need to compute the "maxGr" value...
172
        * We need to know the right size of the page for landscape,
173
        * portrait and user defined sizes.
174
        */
175
        double pixmapSize;
5781 cbradney 176
        pixmapSize = (doc->pageHeight > doc->pageWidth) ? doc->pageHeight : doc->pageWidth;
177
        QImage im = doc->view()->PageToPixmap(pageNr, qRound(pixmapSize * enlargement * (pageDPI / 72.0) / 100.0), false);
2585 subik 178
        int dpm = qRound(100.0 / 2.54 * pageDPI);
179
        im.setDotsPerMeterY(dpm);
180
        im.setDotsPerMeterX(dpm);
283 Franz 181
        if (QFile::exists(fileName) && !overwrite)
182
        {
183
                QApplication::restoreOverrideCursor();
184
/* Changed the following Code from the original QMessageBox::question to QMessageBox::warning
287 Franz 185
         to keep the Code compatible to Qt-3.1.x
186
         f.s 12.05.2004 */
5781 cbradney 187
                over = ScMessageBox::warning(doc->scMW(),
287 Franz 188
                                QObject::tr("File exists. Overwrite?"),
189
                                fileName +"\n"+ QObject::tr("exists already. Overwrite?"),
6548 subik 190
                                CommonStrings::trYes,
191
                                CommonStrings::trNo,
287 Franz 192
                                // hack for multiple overwritting (petr)
2680 cbradney 193
                                (single==true) ? QString::null : QObject::tr("Yes all"),
287 Franz 194
                                0, 0);
283 Franz 195
                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
3953 cbradney 196
                if (over == 0)
359 Franz 197
                        return im.save(fileName, bitmapType, quality);
283 Franz 198
                if (over == 2)
2680 cbradney 199
                        overwrite = true;
283 Franz 200
        }
359 Franz 201
        return im.save(fileName, bitmapType, quality);
283 Franz 202
}
203
 
5781 cbradney 204
bool ExportBitmap::exportCurrent(ScribusDoc* doc)
283 Franz 205
{
5781 cbradney 206
        return exportPage(doc, doc->currentPageNumber(), true);
283 Franz 207
}
208
 
5781 cbradney 209
bool ExportBitmap::exportInterval(ScribusDoc* doc, std::vector<int> &pageNs)
283 Franz 210
{
211
        bool res;
5781 cbradney 212
        doc->scMW()->mainWindowProgressBar->setTotalSteps(pageNs.size());
359 Franz 213
        for (uint a = 0; a < pageNs.size(); ++a)
283 Franz 214
        {
5781 cbradney 215
                doc->scMW()->mainWindowProgressBar->setProgress(a);
216
                res = exportPage(doc, pageNs[a]-1, false);
283 Franz 217
                if (!res)
2680 cbradney 218
                        return false;
283 Franz 219
        }
2680 cbradney 220
        return true;
283 Franz 221
}