ask the icon cache for the inline block icon

The three block-icon call sites each spelled out the same expression that
ItemIconCache::getInlineIcon() now is: the bare icon at the line's text
height, null when the file is missing. They call the helper instead, and
HeaderBar::blockIcon() -- which was that expression and nothing else --
is gone along with its stale "loaded once on first use" comment.

Each site still passes its own widget font, so nothing about the sizing
changes; the rule now lives in one place rather than four.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ne3mejABZoLWKLh8fgpM3x
This commit is contained in:
2026-08-12 10:34:20 +02:00
parent 344d18a5d1
commit ab4aef2ad5
4 changed files with 4 additions and 21 deletions

View File

@@ -266,9 +266,7 @@ void BlueprintSelectionDialog::rebuildGrid()
// Block icon shown to the right of each cost (REQ-UI-BLUEPRINT-CARD); null when no // Block icon shown to the right of each cost (REQ-UI-BLUEPRINT-CARD); null when no
// building_block icon exists, in which case the cost is the bare number. // building_block icon exists, in which case the cost is the bare number.
const QPixmap blockIcon = m_itemIcons->hasIcon(kBlockItemId) const QPixmap blockIcon = m_itemIcons->getInlineIcon(kBlockItemId, font());
? m_itemIcons->getPixmap(kBlockItemId, QFontMetrics(font()).height())
: QPixmap();
const QSize cardSize = getCardSize(font()); const QSize cardSize = getCardSize(font());

View File

@@ -175,9 +175,7 @@ BuildButtonBar::BuildButtonBar(Simulation* sim, const GameConfig* config,
// Block icon shown to the right of each button's cost (REQ-UI-BUILD-COST); null // Block icon shown to the right of each button's cost (REQ-UI-BUILD-COST); null
// when no building_block icon exists, in which case the cost is the bare number. // when no building_block icon exists, in which case the cost is the bare number.
const QPixmap blockIcon = m_itemIcons->hasIcon(kBlockItemId) const QPixmap blockIcon = m_itemIcons->getInlineIcon(kBlockItemId, font());
? m_itemIcons->getPixmap(kBlockItemId, QFontMetrics(font()).height())
: QPixmap();
for (const BuildingDef& def : config->buildings.buildings) for (const BuildingDef& def : config->buildings.buildings)
{ {

View File

@@ -3,7 +3,6 @@
#include <cmath> #include <cmath>
#include <string> #include <string>
#include <QFontMetrics>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QIcon> #include <QIcon>
#include <QLabel> #include <QLabel>
@@ -120,19 +119,11 @@ void HeaderBar::handleEvent(std::shared_ptr<const ExpansionCostChangedEvent> /*e
updateExpandButton(); updateExpandButton();
} }
QPixmap HeaderBar::blockIcon() const
{
if (!m_itemIcons->hasIcon(kBlockItemId)) { return QPixmap(); }
// Sized to the header text height so it sits inline with the caption.
const int sizePx = QFontMetrics(font()).height();
return m_itemIcons->getPixmap(kBlockItemId, sizePx);
}
void HeaderBar::updateBlocksLabel() void HeaderBar::updateBlocksLabel()
{ {
const int blocks = m_sim->getBuildingBlocksStock(); const int blocks = m_sim->getBuildingBlocksStock();
const QPixmap icon = blockIcon(); const QPixmap icon = m_itemIcons->getInlineIcon(kBlockItemId, font());
if (icon.isNull()) if (icon.isNull())
{ {
// Fallback text form when no building_block icon exists (REQ-UI-BLOCKS-ICON). // Fallback text form when no building_block icon exists (REQ-UI-BLOCKS-ICON).
@@ -151,7 +142,7 @@ void HeaderBar::updateExpandButton()
m_expandButton->setEnabled(blocks >= expansionCost); m_expandButton->setEnabled(blocks >= expansionCost);
const QPixmap icon = blockIcon(); const QPixmap icon = m_itemIcons->getInlineIcon(kBlockItemId, font());
if (icon.isNull()) if (icon.isNull())
{ {
// Fallback text form when no building_block icon exists (REQ-UI-EXPAND-BUTTON). // Fallback text form when no building_block icon exists (REQ-UI-EXPAND-BUTTON).

View File

@@ -61,10 +61,6 @@ private:
// (REQ-UI-BLOCKS-ICON). // (REQ-UI-BLOCKS-ICON).
void updateBlocksLabel(); void updateBlocksLabel();
// The building_block icon at the header's text height, or a null pixmap when no
// icon file exists. Loaded once via m_itemIcons on first use.
QPixmap blockIcon() const;
QLabel* m_timeLabel; QLabel* m_timeLabel;
QLabel* m_blocksLabel; QLabel* m_blocksLabel;
QLabel* m_artifactsLabel; QLabel* m_artifactsLabel;