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:
parent
b78a533080
commit
e3d5fe2ec3
@ -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);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ private:
|
||||
const QFont *_font;
|
||||
const QImage *_img;
|
||||
const QColor *_color, *_haloColor, *_bgColor;
|
||||
QRect _rect, _textRect;
|
||||
QRectF _rect, _textRect;
|
||||
QPainterPath _shape;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user