Subversion Repositories Scribus

Rev

Rev 4069 | Rev 5161 | 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
 
3207 craig 91
bool PixmapExportPlugin::run(QString target)
283 Franz 92
{
3207 craig 93
        Q_ASSERT(target.isEmpty());
4069 craig 94
        Q_ASSERT(!ScMW->doc->masterPageMode());
283 Franz 95
        bool res;
3207 craig 96
        ExportBitmap *ex = new ExportBitmap();
4026 craig 97
        ExportForm *dia = new ExportForm(ScMW, ex->pageDPI, ex->quality, ex->bitmapType);
287 Franz 98
 
283 Franz 99
        // interval widgets handling
359 Franz 100
        QString tmp;
4026 craig 101
        dia->RangeVal->setText(tmp.setNum(ScMW->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;
4026 craig 112
                ScMW->mainWindowProgressBar->reset();
359 Franz 113
                if (dia->OnePageRadio->isChecked())
114
                        res = ex->exportActual();
115
                else
283 Franz 116
                {
359 Franz 117
                        if (dia->AllPagesRadio->isChecked())
4069 craig 118
                                parsePagesString("*", &pageNs, ScMW->doc->DocPages.count());
359 Franz 119
                        else
4069 craig 120
                                parsePagesString(dia->RangeVal->text(), &pageNs, ScMW->doc->DocPages.count());
359 Franz 121
                        res = ex->exportInterval(pageNs);
122
                }
4026 craig 123
                ScMW->mainWindowProgressBar->reset();
283 Franz 124
                QApplication::restoreOverrideCursor();
125
                if (!res)
126
                {
4026 craig 127
                        QMessageBox::warning(ScMW, QObject::tr("Save as Image"), QObject::tr("Error writing the output file(s)."));
128
                        ScMW->mainWindowStatusLabel->setText(QObject::tr("Error writing the output file(s)."));
283 Franz 129
                }
130
                else
131
                {
4026 craig 132
                        ScMW->mainWindowStatusLabel->setText(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;
552 fschmid 146
        enlargement = 100;
283 Franz 147
        exportDir = QDir::currentDirPath();
148
        bitmapType = QString("PNG");
2680 cbradney 149
        overwrite = false;
283 Franz 150
}
151
 
152
QString ExportBitmap::getFileName(uint pageNr)
153
{
2907 subik 154
        return QDir::cleanDirPath(QDir::convertSeparators(exportDir + "/" + getFileNameByPage(pageNr, bitmapType.lower())));
283 Franz 155
}
156
 
157
ExportBitmap::~ExportBitmap()
158
{
159
}
160
 
2680 cbradney 161
bool ExportBitmap::exportPage(uint pageNr, bool single = true)
283 Franz 162
{
163
        uint over = 0;
287 Franz 164
        QString fileName = getFileName(pageNr);
165
 
4026 craig 166
        if (!ScMW->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;
4026 craig 174
        (ScMW->doc->pageHeight > ScMW->doc->pageWidth)
175
                        ? pixmapSize = ScMW->doc->pageHeight
176
                        : pixmapSize = ScMW->doc->pageWidth;
177
        QImage im = ScMW->view->PageToPixmap(pageNr, qRound(pixmapSize * enlargement * (pageDPI / 72.0) / 100.0));
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 */
4026 craig 187
                over = ScMessageBox::warning(ScMW,
287 Franz 188
                                QObject::tr("File exists. Overwrite?"),
189
                                fileName +"\n"+ QObject::tr("exists already. Overwrite?"),
3953 cbradney 190
                                QObject::tr("Yes"),
287 Franz 191
                                QObject::tr("No"),
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
 
204
bool ExportBitmap::exportActual()
205
{
4026 craig 206
        return exportPage(ScMW->doc->currentPageNumber(), true);
283 Franz 207
}
208
 
359 Franz 209
bool ExportBitmap::exportInterval(std::vector<int> &pageNs)
283 Franz 210
{
211
        bool res;
4026 craig 212
        ScMW->mainWindowProgressBar->setTotalSteps(pageNs.size());
359 Franz 213
        for (uint a = 0; a < pageNs.size(); ++a)
283 Franz 214
        {
4026 craig 215
                ScMW->mainWindowProgressBar->setProgress(a);
2680 cbradney 216
                res = exportPage(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
}