Subversion Repositories Scribus

Rev

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