forked from qt-creator/qt-creator
Core: Add Tag variant to Core::Button
As specified as Figma component. Change-Id: Id115fe5703b58902bc7479e966787c969e6b073d Reviewed-by: Cristian Adam <cristian.adam@qt.io>
This commit is contained in:
@@ -118,6 +118,10 @@ static const TextFormat &buttonTF(Button::Role role, WidgetState state)
|
||||
static const TextFormat smallLinkHoveredTF
|
||||
{Theme::Token_Text_Accent, smallLinkDefaultTF.uiElement,
|
||||
smallLinkDefaultTF.drawTextFlags};
|
||||
static const TextFormat tagDefaultTF
|
||||
{Theme::Token_Text_Muted, StyleHelper::UiElement::UiElementLabelMedium};
|
||||
static const TextFormat tagHoverTF
|
||||
{Theme::Token_Text_Default, tagDefaultTF.uiElement};
|
||||
|
||||
switch (role) {
|
||||
case Button::MediumPrimary: return mediumPrimaryTF;
|
||||
@@ -128,6 +132,8 @@ static const TextFormat &buttonTF(Button::Role role, WidgetState state)
|
||||
: smallListCheckedTF;
|
||||
case Button::SmallLink: return (state == WidgetStateDefault) ? smallLinkDefaultTF
|
||||
: smallLinkHoveredTF;
|
||||
case Button::Tag: return (state == WidgetStateDefault) ? tagDefaultTF
|
||||
: tagHoverTF;
|
||||
}
|
||||
return mediumPrimaryTF;
|
||||
}
|
||||
@@ -218,6 +224,13 @@ void Button::paintEvent(QPaintEvent *event)
|
||||
}
|
||||
case SmallLink:
|
||||
break;
|
||||
case Tag: {
|
||||
const QBrush fill(hovered ? creatorColor(Theme::Token_Foreground_Subtle)
|
||||
: QBrush(Qt::NoBrush));
|
||||
const QPen outline(hovered ? QPen(Qt::NoPen) : creatorColor(Theme::Token_Stroke_Subtle));
|
||||
drawCardBackground(&p, bgR, fill, outline, brRectRounding);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_pixmap.isNull()) {
|
||||
@@ -244,6 +257,10 @@ void Button::setPixmap(const QPixmap &pixmap)
|
||||
|
||||
void Button::updateMargins()
|
||||
{
|
||||
if (m_role == Tag) {
|
||||
setContentsMargins(HPaddingXs, VPaddingXxs, HPaddingXs, VPaddingXxs);
|
||||
return;
|
||||
}
|
||||
const bool tokenSizeS = m_role == MediumPrimary || m_role == MediumSecondary
|
||||
|| m_role == SmallList || m_role == SmallLink;
|
||||
const int gap = tokenSizeS ? HGapS : HGapXs;
|
||||
|
@@ -80,6 +80,7 @@ public:
|
||||
SmallSecondary,
|
||||
SmallList,
|
||||
SmallLink,
|
||||
Tag,
|
||||
};
|
||||
|
||||
explicit Button(const QString &text, Role role, QWidget *parent = nullptr);
|
||||
|
Reference in New Issue
Block a user