compile
[kdegraphics.git] / okular / core / textdocumentgenerator.h
blobbf4c8f013b87a9b5f27756dae3613fd34f73db4e
1 /***************************************************************************
2 * Copyright (C) 2007 by Tobias Koenig <tokoe@kde.org> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #ifndef _OKULAR_TEXTDOCUMENTGENERATOR_H_
11 #define _OKULAR_TEXTDOCUMENTGENERATOR_H_
13 #include <okular/core/okular_export.h>
15 #include <okular/core/document.h>
16 #include <okular/core/generator.h>
18 class QTextBlock;
19 class QTextDocument;
21 namespace Okular {
23 class TextDocumentConverterPrivate;
24 class TextDocumentGenerator;
25 class TextDocumentGeneratorPrivate;
27 class OKULAR_EXPORT TextDocumentConverter : public QObject
29 Q_OBJECT
31 friend class TextDocumentGenerator;
32 friend class TextDocumentGeneratorPrivate;
34 public:
35 /**
36 * Creates a new generic converter.
38 TextDocumentConverter();
40 /**
41 * Destroys the generic converter.
43 ~TextDocumentConverter();
45 /**
46 * Returns the generated QTextDocument object.
48 virtual QTextDocument *convert( const QString &fileName ) = 0;
50 Q_SIGNALS:
51 /**
52 * Adds a new link object which is located between cursorBegin and
53 * cursorEnd to the generator.
55 void addAction( Action *link, int cursorBegin, int cursorEnd );
57 /**
58 * Adds a new annotation object which is located between cursorBegin and
59 * cursorEnd to the generator.
61 void addAnnotation( Annotation *annotation, int cursorBegin, int cursorEnd );
63 /**
64 * Adds a new title at the given level which is located as position to the generator.
66 void addTitle( int level, const QString &title, const QTextBlock &position );
68 /**
69 * Adds a set of meta data to the generator.
71 void addMetaData( const QString &key, const QString &value, const QString &title );
73 /**
74 * Adds a set of meta data to the generator.
76 * @since 0.7 (KDE 4.1)
78 void addMetaData( DocumentInfo::Key key, const QString &value );
80 /**
81 * This signal should be emitted whenever an error occurred in the converter.
83 * @param message The message which should be shown to the user.
84 * @param duration The time that the message should be shown to the user.
86 void error( const QString &message, int duration );
88 /**
89 * This signal should be emitted whenever the user should be warned.
91 * @param message The message which should be shown to the user.
92 * @param duration The time that the message should be shown to the user.
94 void warning( const QString &message, int duration );
96 /**
97 * This signal should be emitted whenever the user should be noticed.
99 * @param message The message which should be shown to the user.
100 * @param duration The time that the message should be shown to the user.
102 void notice( const QString &message, int duration );
104 protected:
106 * This method can be used to calculate the viewport for a given text block.
108 * @note This method should be called at the end of the convertion, because it
109 * triggers QTextDocument to do the layout calculation.
111 DocumentViewport calculateViewport( QTextDocument *document, const QTextBlock &block );
114 * Returns the generator that owns this converter.
116 * @note May be null if the converter was not created for a generator.
118 * @since 0.7 (KDE 4.1)
120 TextDocumentGenerator* generator() const;
122 private:
123 TextDocumentConverterPrivate *d_ptr;
124 Q_DECLARE_PRIVATE( TextDocumentConverter )
125 Q_DISABLE_COPY( TextDocumentConverter )
129 * @brief QTextDocument-based Generator
131 * This generator provides a document in the form of a QTextDocument object,
132 * parsed using a specialized TextDocumentConverter.
134 class OKULAR_EXPORT TextDocumentGenerator : public Generator
136 /// @cond PRIVATE
137 friend class TextDocumentConverter;
138 /// @endcond
140 Q_OBJECT
142 public:
144 * Creates a new generator that uses the specified @p converter.
146 * @note the generator will take ownership of the converter, so you
147 * don't have to delete it yourself
149 TextDocumentGenerator( TextDocumentConverter *converter, QObject *parent, const QVariantList &args );
150 virtual ~TextDocumentGenerator();
152 // [INHERITED] load a document and fill up the pagesVector
153 bool loadDocument( const QString & fileName, QVector<Okular::Page*> & pagesVector );
155 // [INHERITED] perform actions on document / pages
156 bool canGeneratePixmap() const;
157 void generatePixmap( Okular::PixmapRequest * request );
159 // [INHERITED] print document using already configured QPrinter
160 bool print( QPrinter& printer );
162 // [INHERITED] text exporting
163 Okular::ExportFormat::List exportFormats() const;
164 bool exportTo( const QString &fileName, const Okular::ExportFormat &format );
166 const Okular::DocumentInfo* generateDocumentInfo();
167 const Okular::DocumentSynopsis* generateDocumentSynopsis();
169 protected:
170 bool doCloseDocument();
171 Okular::TextPage* textPage( Okular::Page *page );
173 private:
174 Q_DECLARE_PRIVATE( TextDocumentGenerator )
175 Q_DISABLE_COPY( TextDocumentGenerator )
177 Q_PRIVATE_SLOT( d_func(), void addAction( Action*, int, int ) )
178 Q_PRIVATE_SLOT( d_func(), void addAnnotation( Annotation*, int, int ) )
179 Q_PRIVATE_SLOT( d_func(), void addTitle( int, const QString&, const QTextBlock& ) )
180 Q_PRIVATE_SLOT( d_func(), void addMetaData( const QString&, const QString&, const QString& ) )
181 Q_PRIVATE_SLOT( d_func(), void addMetaData( DocumentInfo::Key, const QString& ) )
186 #endif