Skip to content

Commit

Permalink
Fixed alignment of shortcuts in action search
Browse files Browse the repository at this point in the history
Issue introduced in fb2390a.

We do need to call QStaticText::prepare in this case, because we need to
know its width in the small font, before painting the text.
  • Loading branch information
bjorn committed Mar 18, 2024
1 parent 88e4525 commit c388cc2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Fixed mouse handling issue when zooming while painting (#3863)
* Fixed possible crash after a scripted tool disappears while active
* Fixed updating of used tilesets after resizing map (#3884)
* Fixed alignment of shortcuts in action search
* AppImage: Updated to Sentry 0.6.7

### Tiled 1.10.2 (4 August 2023)
Expand Down
7 changes: 4 additions & 3 deletions src/tiled/actionsearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,21 +154,22 @@ void ActionMatchDelegate::paint(QPainter *painter,
painter->setFont(fonts.big);
painter->drawStaticText(nameRect.topLeft(), staticText);

const QIcon icon = index.data(Qt::DecorationRole).value<QIcon>();
const auto icon = index.data(Qt::DecorationRole).value<QIcon>();
if (!icon.isNull()) {
const auto iconRect = QRect(option.rect.topLeft() + QPoint(margin, margin),
QSize(iconSize, iconSize));

icon.paint(painter, iconRect);
}

const QKeySequence shortcut = index.data(ActionLocatorSource::ShortcutRole).value<QKeySequence>();
const auto shortcut = index.data(ActionLocatorSource::ShortcutRole).value<QKeySequence>();
if (!shortcut.isEmpty()) {
const QString shortcutText = shortcut.toString(QKeySequence::NativeText);
const QFontMetrics smallFontMetrics(fonts.small);

staticText.setTextFormat(Qt::PlainText);
staticText.setText(shortcutText);
staticText.prepare(painter->transform(), fonts.small);

const int centeringMargin = (shortcutRect.height() - smallFontMetrics.height()) / 2;
painter->setOpacity(0.75);
Expand Down Expand Up @@ -242,7 +243,7 @@ QString ActionLocatorSource::placeholderText() const

QVector<ActionLocatorSource::Match> ActionLocatorSource::findActions(const QStringList &words)
{
const QRegularExpression re(QLatin1String("(?<=^|[^&])&"));
static const QRegularExpression re(QLatin1String("(?<=^|[^&])&"));
const QList<Id> actions = ActionManager::actions();
const Id searchActionsId("SearchActions");

Expand Down

0 comments on commit c388cc2

Please sign in to comment.