1 /*
2 SPDX-FileCopyrightText: 2004 Enrico Ros <eros.kde@email.it>
3 SPDX-FileCopyrightText: 2007 Pino Toscano <pino@kde.org>
4
5 Work sponsored by the LiMux project of the city of Munich:
6 SPDX-FileCopyrightText: 2017 Klarälvdalens Datakonsult AB a KDAB Group company <info@kdab.com>
7
8 SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #ifndef _OKULAR_PAGE_PRIVATE_H_
12 #define _OKULAR_PAGE_PRIVATE_H_
13
14 // qt/kde includes
15 #include <QLinkedList>
16 #include <QMap>
17 #include <QString>
18 #include <QTransform>
19 #include <qdom.h>
20
21 // local includes
22 #include "area.h"
23 #include "global.h"
24
25 class QColor;
26
27 namespace Okular
28 {
29 class Action;
30 class Annotation;
31 class DocumentObserver;
32 class DocumentPrivate;
33 class FormField;
34 class HighlightAreaRect;
35 class Page;
36 class PageSize;
37 class PageTransition;
38 class RotationJob;
39 class TextPage;
40 class TilesManager;
41
42 enum PageItem {
43 None = 0,
44 AnnotationPageItems = 0x01,
45 FormFieldPageItems = 0x02,
46 AllPageItems = 0xff,
47
48 /* If set along with AnnotationPageItems, tells saveLocalContents to save
49 * the original annotations (if any) instead of the modified ones */
50 OriginalAnnotationPageItems = 0x100,
51
52 /* If set along with FormFieldPageItems, tells saveLocalContents to save
53 * the original form contents (if any) instead of the modified one */
54 OriginalFormFieldPageItems = 0x200
55 };
Q_DECLARE_FLAGS(PageItems,PageItem)56 Q_DECLARE_FLAGS(PageItems, PageItem)
57
58 class PagePrivate
59 {
60 public:
61 PagePrivate(Page *page, uint n, double w, double h, Rotation o);
62 ~PagePrivate();
63
64 static PagePrivate *get(Page *page);
65
66 void imageRotationDone(RotationJob *job);
67 QTransform rotationMatrix() const;
68
69 /**
70 * Loads the local contents (e.g. annotations) of the page.
71 */
72 bool restoreLocalContents(const QDomNode &pageNode);
73
74 /**
75 * Saves the local contents (e.g. annotations) of the page.
76 */
77 void saveLocalContents(QDomNode &parentNode, QDomDocument &document, PageItems what = AllPageItems) const;
78
79 /**
80 * Rotates the image and object rects of the page to the given @p orientation.
81 */
82 void rotateAt(Rotation orientation);
83
84 /**
85 * Changes the size of the page to the given @p size.
86 *
87 * The @p size is meant to be referred to the page not rotated.
88 */
89 void changeSize(const PageSize &size);
90
91 /**
92 * Clears current text selection highlight areas,
93 * creates new ones if @p r is not nullptr,
94 * and deletes @p r.
95 *
96 * @param r Areas of new text selections.
97 * @param color Color of new text selections.
98 */
99 void setTextSelections(RegularAreaRect *r, const QColor &color);
100
101 /**
102 * Sets the @p color and @p rect of the highlight for the observer with
103 * the given @p id.
104 */
105 void setHighlight(int id, RegularAreaRect *rect, const QColor &color);
106
107 /**
108 * Deletes all highlight objects for the observer with the given @p id.
109 */
110 void deleteHighlights(int id = -1);
111
112 /**
113 * Deletes all text selection objects of the page.
114 */
115 void deleteTextSelections();
116
117 /**
118 * Get the tiles manager for the tiled @p observer
119 */
120 TilesManager *tilesManager(const DocumentObserver *observer) const;
121
122 /**
123 * Set the tiles manager for the tiled @p observer
124 */
125 void setTilesManager(const DocumentObserver *observer, TilesManager *tm);
126
127 /**
128 * Moves contents that are generated from oldPage to this. And clears them from page
129 * so it can be deleted fine.
130 */
131 void adoptGeneratedContents(PagePrivate *oldPage);
132
133 /*
134 * Tries to find an equivalent form field to oldField by looking into the rect, type and name
135 */
136 OKULARCORE_EXPORT static FormField *findEquivalentForm(const Page *p, FormField *oldField);
137
138 void setPixmap(DocumentObserver *observer, QPixmap *pixmap, const NormalizedRect &rect, bool isPartialPixmap);
139
140 class PixmapObject
141 {
142 public:
143 QPixmap *m_pixmap = nullptr;
144 Rotation m_rotation;
145 bool m_isPartialPixmap = false;
146 };
147 QMap<DocumentObserver *, PixmapObject> m_pixmaps;
148 QMap<const DocumentObserver *, TilesManager *> m_tilesManagers;
149
150 Page *m_page;
151 int m_number;
152 Rotation m_orientation;
153 double m_width, m_height;
154 DocumentPrivate *m_doc;
155 NormalizedRect m_boundingBox;
156 Rotation m_rotation;
157
158 TextPage *m_text;
159 PageTransition *m_transition;
160 HighlightAreaRect *m_textSelections;
161 QLinkedList<FormField *> formfields;
162 Action *m_openingAction;
163 Action *m_closingAction;
164 double m_duration;
165 QString m_label;
166
167 bool m_isBoundingBoxKnown : 1;
168 QDomDocument restoredLocalAnnotationList; // <annotationList>...</annotationList>
169 QDomDocument restoredFormFieldList; // <forms>...</forms>
170 };
171
172 }
173
174 Q_DECLARE_OPERATORS_FOR_FLAGS(Okular::PageItems)
175
176 #endif
177