Decomposed painting of SettingsButton.
This commit is contained in:
parent
5e8b8d4129
commit
7d3f27b7ca
2 changed files with 29 additions and 4 deletions
|
|
@ -741,19 +741,35 @@ void SettingsButton::setColorOverride(std::optional<QColor> textColorOverride) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const style::SettingsButton &SettingsButton::st() const {
|
||||||
|
return _st;
|
||||||
|
}
|
||||||
|
|
||||||
void SettingsButton::paintEvent(QPaintEvent *e) {
|
void SettingsButton::paintEvent(QPaintEvent *e) {
|
||||||
Painter p(this);
|
Painter p(this);
|
||||||
|
|
||||||
auto paintOver = (isOver() || isDown()) && !isDisabled();
|
const auto paintOver = (isOver() || isDown()) && !isDisabled();
|
||||||
p.fillRect(e->rect(), paintOver ? _st.textBgOver : _st.textBg);
|
paintBg(p, e->rect(), paintOver);
|
||||||
|
|
||||||
paintRipple(p, 0, 0);
|
paintRipple(p, 0, 0);
|
||||||
|
|
||||||
auto outerw = width();
|
const auto outerw = width();
|
||||||
|
paintText(p, paintOver, outerw);
|
||||||
|
|
||||||
|
if (_toggle) {
|
||||||
|
paintToggle(p, outerw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsButton::paintBg(Painter &p, const QRect &rect, bool over) const {
|
||||||
|
p.fillRect(rect, over ? _st.textBgOver : _st.textBg);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsButton::paintText(Painter &p, bool over, int outerw) const {
|
||||||
p.setFont(_st.font);
|
p.setFont(_st.font);
|
||||||
p.setPen(_textColorOverride
|
p.setPen(_textColorOverride
|
||||||
? QPen(*_textColorOverride)
|
? QPen(*_textColorOverride)
|
||||||
: paintOver
|
: over
|
||||||
? _st.textFgOver
|
? _st.textFgOver
|
||||||
: _st.textFg);
|
: _st.textFg);
|
||||||
p.drawTextLeft(
|
p.drawTextLeft(
|
||||||
|
|
@ -762,7 +778,9 @@ void SettingsButton::paintEvent(QPaintEvent *e) {
|
||||||
outerw,
|
outerw,
|
||||||
_text,
|
_text,
|
||||||
_textWidth);
|
_textWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SettingsButton::paintToggle(Painter &p, int outerw) const {
|
||||||
if (_toggle) {
|
if (_toggle) {
|
||||||
auto rect = toggleRect();
|
auto rect = toggleRect();
|
||||||
_toggle->paint(p, rect.left(), rect.top(), outerw);
|
_toggle->paint(p, rect.left(), rect.top(), outerw);
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
class Painter;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
|
|
||||||
class RippleAnimation;
|
class RippleAnimation;
|
||||||
|
|
@ -273,6 +275,11 @@ protected:
|
||||||
|
|
||||||
void paintEvent(QPaintEvent *e) override;
|
void paintEvent(QPaintEvent *e) override;
|
||||||
|
|
||||||
|
const style::SettingsButton &st() const;
|
||||||
|
void paintBg(Painter &p, const QRect &rect, bool over) const;
|
||||||
|
void paintText(Painter &p, bool over, int outerw) const;
|
||||||
|
void paintToggle(Painter &p, int outerw) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setText(QString &&text);
|
void setText(QString &&text);
|
||||||
QRect toggleRect() const;
|
QRect toggleRect() const;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue