draw different symbol if gps device got no fix

This commit is contained in:
Niels 2010-11-04 19:18:16 +01:00
parent 0dd2f334d0
commit 889c3fbc87
2 changed files with 25 additions and 10 deletions

View File

@ -27,10 +27,11 @@
GpsLayer::GpsLayer(MapWidget *map) :
AbstractLayer(map),
m_gps(new GpsClient(this)),
m_pos(QPointF(9.8, 54)),
m_pos(QPointF(0, 0)),
m_alt(0),
m_track(0),
m_speed(0)
m_speed(0),
m_fix(false)
{
setVisible(false);
connect(m_gps, SIGNAL(position(QPointF)), this, SLOT(position(QPointF)));
@ -39,6 +40,7 @@ GpsLayer::GpsLayer(MapWidget *map) :
connect(m_gps, SIGNAL(speed(qreal)), this, SLOT(speed(qreal)));
connect(m_gps, SIGNAL(connected()), this, SLOT(connected()));
connect(m_gps, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(m_gps, SIGNAL(fixed(bool)), this, SLOT(fixed(bool)));
m_gps->connectGps();
}
@ -60,18 +62,21 @@ void GpsLayer::keyPressed(QKeyEvent *event)
void GpsLayer::paint(QPainter *painter)
{
QPoint pos = map()->geo2screen(m_pos.x(), m_pos.y());
painter->setRenderHint(QPainter::Antialiasing, true);
painter->setPen(QPen(QColor(0, 0, 255, 110), 4));
painter->drawEllipse(pos, 8, 8);
painter->setPen(QPen(QColor(0, 0, 255, 210), 2, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
painter->translate(pos);
painter->rotate(m_track);
painter->drawLine(QPoint(4, 3), QPoint(0, -7));
painter->drawLine(QPoint(-4, 3), QPoint(0, -7));
painter->drawLine(QPoint(4, 3), QPoint(0, 0));
painter->drawLine(QPoint(-4, 3), QPoint(0, 0));
if (m_fix) {
painter->setPen(QPen(QColor(0, 0, 255, 210), 2, Qt::SolidLine, Qt::RoundCap, Qt::MiterJoin));
painter->translate(pos);
painter->rotate(m_track);
painter->drawLine(QPoint(4, 3), QPoint(0, -7));
painter->drawLine(QPoint(-4, 3), QPoint(0, -7));
painter->drawLine(QPoint(4, 3), QPoint(0, 0));
painter->drawLine(QPoint(-4, 3), QPoint(0, 0));
} else {
painter->drawText(pos.x()-8, pos.y()-8, 16, 16, Qt::AlignCenter, "?");
}
}
void GpsLayer::position(const QPointF &pos)
@ -118,3 +123,11 @@ void GpsLayer::disconnected()
map()->update();
}
void GpsLayer::fixed(bool fix)
{
m_fix = fix;
if (isVisible()) {
map()->update();
}
}

View File

@ -45,11 +45,13 @@ private slots:
void speed(qreal speed);
void connected();
void disconnected();
void fixed(bool fix);
private:
GpsClient *m_gps;
QPointF m_pos;
qreal m_alt, m_track, m_speed;
bool m_fix;
};