2007-01-13 23:15:28 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2007 by Tobias Koenig <tokoe@kde.org> *
|
|
|
|
* *
|
|
|
|
* 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 _OKULAR_TEXTDOCUMENTGENERATOR_H_
|
|
|
|
#define _OKULAR_TEXTDOCUMENTGENERATOR_H_
|
|
|
|
|
2014-10-27 21:35:06 +00:00
|
|
|
#include "okularcore_export.h"
|
2007-01-13 23:15:28 +00:00
|
|
|
|
2013-05-18 11:57:46 +00:00
|
|
|
#include "../interfaces/configinterface.h"
|
2011-06-01 08:31:44 +00:00
|
|
|
#include "document.h"
|
|
|
|
#include "generator.h"
|
2013-05-18 11:57:46 +00:00
|
|
|
#include "textdocumentsettings.h"
|
2007-01-13 23:15:28 +00:00
|
|
|
|
|
|
|
class QTextBlock;
|
|
|
|
class QTextDocument;
|
|
|
|
|
|
|
|
namespace Okular
|
|
|
|
{
|
2007-12-08 14:45:32 +00:00
|
|
|
class TextDocumentConverterPrivate;
|
2007-01-13 23:15:28 +00:00
|
|
|
class TextDocumentGenerator;
|
2007-09-14 13:31:55 +00:00
|
|
|
class TextDocumentGeneratorPrivate;
|
2007-01-13 23:15:28 +00:00
|
|
|
|
2014-10-27 21:35:06 +00:00
|
|
|
class OKULARCORE_EXPORT TextDocumentConverter : public QObject
|
2007-01-13 23:15:28 +00:00
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
2008-02-14 23:19:24 +00:00
|
|
|
friend class TextDocumentGenerator;
|
|
|
|
friend class TextDocumentGeneratorPrivate;
|
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a new generic converter.
|
|
|
|
*/
|
|
|
|
TextDocumentConverter();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
/**
|
|
|
|
* Destroys the generic converter.
|
|
|
|
*/
|
2019-12-18 11:51:13 +00:00
|
|
|
~TextDocumentConverter() override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2014-05-10 13:31:59 +00:00
|
|
|
/**
|
2017-08-24 23:17:31 +00:00
|
|
|
* Returns the generated QTextDocument object. The caller takes ownership of the QTextDocument
|
2014-05-10 13:31:59 +00:00
|
|
|
*
|
|
|
|
* @note there is no need to implement this one if you implement convertWithPassword
|
|
|
|
*/
|
|
|
|
virtual QTextDocument *convert(const QString &fileName);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
/**
|
|
|
|
* Returns the generated QTextDocument object.
|
|
|
|
*/
|
2014-05-10 13:31:59 +00:00
|
|
|
virtual Document::OpenResult convertWithPassword(const QString &fileName, const QString &password);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2014-05-10 13:31:59 +00:00
|
|
|
/**
|
|
|
|
* Returns the generated QTextDocument object. Will be null if convert didn't succeed
|
|
|
|
*/
|
|
|
|
QTextDocument *document();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
Q_SIGNALS:
|
|
|
|
/**
|
|
|
|
* Adds a new link object which is located between cursorBegin and
|
|
|
|
* cursorEnd to the generator.
|
|
|
|
*/
|
2020-02-20 09:59:54 +00:00
|
|
|
void addAction(Okular::Action *link, int cursorBegin, int cursorEnd);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
/**
|
|
|
|
* Adds a new annotation object which is located between cursorBegin and
|
|
|
|
* cursorEnd to the generator.
|
|
|
|
*/
|
2020-02-20 09:59:54 +00:00
|
|
|
void addAnnotation(Okular::Annotation *annotation, int cursorBegin, int cursorEnd);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
/**
|
|
|
|
* Adds a new title at the given level which is located as position to the generator.
|
|
|
|
*/
|
|
|
|
void addTitle(int level, const QString &title, const QTextBlock &position);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
/**
|
|
|
|
* Adds a set of meta data to the generator.
|
|
|
|
*/
|
2020-07-09 19:38:29 +00:00
|
|
|
void addMetaData(const QString &key, const QString &value, const QString &title); // clazy:exclude=overloaded-signal
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2019-12-19 22:18:31 +00:00
|
|
|
// TODO When we can do a BIC change rename one of the two addMetaData functions (or see if we can kill one)
|
2008-02-08 14:13:55 +00:00
|
|
|
/**
|
|
|
|
* Adds a set of meta data to the generator.
|
2008-02-14 23:23:14 +00:00
|
|
|
*
|
|
|
|
* @since 0.7 (KDE 4.1)
|
2008-02-08 14:13:55 +00:00
|
|
|
*/
|
2020-07-09 19:38:29 +00:00
|
|
|
void addMetaData(DocumentInfo::Key key, const QString &value); // clazy:exclude=overloaded-signal
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-29 08:17:45 +00:00
|
|
|
/**
|
|
|
|
* This signal should be emitted whenever an error occurred in the converter.
|
|
|
|
*
|
|
|
|
* @param message The message which should be shown to the user.
|
|
|
|
* @param duration The time that the message should be shown to the user.
|
|
|
|
*/
|
|
|
|
void error(const QString &message, int duration);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-29 08:17:45 +00:00
|
|
|
/**
|
|
|
|
* This signal should be emitted whenever the user should be warned.
|
|
|
|
*
|
|
|
|
* @param message The message which should be shown to the user.
|
|
|
|
* @param duration The time that the message should be shown to the user.
|
|
|
|
*/
|
|
|
|
void warning(const QString &message, int duration);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-29 08:17:45 +00:00
|
|
|
/**
|
|
|
|
* This signal should be emitted whenever the user should be noticed.
|
|
|
|
*
|
|
|
|
* @param message The message which should be shown to the user.
|
|
|
|
* @param duration The time that the message should be shown to the user.
|
|
|
|
*/
|
|
|
|
void notice(const QString &message, int duration);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
protected:
|
2014-05-10 13:31:59 +00:00
|
|
|
/**
|
|
|
|
* Sets the converted QTextDocument object.
|
|
|
|
*/
|
|
|
|
void setDocument(QTextDocument *document);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
/**
|
|
|
|
* This method can be used to calculate the viewport for a given text block.
|
|
|
|
*
|
2019-01-11 07:09:34 +00:00
|
|
|
* @note This method should be called at the end of the conversion, because it
|
2007-01-13 23:15:28 +00:00
|
|
|
* triggers QTextDocument to do the layout calculation.
|
|
|
|
*/
|
2007-01-19 16:33:58 +00:00
|
|
|
DocumentViewport calculateViewport(QTextDocument *document, const QTextBlock &block);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2008-02-14 23:19:24 +00:00
|
|
|
/**
|
|
|
|
* Returns the generator that owns this converter.
|
|
|
|
*
|
|
|
|
* @note May be null if the converter was not created for a generator.
|
2008-02-14 23:23:14 +00:00
|
|
|
*
|
|
|
|
* @since 0.7 (KDE 4.1)
|
2008-02-14 23:19:24 +00:00
|
|
|
*/
|
|
|
|
TextDocumentGenerator *generator() const;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
private:
|
2007-12-08 14:45:32 +00:00
|
|
|
TextDocumentConverterPrivate *d_ptr;
|
|
|
|
Q_DECLARE_PRIVATE(TextDocumentConverter)
|
|
|
|
Q_DISABLE_COPY(TextDocumentConverter)
|
2007-01-13 23:15:28 +00:00
|
|
|
};
|
|
|
|
|
2007-09-14 14:19:52 +00:00
|
|
|
/**
|
|
|
|
* @brief QTextDocument-based Generator
|
|
|
|
*
|
|
|
|
* This generator provides a document in the form of a QTextDocument object,
|
|
|
|
* parsed using a specialized TextDocumentConverter.
|
|
|
|
*/
|
2014-10-27 21:35:06 +00:00
|
|
|
class OKULARCORE_EXPORT TextDocumentGenerator : public Generator, public Okular::ConfigInterface
|
2007-01-13 23:15:28 +00:00
|
|
|
{
|
2007-09-01 22:48:28 +00:00
|
|
|
/// @cond PRIVATE
|
2007-01-13 23:15:28 +00:00
|
|
|
friend class TextDocumentConverter;
|
2007-09-01 22:48:28 +00:00
|
|
|
/// @endcond
|
2007-01-13 23:15:28 +00:00
|
|
|
|
|
|
|
Q_OBJECT
|
2013-05-18 11:57:46 +00:00
|
|
|
Q_INTERFACES(Okular::ConfigInterface)
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
public:
|
2007-09-14 14:19:52 +00:00
|
|
|
/**
|
|
|
|
* Creates a new generator that uses the specified @p converter.
|
|
|
|
*
|
2018-10-19 06:00:06 +00:00
|
|
|
* @param converter The text document converter.
|
2013-05-18 11:57:46 +00:00
|
|
|
* @param configName - see Okular::TextDocumentSettings
|
2018-10-19 06:00:06 +00:00
|
|
|
* @param parent The parent object.
|
|
|
|
* @param args The arguments.
|
2013-05-18 11:57:46 +00:00
|
|
|
*
|
2007-09-14 14:19:52 +00:00
|
|
|
* @note the generator will take ownership of the converter, so you
|
|
|
|
* don't have to delete it yourself
|
2013-05-18 11:57:46 +00:00
|
|
|
* @since 0.17 (KDE 4.11)
|
2007-09-14 14:19:52 +00:00
|
|
|
*/
|
2014-09-17 21:52:14 +00:00
|
|
|
TextDocumentGenerator(TextDocumentConverter *converter, const QString &configName, QObject *parent, const QVariantList &args);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2019-12-18 11:51:13 +00:00
|
|
|
~TextDocumentGenerator() override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
// [INHERITED] load a document and fill up the pagesVector
|
2017-03-02 19:38:50 +00:00
|
|
|
Document::OpenResult loadDocumentWithPassword(const QString &fileName, QVector<Okular::Page *> &pagesVector, const QString &password) override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-31 18:31:19 +00:00
|
|
|
// [INHERITED] perform actions on document / pages
|
2017-03-02 19:38:50 +00:00
|
|
|
bool canGeneratePixmap() const override;
|
|
|
|
void generatePixmap(Okular::PixmapRequest *request) override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-10-15 23:01:27 +00:00
|
|
|
// [INHERITED] print document using already configured QPrinter
|
2017-03-02 19:38:50 +00:00
|
|
|
bool print(QPrinter &printer) override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
// [INHERITED] text exporting
|
2017-03-02 19:38:50 +00:00
|
|
|
Okular::ExportFormat::List exportFormats() const override;
|
|
|
|
bool exportTo(const QString &fileName, const Okular::ExportFormat &format) override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2013-05-18 11:57:46 +00:00
|
|
|
// [INHERITED] config interface
|
|
|
|
/// By default checks if the default font has changed or not
|
2017-03-02 19:38:50 +00:00
|
|
|
bool reparseConfig() override;
|
2013-05-18 11:57:46 +00:00
|
|
|
/// Does nothing by default. You need to reimplement it in your generator
|
2017-03-02 19:38:50 +00:00
|
|
|
void addPages(KConfigDialog *dlg) override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2013-05-18 11:57:46 +00:00
|
|
|
/**
|
|
|
|
* Config skeleton for TextDocumentSettingsWidget
|
|
|
|
*
|
|
|
|
* You must use new construtor to initialize TextDocumentSettings,
|
2018-10-19 06:00:06 +00:00
|
|
|
* that contain @p configName .
|
2013-05-18 11:57:46 +00:00
|
|
|
*
|
|
|
|
* @since 0.17 (KDE 4.11)
|
|
|
|
*/
|
|
|
|
TextDocumentSettings *generalSettings();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2017-03-02 19:38:50 +00:00
|
|
|
Okular::DocumentInfo generateDocumentInfo(const QSet<DocumentInfo::Key> &keys) const override;
|
|
|
|
const Okular::DocumentSynopsis *generateDocumentSynopsis() override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-24 15:06:45 +00:00
|
|
|
protected:
|
2017-03-02 19:38:50 +00:00
|
|
|
bool doCloseDocument() override;
|
2018-02-01 18:42:37 +00:00
|
|
|
Okular::TextPage *textPage(Okular::TextRequest *request) override;
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2019-03-30 22:47:17 +00:00
|
|
|
/* @since 1.8 */
|
|
|
|
TextDocumentConverter *converter();
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2019-03-30 22:47:17 +00:00
|
|
|
/* @since 1.8 */
|
|
|
|
void setTextDocument(QTextDocument *textDocument);
|
2020-07-10 22:15:05 +00:00
|
|
|
|
2007-01-13 23:15:28 +00:00
|
|
|
private:
|
2007-09-14 13:31:55 +00:00
|
|
|
Q_DECLARE_PRIVATE(TextDocumentGenerator)
|
|
|
|
Q_DISABLE_COPY(TextDocumentGenerator)
|
2007-01-13 23:15:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|