From 0c592310af086c528db16a362a5302c51521c5a2 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 13 Oct 2022 02:16:56 +0300 Subject: [PATCH] Added ability to customize widget for events in VerticalLayoutReorder. --- ui/wrap/vertical_layout_reorder.cpp | 9 ++++++++- ui/wrap/vertical_layout_reorder.h | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ui/wrap/vertical_layout_reorder.cpp b/ui/wrap/vertical_layout_reorder.cpp index a4cc15f..b882ef6 100644 --- a/ui/wrap/vertical_layout_reorder.cpp +++ b/ui/wrap/vertical_layout_reorder.cpp @@ -50,7 +50,10 @@ void VerticalLayoutReorder::start() { } for (auto i = 0; i != count; ++i) { const auto widget = _layout->widgetAt(i); - widget->events( + const auto eventsProducer = _proxyWidgetCallback + ? _proxyWidgetCallback(i) + : widget; + eventsProducer->events( ) | rpl::start_with_next_done([=](not_null e) { switch (e->type()) { case QEvent::MouseMove: @@ -83,6 +86,10 @@ void VerticalLayoutReorder::clearPinnedIntervals() { _pinnedIntervals.clear(); } +void VerticalLayoutReorder::setMouseEventProxy(ProxyCallback callback) { + _proxyWidgetCallback = std::move(callback); +} + bool VerticalLayoutReorder::Interval::isIn(int index) const { return (index >= from) && (index < (from + length)); } diff --git a/ui/wrap/vertical_layout_reorder.h b/ui/wrap/vertical_layout_reorder.h index 87875b6..a7fa078 100644 --- a/ui/wrap/vertical_layout_reorder.h +++ b/ui/wrap/vertical_layout_reorder.h @@ -16,6 +16,7 @@ class VerticalLayout; class VerticalLayoutReorder final { public: + using ProxyCallback = Fn(int)>; enum class State : uchar { Started, Applied, @@ -38,6 +39,7 @@ public: void finishReordering(); void addPinnedInterval(int from, int length); void clearPinnedIntervals(); + void setMouseEventProxy(ProxyCallback callback); [[nodiscard]] rpl::producer updates() const; private: @@ -85,6 +87,8 @@ private: std::vector _pinnedIntervals; + ProxyCallback _proxyWidgetCallback = nullptr; + RpWidget *_currentWidget = nullptr; int _currentStart = 0; int _currentDesiredIndex = 0;