Subversion Repositories Scribus

Rev

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