1 | /* |
---|
2 | |
---|
3 | Copyright 2014 Adam Reichold |
---|
4 | |
---|
5 | This file is part of qpdfview. |
---|
6 | |
---|
7 | qpdfview is free software: you can redistribute it and/or modify |
---|
8 | it under the terms of the GNU General Public License as published by |
---|
9 | the Free Software Foundation, either version 2 of the License, or |
---|
10 | (at your option) any later version. |
---|
11 | |
---|
12 | qpdfview is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | GNU General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU General Public License |
---|
18 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | |
---|
20 | */ |
---|
21 | |
---|
22 | #ifndef TILEITEM_H |
---|
23 | #define TILEITEM_H |
---|
24 | |
---|
25 | #include <QCache> |
---|
26 | #include <QObject> |
---|
27 | #include <QPixmap> |
---|
28 | |
---|
29 | #include "global.h" |
---|
30 | |
---|
31 | namespace qpdfview |
---|
32 | { |
---|
33 | |
---|
34 | class Settings; |
---|
35 | class RenderParam; |
---|
36 | class RenderTask; |
---|
37 | class PageItem; |
---|
38 | |
---|
39 | class TileItem : public QObject |
---|
40 | { |
---|
41 | Q_OBJECT |
---|
42 | |
---|
43 | public: |
---|
44 | TileItem(PageItem* page); |
---|
45 | ~TileItem(); |
---|
46 | |
---|
47 | const QRect& rect() const { return m_rect; } |
---|
48 | void setRect(const QRect& rect) { m_rect = rect; } |
---|
49 | |
---|
50 | const QRectF& cropRect() const { return m_cropRect; } |
---|
51 | void resetCropRect() { m_cropRect = QRectF(); } |
---|
52 | void setCropRect(const QRectF& cropRect); |
---|
53 | |
---|
54 | void dropPixmap() { m_pixmap = QPixmap(); } |
---|
55 | void dropObsoletePixmap() { m_obsoletePixmap = QPixmap(); } |
---|
56 | |
---|
57 | static void dropCachedPixmaps(PageItem* page); |
---|
58 | |
---|
59 | bool paint(QPainter* painter, const QPointF& topLeft); |
---|
60 | |
---|
61 | public slots: |
---|
62 | void refresh(bool keepObsoletePixmaps = false); |
---|
63 | |
---|
64 | int startRender(bool prefetch = false); |
---|
65 | void cancelRender(); |
---|
66 | |
---|
67 | void deleteAfterRender(); |
---|
68 | |
---|
69 | protected slots: |
---|
70 | void on_renderTask_finished(); |
---|
71 | void on_renderTask_imageReady(const RenderParam& renderParam, |
---|
72 | const QRect& rect, bool prefetch, |
---|
73 | const QImage& image, const QRectF& cropRect); |
---|
74 | |
---|
75 | private: |
---|
76 | Q_DISABLE_COPY(TileItem) |
---|
77 | |
---|
78 | static Settings* s_settings; |
---|
79 | |
---|
80 | typedef QPair< PageItem*, QByteArray > CacheKey; |
---|
81 | typedef QPair< QPixmap, QRectF > CacheObject; |
---|
82 | |
---|
83 | static QCache< CacheKey, CacheObject > s_cache; |
---|
84 | |
---|
85 | CacheKey cacheKey() const; |
---|
86 | |
---|
87 | PageItem* m_page; |
---|
88 | |
---|
89 | QRect m_rect; |
---|
90 | QRectF m_cropRect; |
---|
91 | |
---|
92 | bool m_pixmapError; |
---|
93 | QPixmap m_pixmap; |
---|
94 | QPixmap m_obsoletePixmap; |
---|
95 | |
---|
96 | QPixmap takePixmap(); |
---|
97 | |
---|
98 | bool m_deleteAfterRender; |
---|
99 | RenderTask* m_renderTask; |
---|
100 | |
---|
101 | }; |
---|
102 | |
---|
103 | } // qpdfview |
---|
104 | |
---|
105 | #endif // PAGEITEM_H |
---|