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 "KPrDocument.h"
00031 #include "KPrView.h"
00032 #include "KPrCanvas.h"
00033 #include "imageexport.h"
00034 
00035 ImageExport::ImageExport(KoFilter *, const char *, const QStringList&)
00036     : KoFilter()
00037 {
00038 }
00039 
00040 ImageExport::~ImageExport()
00041 {
00042 }
00043 
00044 
00045 KoFilter::ConversionStatus
00046 ImageExport::convert(const QCString& from, const QCString& to)
00047 {
00048     KoDocument * document = m_chain->inputDocument();
00049 
00050     if ( !document )
00051         return KoFilter::StupidError;
00052 
00053     if ( strcmp(document->className(), "KPrDocument") != 0)
00054     {
00055         kdWarning() << "document isn't a KPrDocument but a "
00056                     << document->className() << endl;
00057         return KoFilter::NotImplemented;
00058     }
00059 
00060     // Check for proper conversion.
00061     if ( from != "application/x-kpresenter" || to != exportFormat() )
00062     {
00063         kdWarning() << "Invalid mimetypes " << to << " " << from << endl;
00064         return KoFilter::NotImplemented;
00065     }
00066     KPrDocument * kpresenterdoc = const_cast<KPrDocument *>(static_cast<const KPrDocument *>(document));
00067 
00068     if ( kpresenterdoc->mimeType() != "application/x-kpresenter" )
00069     {
00070         kdWarning() << "Invalid document mimetype " << kpresenterdoc->mimeType() << endl;
00071         return KoFilter::NotImplemented;
00072     }
00073     KoPageLayout layoutPage= kpresenterdoc->pageLayout();
00074     width =  int( layoutPage.ptWidth );
00075     height = int( layoutPage.ptHeight );
00076     if (extraImageAttribute())
00077     {
00078         KPrView* view = static_cast<KPrView*>( kpresenterdoc->views().getFirst());
00079         if ( view ) // no view if embedded document
00080         {
00081             KPrCanvas * canvas = view->getCanvas();
00082             canvas->drawPageInPix( pixmap, view->getCurrPgNum()-1, 0, true, width,height );
00083         }
00084         else //when it's embedded we use just it.
00085         {
00086             pixmap = QPixmap(width, height);
00087             QPainter  painter(&pixmap);
00088             kpresenterdoc->paintContent(painter, pixmap.rect(), false);
00089         }
00090         if( !saveImage( m_chain->outputFile()))
00091             return KoFilter::CreationError;
00092         return KoFilter::OK;
00093     }
00094     return KoFilter::UserCancelled;
00095 }
00096 
00097 
00098 #include "imageexport.moc"
00099 
KDE Home | KDE Accessibility Home | Description of Access Keys