Added ability to draw outlined Ui::RoundButton.
This commit is contained in:
parent
7182fad08a
commit
1651470638
2 changed files with 16 additions and 3 deletions
|
|
@ -301,6 +301,11 @@ void RoundButton::setBrushOverride(std::optional<QBrush> brush) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RoundButton::setPenOverride(std::optional<QPen> pen) {
|
||||||
|
_penOverride = std::move(pen);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
void RoundButton::finishNumbersAnimation() {
|
void RoundButton::finishNumbersAnimation() {
|
||||||
if (_numbers) {
|
if (_numbers) {
|
||||||
_numbers->finishAnimating();
|
_numbers->finishAnimating();
|
||||||
|
|
@ -371,11 +376,12 @@ void RoundButton::paintEvent(QPaintEvent *e) {
|
||||||
if (_fullRadius) {
|
if (_fullRadius) {
|
||||||
const auto radius = rounded.height() / 2;
|
const auto radius = rounded.height() / 2;
|
||||||
PainterHighQualityEnabler hq(p);
|
PainterHighQualityEnabler hq(p);
|
||||||
p.setPen(Qt::NoPen);
|
p.setPen(_penOverride ? *_penOverride : Qt::NoPen);
|
||||||
p.setBrush(_brushOverride ? *_brushOverride : rect.color()->b);
|
p.setBrush(_brushOverride ? *_brushOverride : rect.color()->b);
|
||||||
p.drawRoundedRect(fill, radius, radius);
|
p.drawRoundedRect(fill, radius, radius);
|
||||||
} else if (_brushOverride) {
|
} else if (_brushOverride) {
|
||||||
p.setPen(Qt::NoPen);
|
PainterHighQualityEnabler hq(p);
|
||||||
|
p.setPen(_penOverride ? *_penOverride : Qt::NoPen);
|
||||||
p.setBrush(*_brushOverride);
|
p.setBrush(*_brushOverride);
|
||||||
const auto radius = _st.radius ? _st.radius : st::buttonRadius;
|
const auto radius = _st.radius ? _st.radius : st::buttonRadius;
|
||||||
p.drawRoundedRect(fill, radius, radius);
|
p.drawRoundedRect(fill, radius, radius);
|
||||||
|
|
@ -383,6 +389,9 @@ void RoundButton::paintEvent(QPaintEvent *e) {
|
||||||
rect.paint(p, fill);
|
rect.paint(p, fill);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
if (_penOverride) {
|
||||||
|
paintRipple(p, rounded.topLeft());
|
||||||
|
}
|
||||||
drawRect(_roundRect);
|
drawRect(_roundRect);
|
||||||
|
|
||||||
auto over = isOver();
|
auto over = isOver();
|
||||||
|
|
@ -391,7 +400,9 @@ void RoundButton::paintEvent(QPaintEvent *e) {
|
||||||
drawRect(_roundRectOver);
|
drawRect(_roundRectOver);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_penOverride) {
|
||||||
paintRipple(p, rounded.topLeft());
|
paintRipple(p, rounded.topLeft());
|
||||||
|
}
|
||||||
|
|
||||||
p.setFont(_st.font);
|
p.setFont(_st.font);
|
||||||
const auto textTop = _st.padding.top() + _st.textTop;
|
const auto textTop = _st.padding.top() + _st.textTop;
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,7 @@ public:
|
||||||
}
|
}
|
||||||
void setWidthChangedCallback(Fn<void()> callback);
|
void setWidthChangedCallback(Fn<void()> callback);
|
||||||
void setBrushOverride(std::optional<QBrush> brush);
|
void setBrushOverride(std::optional<QBrush> brush);
|
||||||
|
void setPenOverride(std::optional<QPen> pen);
|
||||||
void finishNumbersAnimation();
|
void finishNumbersAnimation();
|
||||||
|
|
||||||
int contentWidth() const;
|
int contentWidth() const;
|
||||||
|
|
@ -167,6 +168,7 @@ private:
|
||||||
|
|
||||||
const style::RoundButton &_st;
|
const style::RoundButton &_st;
|
||||||
std::optional<QBrush> _brushOverride;
|
std::optional<QBrush> _brushOverride;
|
||||||
|
std::optional<QPen> _penOverride;
|
||||||
RoundRect _roundRect;
|
RoundRect _roundRect;
|
||||||
RoundRect _roundRectOver;
|
RoundRect _roundRectOver;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue