-
Notifications
You must be signed in to change notification settings - Fork 4
/
cacamap.h
145 lines (125 loc) · 3.78 KB
/
cacamap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
Copyright 2010 Jean Fairlie jmfairlie@gmail.com
CacaMap 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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
/** @file cacamap.h
* CacaMap is a Simple Qt OSM Map Widget
*/
#ifndef CACAMAP_H
#define CACAMAP_H
#include <QtGui>
#include <QtNetwork>
#include <iostream>
#include <vector>
#include "servermanager.h"
/**
* The quint32 version of QPoint
*/
struct longPoint
{
quint32 x;/**< x coord. */
quint32 y;/**< y coord.*/
longPoint(quint32,quint32);
longPoint();
};
/**
Helper struct that handles coordinate transformations
*/
struct myMercator
{
static longPoint geoCoordToPixel(QPointF const &,int , int);
static QPointF pixelToGeoCoord(longPoint const &, int, int);
};
/**
* Struct to define a range of consecutive tiles
* It's used to identify which tiles are visible and need to be rendered/downlaoded
* @see cacaMap::updateTilesToRender()
*/
struct tileSet
{
int zoom;/**< zoom level.*/
qint32 top;/**< topmost row.*/
qint32 bottom;/**< bottommost row.*/
qint32 left;/**< leftmostcolumn. */
qint32 right;/**< rightmost column. */
int offsetx;/**< horizontal offset needed to align the tiles in the wiget.*/
int offsety;/**< vertical offset needed to align the tiles in the widget.*/
};
/**
* Used to represent a specific %tile
* @see cacaMap::tileCache
*/
struct tile
{
int zoom;/**< zoom level.*/
qint32 x;/**< colum number.*/
qint32 y;/**< row number.*/
QString url;/**<used to identify the %tile when it finishes downloading.*/
};
/**
* maximum space allowed for caching tiles
*/
#define CACHE_MAX 1*1024*1024 //1MB
/**
Main map widget
*/
class cacaMap : public QWidget
{
Q_OBJECT
public:
cacaMap(QWidget * _parent=0);
virtual ~cacaMap();
void setGeoCoords(QPointF);
bool zoomIn();
bool zoomOut();
bool setZoom(int level);
QPointF getGeoCoords();
QStringList getServerNames();
void setServer(int);
int getZoom();
private:
QNetworkAccessManager *manager;/**< manages http requests. */
tileSet tilesToRender;/**< range of visible tiles. */
QHash<QString,int> tileCache;/**< list of cached tiles (in HDD). */
QHash<QString,tile> downloadQueue;/**< list of tiles waiting to be downloaded. */
QHash<QString,int> unavailableTiles;/**< list of tiles that were not found on the server.*/
bool downloading;/**< flag that indicates if there is a download going on. */
QString folder;/**< root application folder. */
QMovie loadingAnim;/**< to show a 'loading' animation for yet unavailable tiles. */
QPixmap notAvailableTile;
servermanager servermgr;
void renderMap(QPainter &);
void downloadPicture();
void loadCache();
QString getTilePath(int, qint32);
QPixmap getTilePatch(int,quint32,quint32,int,int,int);
protected:
int zoom;/**< Map zoom level. */
int minZoom;/**< Minimum zoom level (farthest away).*/
int maxZoom;/**< Maximum zoom level (closest).*/
int tileSize; /**< size in px of the square %tile. */
quint32 cacheSize;/**< current %tile cache size in bytes. */
//check QtMobility QGeoCoordinate
QPointF geocoords; /**< current longitude and latitude. */
QPixmap* imgBuffer;
QPixmap tmpbuff;
float buffzoomrate;
bool bufferDirty; /**< image buffer needs to be updated. */
void resizeEvent(QResizeEvent*);
void paintEvent(QPaintEvent *);
void updateTilesToRender();
void updateBuffer();
void updateContent();
protected slots:
void slotDownloadProgress(qint64, qint64);
void slotDownloadReady(QNetworkReply *);
void slotError(QNetworkReply::NetworkError);
};
#endif