filters

kis_tiff_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_tiff_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_group_layer.h>
00033 #include <kis_image.h>
00034 #include <kis_paint_layer.h>
00035 #include <kis_progress_display_interface.h>
00036 
00037 #include "kis_tiff_converter.h"
00038 #include "kis_dlg_options_tiff.h"
00039 #include "kis_wdg_options_tiff.h"
00040 
00041 typedef KGenericFactory<KisTIFFExport, KoFilter> KisTIFFExportFactory;
00042 K_EXPORT_COMPONENT_FACTORY(libkritatiffexport, KisTIFFExportFactory("kofficefilters"))
00043 
00044 KisTIFFExport::KisTIFFExport(KoFilter *, const char *, const QStringList&) : KoFilter()
00045 {
00046 }
00047 
00048 KisTIFFExport::~KisTIFFExport()
00049 {
00050 }
00051 
00052 KoFilter::ConversionStatus KisTIFFExport::convert(const QCString& from, const QCString& to)
00053 {
00054     kdDebug(41008) << "Tiff export! From: " << from << ", To: " << to << "\n";
00055     
00056     if (from != "application/x-krita")
00057         return KoFilter::NotImplemented;
00058 
00059     
00060     KisDlgOptionsTIFF* kdb = new KisDlgOptionsTIFF(0, "options dialog for tiff");
00061  
00062     if(kdb->exec() == QDialog::Rejected)
00063     {
00064         return KoFilter::OK; // FIXME Cancel doesn't exist :(
00065     }
00066     
00067     KisTIFFOptions options = kdb->options();
00068 
00069     delete kdb;
00070 
00071     KisDoc *output = dynamic_cast<KisDoc*>(m_chain->inputDocument());
00072     QString filename = m_chain->outputFile();
00073     
00074     if (!output)
00075         return KoFilter::CreationError;
00076     
00077     if (filename.isEmpty()) return KoFilter::FileNotFound;
00078 
00079     KURL url;
00080     url.setPath(filename);
00081 
00082     KisImageSP img;
00083     
00084     if(options.flatten)
00085     {
00086         img = new KisImage(0, output->currentImage()->width(), output->currentImage()->height(), output->currentImage()->colorSpace(), "");
00087         KisPaintDeviceSP pd = new KisPaintDevice(*output->currentImage()->projection());
00088         KisPaintLayerSP l = new KisPaintLayer(img, "projection", OPACITY_OPAQUE, pd);
00089         img->addLayer(l.data(), img->rootLayer(), 0);
00090     } else {
00091         img = output->currentImage();
00092     }
00093     
00094 
00095     KisTIFFConverter ktc(output, output->undoAdapter());
00096 /*    vKisAnnotationSP_it beginIt = img->beginAnnotations();
00097     vKisAnnotationSP_it endIt = img->endAnnotations();*/
00098     KisImageBuilder_Result res;
00099     if ( (res = ktc.buildFile(url, img, options)) == KisImageBuilder_RESULT_OK) {
00100         kdDebug(41008) << "success !" << endl;
00101         return KoFilter::OK;
00102     }
00103     kdDebug(41008) << " Result = " << res << endl;
00104     return KoFilter::InternalError;
00105 }
00106 
00107 #include <kis_tiff_export.moc>
00108 
KDE Home | KDE Accessibility Home | Description of Access Keys