summaryrefslogtreecommitdiff
path: root/qmapwatchlet/mapview.h
blob: caa2730e3a32a4a09f9f72cecb5c6d77c4be3347 (plain)
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
#ifndef MAPVIEW_H
#define MAPVIEW_H

#include <QtGui/QImage>
#include <QtDeclarative/QDeclarativeItem>
#include <QtLocation/QGeoMappingManager>
#include <QtLocation/QGeoPositionInfoSource>
#include <QtLocation/QGeoSearchReply>

namespace sowatch
{

using QTM_PREPEND_NAMESPACE(QGeoMapData);
using QTM_PREPEND_NAMESPACE(QGeoPositionInfoSource);
using QTM_PREPEND_NAMESPACE(QGeoPositionInfo);
using QTM_PREPEND_NAMESPACE(QGeoBoundingBox);
using QTM_PREPEND_NAMESPACE(QGeoSearchReply);

class MapView : public QDeclarativeItem
{
	Q_OBJECT
	Q_PROPERTY(bool updateEnabled READ updateEnabled WRITE setUpdateEnabled NOTIFY updateEnabledChanged)
	Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval NOTIFY updateIntervalChanged)
	Q_PROPERTY(bool decolor READ decolor WRITE setDecolor NOTIFY decolorChanged)
	Q_PROPERTY(qreal zoomLevel READ zoomLevel WRITE setZoomLevel NOTIFY zoomLevelChanged)
	Q_PROPERTY(QString currentLocationName READ currentLocationName NOTIFY currentLocationNameChanged)

public:
	explicit MapView(QDeclarativeItem *parent = 0);
	~MapView();

	bool updateEnabled() const;
	void setUpdateEnabled(bool enabled);

	int updateInterval() const;
	void setUpdateInterval(int msec);

	bool decolor() const;
	void setDecolor(bool decolor) const;

	qreal zoomLevel() const;
	void setZoomLevel(qreal level);

	QString currentLocationName() const;

	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

public slots:
	void updateCurrentLocationName();

signals:
	void updateEnabledChanged();
	void updateIntervalChanged();
	void zoomLevelChanged();
	void currentLocationNameChanged();
	void decolorChanged();

protected:
	void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry);

private slots:
	void handlePositionUpdate(const QGeoPositionInfo& info);
	void handleMapChanged(const QRectF& rect);
	void handleCurrentLocationNameSearchFinished();
	void handleCurrentLocationNameSearchError(QGeoSearchReply::Error error, const QString& errorString);

private:
	bool _enabled;
	bool _decolor;
	QImage _arrow;
	QGeoMapData *_mapData;
	QGeoPositionInfoSource *_posSource;
	QGeoPositionInfo _pos;
	QString _posName;
	QGeoBoundingBox *_searchArea;
	QGeoSearchReply *_searchReply;
};

}

#endif // MAPVIEW_H