mirror of
https://github.com/tumic0/GPXSee.git
synced 2024-11-24 03:35:53 +01:00
Use generic icon rotate instead of special icon draw functions
This commit is contained in:
parent
320b04c3fa
commit
c6c3e0978c
@ -198,6 +198,8 @@
|
|||||||
<file alias="building.png">icons/map/marine/building.png</file>
|
<file alias="building.png">icons/map/marine/building.png</file>
|
||||||
<file alias="fog-signal.png">icons/map/marine/fog-signal.png</file>
|
<file alias="fog-signal.png">icons/map/marine/fog-signal.png</file>
|
||||||
<file alias="construction.png">icons/map/marine/construction.png</file>
|
<file alias="construction.png">icons/map/marine/construction.png</file>
|
||||||
|
<file alias="radio-call.png">icons/map/marine/radio-call.png</file>
|
||||||
|
<file alias="current.png">icons/map/marine/current.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
|
|
||||||
<!-- Mapsforge rendertheme -->
|
<!-- Mapsforge rendertheme -->
|
||||||
|
BIN
icons/map/marine/current.png
Normal file
BIN
icons/map/marine/current.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 135 B |
BIN
icons/map/marine/radio-call.png
Normal file
BIN
icons/map/marine/radio-call.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 224 B |
@ -10,15 +10,11 @@
|
|||||||
using namespace ENC;
|
using namespace ENC;
|
||||||
|
|
||||||
#define TEXT_EXTENT 160
|
#define TEXT_EXTENT 160
|
||||||
|
|
||||||
#define TSSLPT_SIZE 0.005 /* ll */
|
#define TSSLPT_SIZE 0.005 /* ll */
|
||||||
#define RDOCAL_SIZE 12 /* px */
|
|
||||||
#define CURENT_SIZE 12 /* px */
|
|
||||||
|
|
||||||
typedef QMap<Coordinates, const MapData::Point*> PointMap;
|
typedef QMap<Coordinates, const MapData::Point*> PointMap;
|
||||||
|
|
||||||
const float C1 = 0.866025f; /* sqrt(3)/2 */
|
static const float C1 = 0.866025f; /* sqrt(3)/2 */
|
||||||
|
|
||||||
static const QColor haloColor(Qt::white);
|
static const QColor haloColor(Qt::white);
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
@ -105,67 +101,14 @@ static Coordinates centroid(const QVector<Coordinates> &polygon)
|
|||||||
return Coordinates(cx * factor, cy * factor);
|
return Coordinates(cx * factor, cy * factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
static QImage *rdocalArrow(qreal angle)
|
static double angle(uint type, const QVariant ¶m)
|
||||||
{
|
|
||||||
QImage *img = new QImage(RDOCAL_SIZE*2, RDOCAL_SIZE*2,
|
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
|
||||||
img->fill(Qt::transparent);
|
|
||||||
QPainter p(img);
|
|
||||||
p.setRenderHint(QPainter::Antialiasing);
|
|
||||||
p.setPen(QPen(QColor("#eb49eb"), 1));
|
|
||||||
|
|
||||||
QPointF arrow[3];
|
|
||||||
arrow[0] = QPointF(img->width()/2, img->height()/2);
|
|
||||||
arrow[1] = arrow[0] + QPointF(qSin(angle - M_PI/3) * RDOCAL_SIZE,
|
|
||||||
qCos(angle - M_PI/3) * RDOCAL_SIZE);
|
|
||||||
arrow[2] = arrow[0] + QPointF(qSin(angle - M_PI + M_PI/3) * RDOCAL_SIZE,
|
|
||||||
qCos(angle - M_PI + M_PI/3) * RDOCAL_SIZE);
|
|
||||||
|
|
||||||
QLineF l(arrow[1], arrow[2]);
|
|
||||||
QPointF pt(l.pointAt(0.5));
|
|
||||||
|
|
||||||
p.translate(arrow[0] - pt);
|
|
||||||
p.drawPolyline(QPolygonF() << arrow[1] << arrow[0] << arrow[2]);
|
|
||||||
p.drawEllipse(pt, RDOCAL_SIZE/2, RDOCAL_SIZE/2);
|
|
||||||
|
|
||||||
return img;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QImage *currentArrow(qreal angle)
|
|
||||||
{
|
|
||||||
QImage *img = new QImage(CURENT_SIZE*2, CURENT_SIZE*2,
|
|
||||||
QImage::Format_ARGB32_Premultiplied);
|
|
||||||
img->fill(Qt::transparent);
|
|
||||||
QPainter p(img);
|
|
||||||
p.setRenderHint(QPainter::Antialiasing);
|
|
||||||
p.setPen(QPen(Qt::black, 1));
|
|
||||||
|
|
||||||
QPointF arrow[3];
|
|
||||||
arrow[0] = QPointF(img->width()/2, img->height()/2);
|
|
||||||
arrow[1] = arrow[0] + QPointF(qSin(angle - M_PI/3) * CURENT_SIZE,
|
|
||||||
qCos(angle - M_PI/3) * CURENT_SIZE);
|
|
||||||
arrow[2] = arrow[0] + QPointF(qSin(angle - M_PI + M_PI/3) * CURENT_SIZE,
|
|
||||||
qCos(angle - M_PI + M_PI/3) * CURENT_SIZE);
|
|
||||||
|
|
||||||
QLineF l(arrow[1], arrow[2]);
|
|
||||||
QPointF pt(l.pointAt(0.5));
|
|
||||||
QLineF l2(arrow[0], pt);
|
|
||||||
|
|
||||||
p.translate(arrow[0] - pt);
|
|
||||||
p.drawPolyline(QPolygonF() << arrow[1] << arrow[0] << arrow[2]);
|
|
||||||
p.drawLine(arrow[0], l2.pointAt(2));
|
|
||||||
|
|
||||||
return img;
|
|
||||||
}
|
|
||||||
|
|
||||||
static QImage *image(uint type, const QVariant ¶m)
|
|
||||||
{
|
{
|
||||||
if (type>>16 == RDOCAL || type>>16 == I_RDOCAL)
|
if (type>>16 == RDOCAL || type>>16 == I_RDOCAL)
|
||||||
return rdocalArrow(deg2rad(90 - param.toDouble()));
|
return 90 + param.toDouble();
|
||||||
else if (type>>16 == CURENT)
|
else if (type>>16 == CURENT)
|
||||||
return currentArrow(deg2rad(90 - param.toDouble()));
|
return 90 + param.toDouble();
|
||||||
else
|
else
|
||||||
return 0;
|
return NAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool showLabel(const QImage *img, const Range &range, int zoom, int type)
|
static bool showLabel(const QImage *img, const Range &range, int zoom, int type)
|
||||||
@ -352,20 +295,19 @@ void RasterTile::processPoints(QList<MapData::Point*> &points,
|
|||||||
const Style::Point &style = s.point(point->type());
|
const Style::Point &style = s.point(point->type());
|
||||||
|
|
||||||
const QString *label = point->label().isEmpty() ? 0 : &(point->label());
|
const QString *label = point->label().isEmpty() ? 0 : &(point->label());
|
||||||
QImage *rimg = style.img().isNull()
|
const QImage *img = style.img().isNull() ? 0 : &style.img();
|
||||||
? image(point->type(), point->param()) : 0;
|
|
||||||
const QImage *img = style.img().isNull() ? rimg : &style.img();
|
|
||||||
const QFont *fnt = showLabel(img, _data->zooms(), _zoom, point->type())
|
const QFont *fnt = showLabel(img, _data->zooms(), _zoom, point->type())
|
||||||
? font(style.textFontSize()) : 0;
|
? font(style.textFontSize()) : 0;
|
||||||
const QColor *color = &style.textColor();
|
const QColor *color = &style.textColor();
|
||||||
const QColor *hColor = style.haloColor().isValid()
|
const QColor *hColor = style.haloColor().isValid()
|
||||||
? &style.haloColor() : 0;
|
? &style.haloColor() : 0;
|
||||||
|
double rotate = angle(point->type(), point->param());
|
||||||
|
|
||||||
if ((!label || !fnt) && !img)
|
if ((!label || !fnt) && !img)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PointItem *item = new PointItem(pos, label, fnt, img, rimg, color,
|
TextPointItem *item = new TextPointItem(pos, label, fnt, img, color,
|
||||||
hColor);
|
hColor, 0, 2, rotate);
|
||||||
if (item->isValid() && !item->collides(textItems)) {
|
if (item->isValid() && !item->collides(textItems)) {
|
||||||
textItems.append(item);
|
textItems.append(item);
|
||||||
if (lightsMap.contains(point->pos()))
|
if (lightsMap.contains(point->pos()))
|
||||||
|
@ -28,19 +28,6 @@ public:
|
|||||||
void render();
|
void render();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class PointItem : public TextPointItem
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
PointItem(const QPoint &point, const QString *text, const QFont *font,
|
|
||||||
const QImage *img, const QImage *rimg, const QColor *color,
|
|
||||||
const QColor *haloColor) : TextPointItem(point, text, font, img, color,
|
|
||||||
haloColor, 0, 2), _rimg(rimg) {}
|
|
||||||
~PointItem() {delete _rimg;}
|
|
||||||
|
|
||||||
private:
|
|
||||||
const QImage *_rimg;
|
|
||||||
};
|
|
||||||
|
|
||||||
void fetchData(QList<MapData::Poly*> &polygons, QList<MapData::Line*> &lines,
|
void fetchData(QList<MapData::Poly*> &polygons, QList<MapData::Line*> &lines,
|
||||||
QList<MapData::Point*> &points);
|
QList<MapData::Point*> &points);
|
||||||
QPointF ll2xy(const Coordinates &c) const
|
QPointF ll2xy(const Coordinates &c) const
|
||||||
|
@ -255,7 +255,9 @@ void Style::pointStyle()
|
|||||||
_points[TYPE(I_TRNBSN)] = Point(QImage(":/marine/turning-basin.png"));
|
_points[TYPE(I_TRNBSN)] = Point(QImage(":/marine/turning-basin.png"));
|
||||||
_points[TYPE(I_TRNBSN)].setTextColor(QColor("#eb49eb"));
|
_points[TYPE(I_TRNBSN)].setTextColor(QColor("#eb49eb"));
|
||||||
_points[TYPE(I_WTWGAG)] = Point(QImage(":/marine/gauge.png"), Small);
|
_points[TYPE(I_WTWGAG)] = Point(QImage(":/marine/gauge.png"), Small);
|
||||||
|
_points[TYPE(RDOCAL)] = Point(QImage(":/marine/radio-call.png"));
|
||||||
_points[TYPE(RDOCAL)].setTextColor(QColor("#eb49eb"));
|
_points[TYPE(RDOCAL)].setTextColor(QColor("#eb49eb"));
|
||||||
|
_points[TYPE(I_RDOCAL)] = Point(QImage(":/marine/radio-call.png"));
|
||||||
_points[TYPE(I_RDOCAL)].setTextColor(QColor("#eb49eb"));
|
_points[TYPE(I_RDOCAL)].setTextColor(QColor("#eb49eb"));
|
||||||
_points[TYPE(PYLONS)] = Point(QImage(":/marine/pylon.png"));
|
_points[TYPE(PYLONS)] = Point(QImage(":/marine/pylon.png"));
|
||||||
_points[SUBTYPE(I_BERTHS, 6)] = Point(QImage(":/marine/fleeting-area.png"));
|
_points[SUBTYPE(I_BERTHS, 6)] = Point(QImage(":/marine/fleeting-area.png"));
|
||||||
@ -265,6 +267,7 @@ void Style::pointStyle()
|
|||||||
_points[TYPE(PILBOP)] = Point(QImage(":/marine/boarding-place.png"));
|
_points[TYPE(PILBOP)] = Point(QImage(":/marine/boarding-place.png"));
|
||||||
_points[TYPE(SISTAT)] = Point(QImage(":/marine/pylon.png"));
|
_points[TYPE(SISTAT)] = Point(QImage(":/marine/pylon.png"));
|
||||||
_points[TYPE(SLCONS)] = Point(QImage(":/marine/construction.png"), Small);
|
_points[TYPE(SLCONS)] = Point(QImage(":/marine/construction.png"), Small);
|
||||||
|
_points[TYPE(CURENT)] = Point(QImage(":/marine/current.png"));
|
||||||
|
|
||||||
_points[SUBTYPE(SMCFAC, 7)] = Point(QImage(":/POI/restaurant-11.png"), Small);
|
_points[SUBTYPE(SMCFAC, 7)] = Point(QImage(":/POI/restaurant-11.png"), Small);
|
||||||
_points[SUBTYPE(SMCFAC, 11)] = Point(QImage(":/POI/pharmacy-11.png"), Small);
|
_points[SUBTYPE(SMCFAC, 11)] = Point(QImage(":/POI/pharmacy-11.png"), Small);
|
||||||
|
@ -18,9 +18,9 @@ static void expand(QRectF &rect, int width)
|
|||||||
|
|
||||||
TextPointItem::TextPointItem(const QPoint &point, const QString *text,
|
TextPointItem::TextPointItem(const QPoint &point, const QString *text,
|
||||||
const QFont *font, const QImage *img, const QColor *color,
|
const QFont *font, const QImage *img, const QColor *color,
|
||||||
const QColor *haloColor, const QColor *bgColor, int padding)
|
const QColor *haloColor, const QColor *bgColor, int padding, double rotate)
|
||||||
: TextItem(font ? text : 0), _font(font), _img(img), _color(color),
|
: TextItem(font ? text : 0), _font(font), _img(img), _color(color),
|
||||||
_haloColor(haloColor), _bgColor(bgColor)
|
_haloColor(haloColor), _bgColor(bgColor), _rotate(rotate)
|
||||||
{
|
{
|
||||||
if (_text) {
|
if (_text) {
|
||||||
QFontMetrics fm(*_font);
|
QFontMetrics fm(*_font);
|
||||||
@ -58,8 +58,17 @@ void TextPointItem::paint(QPainter *painter) const
|
|||||||
{
|
{
|
||||||
if (_img && !_img->isNull()) {
|
if (_img && !_img->isNull()) {
|
||||||
QSizeF s(_img->size() / _img->devicePixelRatioF());
|
QSizeF s(_img->size() / _img->devicePixelRatioF());
|
||||||
painter->drawImage(QPointF(_rect.left(), _rect.center().y()
|
if (std::isnan(_rotate))
|
||||||
- s.height()/2), *_img);
|
painter->drawImage(QPointF(_rect.left(), _rect.center().y()
|
||||||
|
- s.height()/2), *_img);
|
||||||
|
else {
|
||||||
|
painter->save();
|
||||||
|
painter->translate(QPointF(_rect.left() + s.width()/2,
|
||||||
|
_rect.center().y()));
|
||||||
|
painter->rotate(_rotate);
|
||||||
|
painter->drawImage(QPointF(-s.width()/2, -s.height()/2), *_img);
|
||||||
|
painter->restore();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_text) {
|
if (_text) {
|
||||||
|
@ -17,7 +17,7 @@ public:
|
|||||||
TextPointItem() : TextItem(0), _font(0), _img(0) {}
|
TextPointItem() : TextItem(0), _font(0), _img(0) {}
|
||||||
TextPointItem(const QPoint &point, const QString *text, const QFont *font,
|
TextPointItem(const QPoint &point, const QString *text, const QFont *font,
|
||||||
const QImage *img, const QColor *color, const QColor *haloColor,
|
const QImage *img, const QColor *color, const QColor *haloColor,
|
||||||
const QColor *bgColor = 0, int padding = 0);
|
const QColor *bgColor = 0, int padding = 0, double rotate = NAN);
|
||||||
|
|
||||||
bool isValid() const {return !_rect.isEmpty();}
|
bool isValid() const {return !_rect.isEmpty();}
|
||||||
|
|
||||||
@ -31,6 +31,7 @@ private:
|
|||||||
const QFont *_font;
|
const QFont *_font;
|
||||||
const QImage *_img;
|
const QImage *_img;
|
||||||
const QColor *_color, *_haloColor, *_bgColor;
|
const QColor *_color, *_haloColor, *_bgColor;
|
||||||
|
double _rotate;
|
||||||
QRectF _rect, _textRect;
|
QRectF _rect, _textRect;
|
||||||
QPainterPath _shape;
|
QPainterPath _shape;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user