Use scroll phase information from wheel events.

This commit is contained in:
John Preston 2023-06-29 11:09:46 +04:00
parent 1cd20ff5e2
commit 75d4ba7be1
2 changed files with 31 additions and 19 deletions

View file

@ -2382,9 +2382,27 @@ void Widget::completeHashtag(QString tag) {
} }
bool Widget::customWheelProcess(not_null<QWheelEvent*> e) { bool Widget::customWheelProcess(not_null<QWheelEvent*> e) {
customScrollProcess(e->phase());
return false;
}
void Widget::customScrollProcess(Qt::ScrollPhase phase) {
const auto now = _scroll->scrollTop(); const auto now = _scroll->scrollTop();
const auto def = _inner->defaultScrollTop(); const auto def = _inner->defaultScrollTop();
const auto bar = _scroll->verticalScrollBar(); const auto bar = _scroll->verticalScrollBar();
if (phase == Qt::ScrollBegin || phase == Qt::ScrollUpdate) {
_allowStoriesExpandTimer.cancel();
_inner->setTouchScrollActive(true);
bar->setMinimum(0);
} else if (phase == Qt::ScrollEnd || phase == Qt::ScrollMomentum) {
_allowStoriesExpandTimer.cancel();
_inner->setTouchScrollActive(false);
if (def > 0 && now >= def) {
bar->setMinimum(def);
} else {
bar->setMinimum(0);
}
} else {
const auto allow = (def <= 0) const auto allow = (def <= 0)
|| (now < def) || (now < def)
|| (now == def && !_allowStoriesExpandTimer.isActive()); || (now == def && !_allowStoriesExpandTimer.isActive());
@ -2395,27 +2413,20 @@ bool Widget::customWheelProcess(not_null<QWheelEvent*> e) {
bar->setMinimum(def); bar->setMinimum(def);
_allowStoriesExpandTimer.callOnce(kWaitTillAllowStoriesExpand); _allowStoriesExpandTimer.callOnce(kWaitTillAllowStoriesExpand);
} }
return false; }
} }
bool Widget::customTouchProcess(not_null<QTouchEvent*> e) { bool Widget::customTouchProcess(not_null<QTouchEvent*> e) {
const auto type = e->type(); const auto type = e->type();
const auto now = _scroll->scrollTop(); customScrollProcess([&] {
const auto def = _inner->defaultScrollTop(); switch (e->type()) {
const auto bar = _scroll->verticalScrollBar(); case QEvent::TouchBegin: return Qt::ScrollBegin;
_allowStoriesExpandTimer.cancel(); case QEvent::TouchUpdate: return Qt::ScrollUpdate;
if (type == QEvent::TouchBegin case QEvent::TouchEnd:
|| type == QEvent::TouchUpdate) { case QEvent::TouchCancel: return Qt::ScrollEnd;
_inner->setTouchScrollActive(true);
bar->setMinimum(0);
} else if (type == QEvent::TouchEnd || type == QEvent::TouchCancel) {
_inner->setTouchScrollActive(false);
if (def > 0 && now >= def) {
bar->setMinimum(def);
} else {
bar->setMinimum(0);
}
} }
Unexpected("Touch event type in Widdget::customTouchProcess.");
}());
return false; return false;
} }

View file

@ -138,6 +138,7 @@ private:
void completeHashtag(QString tag); void completeHashtag(QString tag);
bool customWheelProcess(not_null<QWheelEvent*> e); bool customWheelProcess(not_null<QWheelEvent*> e);
bool customTouchProcess(not_null<QTouchEvent*> e); bool customTouchProcess(not_null<QTouchEvent*> e);
void customScrollProcess(Qt::ScrollPhase phase);
[[nodiscard]] QString currentSearchQuery() const; [[nodiscard]] QString currentSearchQuery() const;
void clearSearchField(); void clearSearchField();