okular/core/generator.h
Piotr Szymanski 3cbcb2fb7f - update openDocument and freegui stuff
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=455516
2005-08-31 18:13:59 +00:00

164 lines
6.7 KiB
C++

/***************************************************************************
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef _KPDF_GENERATOR_H_
#define _KPDF_GENERATOR_H_
#define KPDF_EXPORT_PLUGIN( classname ) \
extern "C" { \
Generator* create_plugin(KPDFDocument* doc) { return new classname(doc); } \
}
#include <qobject.h>
#include <qvaluevector.h>
#include <qstring.h>
#include "core/document.h"
#include "core/textpage.h"
class KPrinter;
class KPDFPage;
class KPDFLink;
class PixmapRequest;
class KConfigDialog;
/* Note: on contents generation and asyncronous queries.
* Many observers may want to request data syncronously or asyncronously.
* - Sync requests. These should be done in-place.
* - Async request must be done in real background. That usually means a
* thread, such as QThread derived classes.
* Once contents are available, they must be immediately stored in the
* KPDFPage they refer to, and a signal is emitted as soon as storing
* (even for sync or async queries) has been done.
*/
/**
* @short [Abstract Class] The information generator.
*
* Most of class members are pure virtuals and they must be implemented to
* provide a class that builds contents (graphics and text).
*
* Generation/query is requested by the 'KPDFDocument' class only, and that
* class stores the resulting data into 'KPDFPage's. The data will then be
* displayed by the GUI components (pageView, thumbnailList, etc..).
*/
class Generator : public QObject
{
public:
/** virtual methods to reimplement **/
// load a document and fill up the pagesVector
virtual bool loadDocument( const QString & fileName, QValueVector< KPDFPage * > & pagesVector ) = 0;
// Document description and Table of contents
virtual const DocumentInfo * generateDocumentInfo() { return 0L; }
virtual const DocumentSynopsis * generateDocumentSynopsis() { return 0L; }
virtual const DocumentFonts * generateDocumentFonts() { return 0L; }
// DRM handling
virtual bool isAllowed( int /*Document::Permisison(s)*/ ) { return true; }
// page contents generation
virtual bool canGeneratePixmap( bool async ) = 0;
virtual void generatePixmap( PixmapRequest * request ) = 0;
// can generate a KPDFText Page
virtual bool canGenerateTextPage() = 0;
virtual void generateSyncTextPage( KPDFPage * page ) = 0;
// gui stuff
virtual QString getXMLFile() = 0;
virtual void setupGUI(KActionCollection * /*ac*/ , QToolBox * /*tBox*/ ) {;};
virtual void freeGUI( ) {;};
// capability querying
// provides internal search
virtual bool supportsSearching() = 0;
virtual bool prefersInternalSearching() = 0;
virtual bool supportsRotation() = 0;
// internal search and gettext
virtual RegularAreaRect * findText( const QString & text, SearchDir dir, const bool strictCase,
const RegularAreaRect * lastRect, KPDFPage * page) = 0;
virtual QString* getText( const RegularAreaRect * area, KPDFPage * page ) = 0;
virtual void setOrientation(QValueVector<KPDFPage*> & pagesVector, int orientation) = 0;
// may come useful later
//virtual bool hasFonts() const = 0;
// return true if wanting to configure the printer yourself in backend
virtual bool canConfigurePrinter( ) { return false; }
// print the document (using a printer configured or not depending on the above function)
// note, if we are only asking for a preview this will be preconfigured
virtual bool print( KPrinter& /*printer*/ ) { return false; }
// access meta data of the generator
virtual QString getMetaData( const QString &/*key*/, const QString &/*option*/ ) { return QString(); }
// tell generator to re-parse configuration and return true if something changed
virtual bool reparseConfig() { return false; }
void setDocument( KPDFDocument * doc ) { m_document=doc; };
/** 'signals' to send events the KPDFDocument **/
// tell the document that the job has been completed
void signalRequestDone( PixmapRequest * request ) { m_document->requestDone( request ); }
/** constructor: takes the Document as a parameter **/
Generator( KPDFDocument * doc ) : m_document( doc ) {};
// add support for settings
virtual void addPages( KConfigDialog* /*dlg*/) { ; } ;
// capture events
// return false if you don't wish kpdf to use its event handlers
// in the pageview after your handling (use with caution)
virtual bool handleEvent (QEvent * /*event*/ ) { return true; } ;
// podner if not making separate handlers for every event type (clutters the api though)
/*virtual bool mouseEvent ( QMouseEvent* event ) { return false; };
virtual bool wheelEvent ( QWheelEvent* event ) { return false; };
virtual bool keyEvent ( QKeyEvent* event ) { return false; };
virtual bool resizeEvent ( QResizeEvent* event ) { return false; };
virtual bool dragEnterEvent ( QDragEnterEvent* event ) { return false; };
virtual bool dropEvent ( QDropEvent* event ) { return false; };
virtual bool paintEvent ( QKeyEvent* event ) { return false; };*/
signals:
void error(QString & string, int duration);
void warning(QString & string, int duration);
void notice(QString & string, int duration);
private:
Generator();
KPDFDocument * m_document;
};
/**
* @short Describes a pixmap type request.
*/
struct PixmapRequest
{
PixmapRequest( int rId, int n, int w, int h, /*double z,*/ int r, int p, bool a = false )
: id( rId ), pageNumber( n ), width( w ), height( h ), /*zoom(z),*/
rotation(r) , priority( p ), async( a ), page( 0 ) {};
PixmapRequest() {;};
// observer id
int id;
// page number and size
int pageNumber;
int width;
int height;
// double zoom;
int rotation;
// asyncronous request priority (less is better, 0 is max)
int priority;
// generate the pixmap in a thread and notify observer when done
bool async;
// this field is set by the Docuemnt prior passing the
// request to the generator
KPDFPage * page;
};
#endif