Subversion Repositories Scribus

Rev

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

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