page.h 4.54 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/***************************************************************************
 *   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_

13 14 15
#include <qmap.h>
#include <qvaluelist.h>

16
class QPixmap;
17
class QRect;
18
class TextPage;
19
class KPDFPageRect;
20
class KPDFPageTransition;
21 22 23 24

/**
 * @short Collector for all the data belonging to a page.
 *
Enrico Ros's avatar
Enrico Ros committed
25 26 27
 * The KPDFPage class contains pixmaps (referenced using observers id as key),
 * a search page (a class used internally for retrieving text), rect classes
 * (that describe links or other active areas in the current page) and more.
28
 *
Enrico Ros's avatar
Enrico Ros committed
29
 * Note: All objects are reparented to this class.
30
 */
31
class KPDFPage
32
{
33 34 35 36 37 38 39 40 41 42 43 44 45 46
    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; }

47
        bool hasPixmap( int id, int width = -1, int height = -1 ) const;
48 49
        bool hasSearchPage() const;
        bool hasRect( int mouseX, int mouseY ) const;
50
        bool hasLink( int mouseX, int mouseY ) const;
51
        const KPDFPageRect * getRect( int mouseX, int mouseY ) const;
52
        const KPDFPageTransition * getTransition() const;
53 54
        const QPoint getLastSearchCenter() const;
        const QString getTextInRect( const QRect & rect, double zoom /*= 1.0*/ ) const;
55

56
        // operations (by KPDFDocument)
57 58 59 60 61
        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 );

62
        // set/delete contents (by KPDFDocument)
63 64
        void setPixmap( int id, QPixmap * pixmap );
        void setSearchPage( TextPage * text );
65
        void setRects( const QValueList< KPDFPageRect * > rects );
66
        void setTransition( const KPDFPageTransition * transition );
67
        void deletePixmap( int id );
68
        void deletePixmapsAndRects();
69 70 71 72 73 74 75 76 77

    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;
78
        QValueList< KPDFPageRect * > m_rects;
79
        const KPDFPageTransition * m_transition;
80
};
81

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107

/**
 * @short A rect on the page that may contain an object.
 *
 * This class describes a rect (geometrical coordinates) and may hold a
 * pointer to an associated object. An object is reparented to this class
 * and deleted when this class is deleted.
 *
 * Objects are stored and read as 'void pointers' so you have to perform
 * the cast on the code that handles the object using information provided
 * by pointerType().
 *
 * Type / Class correspondency tab:
 *  - NoPointer : ''              : no object is stored
 *  - Link      : class KPDFLink  : description of a link
 *  - Image     : class KPDFImage : description of an image
 *
 */
class KPDFPageRect
{
    public:
        KPDFPageRect( int left, int top, int right, int bottom );
        ~KPDFPageRect();

        // query geometric properties
        bool contains( int x, int y ) const;
Enrico Ros's avatar
Enrico Ros committed
108
        QRect geometry() const;
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124

        // set a pointer to data associated to this rect
        enum PointerType { NoPointer, Link, Image };
        void setPointer( void * object, enum PointerType pType );

        // query type and get a const pointer to the stored object
        PointerType pointerType() const;
        const void * pointer() const;

    private:
        void deletePointer();
        int m_xMin, m_xMax, m_yMin, m_yMax;
        PointerType m_pointerType;
        void * m_pointer;
};

125
#endif