Added ability to override painting of action menu items.
This commit is contained in:
parent
aa155db0bd
commit
e94d77847c
2 changed files with 18 additions and 11 deletions
|
|
@ -68,12 +68,6 @@ Action::Action(
|
|||
initResizeHook(parent->sizeValue());
|
||||
processAction();
|
||||
|
||||
paintRequest(
|
||||
) | rpl::start_with_next([=] {
|
||||
Painter p(this);
|
||||
paint(p);
|
||||
}, lifetime());
|
||||
|
||||
enableMouseSelecting();
|
||||
|
||||
connect(_action, &QAction::changed, [=] { processAction(); });
|
||||
|
|
@ -83,6 +77,20 @@ bool Action::hasSubmenu() const {
|
|||
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) {
|
||||
_text.drawLeftElided(
|
||||
p,
|
||||
|
|
@ -95,12 +103,9 @@ void Action::paintText(Painter &p) {
|
|||
void Action::paint(Painter &p) {
|
||||
const auto enabled = isEnabled();
|
||||
const auto selected = isSelected();
|
||||
if (selected && _st.itemBgOver->c.alpha() < 255) {
|
||||
p.fillRect(0, 0, width(), _height, _st.itemBg);
|
||||
}
|
||||
p.fillRect(0, 0, width(), _height, selected ? _st.itemBgOver : _st.itemBg);
|
||||
paintBackground(p, selected);
|
||||
if (enabled) {
|
||||
paintRipple(p, 0, 0);
|
||||
RippleButton::paintRipple(p, 0, 0);
|
||||
}
|
||||
if (const auto icon = (selected ? _iconOver : _icon)) {
|
||||
icon->paint(p, _st.itemIconPosition, width());
|
||||
|
|
|
|||
|
|
@ -33,11 +33,13 @@ public:
|
|||
const style::icon *iconOver = nullptr);
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *e) override;
|
||||
QPoint prepareRippleStartPosition() const override;
|
||||
QImage prepareRippleMask() const override;
|
||||
|
||||
int contentHeight() const override;
|
||||
|
||||
void paintBackground(Painter &p, bool selected);
|
||||
void paintText(Painter &p);
|
||||
|
||||
private:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue