mirror of
https://github.com/tumic0/GPXSee.git
synced 2025-02-22 10:20:47 +01:00
Code cleanup
This commit is contained in:
parent
86cc30433c
commit
4e9faf3a23
@ -17,18 +17,18 @@ static void expand(QRect &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 *bgColor) : _text(text), _font(font), _img(img), _color(color),
|
const QColor *bgColor) : _text(font ? text : 0), _font(font), _img(img),
|
||||||
_bgColor(bgColor)
|
_color(color), _bgColor(bgColor)
|
||||||
{
|
{
|
||||||
if (text) {
|
if (_text) {
|
||||||
QFontMetrics fm(*font);
|
QFontMetrics fm(*_font);
|
||||||
int limit = font->pixelSize() * MAX_TEXT_WIDTH;
|
int limit = _font->pixelSize() * MAX_TEXT_WIDTH;
|
||||||
_textRect = fm.boundingRect(QRect(0, 0, limit, 0), FLAGS, *text);
|
_textRect = fm.boundingRect(QRect(0, 0, limit, 0), FLAGS, *_text);
|
||||||
_textRect.adjust(0, 0, 1, 1);
|
_textRect.adjust(0, 0, 1, 1);
|
||||||
}
|
|
||||||
|
|
||||||
if (_bgColor && _textRect.width() < font->pixelSize() * MIN_BOX_WIDTH)
|
if (_bgColor && _textRect.width() < _font->pixelSize() * MIN_BOX_WIDTH)
|
||||||
expand(_textRect, font->pixelSize() * MIN_BOX_WIDTH);
|
expand(_textRect, _font->pixelSize() * MIN_BOX_WIDTH);
|
||||||
|
}
|
||||||
|
|
||||||
setPos(point);
|
setPos(point);
|
||||||
}
|
}
|
||||||
@ -58,6 +58,14 @@ void TextPointItem::paint(QPainter *painter) const
|
|||||||
- _img->height()/2), *_img);
|
- _img->height()/2), *_img);
|
||||||
|
|
||||||
if (_text) {
|
if (_text) {
|
||||||
|
if (_bgColor) {
|
||||||
|
painter->setPen(*_color);
|
||||||
|
painter->setBrush(*_bgColor);
|
||||||
|
painter->drawRect(_textRect);
|
||||||
|
painter->setBrush(Qt::NoBrush);
|
||||||
|
painter->setFont(*_font);
|
||||||
|
painter->drawText(_textRect, FLAGS, *_text);
|
||||||
|
} else {
|
||||||
QImage img(_textRect.size(), QImage::Format_ARGB32_Premultiplied);
|
QImage img(_textRect.size(), QImage::Format_ARGB32_Premultiplied);
|
||||||
img.fill(Qt::transparent);
|
img.fill(Qt::transparent);
|
||||||
QPainter ip(&img);
|
QPainter ip(&img);
|
||||||
@ -68,18 +76,12 @@ void TextPointItem::paint(QPainter *painter) const
|
|||||||
painter->drawImage(_textRect.x() - 1, _textRect.y() - 1, img);
|
painter->drawImage(_textRect.x() - 1, _textRect.y() - 1, img);
|
||||||
painter->drawImage(_textRect.x() + 1, _textRect.y() + 1, img);
|
painter->drawImage(_textRect.x() + 1, _textRect.y() + 1, img);
|
||||||
painter->drawImage(_textRect.x() - 1, _textRect.y() + 1, img);
|
painter->drawImage(_textRect.x() - 1, _textRect.y() + 1, img);
|
||||||
|
painter->drawImage(_textRect.x() + 1, _textRect.y() - 1, img);
|
||||||
painter->drawImage(_textRect.x(), _textRect.y() - 1, img);
|
painter->drawImage(_textRect.x(), _textRect.y() - 1, img);
|
||||||
painter->drawImage(_textRect.x(), _textRect.y() + 1, img);
|
painter->drawImage(_textRect.x(), _textRect.y() + 1, img);
|
||||||
painter->drawImage(_textRect.x() - 1, _textRect.y(), img);
|
painter->drawImage(_textRect.x() - 1, _textRect.y(), img);
|
||||||
painter->drawImage(_textRect.x() + 1, _textRect.y(), img);
|
painter->drawImage(_textRect.x() + 1, _textRect.y(), img);
|
||||||
|
|
||||||
|
|
||||||
if (_bgColor) {
|
|
||||||
painter->setPen(*_color);
|
|
||||||
painter->setBrush(*_bgColor);
|
|
||||||
painter->drawRect(_textRect);
|
|
||||||
painter->setBrush(Qt::NoBrush);
|
|
||||||
}
|
|
||||||
if (_color) {
|
if (_color) {
|
||||||
painter->setFont(*_font);
|
painter->setFont(*_font);
|
||||||
painter->setPen(*_color);
|
painter->setPen(*_color);
|
||||||
@ -95,6 +97,7 @@ void TextPointItem::paint(QPainter *painter) const
|
|||||||
#endif // QT >= 5.4
|
#endif // QT >= 5.4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//painter->setPen(Qt::red);
|
//painter->setPen(Qt::red);
|
||||||
//painter->drawRect(_rect);
|
//painter->drawRect(_rect);
|
||||||
|
@ -73,7 +73,6 @@ static QColor shieldBgColor1("#dd3e3e");
|
|||||||
static QColor shieldBgColor2("#379947");
|
static QColor shieldBgColor2("#379947");
|
||||||
static QColor shieldBgColor3("#4a7fc1");
|
static QColor shieldBgColor3("#4a7fc1");
|
||||||
|
|
||||||
|
|
||||||
static QString convertUnits(const QString &str)
|
static QString convertUnits(const QString &str)
|
||||||
{
|
{
|
||||||
bool ok;
|
bool ok;
|
||||||
@ -102,26 +101,47 @@ static int minPOIZoom(Style::POIClass cl)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static QFont font(int pixelSize)
|
static QFont pixelSizeFont(int pixelSize)
|
||||||
{
|
{
|
||||||
QFont f;
|
QFont f;
|
||||||
f.setPixelSize(pixelSize);
|
f.setPixelSize(pixelSize);
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The fonts must be initialized on first usage (after the QGuiApplication
|
static QFont *font(Style::FontSize size, Style::FontSize defaultSize
|
||||||
|
= Style::Normal)
|
||||||
|
{
|
||||||
|
/* The fonts must be initialized on first usage (after the QGuiApplication
|
||||||
instance is created) */
|
instance is created) */
|
||||||
#define FONT(name, size) \
|
static QFont large = pixelSizeFont(16);
|
||||||
static const QFont *name() \
|
static QFont normal = pixelSizeFont(14);
|
||||||
{ \
|
static QFont small = pixelSizeFont(12);
|
||||||
static QFont f = font(size); \
|
|
||||||
return &f; \
|
switch (size) {
|
||||||
|
case Style::None:
|
||||||
|
return 0;
|
||||||
|
case Style::Large:
|
||||||
|
return &large;
|
||||||
|
case Style::Normal:
|
||||||
|
return &normal;
|
||||||
|
case Style::Small:
|
||||||
|
return &small;
|
||||||
|
default:
|
||||||
|
return font(defaultSize);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FONT(largeFont, 16)
|
static QFont *poiFont(Style::FontSize size = Style::Normal)
|
||||||
FONT(normalFont, 14)
|
{
|
||||||
FONT(smallFont, 12)
|
static QFont poi = pixelSizeFont(10);
|
||||||
FONT(poiFont, 10)
|
|
||||||
|
switch (size) {
|
||||||
|
case Style::None:
|
||||||
|
return 0;
|
||||||
|
default:
|
||||||
|
return &poi;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static const QColor *shieldBgColor(Label::Shield::Type type)
|
static const QColor *shieldBgColor(Label::Shield::Type type)
|
||||||
{
|
{
|
||||||
@ -347,22 +367,12 @@ void IMGMap::processLines(QList<IMG::Poly> &lines, const QPoint &tile,
|
|||||||
if (Style::isContourLine(poly.type))
|
if (Style::isContourLine(poly.type))
|
||||||
poly.label.setText(convertUnits(poly.label.text()));
|
poly.label.setText(convertUnits(poly.label.text()));
|
||||||
|
|
||||||
const QFont *font;
|
const QFont *fnt = font(style.textFontSize(), Style::Small);
|
||||||
switch (style.textFontSize()) {
|
|
||||||
case Style::Large:
|
|
||||||
font = largeFont();
|
|
||||||
break;
|
|
||||||
case Style::Normal:
|
|
||||||
font = normalFont();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
font = smallFont();
|
|
||||||
}
|
|
||||||
const QColor *color = style.textColor().isValid()
|
const QColor *color = style.textColor().isValid()
|
||||||
? &style.textColor() : 0;
|
? &style.textColor() : 0;
|
||||||
|
|
||||||
TextPathItem *item = new TextPathItem(poly.points,
|
TextPathItem *item = new TextPathItem(poly.points,
|
||||||
&poly.label.text(), tileRect, font, color);
|
&poly.label.text(), tileRect, fnt, color);
|
||||||
if (item->isValid() && !item->collides(textItems))
|
if (item->isValid() && !item->collides(textItems))
|
||||||
textItems.append(item);
|
textItems.append(item);
|
||||||
else
|
else
|
||||||
@ -424,7 +434,6 @@ void IMGMap::processPoints(QList<IMG::Point> &points,
|
|||||||
|
|
||||||
for (int i = 0; i < points.size(); i++) {
|
for (int i = 0; i < points.size(); i++) {
|
||||||
IMG::Point &point = points[i];
|
IMG::Point &point = points[i];
|
||||||
|
|
||||||
const Style::Point &style = _img.style()->point(point.type);
|
const Style::Point &style = _img.style()->point(point.type);
|
||||||
|
|
||||||
if (point.poi && _zoom < minPOIZoom(Style::poiClass(point.type)))
|
if (point.poi && _zoom < minPOIZoom(Style::poiClass(point.type)))
|
||||||
@ -433,31 +442,12 @@ void IMGMap::processPoints(QList<IMG::Point> &points,
|
|||||||
const QString *label = point.label.text().isEmpty()
|
const QString *label = point.label.text().isEmpty()
|
||||||
? 0 : &(point.label.text());
|
? 0 : &(point.label.text());
|
||||||
const QImage *img = style.img().isNull() ? 0 : &style.img();
|
const QImage *img = style.img().isNull() ? 0 : &style.img();
|
||||||
const QFont *font = 0;
|
const QFont *fnt = point.poi
|
||||||
if (point.poi) {
|
? poiFont(style.textFontSize()) : font(style.textFontSize());
|
||||||
if (style.textFontSize() == Style::None)
|
|
||||||
label = 0;
|
|
||||||
else
|
|
||||||
font = poiFont();
|
|
||||||
} else {
|
|
||||||
switch (style.textFontSize()) {
|
|
||||||
case Style::None:
|
|
||||||
label = 0;
|
|
||||||
break;
|
|
||||||
case Style::Small:
|
|
||||||
font = smallFont();
|
|
||||||
break;
|
|
||||||
case Style::Large:
|
|
||||||
font = largeFont();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
font = normalFont();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const QColor *color = style.textColor().isValid()
|
const QColor *color = style.textColor().isValid()
|
||||||
? &style.textColor() : 0;
|
? &style.textColor() : 0;
|
||||||
|
|
||||||
if (!label && !img)
|
if ((!label || !fnt) && !img)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (Style::isSpot(point.type))
|
if (Style::isSpot(point.type))
|
||||||
@ -469,7 +459,7 @@ void IMGMap::processPoints(QList<IMG::Point> &points,
|
|||||||
}
|
}
|
||||||
|
|
||||||
TextPointItem *item = new TextPointItem(
|
TextPointItem *item = new TextPointItem(
|
||||||
ll2xy(point.coordinates).toPoint(), label, font, img, color);
|
ll2xy(point.coordinates).toPoint(), label, fnt, img, color);
|
||||||
if (item->isValid() && !item->collides(textItems))
|
if (item->isValid() && !item->collides(textItems))
|
||||||
textItems.append(item);
|
textItems.append(item);
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user