2004-09-08 12:41:14 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2004 by Enrico Ros <eros.kde@email.it> *
|
|
|
|
* *
|
|
|
|
* 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. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _KPDF_PAGE_H_
|
|
|
|
#define _KPDF_PAGE_H_
|
|
|
|
|
2004-10-02 14:30:30 +00:00
|
|
|
#include <qmap.h>
|
|
|
|
#include <qvaluelist.h>
|
|
|
|
|
2004-09-10 17:44:05 +00:00
|
|
|
class QPainter;
|
2004-09-15 20:45:00 +00:00
|
|
|
class QPixmap;
|
2004-09-16 21:04:49 +00:00
|
|
|
class TextPage;
|
2004-10-09 08:10:56 +00:00
|
|
|
class LinkAction;
|
2004-10-02 14:30:30 +00:00
|
|
|
class LinkDest;
|
|
|
|
class KPDFLink;
|
2004-10-20 16:27:20 +00:00
|
|
|
class KPDFActiveRect;
|
2004-09-08 12:41:14 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @short Collector for all the data belonging to a page.
|
2004-11-07 14:15:33 +00:00
|
|
|
* ### MERGE: definition and implementation must be moved to kpdfpage.h/.cpp
|
2004-09-08 12:41:14 +00:00
|
|
|
*
|
2004-09-15 20:45:00 +00:00
|
|
|
* The KPDFPage class contains pixmaps (referenced using obsedvers id as key),
|
|
|
|
* a search page (a class used internally for searching data), link classes
|
|
|
|
* (that describe links in the current page) plus graphics overlays and more.
|
|
|
|
*
|
|
|
|
* Note: All objects passed to this class will be destoryed on class deletion.
|
2004-09-08 12:41:14 +00:00
|
|
|
*/
|
2004-09-10 17:44:05 +00:00
|
|
|
class KPDFPage
|
2004-09-08 12:41:14 +00:00
|
|
|
{
|
2004-11-06 00:56:55 +00:00
|
|
|
public:
|
|
|
|
KPDFPage( uint number, float width, float height, int rotation );
|
|
|
|
~KPDFPage();
|
|
|
|
|
|
|
|
enum KPDFPageAttributes { Highlight = 1, Bookmark = 2 };
|
|
|
|
|
|
|
|
// query properties (const read-only methods)
|
|
|
|
inline int number() const { return m_number; }
|
|
|
|
inline int rotation() const { return m_rotation; }
|
|
|
|
inline int attributes() const { return m_attributes; }
|
|
|
|
inline float width() const { return m_width; }
|
|
|
|
inline float height() const { return m_height; }
|
|
|
|
inline float ratio() const { return m_height / m_width; }
|
|
|
|
|
|
|
|
bool hasPixmap( int id, int width, int height ) const;
|
|
|
|
bool hasSearchPage() const { return m_text != 0; }
|
|
|
|
bool hasLink( int mouseX, int mouseY ) const;
|
|
|
|
bool hasActiveRect( int mouseX, int mouseY ) const;
|
|
|
|
const QString getTextInRect( const QRect & rect, double zoom = 1.0 ) const;
|
|
|
|
const KPDFLink * getLink( int mouseX, int mouseY ) const;
|
|
|
|
|
2004-11-12 10:58:33 +00:00
|
|
|
// operations (by KPDFDocument)
|
2004-11-06 00:56:55 +00:00
|
|
|
inline void setAttribute( int att ) { m_attributes |= att; }
|
|
|
|
inline void clearAttribute( int att ) { m_attributes &= ~att; }
|
|
|
|
inline void toggleAttribute( int att ) { m_attributes ^= att; }
|
|
|
|
bool hasText( const QString & text, bool strictCase, bool fromTop );
|
|
|
|
|
2004-11-12 10:58:33 +00:00
|
|
|
// set contents (by KPDFDocument)
|
2004-11-06 00:56:55 +00:00
|
|
|
void setPixmap( int id, QPixmap * pixmap );
|
|
|
|
void setSearchPage( TextPage * text );
|
|
|
|
void setLinks( const QValueList<KPDFLink *> links );
|
|
|
|
void setActiveRects( const QValueList<KPDFActiveRect *> rects );
|
2004-11-12 10:58:33 +00:00
|
|
|
void deletePixmapsAndLinks();
|
2004-11-06 00:56:55 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
friend class PagePainter;
|
|
|
|
int m_number, m_rotation, m_attributes;
|
|
|
|
float m_width, m_height;
|
|
|
|
double m_sLeft, m_sTop, m_sRight, m_sBottom;
|
|
|
|
|
|
|
|
QMap< int, QPixmap * > m_pixmaps;
|
|
|
|
TextPage * m_text;
|
|
|
|
QValueList< KPDFLink * > m_links;
|
|
|
|
QValueList< KPDFActiveRect * > m_rects;
|
2004-09-08 12:41:14 +00:00
|
|
|
};
|
2004-10-02 14:30:30 +00:00
|
|
|
|
2004-11-07 14:15:33 +00:00
|
|
|
/**
|
|
|
|
* @short Paints a KPDFPage to an open painter using given flags.
|
|
|
|
* ### MERGE: since this file will be empty, we might consider renaming
|
|
|
|
* ### definition and implementation to pagepainter.*
|
|
|
|
*/
|
2004-11-06 00:56:55 +00:00
|
|
|
class PagePainter
|
|
|
|
{
|
|
|
|
public:
|
2004-11-07 14:15:33 +00:00
|
|
|
// list of flags passed to the painting function. by OR-ing those flags
|
|
|
|
// you can decide wether or not to permit drawing of a certain feature.
|
|
|
|
enum PagePainterFlags { Accessibility = 1, EnhanceLinks = 2,
|
|
|
|
EnhanceRects = 4, Highlight = 8 };
|
|
|
|
|
|
|
|
// draw (using painter 'p') the 'page' requested by 'id' using features
|
|
|
|
// in 'flags'. 'limits' is the bounding rect of the paint operation,
|
|
|
|
// 'width' and 'height' the expected size of page contents (used only
|
|
|
|
// to pick up an alternative pixmap if the pixmap of 'id' is missing.
|
|
|
|
static void paintPageOnPainter( const KPDFPage * page, int id, int flags,
|
2004-11-06 00:56:55 +00:00
|
|
|
QPainter * p, const QRect & limits, int width = -1, int height = -1 );
|
|
|
|
};
|
|
|
|
|
2004-10-02 14:30:30 +00:00
|
|
|
/**
|
|
|
|
* @short Encapsulates data that describes a link.
|
2004-11-07 14:15:33 +00:00
|
|
|
* ### MERGE: MOVE definition/implementation to kpdflink.h/.cpp
|
|
|
|
* ### NOTE: KPDFActiveRect and KPDFLink SHOULD BE MERGED !!
|
2004-10-02 14:30:30 +00:00
|
|
|
*
|
|
|
|
* There are many types of PDF links, here we provide accessors to set the
|
|
|
|
* link to be of the given type. Other functions are for asking if a point
|
|
|
|
* is inside the link rect (in displayed page coordinates).
|
|
|
|
* KPDFLinks are created by the KPDFOutputDevice then stored and deleted
|
|
|
|
* inside the referring KPDFPage.
|
|
|
|
* Note: this structure is similar to XPDF LinkAction and its hieracy, but
|
|
|
|
* is needed for storing data inside pages, since XPDF's PDFDoc deletes
|
|
|
|
* Links objects when changing page (and we need persistant storage).
|
|
|
|
*/
|
2004-09-15 20:45:00 +00:00
|
|
|
class KPDFLink
|
|
|
|
{
|
|
|
|
public:
|
2004-10-09 08:10:56 +00:00
|
|
|
KPDFLink( LinkAction * PDFAction );
|
2004-10-02 14:30:30 +00:00
|
|
|
~KPDFLink();
|
2004-09-15 20:45:00 +00:00
|
|
|
|
2004-10-09 08:10:56 +00:00
|
|
|
// set geometry (only links collected KPDFPage(s))
|
|
|
|
void setGeometry( int left, int top, int right, int bottom );
|
|
|
|
|
|
|
|
// query / others
|
|
|
|
bool contains( int x, int y ) const;
|
|
|
|
void copyString( char * &dest, const char * src ) const;
|
2004-11-07 14:15:33 +00:00
|
|
|
QRect geometry() const; //TODO add intersects( qrect )
|
2004-09-08 12:41:14 +00:00
|
|
|
|
2004-10-06 00:05:49 +00:00
|
|
|
// action queries
|
2004-10-09 08:10:56 +00:00
|
|
|
enum LinkType { Goto, Execute, URI, Named, Movie, Unknown };
|
|
|
|
LinkType type() const;
|
2004-10-06 00:05:49 +00:00
|
|
|
const LinkDest * getDest() const; //1
|
|
|
|
const char * getNamedDest() const; //1
|
|
|
|
const char * getFileName() const; //1,2
|
|
|
|
const char * getParameters() const; //2
|
2004-10-09 08:10:56 +00:00
|
|
|
const char * getName() const; //3
|
|
|
|
const char * getURI() const; //4
|
2004-09-15 20:45:00 +00:00
|
|
|
|
|
|
|
private:
|
2004-10-02 14:30:30 +00:00
|
|
|
// general
|
|
|
|
LinkType m_type;
|
2004-11-07 14:15:33 +00:00
|
|
|
int x_min, x_max, y_min, y_max;
|
2004-09-15 20:45:00 +00:00
|
|
|
|
2004-10-02 14:30:30 +00:00
|
|
|
// actions related
|
|
|
|
LinkDest * m_dest;
|
|
|
|
char * m_destNamed;
|
|
|
|
char * m_fileName;
|
|
|
|
char * m_parameters;
|
|
|
|
char * m_uri;
|
|
|
|
int m_refNum, m_refGen;
|
2004-09-15 20:45:00 +00:00
|
|
|
};
|
2004-10-02 14:30:30 +00:00
|
|
|
|
2004-10-20 16:27:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @short Describes an 'active' rectange on the page.
|
2004-11-07 14:15:33 +00:00
|
|
|
* ### MERGE: MOVE definition/implementation to kpdflink.h/.cpp
|
|
|
|
* ### NOTE: KPDFActiveRect and KPDFLink SHOULD BE MERGED !!
|
2004-10-20 16:27:20 +00:00
|
|
|
*
|
|
|
|
* ...
|
|
|
|
*/
|
|
|
|
class KPDFActiveRect
|
|
|
|
{
|
2004-11-07 14:15:33 +00:00
|
|
|
public:
|
|
|
|
KPDFActiveRect(int left, int top, int width, int height);
|
2004-10-20 16:27:20 +00:00
|
|
|
|
2004-11-07 14:15:33 +00:00
|
|
|
// query
|
|
|
|
bool contains(int x, int y);
|
|
|
|
QRect geometry() const;
|
2004-10-20 16:27:20 +00:00
|
|
|
|
2004-11-07 14:15:33 +00:00
|
|
|
private:
|
|
|
|
int m_left, m_top, m_right, m_bottom;
|
2004-10-20 16:27:20 +00:00
|
|
|
};
|
|
|
|
|
2004-09-08 12:41:14 +00:00
|
|
|
#endif
|