16
|
1 |
#ifndef TILEDWEBVIEW_H
|
|
2 |
#define TILEDWEBVIEW_H
|
|
3 |
|
|
4 |
#include <QGraphicsWebView>
|
|
5 |
|
|
6 |
#include <QTime>
|
|
7 |
#include <QTimer>
|
|
8 |
|
|
9 |
#ifdef USE_OWN_TILED_CACHE
|
|
10 |
#define USE_TILED_CACHE
|
|
11 |
#endif
|
|
12 |
|
|
13 |
//#define USE_ASSISTANT_ITEM
|
|
14 |
|
|
15 |
#ifdef USE_ASSISTANT_ITEM
|
|
16 |
class TiledWebView;
|
|
17 |
class TiledWebViewAssistant : public QGraphicsWidget {
|
|
18 |
public:
|
|
19 |
void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget* widget);
|
|
20 |
TiledWebView* m_master;
|
|
21 |
};
|
|
22 |
#endif
|
|
23 |
|
|
24 |
class TiledWebView : public QGraphicsWebView
|
|
25 |
{
|
|
26 |
Q_OBJECT
|
|
27 |
protected:
|
|
28 |
TiledWebView(QGraphicsItem* parent = 0);
|
|
29 |
virtual ~TiledWebView();
|
|
30 |
|
|
31 |
struct Tile {
|
|
32 |
Tile();
|
|
33 |
QPixmap img;
|
|
34 |
QRectF dirtyRect; // in tile coordinates
|
|
35 |
bool ready;
|
|
36 |
bool used;
|
|
37 |
};
|
|
38 |
|
|
39 |
struct TileSet {
|
|
40 |
TileSet(QPoint aT, QRectF aR) { t = aT; r = aR; }
|
|
41 |
TileSet(const TileSet &o) { t = o.t; r = o.r; }
|
|
42 |
QPoint t;
|
|
43 |
QRectF r;
|
|
44 |
};
|
|
45 |
|
|
46 |
void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget* widget);
|
|
47 |
|
|
48 |
Tile* createTile(const QPoint& p);
|
|
49 |
Tile* tileAt(const QPoint& p) const;
|
|
50 |
Tile* tileAt(int x, int y) const { return tileAt(QPoint(x, y)); }
|
|
51 |
void setTileAt(const QPoint& p,Tile* t);
|
|
52 |
void setTileAt(int x, int y,Tile* t) { setTileAt(QPoint(x, y), t); }
|
|
53 |
QPoint tileAtPoint(const QPointF& p) const;
|
|
54 |
QRectF tileRect(const QPoint& t) const; // return is in tile coords
|
|
55 |
QRectF mapToTileCoords(const QRectF& rect) const
|
|
56 |
{ return QRectF(mapToTileCoords(rect.topLeft()),mapToTileCoords(rect.size())); }
|
|
57 |
|
|
58 |
QPointF mapToTileCoords(const QPointF& p) const { return p * m_tilesScale; }
|
|
59 |
QSizeF mapToTileCoords(const QSizeF& s) const { return s * m_tilesScale; }
|
|
60 |
|
|
61 |
QRectF mapFromTileCoords(const QRectF& rect) const
|
|
62 |
{ return QRectF(mapFromTileCoords(rect.topLeft()),mapFromTileCoords(rect.size())); }
|
|
63 |
|
|
64 |
QPointF mapFromTileCoords(const QPointF& p) const { return p / m_tilesScale; }
|
|
65 |
QSizeF mapFromTileCoords(const QSizeF& s) const { return s / m_tilesScale; }
|
|
66 |
|
|
67 |
QRectF viewPortRect() const;
|
|
68 |
QPoint findTile4Update(bool inView, bool addDirty = false) const;
|
|
69 |
QList<QPoint> findTileLine4Update(bool dirty, bool inView, bool useScrollDirection = true) const;
|
|
70 |
void boundTile(QPoint& t) const;
|
|
71 |
QRectF updateTile(const QPoint& t);
|
|
72 |
void paintTile(QPainter* painter, const QPoint& t, const QRectF& dirtyRect, QRegion& dirtyRegion);
|
|
73 |
void createTileField();
|
|
74 |
|
|
75 |
|
|
76 |
QRectF validateTileRect(const QRectF& rect, const QSize& dim) const;
|
|
77 |
QRectF adjustedTileRect(const QSize& dim) const;
|
|
78 |
QRectF centeredTileRect(const QSize& dim) const;
|
|
79 |
void adjustTilesToViewPort(bool center = false);
|
|
80 |
void moveTilesRect(const QRectF& newTilesRect);
|
|
81 |
void resetTiles(const QRect& r, bool remove);
|
|
82 |
void scrollTileField(const QPoint& diff);
|
|
83 |
static QPixmap* getUnprepPixmap();
|
|
84 |
void checkTilesField();
|
|
85 |
void setPage(QWebPage* page);
|
|
86 |
QList<QRectF> updateViewportTiles(QList<TileSet> *updatedTiles = 0);
|
|
87 |
QList<QRectF> updateScrollAreaTilesChunk(QList<TileSet> *updatedTiles = 0, bool inPaint = 0);
|
|
88 |
void doScaleCommit();
|
|
89 |
void doTilesFieldRebuild();
|
|
90 |
void updateSceneRects(const QList<QRectF>& dirtyTiles);
|
|
91 |
#ifdef USE_ASSISTANT_ITEM
|
|
92 |
void resizeEvent(QGraphicsSceneResizeEvent *event);
|
|
93 |
#endif
|
|
94 |
QSize getTileFieldDim();
|
|
95 |
|
|
96 |
QVector<Tile*> m_tilesPool;
|
|
97 |
Tile** m_tilesField;
|
|
98 |
QSize m_tilesDim;
|
|
99 |
QRectF m_tilesRect;
|
|
100 |
qreal m_tilesScale;
|
|
101 |
bool m_inUpdate;
|
|
102 |
bool m_tilesRectCentered;
|
|
103 |
QTime m_userPaintTS;
|
|
104 |
QTimer m_updateTimer;
|
|
105 |
bool m_tilesFrozen;
|
|
106 |
bool m_needViewportTilesUpdate;
|
|
107 |
bool m_needScaleCommit;
|
|
108 |
bool m_needTilesFieldRebuild;
|
|
109 |
QPoint m_lastScrollDelta;
|
|
110 |
#ifdef USE_ASSISTANT_ITEM
|
|
111 |
TiledWebViewAssistant* m_assistant;
|
|
112 |
#endif // USE_ASSISTANT_ITEM
|
|
113 |
|
|
114 |
private slots:
|
|
115 |
void repaintRequested(QRect);
|
|
116 |
void updateTimeout();
|
|
117 |
void scheduleScaleUpdate();
|
|
118 |
void startUpdateTimer();
|
|
119 |
void stopUpdateTimer();
|
|
120 |
void loadStarted();
|
|
121 |
|
|
122 |
public slots:
|
|
123 |
void viewportUpdated();
|
|
124 |
void commitZoom();
|
|
125 |
void setTiledBackingStoreFrozen(bool frozen);
|
|
126 |
void userActivity();
|
|
127 |
void viewScrolled(QPoint& scrollPos, QPoint& delta);
|
|
128 |
|
|
129 |
friend class TiledWebViewAssistant;
|
|
130 |
};
|
|
131 |
|
|
132 |
#endif // TILEDWEBVIEW_H
|