give the selection cards their own parts instead of label blobs
This commit is contained in:
72
src/ui/selection/ItemChip.cpp
Normal file
72
src/ui/selection/ItemChip.cpp
Normal 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());
|
||||
}
|
||||
Reference in New Issue
Block a user