~ubuntu-branches/ubuntu/precise/koffice/precise

« back to all changes in this revision

Viewing changes to tools/okularodpgenerator/OkularOdpGenerator.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2010-10-27 17:52:57 UTC
  • mfrom: (0.12.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20101027175257-s04zqqk5bs8ckm9o
Tags: 1:2.2.83-0ubuntu1
* Merge with Debian git remaining changes:
 - Add build-deps on librcps-dev, opengtl-dev, libqtgtl-dev, freetds-dev,
   create-resources, libspnav-dev
 - Remove needless build-dep on libwv2-dev
 - koffice-libs recommends create-resources
 - krita recommends pstoedit
 - Keep our patches
* New upstream release 2.3 beta 3
  - Remove debian/patches fixed by upstream
  - Update install files

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* This file is part of the KDE project
 
2
   Copyright (C) 2010 KO GmbH <jos.van.den.oever@kogmbh.com>
 
3
   Copyright (C) 2010 Sven Langkamp <sven.langkamp@gmail.com>
 
4
 
 
5
   This library is free software; you can redistribute it and/or
 
6
   modify it under the terms of the GNU Library General Public
 
7
   License as published by the Free Software Foundation; either
 
8
   version 2 of the License, or (at your option) any later version.
 
9
 
 
10
   This library is distributed in the hope that it will be useful,
 
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
   Library General Public License for more details.
 
14
 
 
15
   You should have received a copy of the GNU Library General Public License
 
16
   along with this library; see the file COPYING.LIB.  If not, write to
 
17
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
*/
 
20
 
 
21
#include <kaboutdata.h>
 
22
 
 
23
#include <KoPADocument.h>
 
24
#include <KoPAPageBase.h>
 
25
#include <KDE/KPluginFactory>
 
26
#include <KDE/KStandardDirs>
 
27
#include <KDE/KMimeType>
 
28
#include <KDE/KParts/ComponentFactory>
 
29
#include <QtCore/QDebug>
 
30
#include <OkularOdpGenerator.h>
 
31
#include <okular/core/page.h>
 
32
#include <qimage.h>
 
33
#include <qpainter.h>
 
34
 
 
35
static KAboutData createAboutData()
 
36
{
 
37
    KAboutData aboutData(
 
38
         "okular_odp",
 
39
         "okular_odp",
 
40
         ki18n( "ODP Backend" ),
 
41
         "0.1",
 
42
         ki18n( "ODP file renderer" ),
 
43
         KAboutData::License_GPL,
 
44
         ki18n( "© 2010 Sven Langkamp" )
 
45
    );
 
46
 
 
47
    // fill the about data
 
48
    return aboutData;
 
49
}
 
50
 
 
51
OKULAR_EXPORT_PLUGIN(OkularOdpGenerator, createAboutData())
 
52
 
 
53
OkularOdpGenerator::OkularOdpGenerator( QObject *parent, const QVariantList &args )
 
54
    : Okular::Generator( parent, args )
 
55
{
 
56
    m_doc = 0;
 
57
}
 
58
 
 
59
OkularOdpGenerator::~OkularOdpGenerator()
 
60
{
 
61
}
 
62
 
 
63
bool OkularOdpGenerator::loadDocument( const QString &fileName, QVector<Okular::Page*> &pages )
 
64
{
 
65
    KComponentData cd("OkularOdpGenerator", QByteArray(),
 
66
                      KComponentData::SkipMainComponentRegistration);
 
67
    KPluginFactory *factory = KPluginLoader("libkpresenterpart", cd).factory();
 
68
    if (!factory) {
 
69
        qDebug() << "could not load libkpresenterpart";
 
70
        return false;
 
71
    }
 
72
    KoPADocument* doc = factory->create<KoPADocument>();
 
73
    m_doc = doc;
 
74
    KUrl url;
 
75
    url.setPath(fileName);
 
76
    doc->setCheckAutoSaveFile(false);
 
77
    doc->setAutoErrorHandlingEnabled(false); // show error dialogs
 
78
    if (!doc->openUrl(url)) {
 
79
        return false;
 
80
    }
 
81
    doc->setReadWrite(false);
 
82
    doc->setAutoSave(0);
 
83
 
 
84
 
 
85
    int pageCount = m_doc->pageCount();
 
86
    for(int i = 0; i < pageCount; i++) {
 
87
        KoPAPageBase* kprpage = m_doc->pages().value(i);
 
88
        if (!kprpage) {
 
89
            continue;
 
90
        }
 
91
        QSize size = kprpage->size().toSize();
 
92
    
 
93
        Okular::Page * page = new Okular::Page( i, size.width(), size.height(), Okular::Rotation0 );
 
94
        pages.append(page);
 
95
    }
 
96
 
 
97
    return true;
 
98
}
 
99
 
 
100
bool OkularOdpGenerator::doCloseDocument()
 
101
{
 
102
    delete m_doc;
 
103
    return true;
 
104
}
 
105
 
 
106
bool OkularOdpGenerator::canGeneratePixmap() const
 
107
{
 
108
    return true;
 
109
}
 
110
 
 
111
void OkularOdpGenerator::generatePixmap( Okular::PixmapRequest *request )
 
112
{
 
113
    QPixmap* pix;
 
114
    if (!m_doc) {
 
115
        pix = new QPixmap(request->width(), request->height());
 
116
        QPainter painter(pix);
 
117
        painter.fillRect(0 ,0 , request->width(), request->height(), Qt::white);
 
118
    } else {
 
119
        KoPAPageBase* page = m_doc->pages().value(request->pageNumber());
 
120
        pix = new QPixmap(page->thumbnail(QSize(request->width(), request->height())));
 
121
    }
 
122
 
 
123
   request->page()->setPixmap( request->id(), pix );
 
124
 
 
125
    signalPixmapRequestDone( request );
 
126
}