Subversion Repositories Scribus

Rev

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