kpresenter/libimageexport/imageexport.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2005 Laurent Montel <montel@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#include <tqpixmap.h>
21#include <tqpainter.h>
22
23#include <tdemessagebox.h>
24
25#include <KoFilterChain.h>
26#include <KoStore.h>
27#include <kgenericfactory.h>
28#include <KoDocument.h>
29
30#include "KPrDocument.h"
31#include "KPrView.h"
32#include "KPrCanvas.h"
33#include "imageexport.h"
34
35ImageExport::ImageExport(KoFilter *, const char *, const TQStringList&)
36 : KoFilter()
37{
38}
39
40ImageExport::~ImageExport()
41{
42}
43
44
45KoFilter::ConversionStatus
46ImageExport::convert(const TQCString& from, const TQCString& to)
47{
48 KoDocument * document = m_chain->inputDocument();
49
50 if ( !document )
51 return KoFilter::StupidError;
52
53 if ( strcmp(document->className(), "KPrDocument") != 0)
54 {
55 kdWarning() << "document isn't a KPrDocument but a "
56 << document->className() << endl;
57 return KoFilter::NotImplemented;
58 }
59
60 // Check for proper conversion.
61 if ( from != "application/x-kpresenter" || to != exportFormat() )
62 {
63 kdWarning() << "Invalid mimetypes " << to << " " << from << endl;
64 return KoFilter::NotImplemented;
65 }
66 KPrDocument * kpresenterdoc = const_cast<KPrDocument *>(static_cast<const KPrDocument *>(document));
67
68 if ( kpresenterdoc->mimeType() != "application/x-kpresenter" )
69 {
70 kdWarning() << "Invalid document mimetype " << kpresenterdoc->mimeType() << endl;
71 return KoFilter::NotImplemented;
72 }
73 KoPageLayout layoutPage= kpresenterdoc->pageLayout();
74 width = int( layoutPage.ptWidth );
75 height = int( layoutPage.ptHeight );
76 if (extraImageAttribute())
77 {
78 KPrView* view = static_cast<KPrView*>( kpresenterdoc->views().getFirst());
79 if ( view ) // no view if embedded document
80 {
81 KPrCanvas * canvas = view->getCanvas();
82 canvas->drawPageInPix( pixmap, view->getCurrPgNum()-1, 0, true, width,height );
83 }
84 else //when it's embedded we use just it.
85 {
86 pixmap = TQPixmap(width, height);
87 TQPainter painter(&pixmap);
88 kpresenterdoc->paintContent(painter, pixmap.rect(), false);
89 }
90 if( !saveImage( m_chain->outputFile()))
91 return KoFilter::CreationError;
92 return KoFilter::OK;
93 }
94 return KoFilter::UserCancelled;
95}
96
97
98#include "imageexport.moc"
99