| 1 | #include "Landmark.h"
|
---|
| 2 | #include <QPen>
|
---|
| 3 | #include <QGeoMapTextObject>
|
---|
| 4 | #include <QGeoMapPixmapObject>
|
---|
| 5 | #include <QGraphicsGeoMap>
|
---|
| 6 |
|
---|
| 7 | using namespace QtMobility;
|
---|
| 8 |
|
---|
| 9 | Landmark::Landmark(QGraphicsGeoMap *geoMap, const QGeoCoordinate &coordinate,QString name,QString type)
|
---|
| 10 | {
|
---|
| 11 | geoMap->addMapObject(this);
|
---|
| 12 | this->geoMap=geoMap;
|
---|
| 13 | pixmap = new QGeoMapPixmapObject();
|
---|
| 14 | pixmap->setCoordinate(coordinate);
|
---|
| 15 |
|
---|
| 16 | if(type=="cross")
|
---|
| 17 | {
|
---|
| 18 | pixmap->setOffset(QPoint(-16, -16));
|
---|
| 19 | pixmap->setPixmap(QPixmap(":cross.png"));
|
---|
| 20 | }
|
---|
| 21 | else
|
---|
| 22 | {
|
---|
| 23 | pixmap->setOffset(QPoint(-2, -30));
|
---|
| 24 | pixmap->setPixmap(QPixmap(":landmark.png"));
|
---|
| 25 | }
|
---|
| 26 | addChildObject(pixmap);
|
---|
| 27 |
|
---|
| 28 | QFont font;
|
---|
| 29 | font.setWeight(QFont::Bold);
|
---|
| 30 | text = new QGeoMapTextObject(coordinate,name, font, QPoint(0, 10));
|
---|
| 31 | text->setPen(QPen(Qt::NoPen));
|
---|
| 32 | text->setBrush(QBrush(Qt::red));
|
---|
| 33 | addChildObject(text);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | Landmark::~Landmark()
|
---|
| 37 | {
|
---|
| 38 | geoMap->removeMapObject(this);
|
---|
| 39 | clearChildObjects();
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | void Landmark::setText(QString string)
|
---|
| 43 | {
|
---|
| 44 | text->setText(string);
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | void Landmark::setColor(Qt::GlobalColor color)
|
---|
| 48 | {
|
---|
| 49 | text->setBrush(QBrush(color));
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | void Landmark::setCoordinate(const QGeoCoordinate &coordinate)
|
---|
| 53 | {
|
---|
| 54 | pixmap->setCoordinate(coordinate);
|
---|
| 55 | text->setCoordinate(coordinate);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | QGeoCoordinate Landmark::coordinate(void)
|
---|
| 59 | {
|
---|
| 60 | return pixmap->coordinate();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | void Landmark::RemoveLandmark(void)
|
---|
| 64 | {
|
---|
| 65 | geoMap->removeMapObject(this);
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | void Landmark::AddLandmark(QGraphicsGeoMap *geoMap)
|
---|
| 69 | {
|
---|
| 70 | geoMap->addMapObject(this);
|
---|
| 71 | this->geoMap=geoMap;
|
---|
| 72 | }
|
---|