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

0001 /*
0002     SPDX-FileCopyrightText: 2004 Enrico Ros <eros.kde@email.it>
0003     SPDX-FileCopyrightText: 2007 Pino Toscano <pino@kde.org>
0004 
0005     Work sponsored by the LiMux project of the city of Munich:
0006     SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com>
0007 
0008     SPDX-License-Identifier: GPL-2.0-or-later
0009 */
0010 
0011 #ifndef _OKULAR_PAGE_PRIVATE_H_
0012 #define _OKULAR_PAGE_PRIVATE_H_
0013 
0014 // qt/kde includes
0015 #include <QMap>
0016 #include <QString>
0017 #include <QTransform>
0018 #include <qdom.h>
0019 
0020 // local includes
0021 #include "area.h"
0022 #include "global.h"
0023 
0024 class QColor;
0025 
0026 namespace Okular
0027 {
0028 class Action;
0029 class Annotation;
0030 class DocumentObserver;
0031 class DocumentPrivate;
0032 class FormField;
0033 class HighlightAreaRect;
0034 class Page;
0035 class PageSize;
0036 class PageTransition;
0037 class RotationJob;
0038 class TextPage;
0039 class TilesManager;
0040 
0041 enum PageItem {
0042     None = 0,
0043     AnnotationPageItems = 0x01,
0044     FormFieldPageItems = 0x02,
0045     AllPageItems = 0xff,
0046 
0047     /* If set along with AnnotationPageItems, tells saveLocalContents to save
0048      * the original annotations (if any) instead of the modified ones */
0049     OriginalAnnotationPageItems = 0x100,
0050 
0051     /* If set along with FormFieldPageItems, tells saveLocalContents to save
0052      * the original form contents (if any) instead of the modified one */
0053     OriginalFormFieldPageItems = 0x200
0054 };
0055 Q_DECLARE_FLAGS(PageItems, PageItem)
0056 
0057 class PagePrivate
0058 {
0059 public:
0060     PagePrivate(Page *page, uint n, double w, double h, Rotation o);
0061     ~PagePrivate();
0062 
0063     static PagePrivate *get(Page *page);
0064 
0065     void imageRotationDone(RotationJob *job);
0066     QTransform rotationMatrix() const;
0067 
0068     /**
0069      * Loads the local contents (e.g. annotations) of the page.
0070      */
0071     bool restoreLocalContents(const QDomNode &pageNode);
0072 
0073     /**
0074      * Saves the local contents (e.g. annotations) of the page.
0075      */
0076     void saveLocalContents(QDomNode &parentNode, QDomDocument &document, PageItems what = AllPageItems) const;
0077 
0078     /**
0079      * Rotates the image and object rects of the page to the given @p orientation.
0080      */
0081     void rotateAt(Rotation orientation);
0082 
0083     /**
0084      * Changes the size of the page to the given @p size.
0085      *
0086      * The @p size is meant to be referred to the page not rotated.
0087      */
0088     void changeSize(const PageSize &size);
0089 
0090     /**
0091      * Clears current text selection highlight areas,
0092      * creates new ones if @p r is not nullptr,
0093      * and deletes @p r.
0094      *
0095      * @param r Areas of new text selections.
0096      * @param color Color of new text selections.
0097      */
0098     void setTextSelections(RegularAreaRect *r, const QColor &color);
0099 
0100     /**
0101      * Sets the @p color and @p rect of the highlight for the observer with
0102      * the given @p id.
0103      */
0104     void setHighlight(int id, RegularAreaRect *rect, const QColor &color);
0105 
0106     /**
0107      * Deletes all highlight objects for the observer with the given @p id.
0108      */
0109     void deleteHighlights(int id = -1);
0110 
0111     /**
0112      * Deletes all text selection objects of the page.
0113      */
0114     void deleteTextSelections();
0115 
0116     /**
0117      * Get the tiles manager for the tiled @p observer
0118      */
0119     TilesManager *tilesManager(const DocumentObserver *observer) const;
0120 
0121     /**
0122      * Set the tiles manager for the tiled @p observer
0123      */
0124     void setTilesManager(const DocumentObserver *observer, TilesManager *tm);
0125 
0126     /**
0127      * Moves contents that are generated from oldPage to this. And clears them from page
0128      * so it can be deleted fine.
0129      */
0130     void adoptGeneratedContents(PagePrivate *oldPage);
0131 
0132     /*
0133      * Tries to find an equivalent form field to oldField by looking into the rect, type and name
0134      */
0135     OKULARCORE_EXPORT static FormField *findEquivalentForm(const Page *p, FormField *oldField);
0136 
0137     void setPixmap(DocumentObserver *observer, QPixmap *pixmap, const NormalizedRect &rect, bool isPartialPixmap);
0138 
0139     class PixmapObject
0140     {
0141     public:
0142         QPixmap *m_pixmap = nullptr;
0143         Rotation m_rotation;
0144         bool m_isPartialPixmap = false;
0145     };
0146     QMap<DocumentObserver *, PixmapObject> m_pixmaps;
0147     QMap<const DocumentObserver *, TilesManager *> m_tilesManagers;
0148 
0149     Page *m_page;
0150     int m_number;
0151     Rotation m_orientation;
0152     double m_width, m_height;
0153     DocumentPrivate *m_doc;
0154     NormalizedRect m_boundingBox;
0155     Rotation m_rotation;
0156 
0157     TextPage *m_text;
0158     PageTransition *m_transition;
0159     HighlightAreaRect *m_textSelections;
0160     QList<FormField *> formfields;
0161     Action *m_openingAction;
0162     Action *m_closingAction;
0163     double m_duration;
0164     QString m_label;
0165 
0166     bool m_isBoundingBoxKnown : 1;
0167     QDomDocument restoredLocalAnnotationList; // <annotationList>...</annotationList>
0168     QDomDocument restoredFormFieldList;       // <forms>...</forms>
0169 };
0170 
0171 }
0172 
0173 Q_DECLARE_OPERATORS_FOR_FLAGS(Okular::PageItems)
0174 
0175 #endif