summaryrefslogtreecommitdiff
path: root/qmapwatchlet/compassview.h
blob: 3e87a65c0de6b5ffa68dac477676d5662c0b79d9 (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
#ifndef COMPASSVIEW_H
#define COMPASSVIEW_H

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

using QTM_PREPEND_NAMESPACE(QGeoPositionInfoSource);
using QTM_PREPEND_NAMESPACE(QGeoPositionInfo);

class CompassView : 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(qreal currentSpeed READ currentSpeed NOTIFY currentSpeedChanged)
	Q_PROPERTY(qreal currentAltitude READ currentAltitude NOTIFY currentAltitudeChanged)

public:
	explicit CompassView(QDeclarativeItem *parent = 0);
	
	bool updateEnabled() const;
	void setUpdateEnabled(bool enabled);

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

	qreal currentSpeed() const;
	qreal currentAltitude() const;

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

signals:
	void updateEnabledChanged();
	void updateIntervalChanged();
	void currentSpeedChanged();
	void currentAltitudeChanged();

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

private slots:
	void handlePositionUpdate(const QGeoPositionInfo& info);
	
private:
	bool _enabled;
	QSize _size;
	QImage _image;
	QGeoPositionInfoSource *_posSource;
	qreal _direction;
	qreal _speed;
	qreal _altitude;
};

#endif // COMPASSVIEW_H