Added ability to override painting of action menu items.

This commit is contained in:
23rd 2022-04-17 00:56:56 +03:00
parent aa155db0bd
commit e94d77847c
2 changed files with 18 additions and 11 deletions

View file

@ -68,12 +68,6 @@ Action::Action(
initResizeHook(parent->sizeValue()); initResizeHook(parent->sizeValue());
processAction(); processAction();
paintRequest(
) | rpl::start_with_next([=] {
Painter p(this);
paint(p);
}, lifetime());
enableMouseSelecting(); enableMouseSelecting();
connect(_action, &QAction::changed, [=] { processAction(); }); connect(_action, &QAction::changed, [=] { processAction(); });
@ -83,6 +77,20 @@ bool Action::hasSubmenu() const {
return _action->menu() != nullptr; return _action->menu() != nullptr;
} }
void Action::paintEvent(QPaintEvent *e) {
Painter p(this);
paint(p);
}
void Action::paintBackground(Painter &p, bool selected) {
if (selected && _st.itemBgOver->c.alpha() < 255) {
p.fillRect(0, 0, width(), _height, _st.itemBg);
}
p.fillRect(
QRect(0, 0, width(), _height),
selected ? _st.itemBgOver : _st.itemBg);
}
void Action::paintText(Painter &p) { void Action::paintText(Painter &p) {
_text.drawLeftElided( _text.drawLeftElided(
p, p,
@ -95,12 +103,9 @@ void Action::paintText(Painter &p) {
void Action::paint(Painter &p) { void Action::paint(Painter &p) {
const auto enabled = isEnabled(); const auto enabled = isEnabled();
const auto selected = isSelected(); const auto selected = isSelected();
if (selected && _st.itemBgOver->c.alpha() < 255) { paintBackground(p, selected);
p.fillRect(0, 0, width(), _height, _st.itemBg);
}
p.fillRect(0, 0, width(), _height, selected ? _st.itemBgOver : _st.itemBg);
if (enabled) { if (enabled) {
paintRipple(p, 0, 0); RippleButton::paintRipple(p, 0, 0);
} }
if (const auto icon = (selected ? _iconOver : _icon)) { if (const auto icon = (selected ? _iconOver : _icon)) {
icon->paint(p, _st.itemIconPosition, width()); icon->paint(p, _st.itemIconPosition, width());

View file

@ -33,11 +33,13 @@ public:
const style::icon *iconOver = nullptr); const style::icon *iconOver = nullptr);
protected: protected:
void paintEvent(QPaintEvent *e) override;
QPoint prepareRippleStartPosition() const override; QPoint prepareRippleStartPosition() const override;
QImage prepareRippleMask() const override; QImage prepareRippleMask() const override;
int contentHeight() const override; int contentHeight() const override;
void paintBackground(Painter &p, bool selected);
void paintText(Painter &p); void paintText(Painter &p);
private: private: