filters

kis_png_export.cc

00001 /*
00002  *  Copyright (c) 2005 Cyrille Berger <cberger@cberger.net>
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018  */
00019 
00020 #include "kis_png_export.h"
00021 
00022 #include <qcheckbox.h>
00023 #include <qslider.h>
00024 
00025 #include <kapplication.h>
00026 #include <kdialogbase.h>
00027 #include <kgenericfactory.h>
00028 
00029 #include <KoFilterChain.h>
00030 
00031 #include <kis_doc.h>
00032 #include <kis_image.h>
00033 #include <kis_paint_layer.h>
00034 #include <kis_progress_display_interface.h>
00035 
00036 #include "kis_png_converter.h"
00037 #include "kis_wdg_options_png.h"
00038 
00039 typedef KGenericFactory<KisPNGExport, KoFilter> KisPNGExportFactory;
00040 K_EXPORT_COMPONENT_FACTORY(libkritapngexport, KisPNGExportFactory("kofficefilters"))
00041 
00042 KisPNGExport::KisPNGExport(KoFilter *, const char *, const QStringList&) : KoFilter()
00043 {
00044 }
00045 
00046 KisPNGExport::~KisPNGExport()
00047 {
00048 }
00049 
00050 KoFilter::ConversionStatus KisPNGExport::convert(const QCString& from, const QCString& to)
00051 {
00052     kdDebug(41008) << "Png export! From: " << from << ", To: " << to << "\n";
00053     
00054     if (from != "application/x-krita")
00055         return KoFilter::NotImplemented;
00056 
00057     
00058     KDialogBase* kdb = new KDialogBase(0, "", false, i18n("PNG Export Options"), KDialogBase::Ok | KDialogBase::Cancel);
00059  
00060     KisWdgOptionsPNG* wdg = new KisWdgOptionsPNG(kdb);
00061     kdb->setMainWidget(wdg);
00062     kapp->restoreOverrideCursor();
00063     if(kdb->exec() == QDialog::Rejected)
00064     {
00065         return KoFilter::OK; // FIXME Cancel doesn't exist :(
00066     }
00067 
00068     bool alpha = wdg->alpha->isChecked();
00069     bool interlace = wdg->interlacing->isChecked();
00070     int compression = wdg->compressionLevel->value();
00071     
00072     delete kdb;
00073 
00074     KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
00075     QString filename = m_chain->outputFile();
00076     
00077     if (!output)
00078         return KoFilter::CreationError;
00079     
00080     
00081     if (filename.isEmpty()) return KoFilter::FileNotFound;
00082 
00083     KURL url;
00084     url.setPath(filename);
00085 
00086     KisImageSP img = output->currentImage();
00087 
00088     KisPNGConverter kpc(output, output->undoAdapter());
00089 
00090     vKisAnnotationSP_it beginIt = img->beginAnnotations();
00091     vKisAnnotationSP_it endIt = img->endAnnotations();
00092     KisImageBuilder_Result res;
00093 
00094     KisPaintDeviceSP pd = new KisPaintDevice(*img->projection());
00095     KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
00096     
00097     if ( (res = kpc.buildFile(url, l, beginIt, endIt, compression, interlace, alpha)) == KisImageBuilder_RESULT_OK) {
00098         kdDebug(41008) << "success !" << endl;
00099         return KoFilter::OK;
00100     }
00101     kdDebug(41008) << " Result = " << res << endl;
00102     return KoFilter::InternalError;
00103 }
00104 
00105 #include <kis_png_export.moc>
00106 
KDE Home | KDE Accessibility Home | Description of Access Keys