compile
[kdegraphics.git] / okular / core / page.h
bloba3699335fa6877c15779a8d46bbd91e3ae5e4076
1 /***************************************************************************
2 * Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
3 * *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #ifndef _OKULAR_PAGE_H_
11 #define _OKULAR_PAGE_H_
13 #include <QtCore/QLinkedList>
15 #include <okular/core/okular_export.h>
16 #include <okular/core/area.h>
17 #include <okular/core/global.h>
19 class QPixmap;
21 class PagePainter;
23 namespace Okular {
25 class Annotation;
26 class Document;
27 class DocumentPrivate;
28 class FormField;
29 class PagePrivate;
30 class PageTransition;
31 class SourceReference;
32 class TextPage;
33 class TextSelection;
35 /**
36 * @short Collector for all the data belonging to a page.
38 * The Page class contains pixmaps (referenced using observers id as key),
39 * a search page (a class used internally for retrieving text), rect classes
40 * (that describe links or other active areas in the current page) and more.
42 * All coordinates are normalized to the page, so {x,y} are valid in [0,1]
43 * range as long as NormalizedRect components.
45 * Note: The class takes ownership of all objects.
47 class OKULAR_EXPORT Page
49 public:
50 /**
51 * An action to be executed when particular events happen.
53 enum PageAction
55 Opening, ///< An action to be executed when the page is "opened".
56 Closing ///< An action to be executed when the page is "closed".
59 /**
60 * Creates a new page.
62 * @param number The number of the page in the document.
63 * @param width The width of the page.
64 * @param height The height of the page.
65 * @param orientation The orientation of the page
67 Page( uint number, double width, double height, Rotation orientation );
69 /**
70 * Destroys the page.
72 ~Page();
74 /**
75 * Returns the number of the page in the document.
77 int number() const;
79 /**
80 * Returns the orientation of the page as defined by the document.
82 Rotation orientation() const;
84 /**
85 * Returns the rotation of the page as defined by the user.
87 Rotation rotation() const;
89 /**
90 * Returns the total orientation which is the original orientation plus
91 * the user defined rotation.
93 Rotation totalOrientation() const;
95 /**
96 * Returns the width of the page.
98 double width() const;
101 * Returns the height of the page.
103 double height() const;
106 * Returns the ration (height / width) of the page.
108 double ratio() const;
111 * Returns the bounding box of the page content in normalized [0,1] coordinates,
112 * in terms of the upright orientation (Rotation0).
113 * If it has not been computed yet, returns the full page (i.e., (0, 0, 1, 1)).
114 * Note that the bounding box may be null if the page is blank.
116 * @since 0.7 (KDE 4.1)
118 NormalizedRect boundingBox() const;
121 * Returns whether the bounding box of the page has been computed.
122 * Note that even if the bounding box is computed, it may be null if the page is blank.
124 * @since 0.7 (KDE 4.1)
126 bool isBoundingBoxKnown() const;
129 * Sets the bounding box of the page content in normalized [0,1] coordinates,
130 * in terms of the upright orientation (Rotation0).
131 * (This does not inform the document's observers, call Document::SetPageBoundingBox
132 * instead if you want that.)
134 * @since 0.7 (KDE 4.1)
136 void setBoundingBox( const NormalizedRect& bbox );
139 * Returns whether the page has a pixmap of size @p width x @p height
140 * for the observer with given @p id.
142 bool hasPixmap( int id, int width = -1, int height = -1 ) const;
145 * Returns whether the page provides a text page (@ref TextPage).
147 bool hasTextPage() const;
150 * Returns whether the page has an object rect which includes the point (@p x, @p y)
151 * at scale (@p xScale, @p yScale).
153 bool hasObjectRect( double x, double y, double xScale, double yScale ) const;
156 * Returns whether the page provides highlighting for the observer with the
157 * given @p id.
159 bool hasHighlights( int id = -1 ) const;
162 * Returns whether the page provides a transition effect.
164 bool hasTransition() const;
167 * Returns whether the page provides annotations.
169 bool hasAnnotations() const;
172 * Returns the bounding rect of the text which matches the following criteria
173 * or 0 if the search is not successful.
175 * @param id An unique id for this search.
176 * @param text The search text.
177 * @param direction The direction of the search (@ref SearchDirection)
178 * @param caseSensitivity If Qt::CaseSensitive, the search is case sensitive; otherwise
179 * the search is case insensitive.
180 * @param lastRect If 0 (default) the search starts at the beginning of the page, otherwise
181 * right/below the coordinates of the the given rect.
183 RegularAreaRect* findText( int id, const QString & text, SearchDirection direction,
184 Qt::CaseSensitivity caseSensitivity, const RegularAreaRect * lastRect=0) const;
187 * Returns the page text (or part of it).
188 * @see TextPage::text()
190 QString text( const RegularAreaRect * rect = 0 ) const;
193 * Returns the rectangular area of the given @p selection.
195 RegularAreaRect * textArea( TextSelection *selection ) const;
198 * Returns the object rect of the given @p type which is at point (@p x, @p y) at scale (@p xScale, @p yScale).
200 const ObjectRect * objectRect( ObjectRect::ObjectType type, double x, double y, double xScale, double yScale ) const;
203 * Returns the transition effect of the page or 0 if no transition
204 * effect is set (see hasTransition()).
206 const PageTransition * transition() const;
209 * Returns the list of annotations of the page.
211 QLinkedList< Annotation* > annotations() const;
214 * Returns the @ref Action object which is associated with the given page @p action
215 * or 0 if no page action is set.
217 const Action * pageAction( PageAction action ) const;
220 * Returns the list of FormField of the page.
222 QLinkedList< FormField * > formFields() const;
225 * Sets the @p pixmap for the observer with the given @p id.
227 void setPixmap( int id, QPixmap *pixmap );
230 * Sets the @p text page.
232 void setTextPage( TextPage * text );
235 * Sets the list of object @p rects of the page.
237 void setObjectRects( const QLinkedList< ObjectRect * > & rects );
240 * Sets the list of source reference objects @p rects.
242 void setSourceReferences( const QLinkedList< SourceRefObjectRect * > & rects );
245 * Sets the duration of the page to @p seconds when displayed in presentation mode.
247 * Setting a negative number disables the duration.
249 void setDuration( double seconds );
252 * Returns the duration in seconds of the page when displayed in presentation mode.
254 * A negative number means that no time is set.
256 double duration() const;
259 * Sets the labels for the page to @p label .
261 void setLabel( const QString& label );
264 * Returns the label of the page, or a null string if not set.
266 QString label() const;
269 * Returns the current text selection.
271 const RegularAreaRect * textSelection() const;
274 * Returns the color of the current text selection, or an invalid color
275 * if no text selection has been set.
277 QColor textSelectionColor() const;
280 * Adds a new @p annotation to the page.
282 void addAnnotation( Annotation * annotation );
285 * Removes the @p annotation from the page.
287 bool removeAnnotation( Annotation * annotation );
290 * Sets the page @p transition effect.
292 void setTransition( PageTransition * transition );
295 * Sets the @p link object for the given page @p action.
297 void setPageAction( PageAction action, Action * link );
300 * Sets @p fields as list of FormField of the page.
302 void setFormFields( const QLinkedList< FormField * >& fields );
305 * Deletes the pixmap for the observer with the given @p id.
307 void deletePixmap( int id );
310 * Deletes all pixmaps of the page.
312 void deletePixmaps();
315 * Deletes all object rects of the page.
317 void deleteRects();
320 * Deletes all source reference objects of the page.
322 void deleteSourceReferences();
325 * Deletes all annotations of the page.
327 void deleteAnnotations();
329 private:
330 PagePrivate* const d;
331 /// @cond PRIVATE
332 friend class PagePrivate;
333 friend class Document;
334 friend class DocumentPrivate;
337 * To improve performance PagePainter accesses the following
338 * member variables directly.
340 friend class ::PagePainter;
341 /// @endcond
343 const QPixmap * _o_nearestPixmap( int, int, int ) const;
345 QLinkedList< ObjectRect* > m_rects;
346 QLinkedList< HighlightAreaRect* > m_highlights;
347 QLinkedList< Annotation* > m_annotations;
349 Q_DISABLE_COPY( Page )
354 #endif