File indexing completed on 2024-04-28 04:32:46
0001 /* 0002 SPDX-FileCopyrightText: 2007 Tobias Koenig <tokoe@kde.org> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef _OKULAR_TEXTDOCUMENTGENERATOR_H_ 0008 #define _OKULAR_TEXTDOCUMENTGENERATOR_H_ 0009 0010 #include "okularcore_export.h" 0011 0012 #include "../interfaces/configinterface.h" 0013 #include "document.h" 0014 #include "generator.h" 0015 #include "textdocumentsettings.h" 0016 0017 class QTextBlock; 0018 class QTextDocument; 0019 0020 namespace Okular 0021 { 0022 class TextDocumentConverterPrivate; 0023 class TextDocumentGenerator; 0024 class TextDocumentGeneratorPrivate; 0025 0026 class OKULARCORE_EXPORT TextDocumentConverter : public QObject 0027 { 0028 Q_OBJECT 0029 0030 friend class TextDocumentGenerator; 0031 friend class TextDocumentGeneratorPrivate; 0032 0033 public: 0034 /** 0035 * Creates a new generic converter. 0036 */ 0037 TextDocumentConverter(); 0038 0039 /** 0040 * Destroys the generic converter. 0041 */ 0042 ~TextDocumentConverter() override; 0043 0044 /** 0045 * Returns the generated QTextDocument object. The caller takes ownership of the QTextDocument 0046 * 0047 * @note there is no need to implement this one if you implement convertWithPassword 0048 */ 0049 virtual QTextDocument *convert(const QString &fileName); 0050 0051 /** 0052 * Returns the generated QTextDocument object. 0053 */ 0054 virtual Document::OpenResult convertWithPassword(const QString &fileName, const QString &password); 0055 0056 /** 0057 * Returns the generated QTextDocument object. Will be null if convert didn't succeed 0058 */ 0059 QTextDocument *document(); 0060 0061 Q_SIGNALS: 0062 /** 0063 * Adds a new link object which is located between cursorBegin and 0064 * cursorEnd to the generator. 0065 */ 0066 void addAction(Okular::Action *link, int cursorBegin, int cursorEnd); 0067 0068 /** 0069 * Adds a new annotation object which is located between cursorBegin and 0070 * cursorEnd to the generator. 0071 */ 0072 void addAnnotation(Okular::Annotation *annotation, int cursorBegin, int cursorEnd); 0073 0074 /** 0075 * Adds a new title at the given level which is located as position to the generator. 0076 */ 0077 void addTitle(int level, const QString &title, const QTextBlock &position); 0078 0079 /** 0080 * Adds a set of meta data to the generator. 0081 * 0082 * @since 0.7 (KDE 4.1) 0083 */ 0084 void addMetaData(DocumentInfo::Key key, const QString &value); 0085 0086 /** 0087 * This signal should be emitted whenever an error occurred in the converter. 0088 * 0089 * @param message The message which should be shown to the user. 0090 * @param duration The time that the message should be shown to the user. 0091 */ 0092 void error(const QString &message, int duration); 0093 0094 /** 0095 * This signal should be emitted whenever the user should be warned. 0096 * 0097 * @param message The message which should be shown to the user. 0098 * @param duration The time that the message should be shown to the user. 0099 */ 0100 void warning(const QString &message, int duration); 0101 0102 /** 0103 * This signal should be emitted whenever the user should be noticed. 0104 * 0105 * @param message The message which should be shown to the user. 0106 * @param duration The time that the message should be shown to the user. 0107 */ 0108 void notice(const QString &message, int duration); 0109 0110 protected: 0111 /** 0112 * Sets the converted QTextDocument object. 0113 */ 0114 void setDocument(QTextDocument *document); 0115 0116 /** 0117 * This method can be used to calculate the viewport for a given text block. 0118 * 0119 * @note This method should be called at the end of the conversion, because it 0120 * triggers QTextDocument to do the layout calculation. 0121 */ 0122 DocumentViewport calculateViewport(QTextDocument *document, const QTextBlock &block); 0123 0124 /** 0125 * Returns the generator that owns this converter. 0126 * 0127 * @note May be null if the converter was not created for a generator. 0128 * 0129 * @since 0.7 (KDE 4.1) 0130 */ 0131 TextDocumentGenerator *generator() const; 0132 0133 private: 0134 TextDocumentConverterPrivate *d_ptr; 0135 Q_DECLARE_PRIVATE(TextDocumentConverter) 0136 Q_DISABLE_COPY(TextDocumentConverter) 0137 }; 0138 0139 /** 0140 * @brief QTextDocument-based Generator 0141 * 0142 * This generator provides a document in the form of a QTextDocument object, 0143 * parsed using a specialized TextDocumentConverter. 0144 */ 0145 class OKULARCORE_EXPORT TextDocumentGenerator : public Generator, public Okular::ConfigInterface 0146 { 0147 /// @cond PRIVATE 0148 friend class TextDocumentConverter; 0149 /// @endcond 0150 0151 Q_OBJECT 0152 Q_INTERFACES(Okular::ConfigInterface) 0153 0154 public: 0155 /** 0156 * Creates a new generator that uses the specified @p converter. 0157 * 0158 * @param converter The text document converter. 0159 * @param configName - see Okular::TextDocumentSettings 0160 * @param parent The parent object. 0161 * @param args The arguments. 0162 * 0163 * @note the generator will take ownership of the converter, so you 0164 * don't have to delete it yourself 0165 * @since 0.17 (KDE 4.11) 0166 */ 0167 TextDocumentGenerator(TextDocumentConverter *converter, const QString &configName, QObject *parent, const QVariantList &args); 0168 0169 ~TextDocumentGenerator() override; 0170 0171 // [INHERITED] load a document and fill up the pagesVector 0172 Document::OpenResult loadDocumentWithPassword(const QString &fileName, QVector<Okular::Page *> &pagesVector, const QString &password) override; 0173 0174 // [INHERITED] perform actions on document / pages 0175 bool canGeneratePixmap() const override; 0176 void generatePixmap(Okular::PixmapRequest *request) override; 0177 0178 // [INHERITED] print document using already configured QPrinter 0179 Document::PrintError print(QPrinter &printer) override; 0180 0181 // [INHERITED] text exporting 0182 Okular::ExportFormat::List exportFormats() const override; 0183 bool exportTo(const QString &fileName, const Okular::ExportFormat &format) override; 0184 0185 // [INHERITED] config interface 0186 /// By default checks if the default font has changed or not 0187 bool reparseConfig() override; 0188 /// Does nothing by default. You need to reimplement it in your generator 0189 void addPages(KConfigDialog *dlg) override; 0190 0191 /** 0192 * Config skeleton for TextDocumentSettingsWidget 0193 * 0194 * You must use new construtor to initialize TextDocumentSettings, 0195 * that contain @p configName . 0196 * 0197 * @since 0.17 (KDE 4.11) 0198 */ 0199 TextDocumentSettings *generalSettings(); 0200 0201 Okular::DocumentInfo generateDocumentInfo(const QSet<DocumentInfo::Key> &keys) const override; 0202 const Okular::DocumentSynopsis *generateDocumentSynopsis() override; 0203 0204 protected: 0205 bool doCloseDocument() override; 0206 Okular::TextPage *textPage(Okular::TextRequest *request) override; 0207 0208 /* @since 1.8 */ 0209 TextDocumentConverter *converter(); 0210 0211 /* @since 1.8 */ 0212 void setTextDocument(QTextDocument *textDocument); 0213 0214 private: 0215 Q_DECLARE_PRIVATE(TextDocumentGenerator) 0216 Q_DISABLE_COPY(TextDocumentGenerator) 0217 }; 0218 0219 } 0220 0221 #endif