source: terepaima/terepaima-0.4.16/sources/pageitem.h

desarrollostretch
Last change on this file was 1f4adec, checked in by aosorio <aosorio@…>, 8 years ago

Agregado proyecto base, esto luego del dh_make -f

  • Property mode set to 100644
File size: 6.3 KB
Line 
1/*
2
3Copyright 2012-2014 Adam Reichold
4
5This file is part of qpdfview.
6
7qpdfview is free software: you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation, either version 2 of the License, or
10(at your option) any later version.
11
12qpdfview is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with qpdfview.  If not, see <http://www.gnu.org/licenses/>.
19
20*/
21
22#ifndef PAGEITEM_H
23#define PAGEITEM_H
24
25#include <QCache>
26#include <QGraphicsObject>
27#include <QIcon>
28#include <QSet>
29
30class QGraphicsProxyWidget;
31
32#include "renderparam.h"
33
34namespace qpdfview
35{
36
37namespace Model
38{
39struct Link;
40class Annotation;
41class FormField;
42class Page;
43}
44
45class Settings;
46class RenderTask;
47class TileItem;
48
49class PageItem : public QGraphicsObject
50{
51    Q_OBJECT
52
53    friend class TileItem;
54
55public:
56    enum PaintMode
57    {
58        DefaultMode,
59        PresentationMode,
60        ThumbnailMode
61    };
62
63    PageItem(Model::Page* page, int index, PaintMode paintMode = DefaultMode, QGraphicsItem* parent = 0);
64    ~PageItem();
65
66    const QRectF& uncroppedBoundingRect() const { return m_boundingRect; }
67
68    QRectF boundingRect() const;
69    void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget*);
70
71    int index() const { return m_index; }
72
73    const QSizeF& size() const { return m_size; }
74
75    QSizeF displayedSize() const { return displayedSize(renderParam()); }
76    QSizeF displayedSize(const RenderParam& renderParam) const;
77
78    const QList< QRectF >& highlights() const { return m_highlights; }
79    void setHighlights(const QList< QRectF >& highlights);
80
81    RubberBandMode rubberBandMode() const { return m_rubberBandMode; }
82    void setRubberBandMode(RubberBandMode rubberBandMode);
83
84    bool showsAnnotationOverlay() const { return !m_annotationOverlay.isEmpty(); }
85    bool showsFormFieldOverlay() const { return !m_formFieldOverlay.isEmpty(); }
86
87    const RenderParam& renderParam() const { return m_renderParam; }
88    void setRenderParam(const RenderParam& renderParam);
89
90    const QTransform& transform() const { return m_transform; }
91    const QTransform& normalizedTransform() const { return m_normalizedTransform; }
92
93    QPointF sourcePos(const QPointF& point) const { return m_transform.inverted().map(point); }
94    QPointF normalizedSourcePos(const QPointF& point) const { return m_normalizedTransform.inverted().map(point); }
95
96signals:
97    void cropRectChanged();
98
99    void linkClicked(bool newTab, int page, qreal left = qQNaN(), qreal top = qQNaN());
100    void linkClicked(bool newTab, const QString& fileName, int page);
101    void linkClicked(const QString& url);
102
103    void rubberBandStarted();
104    void rubberBandFinished();
105
106    void zoomToSelection(int page, const QRectF& rect);
107
108    void wasModified();
109
110public slots:
111    void refresh(bool keepObsoletePixmaps = false, bool dropCachedPixmaps = false);
112
113    int startRender(bool prefetch = false);
114    void cancelRender();
115
116protected slots:
117    void showAnnotationOverlay(Model::Annotation* selectedAnnotation);
118    void hideAnnotationOverlay(bool deleteLater = true);
119    void updateAnnotationOverlay();
120
121    void showFormFieldOverlay(Model::FormField* selectedFormField);
122    void hideFormFieldOverlay(bool deleteLater = true);
123    void updateFormFieldOverlay();
124
125protected:
126    void hoverEnterEvent(QGraphicsSceneHoverEvent*);
127    void hoverMoveEvent(QGraphicsSceneHoverEvent* event);
128    void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
129
130    void mousePressEvent(QGraphicsSceneMouseEvent* event);
131    void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
132    void mouseReleaseEvent(QGraphicsSceneMouseEvent* event);
133
134    void contextMenuEvent(QGraphicsSceneContextMenuEvent* event);
135
136private slots:
137    virtual void loadInteractiveElements();
138
139private:
140    Q_DISABLE_COPY(PageItem)
141
142    static Settings* s_settings;
143
144    Model::Page* m_page;
145    QSizeF m_size;
146
147    QRectF m_cropRect;
148
149    void updateCropRect();
150
151    int m_index;
152    PaintMode m_paintMode;
153
154    bool presentationMode() const;
155    bool thumbnailMode() const;
156
157    bool useTiling() const;
158
159    QList< QRectF > m_highlights;
160
161    // interactive elements
162
163    QList< Model::Link* > m_links;
164    QList< Model::Annotation* > m_annotations;
165    QList< Model::FormField* > m_formFields;
166
167    RubberBandMode m_rubberBandMode;
168    QRectF m_rubberBand;
169
170    void copyToClipboard(const QPoint& screenPos);
171    void addAnnotation(const QPoint& screenPos);
172
173    void showLinkContextMenu(Model::Link* link, const QPoint& screenPos);
174    void showAnnotationContextMenu(Model::Annotation* annotation, const QPoint& screenPos);
175
176    // overlay
177
178    typedef QMap< Model::Annotation*, QGraphicsProxyWidget* > AnnotationOverlay;
179    AnnotationOverlay m_annotationOverlay;
180
181    typedef QMap< Model::FormField*, QGraphicsProxyWidget* > FormFieldOverlay;
182    FormFieldOverlay m_formFieldOverlay;
183
184    template< typename Overlay, typename Element > void showOverlay(Overlay& overlay, const char* hideOverlay, const QList< Element* >& elements, Element* selectedElement);
185    template< typename Overlay, typename Element > void addProxy(Overlay& overlay, const char* hideOverlay, Element* element);
186    template< typename Overlay > void hideOverlay(Overlay& overlay, bool deleteLater);
187    template< typename Overlay > void updateOverlay(const Overlay& overlay) const;
188
189    void setProxyGeometry(Model::Annotation* annotation, QGraphicsProxyWidget* proxy) const;
190    void setProxyGeometry(Model::FormField* formField, QGraphicsProxyWidget* proxy) const;
191
192    // geometry
193
194    RenderParam m_renderParam;
195
196    QTransform m_transform;
197    QTransform m_normalizedTransform;
198    QRectF m_boundingRect;
199
200    void prepareGeometry();
201
202    QVector< TileItem* > m_tileItems;
203    mutable QSet< TileItem* > m_exposedTileItems;
204
205    void prepareTiling();
206
207    // paint
208
209    void paintPage(QPainter* painter, const QRectF& exposedRect) const;
210
211    void paintLinks(QPainter* painter) const;
212    void paintFormFields(QPainter* painter) const;
213
214    void paintHighlights(QPainter* painter) const;
215    void paintRubberBand(QPainter* painter) const;
216
217};
218
219} // qpdfview
220
221#endif // PAGEITEM_H
Note: See TracBrowser for help on using the repository browser.