File indexing completed on 2024-04-28 04:32:44

0001 /*
0002     SPDX-FileCopyrightText: 2004 Enrico Ros <eros.kde@email.it>
0003 
0004     Work sponsored by the LiMux project of the city of Munich:
0005     SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 
0010 #ifndef _OKULAR_PAGE_H_
0011 #define _OKULAR_PAGE_H_
0012 
0013 #include "area.h"
0014 #include "global.h"
0015 #include "okularcore_export.h"
0016 #include "textpage.h"
0017 
0018 class QPixmap;
0019 
0020 class PagePainter;
0021 
0022 namespace Okular
0023 {
0024 class Annotation;
0025 class Document;
0026 class DocumentObserver;
0027 class DocumentPrivate;
0028 class FormField;
0029 class PagePrivate;
0030 class PageTransition;
0031 class SourceReference;
0032 class TextSelection;
0033 class Tile;
0034 
0035 /**
0036  * @short Collector for all the data belonging to a page.
0037  *
0038  * The Page class contains pixmaps (referenced using observers id as key),
0039  * a search page (a class used internally for retrieving text), rect classes
0040  * (that describe links or other active areas in the current page) and more.
0041  *
0042  * All coordinates are normalized to the page, so {x,y} are valid in [0,1]
0043  * range as long as NormalizedRect components.
0044  *
0045  * Note: The class takes ownership of all objects.
0046  */
0047 class OKULARCORE_EXPORT Page
0048 {
0049 public:
0050     /**
0051      * An action to be executed when particular events happen.
0052      */
0053     enum PageAction {
0054         Opening, ///< An action to be executed when the page is "opened".
0055         Closing  ///< An action to be executed when the page is "closed".
0056     };
0057 
0058     /**
0059      * Creates a new page.
0060      *
0061      * @param pageNumber The number of the page in the document.
0062      * @param width The width of the page.
0063      * @param height The height of the page.
0064      * @param orientation The orientation of the page
0065      */
0066     Page(uint pageNumber, double width, double height, Rotation orientation);
0067 
0068     /**
0069      * Destroys the page.
0070      */
0071     ~Page();
0072 
0073     /**
0074      * Returns the number of the page in the document.
0075      */
0076     int number() const;
0077 
0078     /**
0079      * Returns the orientation of the page as defined by the document.
0080      */
0081     Rotation orientation() const;
0082 
0083     /**
0084      * Returns the rotation of the page as defined by the user.
0085      */
0086     Rotation rotation() const;
0087 
0088     /**
0089      * Returns the total orientation which is the original orientation plus
0090      * the user defined rotation.
0091      */
0092     Rotation totalOrientation() const;
0093 
0094     /**
0095      * Returns the width of the page.
0096      */
0097     double width() const;
0098 
0099     /**
0100      * Returns the height of the page.
0101      */
0102     double height() const;
0103 
0104     /**
0105      * Returns the ration (height / width) of the page.
0106      */
0107     double ratio() const;
0108 
0109     /**
0110      * Returns the bounding box of the page content in normalized [0,1] coordinates,
0111      * in terms of the upright orientation (Rotation0).
0112      * If it has not been computed yet, returns the full page (i.e., (0, 0, 1, 1)).
0113      * Note that the bounding box may be null if the page is blank.
0114      *
0115      * @since 0.7 (KDE 4.1)
0116      */
0117     NormalizedRect boundingBox() const;
0118 
0119     /**
0120      * Returns whether the bounding box of the page has been computed.
0121      * Note that even if the bounding box is computed, it may be null if the page is blank.
0122      *
0123      * @since 0.7 (KDE 4.1)
0124      */
0125     bool isBoundingBoxKnown() const;
0126 
0127     /**
0128      * Sets the bounding box of the page content in normalized [0,1] coordinates,
0129      * in terms of the upright orientation (Rotation0).
0130      * (This does not inform the document's observers, call Document::SetPageBoundingBox
0131      * instead if you want that.)
0132      *
0133      * @since 0.7 (KDE 4.1)
0134      */
0135     void setBoundingBox(const NormalizedRect &bbox);
0136 
0137     /**
0138      * Returns whether the page of size @p width x @p height has a @p pixmap
0139      * in the region given by @p rect for the given @p observer
0140      * If there is a partially rendered pixmap the answer is false.
0141      */
0142     bool hasPixmap(DocumentObserver *observer, int width = -1, int height = -1, const NormalizedRect &rect = NormalizedRect()) const;
0143 
0144     /**
0145      * Sets the size of the page (in screen pixels) if there is a TilesManager.
0146      */
0147     void setPageSize(DocumentObserver *observer, int width, int height);
0148 
0149     /**
0150      * Returns whether the page provides a text page (@ref TextPage).
0151      */
0152     bool hasTextPage() const;
0153 
0154     /**
0155      * Returns whether the page has an object rect which includes the point (@p x, @p y)
0156      * at scale (@p xScale, @p yScale).
0157      */
0158     bool hasObjectRect(double x, double y, double xScale, double yScale) const;
0159 
0160     /**
0161      * Returns whether the page provides highlighting for the observer with the
0162      * given @p id.
0163      */
0164     bool hasHighlights(int id = -1) const;
0165 
0166     /**
0167      * Returns whether the page provides a transition effect.
0168      */
0169     bool hasTransition() const;
0170 
0171     /**
0172      * Returns whether the page provides annotations.
0173      */
0174     bool hasAnnotations() const;
0175 
0176     /**
0177      * Returns the bounding rect of the text which matches the following criteria
0178      * or 0 if the search is not successful.
0179      *
0180      * @param id An unique id for this search.
0181      * @param text The search text.
0182      * @param direction The direction of the search (@ref SearchDirection)
0183      * @param caseSensitivity If Qt::CaseSensitive, the search is case sensitive; otherwise
0184      *                        the search is case insensitive.
0185      * @param lastRect If 0 (default) the search starts at the beginning of the page, otherwise
0186      *                 right/below the coordinates of the given rect.
0187      */
0188     RegularAreaRect *findText(int id, const QString &text, SearchDirection direction, Qt::CaseSensitivity caseSensitivity, const RegularAreaRect *lastRect = nullptr) const;
0189 
0190     /**
0191      * Returns the page text (or part of it).
0192      * @see TextPage::text()
0193      */
0194     QString text(const RegularAreaRect *area = nullptr) const;
0195 
0196     /**
0197      * Returns the page text (or part of it).
0198      * @see TextPage::text()
0199      * @since 0.10 (KDE 4.4)
0200      */
0201     QString text(const RegularAreaRect *area, TextPage::TextAreaInclusionBehaviour b) const;
0202 
0203     /**
0204      * Returns the page text (or part of it) including the bounding
0205      * rectangles. Note that ownership of the contents of the returned
0206      * list belongs to the caller.
0207      * @see TextPage::words()
0208      * @since 0.14 (KDE 4.8)
0209      */
0210     TextEntity::List words(const RegularAreaRect *area, TextPage::TextAreaInclusionBehaviour b) const;
0211 
0212     /**
0213      * Returns the area and text of the word at the given point
0214      * Note that ownership of the returned area belongs to the caller.
0215      * @see TextPage::wordAt()
0216      * @since 0.15 (KDE 4.9)
0217      */
0218     RegularAreaRect *wordAt(const NormalizedPoint &p, QString *word = nullptr) const;
0219 
0220     /**
0221      * Returns the rectangular area of the given @p selection.
0222      */
0223     RegularAreaRect *textArea(TextSelection *selection) const;
0224 
0225     /**
0226      * Returns the object rect of the given @p type which is at point (@p x, @p y) at scale (@p xScale, @p yScale).
0227      */
0228     const ObjectRect *objectRect(ObjectRect::ObjectType type, double x, double y, double xScale, double yScale) const;
0229 
0230     /**
0231      * Returns all object rects of the given @p type which are at point (@p x, @p y) at scale (@p xScale, @p yScale).
0232      * @since 0.16 (KDE 4.10)
0233      */
0234     QList<const ObjectRect *> objectRects(ObjectRect::ObjectType type, double x, double y, double xScale, double yScale) const;
0235 
0236     /**
0237      * Returns the object rect of the given @p type which is nearest to the point (@p x, @p y) at scale (@p xScale, @p yScale).
0238      *
0239      * @since 0.8.2 (KDE 4.2.2)
0240      */
0241     const ObjectRect *nearestObjectRect(ObjectRect::ObjectType type, double x, double y, double xScale, double yScale, double *distance) const;
0242 
0243     /**
0244      * Returns the transition effect of the page or 0 if no transition
0245      * effect is set (see hasTransition()).
0246      */
0247     const PageTransition *transition() const;
0248 
0249     /**
0250      * Returns the list of annotations of the page.
0251      */
0252     QList<Annotation *> annotations() const;
0253 
0254     /**
0255      * Returns the annotation with the given unique name.
0256      * @since 1.3
0257      */
0258     Annotation *annotation(const QString &uniqueName) const;
0259 
0260     /**
0261      * Returns the @ref Action object which is associated with the given page @p action
0262      * or 0 if no page action is set.
0263      */
0264     const Action *pageAction(PageAction action) const;
0265 
0266     /**
0267      * Returns the list of FormField of the page.
0268      */
0269     QList<FormField *> formFields() const;
0270 
0271     /**
0272      * Sets the region described by @p rect with @p pixmap for the
0273      * given @p observer.
0274      * If @p rect is not set (default) the @p pixmap is set to the entire
0275      * page.
0276      */
0277     void setPixmap(DocumentObserver *observer, QPixmap *pixmap, const NormalizedRect &rect = NormalizedRect());
0278 
0279     /**
0280      * Sets the @p text page.
0281      */
0282     void setTextPage(TextPage *text);
0283 
0284     /**
0285      * Sets the list of object @p rects of the page.
0286      */
0287     void setObjectRects(const QList<ObjectRect *> &rects);
0288 
0289     /**
0290      * Gets the list of object rects of the page.
0291      *
0292      * @since 22.04
0293      */
0294     const QList<ObjectRect *> &objectRects() const;
0295 
0296     /**
0297      * Sets the list of source reference objects @p rects.
0298      */
0299     void setSourceReferences(const QList<SourceRefObjectRect *> &rects);
0300 
0301     /**
0302      * Sets the duration of the page to @p seconds when displayed in presentation mode.
0303      *
0304      * Setting a negative number disables the duration.
0305      */
0306     void setDuration(double seconds);
0307 
0308     /**
0309      * Returns the duration in seconds of the page when displayed in presentation mode.
0310      *
0311      * A negative number means that no time is set.
0312      */
0313     double duration() const;
0314 
0315     /**
0316      * Sets the labels for the page to @p label .
0317      */
0318     void setLabel(const QString &label);
0319 
0320     /**
0321      * Returns the label of the page, or a null string if not set.
0322      */
0323     QString label() const;
0324 
0325     /**
0326      * Returns the current text selection.
0327      */
0328     const RegularAreaRect *textSelection() const;
0329 
0330     /**
0331      * Returns the color of the current text selection, or an invalid color
0332      * if no text selection has been set.
0333      */
0334     QColor textSelectionColor() const;
0335 
0336     /**
0337      * Adds a new @p annotation to the page.
0338      */
0339     void addAnnotation(Annotation *annotation);
0340 
0341     /**
0342      * Removes the @p annotation from the page.
0343      */
0344     bool removeAnnotation(Annotation *annotation);
0345 
0346     /**
0347      * Sets the page @p transition effect.
0348      */
0349     void setTransition(PageTransition *transition);
0350 
0351     /**
0352      * Sets the @p link object for the given page @p action.
0353      */
0354     void setPageAction(PageAction action, Action *link);
0355 
0356     /**
0357      * Sets @p fields as list of FormField of the page.
0358      */
0359     void setFormFields(const QList<FormField *> &fields);
0360 
0361     /**
0362      * Deletes the pixmap for the given @p observer
0363      */
0364     void deletePixmap(DocumentObserver *observer);
0365 
0366     /**
0367      * Deletes all pixmaps of the page.
0368      */
0369     void deletePixmaps();
0370 
0371     /**
0372      * Deletes all object rects of the page.
0373      */
0374     void deleteRects();
0375 
0376     /**
0377      * Deletes all source reference objects of the page.
0378      */
0379     void deleteSourceReferences();
0380 
0381     /**
0382      * Deletes all annotations of the page.
0383      */
0384     void deleteAnnotations();
0385 
0386     /**
0387      * Returns whether pixmaps for the tiled observer are handled by a
0388      * tile manager.
0389      *
0390      * @since 0.19 (KDE 4.13)
0391      */
0392     bool hasTilesManager(const DocumentObserver *observer) const;
0393 
0394     /**
0395      * Returns a list of all tiles intersecting with @p rect.
0396      *
0397      * The list contains only tiles with a pixmap
0398      *
0399      * @since 0.19 (KDE 4.13)
0400      */
0401     QList<Tile> tilesAt(const DocumentObserver *observer, const NormalizedRect &rect) const;
0402 
0403 private:
0404     PagePrivate *d;
0405     /// @cond PRIVATE
0406     friend class PagePrivate;
0407     friend class Document;
0408     friend class DocumentPrivate;
0409     friend class PixmapRequestPrivate;
0410 
0411     /**
0412      * To improve performance PagePainter accesses the following
0413      * member variables directly.
0414      */
0415     friend class ::PagePainter;
0416     /// @endcond
0417 
0418     const QPixmap *_o_nearestPixmap(DocumentObserver *, int, int) const;
0419 
0420     QList<ObjectRect *> m_rects;
0421     QList<HighlightAreaRect *> m_highlights;
0422     QList<Annotation *> m_annotations;
0423 
0424     Q_DISABLE_COPY(Page)
0425 };
0426 
0427 }
0428 
0429 #endif