Skip to content

Commit

Permalink
Added ability to draw outlined Ui::RoundButton.
Browse files Browse the repository at this point in the history
  • Loading branch information
23rd committed Oct 7, 2021
1 parent 7182fad commit 1651470
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ui/widgets/buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ void RoundButton::setBrushOverride(std::optional<QBrush> brush) {
update();
}

void RoundButton::setPenOverride(std::optional<QPen> pen) {
_penOverride = std::move(pen);
update();
}

void RoundButton::finishNumbersAnimation() {
if (_numbers) {
_numbers->finishAnimating();
Expand Down Expand Up @@ -371,18 +376,22 @@ void RoundButton::paintEvent(QPaintEvent *e) {
if (_fullRadius) {
const auto radius = rounded.height() / 2;
PainterHighQualityEnabler hq(p);
p.setPen(Qt::NoPen);
p.setPen(_penOverride ? *_penOverride : Qt::NoPen);
p.setBrush(_brushOverride ? *_brushOverride : rect.color()->b);
p.drawRoundedRect(fill, radius, radius);
} else if (_brushOverride) {
p.setPen(Qt::NoPen);
PainterHighQualityEnabler hq(p);
p.setPen(_penOverride ? *_penOverride : Qt::NoPen);
p.setBrush(*_brushOverride);
const auto radius = _st.radius ? _st.radius : st::buttonRadius;
p.drawRoundedRect(fill, radius, radius);
} else {
rect.paint(p, fill);
}
};
if (_penOverride) {
paintRipple(p, rounded.topLeft());
}
drawRect(_roundRect);

auto over = isOver();
Expand All @@ -391,7 +400,9 @@ void RoundButton::paintEvent(QPaintEvent *e) {
drawRect(_roundRectOver);
}

paintRipple(p, rounded.topLeft());
if (!_penOverride) {
paintRipple(p, rounded.topLeft());
}

p.setFont(_st.font);
const auto textTop = _st.padding.top() + _st.textTop;
Expand Down
2 changes: 2 additions & 0 deletions ui/widgets/buttons.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class RoundButton : public RippleButton {
}
void setWidthChangedCallback(Fn<void()> callback);
void setBrushOverride(std::optional<QBrush> brush);
void setPenOverride(std::optional<QPen> pen);
void finishNumbersAnimation();

int contentWidth() const;
Expand Down Expand Up @@ -167,6 +168,7 @@ class RoundButton : public RippleButton {

const style::RoundButton &_st;
std::optional<QBrush> _brushOverride;
std::optional<QPen> _penOverride;
RoundRect _roundRect;
RoundRect _roundRectOver;

Expand Down

0 comments on commit 1651470

Please sign in to comment.