Replaced timer for dragging scroll in Dialogs::Widget with manager.

This commit is contained in:
23rd 2022-03-14 18:18:10 +03:00
parent 6793d2cc7c
commit 72ecc286dc
5 changed files with 19 additions and 34 deletions

View file

@ -1130,7 +1130,7 @@ void InnerWidget::finishReorderPinned() {
_aboveIndex = -1;
}
if (wasDragging) {
draggingScrollDelta(0);
_draggingScroll.cancel();
}
}
@ -1220,7 +1220,7 @@ bool InnerWidget::updateReorderPinned(QPoint localPosition) {
return 0;
}();
draggingScrollDelta(delta);
_draggingScroll.checkDeltaScroll(delta);
return true;
}
@ -1930,6 +1930,10 @@ rpl::producer<> InnerWidget::updated() const {
return _updated.events();
}
rpl::producer<int> InnerWidget::scrollByDeltaRequests() const {
return _draggingScroll.scrolls();
}
rpl::producer<> InnerWidget::listBottomReached() const {
return _listBottomReached.events();
}

View file

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_key.h"
#include "data/data_messages.h"
#include "ui/dragging_scroll_manager.h"
#include "ui/effects/animations.h"
#include "ui/rp_widget.h"
#include "base/flags.h"
@ -125,6 +126,8 @@ public:
[[nodiscard]] rpl::producer<ChosenRow> chosenRow() const;
[[nodiscard]] rpl::producer<> updated() const;
[[nodiscard]] rpl::producer<int> scrollByDeltaRequests() const;
[[nodiscard]] RowDescriptor resolveChatNext(RowDescriptor from = {}) const;
[[nodiscard]] RowDescriptor resolveChatPrevious(RowDescriptor from = {}) const;
@ -134,7 +137,6 @@ public Q_SLOTS:
void onParentGeometryChanged();
Q_SIGNALS:
void draggingScrollDelta(int delta);
void mustScrollTo(int scrollToTop, int scrollToBottom);
void dialogMoved(int movedFrom, int movedTo);
void searchMessages();
@ -401,6 +403,8 @@ private:
object_ptr<Ui::IconButton> _cancelSearchInChat;
object_ptr<Ui::IconButton> _cancelSearchFromUser;
Ui::DraggingScrollManager _draggingScroll;
Key _searchInChat;
History *_searchInMigrated = nullptr;
PeerData *_searchFromPeer = nullptr;

View file

@ -209,7 +209,13 @@ Widget::Widget(
fullSearchRefreshOn(session().settings().skipArchiveInSearchChanges(
) | rpl::to_empty);
connect(_inner, SIGNAL(draggingScrollDelta(int)), this, SLOT(onDraggingScrollDelta(int)));
_inner->scrollByDeltaRequests(
) | rpl::start_with_next([=](int delta) {
if (_scroll) {
_scroll->scrollToY(_scroll->scrollTop() + delta);
}
}, lifetime());
connect(_inner, &InnerWidget::mustScrollTo, [=](int top, int bottom) {
if (_scroll) {
_scroll->scrollToY(top, bottom);
@ -866,27 +872,6 @@ void Widget::loadMoreBlockedByDate() {
session().api().requestMoreBlockedByDateDialogs();
}
void Widget::onDraggingScrollDelta(int delta) {
_draggingScrollDelta = _scroll ? delta : 0;
if (_draggingScrollDelta) {
if (!_draggingScrollTimer) {
_draggingScrollTimer.create(this);
_draggingScrollTimer->setSingleShot(false);
connect(_draggingScrollTimer, SIGNAL(timeout()), this, SLOT(onDraggingScrollTimer()));
}
_draggingScrollTimer->start(15);
} else {
_draggingScrollTimer.destroy();
}
}
void Widget::onDraggingScrollTimer() {
const auto delta = (_draggingScrollDelta > 0)
? qMin(_draggingScrollDelta * 3 / 20 + 1, Ui::kMaxScrollSpeed)
: qMax(_draggingScrollDelta * 3 / 20 - 1, -Ui::kMaxScrollSpeed);
_scroll->scrollToY(_scroll->scrollTop() + delta);
}
bool Widget::onSearchMessages(bool searchCache) {
auto result = false;
auto q = _filter->getLastText().trimmed();

View file

@ -102,8 +102,6 @@ public:
~Widget();
public Q_SLOTS:
void onDraggingScrollDelta(int delta);
void onListScroll();
bool onCancelSearch();
void onCancelSearchInChat();
@ -117,9 +115,6 @@ public Q_SLOTS:
void onChooseByDrag();
private Q_SLOTS:
void onDraggingScrollTimer();
protected:
void dragEnterEvent(QDragEnterEvent *e) override;
void dragMoveEvent(QDragMoveEvent *e) override;
@ -247,9 +242,6 @@ private:
QPixmap _widthAnimationCache;
object_ptr<QTimer> _draggingScrollTimer = { nullptr };
int _draggingScrollDelta = 0;
int _topDelta = 0;
rpl::event_stream<> _closeForwardBarRequests;

@ -1 +1 @@
Subproject commit d27e4803a130a262b84a54c915fc83f8c9bbe2f4
Subproject commit ba40979470132db759fe8b8e7ff8ca70845f92c1