Skip to content

Commit

Permalink
Fixed updating of object label when text changes without changing size
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn committed Nov 18, 2024
1 parent f6c35a8 commit 94f71d9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* Fixed crash when accessing a world through a symlink (#4042)
* Fixed performance issue when tinting tiles from large tilesets
* Fixed error reporting when exporting on the command-line (by Shuhei Nagasawa, #4015)
* Fixed updating of object label when text changes without changing size
* Fixed minimum value of spinbox in Tile Animation Editor

### Tiled 1.11.0 (27 June 2024)
Expand Down
11 changes: 8 additions & 3 deletions src/tiled/objectselectionitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,13 @@ void MapObjectLabel::syncWithMapObject(const MapRenderer &renderer)
if (!nameVisible)
return;

if (mText != mObject->name()) {
mText = mObject->name();
update();
}

const QFontMetricsF metrics(scene() ? scene()->font() : QApplication::font());
QRectF boundingRect = metrics.boundingRect(mObject->name());
QRectF boundingRect = metrics.boundingRect(mText);

const qreal margin = Utils::dpiScaled(labelMargin);
const qreal distance = Utils::dpiScaled(labelDistance);
Expand Down Expand Up @@ -251,9 +256,9 @@ void MapObjectLabel::paint(QPainter *painter,

painter->drawRoundedRect(mBoundingRect, 4, 4);
painter->setPen(Qt::black);
painter->drawText(mTextPos + QPointF(1,1), mObject->name());
painter->drawText(mTextPos + QPointF(1,1), mText);
painter->setPen(Qt::white);
painter->drawText(mTextPos, mObject->name());
painter->drawText(mTextPos, mText);
}


Expand Down
1 change: 1 addition & 0 deletions src/tiled/objectselectionitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class MapObjectLabel : public QGraphicsItem

private:
QRectF mBoundingRect;
QString mText;
QPointF mTextPos;
const MapObject *mObject;
QColor mColor;
Expand Down

0 comments on commit 94f71d9

Please sign in to comment.