Debian Codegraph @

src/QMapControl/browserimagemanager.h

raw symbols SCIP
1 /***************************************************************************
2 * Copyright (C) 2008 by Chris Browet *
3 * [email protected] *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #ifndef BROWSERIMAGEMANAGER_H
21 #define BROWSERIMAGEMANAGER_H
22
23 #include <QObject>
24 #include <QPixmap>
25
26 #include <QtNetwork/QtNetwork>
27 #include <QWebEnginePage>
28 #include <QWebEngineHistory>
29 #include <QWebEngineSettings>
30 #include <QWebEngineView>
31
32 #include <QThread>
33
34 #include "IImageManager.h"
35
36 /**
37 @author Chris Browet <[email protected]>
38 */
39
40 class BrowserWebPage : public QWebEnginePage
41 {
42 friend class BrowserImageManager;
43
44 protected:
45 virtual void javaScriptConsoleMessage ( const QString & message, int lineNumber, const QString & sourceID );
46 virtual void javaScriptAlert ( const QString & msg ) ;
47 void launchRequest ( const QUrl & url );
48
49 private:
50 qreal tllat, tllon;
51 qreal brlat, brlon;
52
53 int ox, oy, sw, sh;
54 };
55
56 #ifdef BROWSERIMAGEMANAGER_IS_THREADED
57 class BrowserImageManager : public QThread, public IImageManager
58 #else
59 class BrowserImageManager : public QObject, public IImageManager
60 #endif
61 {
62 Q_OBJECT;
63 public:
64 BrowserImageManager(QObject* parent = 0);
65 BrowserImageManager(const BrowserImageManager&);
66 BrowserImageManager& operator=(const BrowserImageManager&);
67 ~BrowserImageManager();
68
69 //! returns a QPixmap of the asked image
70 /*!
71 * If this component doesn´t have the image a network query gets started to load it.
72 * @param host the host of the image
73 * @param path the path to the image
74 * @return the pixmap of the asked image
75 */
76 QImage getImage(IMapAdapter* anAdapter, const QString &url);
77 QByteArray getData(IMapAdapter* anAdapter, const QString &url);
78
79 //QPixmap prefetchImage(const QString& host, const QString& path);
80 QImage prefetchImage(IMapAdapter* anAdapter, int x, int y, int z);
81
82 void receivedData(const QByteArray& ba, const QHash<QString, QString>& headers, const QString& url);
83
84 /*!
85 * This method is called by MapNetwork, after all images in its queue were loaded.
86 * The BrowserImageManager emits a signal, which is used in MapControl to remove the zoom image.
87 * The zoom image should be removed on Tile Images with transparency.
88 * Else the zoom image stay visible behind the newly loaded tiles.
89 */
90 void loadingQueueEmpty();
91
92 /*!
93 * Aborts all current loading threads.
94 * This is useful when changing the zoom-factor, though newly needed images loads faster
95 */
96 void abortLoading();
97
98 void setCacheDir(const QDir& path);
99 QDir getCacheDir();
100 void setCacheMaxSize(int max);
101
102 private:
103 QPixmap emptyPixmap;
104 QPixmap errorPixmap;
105 QStringList prefetch;
106
107 QQueue<LoadingRequest> loadingRequests;
108 bool requestActive;
109 int requestDuration;
110 void launchRequest();
111
112 static BrowserImageManager* m_BrowserImageManagerInstance;
113
114 BrowserWebPage* page;
115 QNetworkAccessManager* qnam;
116
117 signals:
118 void dataRequested();
119 void dataReceived();
120 void loadingFinished();
121
122 private slots:
123 void pageLoadFinished(bool);
124 void slotLoadProgress(int p);
125
126 #ifdef BROWSERIMAGEMANAGER_IS_THREADED
127 private slots:
128 void checkRequests();
129
130 protected:
131 virtual void run();
132 #else
133 private:
134 QTimer* timeoutTimer;
135
136 private slots:
137 void timeout();
138
139 #endif // BROWSERIMAGEMANAGER_IS_THREADED
140 };
141
142 #endif