From e3d5fe2ec38eb685086a1f9aaae18fbee88fad98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Tue, 15 Feb 2022 00:01:48 +0100 Subject: [PATCH] Fixed point text items bounds computation --- src/map/textpointitem.cpp | 15 ++++++++------- src/map/textpointitem.h | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/map/textpointitem.cpp b/src/map/textpointitem.cpp index f7888e98..e436ecbd 100644 --- a/src/map/textpointitem.cpp +++ b/src/map/textpointitem.cpp @@ -11,7 +11,7 @@ #define MIN_BOX_WIDTH 2 -static void expand(QRect &rect, int width) +static void expand(QRectF &rect, int width) { rect.adjust(-(width/2 - rect.width()/2), 0, width/2 - rect.width()/2, 0); } @@ -38,14 +38,14 @@ TextPointItem::TextPointItem(const QPoint &point, const QString *text, void TextPointItem::setPos(const QPoint &point, bool padding) { QPainterPath shape; - QRect iconRect; + QRectF iconRect; if (_img && !_img->isNull()) { - QSize s(_img->size() / _img->devicePixelRatioF()); + QSizeF s(_img->size() / _img->devicePixelRatioF()); int xOffset = padding ? s.width() : s.width() / 2; - iconRect = QRect(QPoint(point.x() - xOffset, point.y() + iconRect = QRectF(QPointF(point.x() - xOffset, point.y() - s.height()/2), s); - _textRect.moveTopLeft(QPoint(point.x() + s.width()/2, point.y() + _textRect.moveTopLeft(QPointF(point.x() + s.width()/2, point.y() - _textRect.height()/2)); } else _textRect.moveCenter(point); @@ -58,8 +58,8 @@ void TextPointItem::setPos(const QPoint &point, bool padding) void TextPointItem::paint(QPainter *painter) const { if (_img && !_img->isNull()) { - QSize s(_img->size() / _img->devicePixelRatioF()); - painter->drawImage(QPoint(_rect.left(), _rect.center().y() + QSizeF s(_img->size() / _img->devicePixelRatioF()); + painter->drawImage(QPointF(_rect.left(), _rect.center().y() - s.height()/2), *_img); } @@ -100,5 +100,6 @@ void TextPointItem::paint(QPainter *painter) const } //painter->setPen(Qt::red); + //painter->setRenderHint(QPainter::Antialiasing, false); //painter->drawRect(_rect); } diff --git a/src/map/textpointitem.h b/src/map/textpointitem.h index eff6800a..10704d72 100644 --- a/src/map/textpointitem.h +++ b/src/map/textpointitem.h @@ -31,7 +31,7 @@ private: const QFont *_font; const QImage *_img; const QColor *_color, *_haloColor, *_bgColor; - QRect _rect, _textRect; + QRectF _rect, _textRect; QPainterPath _shape; };