filters

imageexport.cpp

00001 /* This file is part of the KDE project
00002    Copyright (C) 2005 Laurent Montel <montel@kde.org>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library 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 GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <qpixmap.h>
00021 #include <qpainter.h>
00022 
00023 #include <kmessagebox.h>
00024 
00025 #include <KoFilterChain.h>
00026 #include <KoStore.h>
00027 #include <kgenericfactory.h>
00028 #include <KoDocument.h>
00029 
00030 #include "imageexport.h"
00031 #include "kchart_part.h"
00032 
00033 ImageExport::ImageExport(KoFilter *, const char *, const QStringList&)
00034     : KoFilter()
00035 {
00036 }
00037 
00038 ImageExport::~ImageExport()
00039 {
00040 }
00041 
00042 
00043 KoFilter::ConversionStatus
00044 ImageExport::convert(const QCString& from, const QCString& to)
00045 {
00046     // Check for proper conversion.
00047     if ( from != "application/x-kchart" || to != exportFormat() )
00048         return KoFilter::NotImplemented;
00049 
00050     // Read the contents of the KChart file
00051     KoStoreDevice* storeIn = m_chain->storageFile( "root", KoStore::Read );
00052     if ( !storeIn ) {
00053     KMessageBox::error( 0, i18n("Failed to read data." ),
00054                 i18n( "Export Error" ) );
00055     return KoFilter::FileNotFound;
00056     }
00057 
00058     // Get the XML tree.
00059     QDomDocument  domIn;
00060     domIn.setContent( storeIn );
00061     QDomElement   docNode = domIn.documentElement();
00062 
00063     // Read the document from the XML tree.
00064     KChart::KChartPart  kchartDoc;
00065     if ( !kchartDoc.loadXML(0, domIn) ) {
00066         KMessageBox::error( 0, i18n( "Malformed XML data." ),
00067                 i18n( "Export Error" ) );
00068         return KoFilter::WrongFormat;
00069     }
00070     width = 500;
00071     height = 400;
00072     extraImageAttribute();
00073     pixmap = QPixmap(width, height);
00074     QPainter  painter(&pixmap);
00075     kchartDoc.paintContent(painter, pixmap.rect(), false);
00076     saveImage( m_chain->outputFile());
00077     return KoFilter::OK; 
00078 }
00079 
00080 
00081 #include "imageexport.moc"
00082 
KDE Home | KDE Accessibility Home | Description of Access Keys