Target selector: Fix drawing of the run icon

With the new layout calculations (see QTCREATORBUG-24148), the
option rect can now be used to center the icon with the provided
functions in QRect.
The current code kind of works if RunColumnWidth matches the row height,
so that it can do things like subtracting vertical from horizontal
dimensions. But in fact, the icon is not centered on the option.rect.

fillRect(option.rect, Qt::red) <-to verify.

Apart from that it has a few more downsides.

This change:
- Uses the run icon made for dark background
- Paints the icon at its native 16x16px (instead of 15x15px)
- Uses QRect::center()/moveCenter() to actually center the icon

Change-Id: Ib280c650bd454b551f9e30ca108579fee06d81f0
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Alessandro Portale
2020-06-29 19:18:16 +02:00
parent f9df5b445a
commit 42b5aa4aca

View File

@@ -477,14 +477,10 @@ void TargetSelectorDelegate::paint(QPainter *painter,
->setData(index, index.model()->data(index, Qt::UserRole + 1).toString(), Qt::ToolTipRole); ->setData(index, index.model()->data(index, Qt::UserRole + 1).toString(), Qt::ToolTipRole);
painter->drawText(option.rect.left() + 6, option.rect.top() + (option.rect.height() - fm.height()) / 2 + fm.ascent(), elidedText); painter->drawText(option.rect.left() + 6, option.rect.top() + (option.rect.height() - fm.height()) / 2 + fm.ascent(), elidedText);
if (index.column() == 1 && option.state & QStyle::State_MouseOver) { if (index.column() == 1 && option.state & QStyle::State_MouseOver) {
const QIcon icon = Utils::Icons::RUN_SMALL.icon(); const QIcon icon = Utils::Icons::RUN_SMALL_TOOLBAR.icon();
QRect iconRect(option.rect.right() - option.rect.height(), QRect iconRect(0, 0, 16, 16);
option.rect.top(), iconRect.moveCenter(option.rect.center());
option.rect.height() / painter->device()->devicePixelRatio(), icon.paint(painter, iconRect);
option.rect.height() / painter->device()->devicePixelRatio());
iconRect.translate((option.rect.width() - iconRect.width()) / 2,
(option.rect.height() - iconRect.height()) / 2);
icon.paint(painter, iconRect, Qt::AlignHCenter | Qt::AlignVCenter);
} }
painter->restore(); painter->restore();