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) {
|
||||
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);
|
||||
if (_touchEnabled && ev->device()->type() == base::TouchDevice::TouchScreen) {
|
||||
touchEvent(ev);
|
||||
return true;
|
||||
}
|
||||
} else if (type == QEvent::Wheel) {
|
||||
if (_customWheelProcess
|
||||
&& _customWheelProcess(static_cast<QWheelEvent*>(e))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QScrollArea::viewportEvent(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -172,6 +172,10 @@ public:
|
|||
void scrolled();
|
||||
void innerResized();
|
||||
|
||||
void setCustomWheelProcess(Fn<bool(not_null<QWheelEvent*>)> process) {
|
||||
_customWheelProcess = std::move(process);
|
||||
}
|
||||
|
||||
[[nodiscard]] rpl::producer<> scrolls() const;
|
||||
[[nodiscard]] rpl::producer<> innerResizes() const;
|
||||
[[nodiscard]] rpl::producer<> geometryChanged() const;
|
||||
|
|
@ -227,6 +231,7 @@ private:
|
|||
crl::time _touchTime = 0;
|
||||
base::Timer _touchScrollTimer;
|
||||
|
||||
Fn<bool(not_null<QWheelEvent*>)> _customWheelProcess;
|
||||
bool _widgetAcceptsTouch = false;
|
||||
|
||||
object_ptr<QWidget> _widget = { nullptr };
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue