mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-25 16:13:54 -07:00
list position fixed
This commit is contained in:
parent
4447214c7a
commit
4850bcf809
2 changed files with 26 additions and 7 deletions
|
|
@ -184,7 +184,7 @@ void GameView::clearSubtypeLabels()
|
||||||
QtUtils::clearLayoutRec(subtypeCountLayout);
|
QtUtils::clearLayoutRec(subtypeCountLayout);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::rebuildSubtypeLabels(const QList<SubtypeEntry> &entries)
|
QSize GameView::rebuildSubtypeLabels(const QList<SubtypeEntry> &entries)
|
||||||
{
|
{
|
||||||
clearSubtypeLabels();
|
clearSubtypeLabels();
|
||||||
|
|
||||||
|
|
@ -192,6 +192,10 @@ void GameView::rebuildSubtypeLabels(const QList<SubtypeEntry> &entries)
|
||||||
const QString countStyle =
|
const QString countStyle =
|
||||||
QStringLiteral("color: white; font-size: 14px; font-weight: bold; background: transparent;");
|
QStringLiteral("color: white; font-size: 14px; font-weight: bold; background: transparent;");
|
||||||
|
|
||||||
|
int totalHeight = 0;
|
||||||
|
int maxNameWidth = 0;
|
||||||
|
int maxCountWidth = 0;
|
||||||
|
|
||||||
int row = 0;
|
int row = 0;
|
||||||
for (const SubtypeEntry &entry : entries) {
|
for (const SubtypeEntry &entry : entries) {
|
||||||
auto *nameLabel = new QLabel(entry.name, subtypeCountContainer);
|
auto *nameLabel = new QLabel(entry.name, subtypeCountContainer);
|
||||||
|
|
@ -204,8 +208,23 @@ void GameView::rebuildSubtypeLabels(const QList<SubtypeEntry> &entries)
|
||||||
countLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
countLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
subtypeCountLayout->addWidget(countLabel, row, 1);
|
subtypeCountLayout->addWidget(countLabel, row, 1);
|
||||||
|
|
||||||
|
QSize nameSize = nameLabel->sizeHint();
|
||||||
|
QSize countSize = countLabel->sizeHint();
|
||||||
|
maxNameWidth = qMax(maxNameWidth, nameSize.width());
|
||||||
|
maxCountWidth = qMax(maxCountWidth, countSize.width());
|
||||||
|
totalHeight += qMax(nameSize.height(), countSize.height());
|
||||||
|
|
||||||
++row;
|
++row;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int spacing = subtypeCountLayout->spacing();
|
||||||
|
int margins = subtypeCountLayout->contentsMargins().left() + subtypeCountLayout->contentsMargins().right();
|
||||||
|
int verticalMargins = subtypeCountLayout->contentsMargins().top() + subtypeCountLayout->contentsMargins().bottom();
|
||||||
|
|
||||||
|
int width = maxNameWidth + spacing + maxCountWidth + margins;
|
||||||
|
int height = totalHeight + (row - 1) * spacing + verticalMargins;
|
||||||
|
|
||||||
|
return QSize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameView::updateTotalSelectionCount(const QSize &viewSize)
|
void GameView::updateTotalSelectionCount(const QSize &viewSize)
|
||||||
|
|
@ -257,16 +276,16 @@ void GameView::updateTotalSelectionCount(const QSize &viewSize)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
rebuildSubtypeLabels(entries);
|
QSize containerSize = rebuildSubtypeLabels(entries);
|
||||||
subtypeCountContainer->adjustSize();
|
subtypeCountContainer->resize(containerSize);
|
||||||
|
|
||||||
int x = availableWidth - subtypeCountContainer->width() - kMarginInPixels;
|
int x = availableWidth - containerSize.width() - kMarginInPixels;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
if (totalCountLabel->isVisible()) {
|
if (totalCountLabel->isVisible()) {
|
||||||
y = totalCountLabel->y() - subtypeCountContainer->height() - kSpacingBetweenLabels;
|
y = totalCountLabel->y() - containerSize.height() - kSpacingBetweenLabels;
|
||||||
} else {
|
} else {
|
||||||
y = availableHeight - subtypeCountContainer->height() - kMarginInPixels;
|
y = availableHeight - containerSize.height() - kMarginInPixels;
|
||||||
}
|
}
|
||||||
|
|
||||||
y = qMax(kMarginInPixels, y);
|
y = qMax(kMarginInPixels, y);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ private:
|
||||||
QGridLayout *subtypeCountLayout; ///< Grid layout for subtype name/count pairs
|
QGridLayout *subtypeCountLayout; ///< Grid layout for subtype name/count pairs
|
||||||
QPointF selectionOrigin;
|
QPointF selectionOrigin;
|
||||||
|
|
||||||
void rebuildSubtypeLabels(const QList<SubtypeEntry> &entries);
|
QSize rebuildSubtypeLabels(const QList<SubtypeEntry> &entries);
|
||||||
void clearSubtypeLabels();
|
void clearSubtypeLabels();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue