Fix color widget sizing

Took 16 minutes
This commit is contained in:
Lukas Brübach 2026-08-25 19:03:25 +02:00
parent 770d72d179
commit c44883b453

View file

@ -79,8 +79,6 @@ void ColorIdentityWidget::resizeEvent(QResizeEvent *event)
{ {
QWidget::resizeEvent(event); QWidget::resizeEvent(event);
// Layout passes resize this widget repeatedly with identical sizes, so bail out before
// touching the children when neither the width nor the resulting symbol size changed.
const int totalWidth = event->size().width(); const int totalWidth = event->size().width();
if (totalWidth == lastWidth && lastIconSize != -1) { if (totalWidth == lastWidth && lastIconSize != -1) {
return; return;
@ -90,13 +88,12 @@ void ColorIdentityWidget::resizeEvent(QResizeEvent *event)
const int totalHeight = totalWidth / 6; // Set height to 1/4 of the width const int totalHeight = totalWidth / 6; // Set height to 1/4 of the width
setFixedHeight(totalHeight); setFixedHeight(totalHeight);
QList<ManaSymbolWidget *> manaSymbols = findChildren<ManaSymbolWidget *>(); const int count = layout->count();
if (manaSymbols.isEmpty()) { if (count == 0) {
return; return;
} }
const int spacing = layout->spacing(); const int spacing = layout->spacing();
const int count = manaSymbols.size();
const int availableWidth = totalWidth - (spacing * (count - 1)); const int availableWidth = totalWidth - (spacing * (count - 1));
const int iconSize = qMin(availableWidth / count, totalHeight); // Ensure icons fit within the new height const int iconSize = qMin(availableWidth / count, totalHeight); // Ensure icons fit within the new height
@ -105,8 +102,10 @@ void ColorIdentityWidget::resizeEvent(QResizeEvent *event)
} }
lastIconSize = iconSize; lastIconSize = iconSize;
for (ManaSymbolWidget *manaSymbol : manaSymbols) { for (int i = 0; i < count; ++i) {
manaSymbol->setFixedSize(iconSize, iconSize); if (auto *w = qobject_cast<ManaSymbolWidget *>(layout->itemAt(i)->widget())) {
w->setFixedSize(iconSize, iconSize);
}
} }
} }