1
0
mirror of git://projects.qi-hardware.com/nanomap.git synced 2024-11-23 17:07:11 +02:00

draw poi name if it is near the middle of the screen

This commit is contained in:
Niels 2011-03-23 00:32:10 +01:00
parent a3d3597d73
commit 880bc8b3ba
2 changed files with 30 additions and 7 deletions

View File

@ -28,14 +28,17 @@
#include <QtCore/QSettings> #include <QtCore/QSettings>
#include <QtXml/QXmlStreamReader> #include <QtXml/QXmlStreamReader>
QHash<QString, QPixmap*> PoiLayer::m_iconCache = QHash<QString, QPixmap*>();
PoiLayer::PoiLayer(MapWidget *map) : PoiLayer::PoiLayer(MapWidget *map) :
AbstractLayer(map), AbstractLayer(map),
m_level(0),
m_points(), m_points(),
m_pointsOnScreen(), m_pointsOnScreen(),
m_icons(), m_icons(),
m_names(),
m_pointsOffset(0, 0), m_pointsOffset(0, 0),
m_iconPath(), m_iconPath()
m_iconCache()
{ {
QSettings set(QDir::homePath()+"/Maps/nanomap.conf", QSettings::NativeFormat); QSettings set(QDir::homePath()+"/Maps/nanomap.conf", QSettings::NativeFormat);
@ -100,6 +103,7 @@ void PoiLayer::load(const QString &filename)
} }
m_points << pos; m_points << pos;
m_icons << t; m_icons << t;
m_names << tags.value("name", "");
break; break;
} }
} }
@ -114,6 +118,7 @@ void PoiLayer::load(const QString &filename)
void PoiLayer::zoom(int level) void PoiLayer::zoom(int level)
{ {
m_level = level;
if (m_points.isEmpty()) { if (m_points.isEmpty()) {
return; return;
} }
@ -137,10 +142,27 @@ void PoiLayer::pan(const QPoint &move)
void PoiLayer::paint(QPainter *painter) void PoiLayer::paint(QPainter *painter)
{ {
QFont font = painter->font();
font.setPointSize(8);
painter->setFont(font);
QFontMetrics fm(font);
int dy = -fm.ascent()-10;
painter->setBrush(QColor(200, 200, 255, 190));
QPoint p; QPoint p;
for (int i = 0; i < m_pointsOnScreen.count(); ++i) { for (int i = 0; i < m_pointsOnScreen.count(); ++i) {
p = m_pointsOnScreen.at(i); p = m_pointsOnScreen.at(i) + m_pointsOffset;
painter->drawPixmap(p + m_pointsOffset, *m_iconCache.value(m_icons.at(i))); painter->drawPixmap(p - QPoint(8, 8), *m_iconCache.value(m_icons.at(i)));
QPoint delta = p - QPoint(160, 120);
if (m_level > 12 && delta.manhattanLength() < 25) {
int dx = fm.width(m_names.at(i));
painter->setPen(QColor(200, 200, 255, 190));
painter->drawRect(QRect(p - QPoint(dx/2, -10), QSize(dx, fm.height())));
painter->setPen(Qt::black);
painter->drawText(p - QPoint(dx/2, dy), m_names.at(i));
}
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de> * Copyright 2010-2011 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -38,12 +38,13 @@ protected:
virtual void paint(QPainter *painter); virtual void paint(QPainter *painter);
private: private:
int m_level;
QList<QPointF> m_points; QList<QPointF> m_points;
QList<QPoint> m_pointsOnScreen; QList<QPoint> m_pointsOnScreen;
QStringList m_icons; QStringList m_icons, m_names;
QPoint m_pointsOffset; QPoint m_pointsOffset;
QString m_iconPath; QString m_iconPath;
QHash<QString, QPixmap*> m_iconCache; static QHash<QString, QPixmap*> m_iconCache;
}; };