Subversion Repositories Scribus

Rev

Rev 3241 | Rev 3352 | 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);
67
        return about;
1208 cbradney 68
}
69
 
3241 craig 70
void PixmapExportPlugin::deleteAboutData(const AboutData* about) const
1208 cbradney 71
{
3241 craig 72
        Q_ASSERT(about);
73
        delete about;
1208 cbradney 74
}
75
 
3207 craig 76
bool PixmapExportPlugin::run(QString target)
283 Franz 77
{
3207 craig 78
        Q_ASSERT(target.isEmpty());
283 Franz 79
        bool res;
3207 craig 80
        ExportBitmap *ex = new ExportBitmap();
81
        ExportForm *dia = new ExportForm(ScApp, ex->pageDPI, ex->quality, ex->bitmapType);
287 Franz 82
 
283 Franz 83
        // interval widgets handling
359 Franz 84
        QString tmp;
3207 craig 85
        dia->RangeVal->setText(tmp.setNum(ScApp->doc->currentPage->pageNr()+1));
283 Franz 86
        // main "loop"
87
        if (dia->exec()==QDialog::Accepted)
88
        {
89
                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
359 Franz 90
                std::vector<int> pageNs;
2585 subik 91
                ex->pageDPI = dia->DPIBox->value();
552 fschmid 92
                ex->enlargement = dia->EnlargementBox->value();
283 Franz 93
                ex->quality = dia->QualityBox->value();
94
                ex->exportDir = dia->OutputDirectory->text();
95
                ex->bitmapType = dia->bitmapType;
3207 craig 96
                ScApp->mainWindowProgressBar->reset();
359 Franz 97
                if (dia->OnePageRadio->isChecked())
98
                        res = ex->exportActual();
99
                else
283 Franz 100
                {
359 Franz 101
                        if (dia->AllPagesRadio->isChecked())
3207 craig 102
                                ScApp->parsePagesString("*", &pageNs, ScApp->doc->pageCount);
359 Franz 103
                        else
3207 craig 104
                                ScApp->parsePagesString(dia->RangeVal->text(), &pageNs, ScApp->doc->pageCount);
359 Franz 105
                        res = ex->exportInterval(pageNs);
106
                }
3207 craig 107
                ScApp->mainWindowProgressBar->reset();
283 Franz 108
                QApplication::restoreOverrideCursor();
109
                if (!res)
110
                {
3207 craig 111
                        QMessageBox::warning(ScApp, QObject::tr("Save as Image"), QObject::tr("Error writing the output file(s)."));
112
                        ScApp->mainWindowStatusLabel->setText(QObject::tr("Error writing the output file(s)."));
283 Franz 113
                }
114
                else
115
                {
3207 craig 116
                        ScApp->mainWindowStatusLabel->setText(QObject::tr("Export successful."));
283 Franz 117
                }
118
        } // if accepted
119
        // clean the trash
120
        delete ex;
121
        delete dia;
3207 craig 122
        return true;
283 Franz 123
}
124
 
125
 
3207 craig 126
ExportBitmap::ExportBitmap()
283 Franz 127
{
2585 subik 128
        pageDPI = 72;
283 Franz 129
        quality = 100;
552 fschmid 130
        enlargement = 100;
283 Franz 131
        exportDir = QDir::currentDirPath();
132
        bitmapType = QString("PNG");
2680 cbradney 133
        overwrite = false;
283 Franz 134
}
135
 
136
QString ExportBitmap::getFileName(uint pageNr)
137
{
2907 subik 138
        return QDir::cleanDirPath(QDir::convertSeparators(exportDir + "/" + getFileNameByPage(pageNr, bitmapType.lower())));
283 Franz 139
}
140
 
141
ExportBitmap::~ExportBitmap()
142
{
143
}
144
 
2680 cbradney 145
bool ExportBitmap::exportPage(uint pageNr, bool single = true)
283 Franz 146
{
147
        uint over = 0;
287 Franz 148
        QString fileName = getFileName(pageNr);
149
 
3207 craig 150
        if (!ScApp->doc->Pages.at(pageNr))
2680 cbradney 151
                return false;
287 Franz 152
 
2613 subik 153
        /* a little magic here - I need to compute the "maxGr" value...
154
        * We need to know the right size of the page for landscape,
155
        * portrait and user defined sizes.
156
        */
157
        double pixmapSize;
3207 craig 158
        (ScApp->doc->pageHeight > ScApp->doc->pageWidth)
159
                        ? pixmapSize = ScApp->doc->pageHeight
160
                        : pixmapSize = ScApp->doc->pageWidth;
161
        QImage im = ScApp->view->PageToPixmap(pageNr, qRound(pixmapSize * enlargement * (pageDPI / 72.0) / 100.0));
2585 subik 162
        int dpm = qRound(100.0 / 2.54 * pageDPI);
163
        im.setDotsPerMeterY(dpm);
164
        im.setDotsPerMeterX(dpm);
283 Franz 165
        if (QFile::exists(fileName) && !overwrite)
166
        {
167
                QApplication::restoreOverrideCursor();
168
/* Changed the following Code from the original QMessageBox::question to QMessageBox::warning
287 Franz 169
         to keep the Code compatible to Qt-3.1.x
170
         f.s 12.05.2004 */
3207 craig 171
                over = QMessageBox::warning(ScApp,
287 Franz 172
                                QObject::tr("File exists. Overwrite?"),
173
                                fileName +"\n"+ QObject::tr("exists already. Overwrite?"),
174
                                QObject::tr("No"),
175
                                QObject::tr("Yes"),
176
                                // hack for multiple overwritting (petr)
2680 cbradney 177
                                (single==true) ? QString::null : QObject::tr("Yes all"),
287 Franz 178
                                0, 0);
283 Franz 179
                QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
180
                if (over == 1)
359 Franz 181
                        return im.save(fileName, bitmapType, quality);
283 Franz 182
                if (over == 2)
2680 cbradney 183
                        overwrite = true;
283 Franz 184
        }
359 Franz 185
        return im.save(fileName, bitmapType, quality);
283 Franz 186
}
187
 
188
bool ExportBitmap::exportActual()
189
{
3207 craig 190
        return exportPage(ScApp->doc->currentPage->pageNr(), true);
283 Franz 191
}
192
 
359 Franz 193
bool ExportBitmap::exportInterval(std::vector<int> &pageNs)
283 Franz 194
{
195
        bool res;
3207 craig 196
        ScApp->mainWindowProgressBar->setTotalSteps(pageNs.size());
359 Franz 197
        for (uint a = 0; a < pageNs.size(); ++a)
283 Franz 198
        {
3207 craig 199
                ScApp->mainWindowProgressBar->setProgress(a);
2680 cbradney 200
                res = exportPage(pageNs[a]-1, false);
283 Franz 201
                if (!res)
2680 cbradney 202
                        return false;
283 Franz 203
        }
2680 cbradney 204
        return true;
283 Franz 205
}