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
|
static const TextFormat smallLinkHoveredTF
|
||||||
{Theme::Token_Text_Accent, smallLinkDefaultTF.uiElement,
|
{Theme::Token_Text_Accent, smallLinkDefaultTF.uiElement,
|
||||||
smallLinkDefaultTF.drawTextFlags};
|
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) {
|
switch (role) {
|
||||||
case Button::MediumPrimary: return mediumPrimaryTF;
|
case Button::MediumPrimary: return mediumPrimaryTF;
|
||||||
@@ -128,6 +132,8 @@ static const TextFormat &buttonTF(Button::Role role, WidgetState state)
|
|||||||
: smallListCheckedTF;
|
: smallListCheckedTF;
|
||||||
case Button::SmallLink: return (state == WidgetStateDefault) ? smallLinkDefaultTF
|
case Button::SmallLink: return (state == WidgetStateDefault) ? smallLinkDefaultTF
|
||||||
: smallLinkHoveredTF;
|
: smallLinkHoveredTF;
|
||||||
|
case Button::Tag: return (state == WidgetStateDefault) ? tagDefaultTF
|
||||||
|
: tagHoverTF;
|
||||||
}
|
}
|
||||||
return mediumPrimaryTF;
|
return mediumPrimaryTF;
|
||||||
}
|
}
|
||||||
@@ -218,6 +224,13 @@ void Button::paintEvent(QPaintEvent *event)
|
|||||||
}
|
}
|
||||||
case SmallLink:
|
case SmallLink:
|
||||||
break;
|
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()) {
|
if (!m_pixmap.isNull()) {
|
||||||
@@ -244,6 +257,10 @@ void Button::setPixmap(const QPixmap &pixmap)
|
|||||||
|
|
||||||
void Button::updateMargins()
|
void Button::updateMargins()
|
||||||
{
|
{
|
||||||
|
if (m_role == Tag) {
|
||||||
|
setContentsMargins(HPaddingXs, VPaddingXxs, HPaddingXs, VPaddingXxs);
|
||||||
|
return;
|
||||||
|
}
|
||||||
const bool tokenSizeS = m_role == MediumPrimary || m_role == MediumSecondary
|
const bool tokenSizeS = m_role == MediumPrimary || m_role == MediumSecondary
|
||||||
|| m_role == SmallList || m_role == SmallLink;
|
|| m_role == SmallList || m_role == SmallLink;
|
||||||
const int gap = tokenSizeS ? HGapS : HGapXs;
|
const int gap = tokenSizeS ? HGapS : HGapXs;
|
||||||
|
@@ -80,6 +80,7 @@ public:
|
|||||||
SmallSecondary,
|
SmallSecondary,
|
||||||
SmallList,
|
SmallList,
|
||||||
SmallLink,
|
SmallLink,
|
||||||
|
Tag,
|
||||||
};
|
};
|
||||||
|
|
||||||
explicit Button(const QString &text, Role role, QWidget *parent = nullptr);
|
explicit Button(const QString &text, Role role, QWidget *parent = nullptr);
|
||||||
|
Reference in New Issue
Block a user