Allow custom wheel event processing in ScrollArea.
This commit is contained in:
parent
fc8d4d25de
commit
8908c9b5c0
2 changed files with 15 additions and 1 deletions
|
|
@ -490,12 +490,21 @@ bool ScrollArea::eventFilter(QObject *obj, QEvent *e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScrollArea::viewportEvent(QEvent *e) {
|
bool ScrollArea::viewportEvent(QEvent *e) {
|
||||||
if (e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchUpdate || e->type() == QEvent::TouchEnd || e->type() == QEvent::TouchCancel) {
|
const auto type = e->type();
|
||||||
|
if (type == QEvent::TouchBegin
|
||||||
|
|| type == QEvent::TouchUpdate
|
||||||
|
|| type == QEvent::TouchEnd
|
||||||
|
|| type == QEvent::TouchCancel) {
|
||||||
QTouchEvent *ev = static_cast<QTouchEvent*>(e);
|
QTouchEvent *ev = static_cast<QTouchEvent*>(e);
|
||||||
if (_touchEnabled && ev->device()->type() == base::TouchDevice::TouchScreen) {
|
if (_touchEnabled && ev->device()->type() == base::TouchDevice::TouchScreen) {
|
||||||
touchEvent(ev);
|
touchEvent(ev);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
} else if (type == QEvent::Wheel) {
|
||||||
|
if (_customWheelProcess
|
||||||
|
&& _customWheelProcess(static_cast<QWheelEvent*>(e))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return QScrollArea::viewportEvent(e);
|
return QScrollArea::viewportEvent(e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -172,6 +172,10 @@ public:
|
||||||
void scrolled();
|
void scrolled();
|
||||||
void innerResized();
|
void innerResized();
|
||||||
|
|
||||||
|
void setCustomWheelProcess(Fn<bool(not_null<QWheelEvent*>)> process) {
|
||||||
|
_customWheelProcess = std::move(process);
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] rpl::producer<> scrolls() const;
|
[[nodiscard]] rpl::producer<> scrolls() const;
|
||||||
[[nodiscard]] rpl::producer<> innerResizes() const;
|
[[nodiscard]] rpl::producer<> innerResizes() const;
|
||||||
[[nodiscard]] rpl::producer<> geometryChanged() const;
|
[[nodiscard]] rpl::producer<> geometryChanged() const;
|
||||||
|
|
@ -227,6 +231,7 @@ private:
|
||||||
crl::time _touchTime = 0;
|
crl::time _touchTime = 0;
|
||||||
base::Timer _touchScrollTimer;
|
base::Timer _touchScrollTimer;
|
||||||
|
|
||||||
|
Fn<bool(not_null<QWheelEvent*>)> _customWheelProcess;
|
||||||
bool _widgetAcceptsTouch = false;
|
bool _widgetAcceptsTouch = false;
|
||||||
|
|
||||||
object_ptr<QWidget> _widget = { nullptr };
|
object_ptr<QWidget> _widget = { nullptr };
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue