Date:2011-03-23 00:32:10 (13 years 6 days ago)
Author:nielsk
Commit:880bc8b3bae76f054b583efa18e0fee22cfd9342
Message:draw poi name if it is near the middle of the screen

Files: poilayer.cpp (4 diffs)
poilayer.h (2 diffs)

Change Details

poilayer.cpp
2828#include <QtCore/QSettings>
2929#include <QtXml/QXmlStreamReader>
3030
31QHash<QString, QPixmap*> PoiLayer::m_iconCache = QHash<QString, QPixmap*>();
32
3133PoiLayer::PoiLayer(MapWidget *map) :
3234    AbstractLayer(map),
35    m_level(0),
3336    m_points(),
3437    m_pointsOnScreen(),
3538    m_icons(),
39    m_names(),
3640    m_pointsOffset(0, 0),
37    m_iconPath(),
38    m_iconCache()
41    m_iconPath()
3942{
4043    QSettings set(QDir::homePath()+"/Maps/nanomap.conf", QSettings::NativeFormat);
4144
...... 
100103                                }
101104                                m_points << pos;
102105                                m_icons << t;
106                                m_names << tags.value("name", "");
103107                                break;
104108                            }
105109                        }
...... 
114118
115119void PoiLayer::zoom(int level)
116120{
121    m_level = level;
117122    if (m_points.isEmpty()) {
118123        return;
119124    }
...... 
137142
138143void PoiLayer::paint(QPainter *painter)
139144{
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));
140153    QPoint p;
141154    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        }
144166    }
145167}
146168
poilayer.h
11/*
2 * Copyright 2010 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de>
2 * Copyright 2010-2011 Niels Kummerfeldt <niels.kummerfeldt@tu-harburg.de>
33 *
44 * This program is free software; you can redistribute it and/or modify
55 * it under the terms of the GNU General Public License as published by
...... 
3838    virtual void paint(QPainter *painter);
3939
4040private:
41    int m_level;
4142    QList<QPointF> m_points;
4243    QList<QPoint> m_pointsOnScreen;
43    QStringList m_icons;
44    QStringList m_icons, m_names;
4445    QPoint m_pointsOffset;
4546    QString m_iconPath;
46    QHash<QString, QPixmap*> m_iconCache;
47    static QHash<QString, QPixmap*> m_iconCache;
4748
4849};
4950

Archive Download the corresponding diff file

Branches:
master



interactive