give the selection cards their own parts instead of label blobs

This commit is contained in:
2026-08-07 18:43:23 +02:00
parent 2289277e12
commit 075e44d295
54 changed files with 1505 additions and 533 deletions

View File

@@ -0,0 +1,72 @@
#include "ItemChip.h"
#include <QFont>
#include <QHBoxLayout>
#include <QLabel>
#include <QPalette>
#include <QVBoxLayout>
namespace
{
// Point-size rise of the count and drop of the sub-line, relative to the card's text.
const int kCountSizeRisePt = 2;
const int kSubLineSizeDropPt = 1;
} // namespace
ItemChip::ItemChip(const QPixmap& icon, QWidget* parent)
: QWidget(parent)
{
// Its own boxed chrome, drawn with palette colors like the rest of the panel's
// furniture rather than from visuals.toml, which is for world rendering.
setAttribute(Qt::WA_StyledBackground, true);
setStyleSheet(QStringLiteral(
"ItemChip { border: 1px solid palette(mid); border-radius: 3px; }"));
QHBoxLayout* layout = new QHBoxLayout(this);
layout->setContentsMargins(4, 3, 4, 3);
layout->setSpacing(6);
m_iconLabel = new QLabel(this);
m_iconLabel->setPixmap(icon);
m_iconLabel->setVisible(!icon.isNull());
QWidget* text = new QWidget(this);
QVBoxLayout* textLayout = new QVBoxLayout(text);
textLayout->setContentsMargins(0, 0, 0, 0);
textLayout->setSpacing(0);
m_countLabel = new QLabel(text);
QFont countFont = m_countLabel->font();
countFont.setPointSize(countFont.pointSize() + kCountSizeRisePt);
m_countLabel->setFont(countFont);
m_subLineLabel = new QLabel(text);
QFont subLineFont = m_subLineLabel->font();
subLineFont.setPointSize(qMax(1, subLineFont.pointSize() - kSubLineSizeDropPt));
m_subLineLabel->setFont(subLineFont);
QPalette subLinePalette = m_subLineLabel->palette();
subLinePalette.setColor(QPalette::WindowText,
palette().color(QPalette::Disabled, QPalette::WindowText));
m_subLineLabel->setPalette(subLinePalette);
m_subLineLabel->hide();
textLayout->addWidget(m_countLabel);
textLayout->addWidget(m_subLineLabel);
layout->addWidget(m_iconLabel);
layout->addWidget(text);
}
void ItemChip::setCount(const QString& count)
{
m_countLabel->setText(count);
}
void ItemChip::setSubLine(const QString& subLine)
{
m_subLineLabel->setText(subLine);
m_subLineLabel->setVisible(!subLine.isEmpty());
}