poilayer.cpp |
28 | 28 | #include <QtCore/QSettings> |
29 | 29 | #include <QtXml/QXmlStreamReader> |
30 | 30 | |
| 31 | QHash<QString, QPixmap*> PoiLayer::m_iconCache = QHash<QString, QPixmap*>(); |
| 32 | |
31 | 33 | PoiLayer::PoiLayer(MapWidget *map) : |
32 | 34 | AbstractLayer(map), |
| 35 | m_level(0), |
33 | 36 | m_points(), |
34 | 37 | m_pointsOnScreen(), |
35 | 38 | m_icons(), |
| 39 | m_names(), |
36 | 40 | m_pointsOffset(0, 0), |
37 | | m_iconPath(), |
38 | | m_iconCache() |
| 41 | m_iconPath() |
39 | 42 | { |
40 | 43 | QSettings set(QDir::homePath()+"/Maps/nanomap.conf", QSettings::NativeFormat); |
41 | 44 | |
... | ... | |
100 | 103 | } |
101 | 104 | m_points << pos; |
102 | 105 | m_icons << t; |
| 106 | m_names << tags.value("name", ""); |
103 | 107 | break; |
104 | 108 | } |
105 | 109 | } |
... | ... | |
114 | 118 | |
115 | 119 | void PoiLayer::zoom(int level) |
116 | 120 | { |
| 121 | m_level = level; |
117 | 122 | if (m_points.isEmpty()) { |
118 | 123 | return; |
119 | 124 | } |
... | ... | |
137 | 142 | |
138 | 143 | void PoiLayer::paint(QPainter *painter) |
139 | 144 | { |
| 145 | QFont font = painter->font(); |
| 146 | font.setPointSize(8); |
| 147 | painter->setFont(font); |
| 148 | |
| 149 | QFontMetrics fm(font); |
| 150 | int dy = -fm.ascent()-10; |
| 151 | |
| 152 | painter->setBrush(QColor(200, 200, 255, 190)); |
140 | 153 | QPoint p; |
141 | 154 | for (int i = 0; i < m_pointsOnScreen.count(); ++i) { |
142 | | p = m_pointsOnScreen.at(i); |
143 | | painter->drawPixmap(p + m_pointsOffset, *m_iconCache.value(m_icons.at(i))); |
| 155 | p = m_pointsOnScreen.at(i) + m_pointsOffset; |
| 156 | painter->drawPixmap(p - QPoint(8, 8), *m_iconCache.value(m_icons.at(i))); |
| 157 | |
| 158 | QPoint delta = p - QPoint(160, 120); |
| 159 | if (m_level > 12 && delta.manhattanLength() < 25) { |
| 160 | int dx = fm.width(m_names.at(i)); |
| 161 | painter->setPen(QColor(200, 200, 255, 190)); |
| 162 | painter->drawRect(QRect(p - QPoint(dx/2, -10), QSize(dx, fm.height()))); |
| 163 | painter->setPen(Qt::black); |
| 164 | painter->drawText(p - QPoint(dx/2, dy), m_names.at(i)); |
| 165 | } |
144 | 166 | } |
145 | 167 | } |
146 | 168 | |
poilayer.h |
1 | 1 | /* |
2 | | * Copyright 2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de> |
| 2 | * Copyright 2010-2011 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de> |
3 | 3 | * |
4 | 4 | * This program is free software; you can redistribute it and/or modify |
5 | 5 | * it under the terms of the GNU General Public License as published by |
... | ... | |
38 | 38 | virtual void paint(QPainter *painter); |
39 | 39 | |
40 | 40 | private: |
| 41 | int m_level; |
41 | 42 | QList<QPointF> m_points; |
42 | 43 | QList<QPoint> m_pointsOnScreen; |
43 | | QStringList m_icons; |
| 44 | QStringList m_icons, m_names; |
44 | 45 | QPoint m_pointsOffset; |
45 | 46 | QString m_iconPath; |
46 | | QHash<QString, QPixmap*> m_iconCache; |
| 47 | static QHash<QString, QPixmap*> m_iconCache; |
47 | 48 | |
48 | 49 | }; |
49 | 50 | |