1
0
mirror of https://github.com/tumic0/GPXSee.git synced 2024-11-24 03:35:53 +01:00

Fixed point text items bounds computation

This commit is contained in:
Martin Tůma 2022-02-15 00:01:48 +01:00
parent b78a533080
commit e3d5fe2ec3
2 changed files with 9 additions and 8 deletions

View File

@ -11,7 +11,7 @@
#define MIN_BOX_WIDTH 2 #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); 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) void TextPointItem::setPos(const QPoint &point, bool padding)
{ {
QPainterPath shape; QPainterPath shape;
QRect iconRect; QRectF iconRect;
if (_img && !_img->isNull()) { if (_img && !_img->isNull()) {
QSize s(_img->size() / _img->devicePixelRatioF()); QSizeF s(_img->size() / _img->devicePixelRatioF());
int xOffset = padding ? s.width() : s.width() / 2; 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); - 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)); - _textRect.height()/2));
} else } else
_textRect.moveCenter(point); _textRect.moveCenter(point);
@ -58,8 +58,8 @@ void TextPointItem::setPos(const QPoint &point, bool padding)
void TextPointItem::paint(QPainter *painter) const void TextPointItem::paint(QPainter *painter) const
{ {
if (_img && !_img->isNull()) { if (_img && !_img->isNull()) {
QSize s(_img->size() / _img->devicePixelRatioF()); QSizeF s(_img->size() / _img->devicePixelRatioF());
painter->drawImage(QPoint(_rect.left(), _rect.center().y() painter->drawImage(QPointF(_rect.left(), _rect.center().y()
- s.height()/2), *_img); - s.height()/2), *_img);
} }
@ -100,5 +100,6 @@ void TextPointItem::paint(QPainter *painter) const
} }
//painter->setPen(Qt::red); //painter->setPen(Qt::red);
//painter->setRenderHint(QPainter::Antialiasing, false);
//painter->drawRect(_rect); //painter->drawRect(_rect);
} }

View File

@ -31,7 +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;
QRect _rect, _textRect; QRectF _rect, _textRect;
QPainterPath _shape; QPainterPath _shape;
}; };