Moved mouse selecting of menu items to menu base item.
This commit is contained in:
parent
4325eb2f1b
commit
0d6a0d9cef
3 changed files with 16 additions and 17 deletions
|
|
@ -71,23 +71,7 @@ Action::Action(
|
||||||
paint(p);
|
paint(p);
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
|
|
||||||
events(
|
enableMouseSelecting();
|
||||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
|
||||||
return _action->isEnabled()
|
|
||||||
&& ((e->type() == QEvent::Leave)
|
|
||||||
|| (e->type() == QEvent::Enter));
|
|
||||||
}) | rpl::map([=](not_null<QEvent*> e) {
|
|
||||||
return (e->type() == QEvent::Enter);
|
|
||||||
}) | rpl::start_with_next([=](bool selected) {
|
|
||||||
setSelected(selected);
|
|
||||||
}, lifetime());
|
|
||||||
|
|
||||||
events(
|
|
||||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
|
||||||
return _action->isEnabled() && (e->type() == QEvent::MouseMove);
|
|
||||||
}) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
|
||||||
setSelected(true);
|
|
||||||
}, lifetime());
|
|
||||||
|
|
||||||
connect(_action, &QAction::changed, [=] { processAction(); });
|
connect(_action, &QAction::changed, [=] { processAction(); });
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -115,4 +115,17 @@ void ItemBase::finishAnimating() {
|
||||||
RippleButton::finishAnimating();
|
RippleButton::finishAnimating();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ItemBase::enableMouseSelecting() {
|
||||||
|
events(
|
||||||
|
) | rpl::filter([=](not_null<QEvent*> e) {
|
||||||
|
return action()->isEnabled()
|
||||||
|
&& ((e->type() == QEvent::Leave)
|
||||||
|
|| (e->type() == QEvent::Enter));
|
||||||
|
}) | rpl::map([=](not_null<QEvent*> e) {
|
||||||
|
return (e->type() == QEvent::Enter);
|
||||||
|
}) | rpl::start_with_next([=](bool selected) {
|
||||||
|
setSelected(selected);
|
||||||
|
}, lifetime());
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Ui::Menu
|
} // namespace Ui::Menu
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ protected:
|
||||||
void init();
|
void init();
|
||||||
void initResizeHook(rpl::producer<QSize> &&size);
|
void initResizeHook(rpl::producer<QSize> &&size);
|
||||||
|
|
||||||
|
void enableMouseSelecting();
|
||||||
|
|
||||||
virtual int contentHeight() const = 0;
|
virtual int contentHeight() const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue