generator.h 26.7 KB
Newer Older
1
/***************************************************************************
2
 *   Copyright (C) 2004-5 by Enrico Ros <eros.kde@email.it>                *
3
 *   Copyright (C) 2005   by Piotr Szymanski <niedakh@gmail.com>           *
4
 *   Copyright (C) 2008   by Albert Astals Cid <aacid@kde.org>             *
5 6 7
 *   Copyright (C) 2017   Klarälvdalens Datakonsult AB, a KDAB Group       *
 *                        company, info@kdab.com. Work sponsored by the    *
 *                        LiMux project of the city of Munich              *
8 9 10 11 12 13 14
 *                                                                         *
 *   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.                                   *
 ***************************************************************************/

15 16
#ifndef _OKULAR_GENERATOR_H_
#define _OKULAR_GENERATOR_H_
17

18
#include "okularcore_export.h"
19
#include "document.h"
20 21 22
#include "fontinfo.h"
#include "global.h"
#include "pagesize.h"
23

Yuri Chornoivan's avatar
Yuri Chornoivan committed
24 25 26 27 28 29 30
#include <QList>
#include <QObject>
#include <QSharedDataPointer>
#include <QSizeF>
#include <QString>
#include <QVariant>
#include <QVector>
31

Frederik Gladhorn's avatar
Frederik Gladhorn committed
32
#include <QMimeType>
33
#include <kpluginfactory.h>
34

35 36
#define OKULAR_EXPORT_PLUGIN(classname, json ) \
    static_assert(json[0] != '\0', "arg2 must be a string literal"); \
37
    K_PLUGIN_CLASS_WITH_JSON(classname, json)
38

39
class QByteArray;
40
class QMutex;
41
class QPrinter;
John Layt's avatar
John Layt committed
42
class QPrintDialog;
Vishesh Handa's avatar
Vishesh Handa committed
43
class QIcon;
44 45 46

namespace Okular {

Albert Astals Cid's avatar
Albert Astals Cid committed
47
class BackendOpaqueAction;
48 49
class DocumentFonts;
class DocumentInfo;
50
class DocumentObserver;
51 52
class DocumentSynopsis;
class EmbeddedFile;
53
class ExportFormatPrivate;
54
class FontInfo;
55
class GeneratorPrivate;
56 57
class Page;
class PixmapRequest;
58
class PixmapRequestPrivate;
Pino Toscano's avatar
Pino Toscano committed
59
class TextPage;
60 61
class TextRequest;
class TextRequestPrivate;
62
class NormalizedRect;
63
class SourceReference;
64

Tobias Koenig's avatar
Tobias Koenig committed
65
/* Note: on contents generation and asynchronous queries.
Yuri Chornoivan's avatar
Yuri Chornoivan committed
66
 * Many observers may want to request data synchronously or asynchronously.
Enrico Ros's avatar
Enrico Ros committed
67
 * - Sync requests. These should be done in-place.
68 69 70
 * - 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
71
 * Page they refer to, and a signal is emitted as soon as storing
72 73 74
 * (even for sync or async queries) has been done.
 */

Tobias Koenig's avatar
Tobias Koenig committed
75 76 77 78
/**
 * @short Defines an entry for the export menu
 *
 * This class encapsulates information about an export format.
79
 * Every Generator can support 0 or more export formats which can be
80
 * queried with @ref Generator::exportFormats().
Tobias Koenig's avatar
Tobias Koenig committed
81
 */
82
class OKULARCORE_EXPORT ExportFormat
Tobias Koenig's avatar
Tobias Koenig committed
83
{
84 85 86 87 88
    public:
        typedef QList<ExportFormat> List;

        /**
         * Creates an empty export format.
89 90
         *
         * @see isNull()
91 92 93 94 95 96 97 98 99
         */
        ExportFormat();

        /**
         * Creates a new export format.
         *
         * @param description The i18n'ed description of the format.
         * @param mimeType The supported mime type of the format.
         */
Frederik Gladhorn's avatar
Frederik Gladhorn committed
100
        ExportFormat( const QString &description, const QMimeType &mimeType );
101 102 103 104 105 106 107 108

        /**
         * Creates a new export format.
         *
         * @param icon The icon used in the GUI for this format.
         * @param description The i18n'ed description of the format.
         * @param mimeType The supported mime type of the format.
         */
Frederik Gladhorn's avatar
Frederik Gladhorn committed
109
        ExportFormat( const QIcon &icon, const QString &description, const QMimeType &mimeType );
110 111 112 113 114 115

        /**
         * Destroys the export format.
         */
        ~ExportFormat();

116 117 118
        /**
         * @internal
         */
119
        ExportFormat( const ExportFormat &other );
120 121 122 123

        /**
         * @internal
         */
124 125 126 127 128 129 130 131 132 133
        ExportFormat& operator=( const ExportFormat &other );

        /**
         * Returns the description of the format.
         */
        QString description() const;

        /**
         * Returns the mime type of the format.
         */
Frederik Gladhorn's avatar
Frederik Gladhorn committed
134
        QMimeType mimeType() const;
135 136 137 138

        /**
         * Returns the icon for GUI representations of the format.
         */
Vishesh Handa's avatar
Vishesh Handa committed
139
        QIcon icon() const;
140

141 142 143 144 145 146 147 148
        /**
         * Returns whether the export format is null/valid.
         *
         * An ExportFormat is null if the mimetype is not valid or the
         * description is empty, or both.
         */
        bool isNull() const;

149
        /**
150
         * Type of standard export format.
151
         */
152 153 154
        enum StandardExportFormat
        {
            PlainText,         ///< Plain text
155
            PDF,               ///< PDF, aka Portable Document Format
156 157
            OpenDocumentText,  ///< OpenDocument Text format @since 0.8 (KDE 4.2)
            HTML   ///< OpenDocument Text format @since 0.8 (KDE 4.2)
158 159 160 161 162 163
        };

        /**
         * Builds a standard format for the specified @p type .
         */
        static ExportFormat standardFormat( StandardExportFormat type );
164

165 166 167 168
        bool operator==( const ExportFormat &other ) const;

        bool operator!=( const ExportFormat &other ) const;

169
    private:
170
        /// @cond PRIVATE
171
        friend class ExportFormatPrivate;
172
        /// @endcond
173
        QSharedDataPointer<ExportFormatPrivate> d;
Tobias Koenig's avatar
Tobias Koenig committed
174 175
};

176 177 178
/**
 * @short [Abstract Class] The information generator.
 *
Pino Toscano's avatar
Pino Toscano committed
179 180 181
 * Most of class members are virtuals and some of them pure virtual. The pure
 * virtuals provide the minimal functionalities for a Generator, that is being
 * able to generate QPixmap for the Page 's of the Document.
182
 *
Pino Toscano's avatar
Pino Toscano committed
183 184 185 186 187 188 189 190
 * Implementing the other functions will make the Generator able to provide
 * more contents and/or functionalities (like text extraction).
 *
 * Generation/query is requested by the Document class only, and that
 * class stores the resulting data into Page s. The data will then be
 * displayed by the GUI components (PageView, ThumbnailList, etc..).
 *
 * @see PrintInterface, ConfigInterface, GuiInterface
191
 */
192
class OKULARCORE_EXPORT Generator : public QObject
193
{
194
    /// @cond PRIVATE
195 196
    friend class PixmapGenerationThread;
    friend class TextPageGenerationThread;
197
    /// @endcond
198

Pino Toscano's avatar
Pino Toscano committed
199 200
    Q_OBJECT

201
    public:
Pino Toscano's avatar
Pino Toscano committed
202 203 204 205
        /**
         * Describe the possible optional features that a Generator can
         * provide.
         */
206 207
        enum GeneratorFeature
        {
208
            Threaded,          ///< Whether the Generator supports asynchronous generation of pictures or text pages
209
            TextExtraction,    ///< Whether the Generator can extract text from the document in the form of TextPage's
210
            ReadRawData,       ///< Whether the Generator can read a document directly from its raw data.
211
            FontInfo,          ///< Whether the Generator can provide information about the fonts used in the document
John Layt's avatar
John Layt committed
212 213 214
            PageSizes,         ///< Whether the Generator can change the size of the document pages.
            PrintNative,       ///< Whether the Generator supports native cross-platform printing (QPainter-based).
            PrintPostscript,   ///< Whether the Generator supports postscript-based file printing.
215
            PrintToFile,       ///< Whether the Generator supports export to PDF & PS through the Print Dialog
216
            TiledRendering,    ///< Whether the Generator can render tiles @since 0.16 (KDE 4.10)
217 218
            SwapBackingFile,   ///< Whether the Generator can hot-swap the file it's reading from @since 1.3
            SupportsCancelling ///< Whether the Generator can cancel requests @since 1.4
219 220
        };

221
        /**
222
         * Creates a new generator.
223
         */
Yuri Chornoivan's avatar
Yuri Chornoivan committed
224
        explicit Generator(QObject* parent = nullptr, const QVariantList& args = QVariantList());
225 226 227 228 229 230 231 232 233 234

        /**
         * Destroys the generator.
         */
        virtual ~Generator();

        /**
         * Loads the document with the given @p fileName and fills the
         * @p pagesVector with the parsed pages.
         *
235 236
         * @note If you implement the WithPassword variants you don't need to implement this one
         *
237 238
         * @returns true on success, false otherwise.
         */
239
        virtual bool loadDocument( const QString & fileName, QVector< Page * > & pagesVector );
240

241 242 243 244
        /**
         * Loads the document from the raw data @p fileData and fills the
         * @p pagesVector with the parsed pages.
         *
245 246
         * @note If you implement the WithPassword variants you don't need to implement this one
         *
247 248 249 250 251 252
         * @note the Generator has to have the feature @ref ReadRawData enabled
         *
         * @returns true on success, false otherwise.
         */
        virtual bool loadDocumentFromData( const QByteArray & fileData, QVector< Page * > & pagesVector );

253 254 255 256 257 258
        /**
         * Loads the document with the given @p fileName and @p password and fills the
         * @p pagesVector with the parsed pages.
         *
         * @note Do not implement this if your format doesn't support passwords, it'll cleanly call loadDocument()
         *
Fabio D'Urso's avatar
Fabio D'Urso committed
259 260
         * @since 0.20 (KDE 4.14)
         *
261 262 263 264 265 266 267 268 269 270 271 272
         * @returns a LoadResult defining the result of the operation
         */
        virtual Document::OpenResult loadDocumentWithPassword( const QString & fileName, QVector< Page * > & pagesVector, const QString &password );

        /**
         * Loads the document from the raw data @p fileData and @p password and fills the
         * @p pagesVector with the parsed pages.
         *
         * @note Do not implement this if your format doesn't support passwords, it'll cleanly call loadDocumentFromData()
         *
         * @note the Generator has to have the feature @ref ReadRawData enabled
         *
Fabio D'Urso's avatar
Fabio D'Urso committed
273 274
         * @since 0.20 (KDE 4.14)
         *
275 276 277 278
         * @returns a LoadResult defining the result of the operation
         */
        virtual Document::OpenResult loadDocumentFromDataWithPassword( const QByteArray & fileData, QVector< Page * > & pagesVector, const QString &password );

279 280 281 282 283 284 285 286 287 288 289 290
        /**
         * Describes the result of an swap file operation.
         *
         * @since 1.3
         */
        enum SwapBackingFileResult
        {
            SwapBackingFileError,               //< The document could not be swapped
            SwapBackingFileNoOp,                //< The document was swapped and nothing needs to be done
            SwapBackingFileReloadInternalData   //< The document was swapped and internal data (forms, annotations, etc) needs to be reloaded
        };

291 292 293 294 295 296
        /**
         * Changes the path of the file we are reading from. The new path must
         * point to a copy of the same document.
         *
         * @note the Generator has to have the feature @ref SwapBackingFile enabled
         *
297
         * @since 1.3
298
         */
Albert Astals Cid's avatar
Albert Astals Cid committed
299
        virtual SwapBackingFileResult swapBackingFile( const QString & newFileName, QVector<Okular::Page*> & newPagesVector );
300

301 302 303 304 305 306
        /**
         * This method is called when the document is closed and not used
         * any longer.
         *
         * @returns true on success, false otherwise.
         */
307
        bool closeDocument();
Piotr Szymanski's avatar
Piotr Szymanski committed
308

309
        /**
310 311
         * This method returns whether the generator is ready to
         * handle a new pixmap request.
312
         */
313
        virtual bool canGeneratePixmap() const;
Piotr Szymanski's avatar
Piotr Szymanski committed
314

315
        /**
316 317
         * This method can be called to trigger the generation of
         * a new pixmap as described by @p request.
318
         */
319
        virtual void generatePixmap( PixmapRequest * request );
320

321 322 323 324
        /**
         * This method returns whether the generator is ready to
         * handle a new text page request.
         */
325
        virtual bool canGenerateTextPage() const;
326

327
        /**
328 329
         * This method can be called to trigger the generation of
         * a text page for the given @p page.
330
         *
331
         * The generation is done in the calling thread.
332
         *
333
         * @see TextPage
334
         */
335
        void generateTextPage( Page * page );
336 337

        /**
338
         * Returns the general information object of the document.
Albert Astals Cid's avatar
douc++  
Albert Astals Cid committed
339 340
         *
         * Changed signature in okular version 0.21
341
         */
342
        virtual DocumentInfo generateDocumentInfo( const QSet<DocumentInfo::Key> &keys ) const;
343 344 345 346 347 348 349 350

        /**
         * Returns the 'table of content' object of the document or 0 if
         * no table of content is available.
         */
        virtual const DocumentSynopsis * generateDocumentSynopsis();

        /**
Yuri Chornoivan's avatar
Yuri Chornoivan committed
351
         * Returns the 'list of embedded fonts' object of the specified \p page
352 353
         * of the document.
         *
354
         * \param page a page of the document, starting from 0 - -1 indicates all
355
         * the other fonts
356
         */
357
        virtual FontInfo::List fontsForPage( int page );
358 359 360 361 362 363 364 365 366 367 368 369

        /**
         * Returns the 'list of embedded files' object of the document or 0 if
         * no list of embedded files is available.
         */
        virtual const QList<EmbeddedFile*> * embeddedFiles() const;

        /**
         * This enum identifies the metric of the page size.
         */
        enum PageSizeMetric
        {
370
          None,   ///< The page size is not defined in a physical metric.
371 372
          Points, ///< The page size is given in 1/72 inches.
          Pixels  ///< The page size is given in screen pixels @since 0.19 (KDE 4.13)
373 374 375
        };

        /**
376
         * This method returns the metric of the page size. Default is @ref None.
377 378 379 380
         */
        virtual PageSizeMetric pagesSizeMetric() const;

        /**
Yuri Chornoivan's avatar
Yuri Chornoivan committed
381
         * Returns whether the given @p action is allowed in the document.
382
         * @see @ref Okular::Permission
383
         */
384
        virtual bool isAllowed( Permission action ) const;
385

386 387 388
        /**
         * This method is called when the orientation has been changed by the user.
         */
389
        virtual void rotationChanged( Rotation orientation, Rotation oldOrientation );
390 391

        /**
392
         * Returns the list of supported page sizes.
393
         */
394
        virtual PageSize::List pageSizes() const;
395 396

        /**
397
         * This method is called when the page size has been changed by the user.
398
         */
399
        virtual void pageSizeChanged( const PageSize &pageSize, const PageSize &oldPageSize );
400 401 402 403

        /**
         * This method is called to print the document to the given @p printer.
         */
404
        virtual bool print( QPrinter &printer );
405

406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421
        /**
         * Possible print errors
         * @since 0.11 (KDE 4.5)
         */
        enum PrintError
        {
            NoPrintError,                       ///< There was no print error
            UnknownPrintError,
            TemporaryFileOpenPrintError,
            FileConversionPrintError,
            PrintingProcessCrashPrintError,
            PrintingProcessStartPrintError,
            PrintToFilePrintError,
            InvalidPrinterStatePrintError,
            UnableToFindFilePrintError,
            NoFileToPrintError,
422 423
            NoBinaryToPrintError,
            InvalidPageSizePrintError ///< @since 0.18.2 (KDE 4.12.2)
424 425
        };
        
426 427 428 429
        /**
         * This method returns the meta data of the given @p key with the given @p option
         * of the document.
         */
430
        virtual QVariant metaData( const QString &key, const QVariant &option ) const;
431 432 433 434

        /**
         * Returns the list of additional supported export formats.
         */
Tobias Koenig's avatar
Tobias Koenig committed
435
        virtual ExportFormat::List exportFormats() const;
436 437

        /**
Tobias Koenig's avatar
Tobias Koenig committed
438 439
         * This method is called to export the document in the given @p format and save it
         * under the given @p fileName. The format must be one of the supported export formats.
440
         */
Tobias Koenig's avatar
Tobias Koenig committed
441
        virtual bool exportTo( const QString &fileName, const ExportFormat &format );
442

443 444 445 446 447 448 449
        /**
         * This method is called to know which wallet data should be used for the given file name.
         * Unless you have very special requirements to where wallet data should be stored you
         * don't need to reimplement this method.
         */
        virtual void walletDataForFile( const QString &fileName, QString *walletName, QString *walletFolder, QString *walletKey ) const;

450 451 452
        /**
         * Query for the specified @p feature.
         */
453
        bool hasFeature( GeneratorFeature feature ) const;
454

455 456 457 458 459 460 461
        /**
         * Update DPI of the generator
         *
         * @since 0.19 (KDE 4.13)
         */
        void setDPI(const QSizeF &dpi);

462 463 464
        /**
         * Returns the 'layers model' object of the document or NULL if
         * layers model is not available.
465 466
         *
         * @since 0.24
467 468 469
         */
        virtual QAbstractItemModel * layersModel() const;

Albert Astals Cid's avatar
Albert Astals Cid committed
470 471 472 473 474
        /**
         * Calls the backend to execute an BackendOpaqueAction
         */
        virtual void opaqueAction( const BackendOpaqueAction *action );

475 476
    Q_SIGNALS:
        /**
Pino Toscano's avatar
Pino Toscano committed
477
         * This signal should be emitted whenever an error occurred in the generator.
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
         *
         * @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 );

        /**
         * 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 );

        /**
         * 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 );
499

Piotr Szymanski's avatar
Piotr Szymanski committed
500
    protected:
501
        /**
502
         * This method must be called when the pixmap request triggered by generatePixmap()
503 504
         * has been finished.
         */
Tobias Koenig's avatar
Tobias Koenig committed
505
        void signalPixmapRequestDone( PixmapRequest * request );
506

507 508 509 510 511
        /**
         * This method must be called when a text generation has been finished.
         */
        void signalTextGenerationDone( Page *page, TextPage *textPage );

512 513 514 515 516 517 518 519
        /**
         * This method is called when the document is closed and not used
         * any longer.
         *
         * @returns true on success, false otherwise.
         */
        virtual bool doCloseDocument() = 0;

520
        /**
521 522 523
         * Returns the image of the page as specified in
         * the passed pixmap @p request.
         *
524 525
         * Must return a null image if the request was cancelled and the generator supports cancelling
         *
526 527
         * @warning this method may be executed in its own separated thread if the
         * @ref Threaded is enabled!
528
         */
529
        virtual QImage image( PixmapRequest *page );
530

531
        /**
532 533 534
         * Returns the text page for the given @p request.
         *
         * Must return a null pointer if the request was cancelled and the generator supports cancelling
535
         *
536 537
         * @warning this method may be executed in its own separated thread if the
         * @ref Threaded is enabled!
538 539
         *
         * @since 1.4
540
         */
541
        virtual TextPage* textPage( TextRequest *request );
542

543 544 545
        /**
         * Returns a pointer to the document.
         */
Pino Toscano's avatar
Pino Toscano committed
546
        const Document * document() const;
547

548 549 550 551 552
        /**
         * Toggle the @p feature .
         */
        void setFeature( GeneratorFeature feature, bool on = true );

553 554 555 556
        /**
         * Internal document setting
         */
        enum DocumentMetaDataKey {
557 558 559 560
            PaperColorMetaData,         ///< Returns (QColor) the paper color if set in Settings or the default color (white) if option is true (otherwise returns a non initialized QColor)
            TextAntialiasMetaData,      ///< Returns (bool) text antialias from Settings (option is not used)
            GraphicsAntialiasMetaData,  ///< Returns (bool)graphic antialias from Settings (option is not used)
            TextHintingMetaData         ///< Returns (bool)text hinting from Settings (option is not used)
561 562 563 564 565 566 567 568
        };

        /**
         * Request a meta data of the Document, if available, like an internal
         * setting.
         *
         * @since 1.1
         */
Albert Astals Cid's avatar
Albert Astals Cid committed
569
        QVariant documentMetaData( const DocumentMetaDataKey key, const QVariant &option = QVariant() ) const;
570

571 572 573 574
        /**
         * Request a meta data of the Document, if available, like an internal
         * setting.
         */
575
        OKULARCORE_DEPRECATED QVariant documentMetaData( const QString &key, const QVariant &option = QVariant() ) const;
576

577 578 579 580 581
        /**
         * Return the pointer to a mutex the generator can use freely.
         */
        QMutex* userMutex() const;

582 583 584 585 586 587 588 589 590
        /**
         * Set the bounding box of a page after the page has already been handed
         * to the Document. Call this instead of Page::setBoundingBox() to ensure
         * that all observers are notified.
         *
         * @since 0.7 (KDE 4.1)
         */
        void updatePageBoundingBox( int page, const NormalizedRect & boundingBox );

591 592 593 594 595 596
        /**
         * Returns DPI, previously set via setDPI()
         * @since 0.19 (KDE 4.13)
         */
        QSizeF dpi() const;

597 598 599 600 601 602 603 604
    protected Q_SLOTS:
        /**
         * Gets the font data for the given font
         *
         * @since 0.8 (KDE 4.1)
         */
        void requestFontData(const Okular::FontInfo &font, QByteArray *data);

605 606 607 608 609
        /**
         * Returns the last print error in case print() failed
         * @since 0.11 (KDE 4.5)
         */
        Okular::Generator::PrintError printError() const;
610

611 612 613 614 615 616 617
        /**
         * This method can be called to trigger a partial pixmap update for the given request
         * Make sure you call it in a way it's executed in the main thread.
         * @since 1.3
         */
        void signalPartialPixmapRequest( Okular::PixmapRequest *request, const QImage &image );

618
    protected:
619
        /// @cond PRIVATE
620
        Generator(GeneratorPrivate &dd, QObject *parent, const QVariantList &args);
621 622
        Q_DECLARE_PRIVATE( Generator )
        GeneratorPrivate *d_ptr;
623

624
        friend class Document;
625
        friend class DocumentPrivate;
626
        /// @endcond PRIVATE
627

628 629 630 631 632
    private:
        Q_DISABLE_COPY( Generator )

        Q_PRIVATE_SLOT( d_func(), void pixmapGenerationFinished() )
        Q_PRIVATE_SLOT( d_func(), void textpageGenerationFinished() )
633 634 635 636 637
};

/**
 * @short Describes a pixmap type request.
 */
638
class OKULARCORE_EXPORT PixmapRequest
639
{
640
    friend class Document;
641
    friend class DocumentPrivate;
642 643

    public:
644 645 646 647 648 649 650 651
        enum PixmapRequestFeature
        {
            NoFeature = 0,
            Asynchronous = 1,
            Preload = 2
        };
        Q_DECLARE_FLAGS( PixmapRequestFeatures, PixmapRequestFeature )

652 653 654
        /**
         * Creates a new pixmap request.
         *
655
         * @param observer The observer.
656 657 658 659
         * @param pageNumber The page number.
         * @param width The width of the page.
         * @param height The height of the page.
         * @param priority The priority of the request.
660
         * @param features The features of generation.
661
         */
662
        PixmapRequest( DocumentObserver *observer, int pageNumber, int width, int height, int priority, PixmapRequestFeatures features );
663 664 665 666 667 668 669

        /**
         * Destroys the pixmap request.
         */
        ~PixmapRequest();

        /**
670
         * Returns the observer of the request.
671
         */
672
        DocumentObserver *observer() const;
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703

        /**
         * Returns the page number of the request.
         */
        int pageNumber() const;

        /**
         * Returns the page width of the requested pixmap.
         */
        int width() const;

        /**
         * Returns the page height of the requested pixmap.
         */
        int height() const;

        /**
         * Returns the priority (less it better, 0 is maximum) of the
         * request.
         */
        int priority() const;

        /**
         * Returns whether the generation should be done synchronous or
         * asynchronous.
         *
         * If asynchronous, the pixmap is created in a thread and the observer
         * is notified when the job is done.
         */
        bool asynchronous() const;

704 705 706 707 708 709
        /**
         * Returns whether the generation request is for a page that is not important
         * i.e. it's just for speeding up future rendering
         */
        bool preload() const;

710 711 712 713 714
        /**
         * Returns a pointer to the page where the pixmap shall be generated for.
         */
        Page *page() const;

715
        /**
716 717
         * Sets whether the generator should render only the given normalized
         * rect or the entire page
718 719
         *
         * @since 0.16 (KDE 4.10)
720 721 722 723 724 725
         */
        void setTile( bool tile );

        /**
         * Returns whether the generator should render just the region given by
         * normalizedRect() or the entire page.
726 727
         *
         * @since 0.16 (KDE 4.10)
728 729 730 731 732
         */
        bool isTile() const;

        /**
         * Sets the region of the page to request.
733 734
         *
         * @since 0.16 (KDE 4.10)
735
         */
736
        void setNormalizedRect( const NormalizedRect &rect );
737 738

        /**
739
         * Returns the normalized region of the page to request.
740 741
         *
         * @since 0.16 (KDE 4.10)
742
         */
743
        const NormalizedRect& normalizedRect() const;
Mailson Menezes's avatar
Mailson Menezes committed
744

745 746 747 748 749 750 751 752 753 754 755 756 757 758
        /**
         * Sets whether the request should report back updates if possible
         *
         * @since 1.3
         */
        void setPartialUpdatesWanted(bool partialUpdatesWanted);

        /**
         * Should the request report back updates if possible?
         *
         * @since 1.3
         */
        bool partialUpdatesWanted() const;

759 760 761 762 763 764 765
        /**
         * Should the request be aborted if possible?
         *
         * @since 1.4
         */
        bool shouldAbortRender() const;

Pino Toscano's avatar
Pino Toscano committed
766 767 768
    private:
        Q_DISABLE_COPY( PixmapRequest )

769 770
        friend class PixmapRequestPrivate;
        PixmapRequestPrivate* const d;
771 772
};

773 774 775 776 777 778 779 780 781 782 783
/**
 * @short Describes a text request.
 *
 * @since 1.4
 */
class OKULARCORE_EXPORT TextRequest
{
    public:
        /**
         * Creates a new text request.
         */
Yuri Chornoivan's avatar
Yuri Chornoivan committed
784
        explicit TextRequest( Page *page );
785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809

        TextRequest();

        /**
         * Destroys the pixmap request.
         */
        ~TextRequest();

        /**
         * Returns a pointer to the page where the pixmap shall be generated for.
         */
        Page *page() const;

        /**
         * Should the request be aborted if possible?
         */
        bool shouldAbortExtraction() const;

    private:
        Q_DISABLE_COPY( TextRequest )

        friend TextRequestPrivate;
        TextRequestPrivate* const d;
};

810 811
}

812
Q_DECLARE_METATYPE(Okular::Generator::PrintError)
813
Q_DECLARE_METATYPE(Okular::PixmapRequest*)
814

815 816 817
#define OkularGeneratorInterface_iid "org.kde.okular.Generator"
Q_DECLARE_INTERFACE(Okular::Generator, OkularGeneratorInterface_iid)

818
#ifndef QT_NO_DEBUG_STREAM
819
OKULARCORE_EXPORT QDebug operator<<( QDebug str, const Okular::PixmapRequest &req );
820
#endif
821

822
#endif
823 824

/* kate: replace-tabs on; indent-width 4; */