Improve menu selection tracking.
This commit is contained in:
parent
556a5dd90b
commit
315a0457cf
2 changed files with 20 additions and 26 deletions
|
|
@ -12,7 +12,6 @@ ItemBase::ItemBase(
|
||||||
not_null<RpWidget*> parent,
|
not_null<RpWidget*> parent,
|
||||||
const style::Menu &st)
|
const style::Menu &st)
|
||||||
: RippleButton(parent, st.ripple) {
|
: RippleButton(parent, st.ripple) {
|
||||||
init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemBase::setSelected(
|
void ItemBase::setSelected(
|
||||||
|
|
@ -78,20 +77,6 @@ int ItemBase::minWidth() const {
|
||||||
return _minWidth.current();
|
return _minWidth.current();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemBase::init() {
|
|
||||||
events(
|
|
||||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
|
||||||
return isEnabled()
|
|
||||||
&& isSelected()
|
|
||||||
&& (e->type() == QEvent::MouseButtonRelease);
|
|
||||||
}) | rpl::to_empty | rpl::start_with_next([=] {
|
|
||||||
const auto point = mapFromGlobal(QCursor::pos());
|
|
||||||
if (!rect().contains(point)) {
|
|
||||||
setSelected(false);
|
|
||||||
}
|
|
||||||
}, lifetime());
|
|
||||||
}
|
|
||||||
|
|
||||||
void ItemBase::initResizeHook(rpl::producer<QSize> &&size) {
|
void ItemBase::initResizeHook(rpl::producer<QSize> &&size) {
|
||||||
std::move(
|
std::move(
|
||||||
size
|
size
|
||||||
|
|
@ -109,16 +94,25 @@ void ItemBase::finishAnimating() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ItemBase::enableMouseSelecting() {
|
void ItemBase::enableMouseSelecting() {
|
||||||
events(
|
enableMouseSelecting(this);
|
||||||
) | rpl::filter([=](not_null<QEvent*> e) {
|
}
|
||||||
return action()->isEnabled()
|
|
||||||
&& ((e->type() == QEvent::Leave)
|
void ItemBase::enableMouseSelecting(not_null<RpWidget*> widget) {
|
||||||
|| (e->type() == QEvent::Enter)
|
widget->events(
|
||||||
|| (e->type() == QEvent::MouseMove));
|
) | rpl::start_with_next([=](not_null<QEvent*> e) {
|
||||||
}) | rpl::map([=](not_null<QEvent*> e) {
|
const auto type = e->type();
|
||||||
return (e->type() != QEvent::Leave);
|
if (((type == QEvent::Leave)
|
||||||
}) | rpl::start_with_next([=](bool selected) {
|
|| (type == QEvent::Enter)
|
||||||
setSelected(selected);
|
|| (type == QEvent::MouseMove)) && action()->isEnabled()) {
|
||||||
|
setSelected(e->type() != QEvent::Leave);
|
||||||
|
} else if ((type == QEvent::MouseButtonRelease)
|
||||||
|
&& isEnabled()
|
||||||
|
&& isSelected()) {
|
||||||
|
const auto point = mapFromGlobal(QCursor::pos());
|
||||||
|
if (!rect().contains(point)) {
|
||||||
|
setSelected(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}, lifetime());
|
}, lifetime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -45,10 +45,10 @@ public:
|
||||||
virtual void finishAnimating();
|
virtual void finishAnimating();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void init();
|
|
||||||
void initResizeHook(rpl::producer<QSize> &&size);
|
void initResizeHook(rpl::producer<QSize> &&size);
|
||||||
|
|
||||||
void enableMouseSelecting();
|
void enableMouseSelecting();
|
||||||
|
void enableMouseSelecting(not_null<RpWidget*> widget);
|
||||||
|
|
||||||
virtual int contentHeight() const = 0;
|
virtual int contentHeight() const = 0;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue