mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Use scroll phase information from wheel events.
This commit is contained in:
parent
1cd20ff5e2
commit
75d4ba7be1
2 changed files with 31 additions and 19 deletions
|
@ -2382,40 +2382,51 @@ void Widget::completeHashtag(QString tag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::customWheelProcess(not_null<QWheelEvent*> e) {
|
bool Widget::customWheelProcess(not_null<QWheelEvent*> e) {
|
||||||
const auto now = _scroll->scrollTop();
|
customScrollProcess(e->phase());
|
||||||
const auto def = _inner->defaultScrollTop();
|
|
||||||
const auto bar = _scroll->verticalScrollBar();
|
|
||||||
const auto allow = (def <= 0)
|
|
||||||
|| (now < def)
|
|
||||||
|| (now == def && !_allowStoriesExpandTimer.isActive());
|
|
||||||
if (allow) {
|
|
||||||
_scroll->verticalScrollBar()->setMinimum(0);
|
|
||||||
_allowStoriesExpandTimer.cancel();
|
|
||||||
} else {
|
|
||||||
bar->setMinimum(def);
|
|
||||||
_allowStoriesExpandTimer.callOnce(kWaitTillAllowStoriesExpand);
|
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Widget::customTouchProcess(not_null<QTouchEvent*> e) {
|
void Widget::customScrollProcess(Qt::ScrollPhase phase) {
|
||||||
const auto type = e->type();
|
|
||||||
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();
|
||||||
_allowStoriesExpandTimer.cancel();
|
if (phase == Qt::ScrollBegin || phase == Qt::ScrollUpdate) {
|
||||||
if (type == QEvent::TouchBegin
|
_allowStoriesExpandTimer.cancel();
|
||||||
|| type == QEvent::TouchUpdate) {
|
|
||||||
_inner->setTouchScrollActive(true);
|
_inner->setTouchScrollActive(true);
|
||||||
bar->setMinimum(0);
|
bar->setMinimum(0);
|
||||||
} else if (type == QEvent::TouchEnd || type == QEvent::TouchCancel) {
|
} else if (phase == Qt::ScrollEnd || phase == Qt::ScrollMomentum) {
|
||||||
|
_allowStoriesExpandTimer.cancel();
|
||||||
_inner->setTouchScrollActive(false);
|
_inner->setTouchScrollActive(false);
|
||||||
if (def > 0 && now >= def) {
|
if (def > 0 && now >= def) {
|
||||||
bar->setMinimum(def);
|
bar->setMinimum(def);
|
||||||
} else {
|
} else {
|
||||||
bar->setMinimum(0);
|
bar->setMinimum(0);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
const auto allow = (def <= 0)
|
||||||
|
|| (now < def)
|
||||||
|
|| (now == def && !_allowStoriesExpandTimer.isActive());
|
||||||
|
if (allow) {
|
||||||
|
_scroll->verticalScrollBar()->setMinimum(0);
|
||||||
|
_allowStoriesExpandTimer.cancel();
|
||||||
|
} else {
|
||||||
|
bar->setMinimum(def);
|
||||||
|
_allowStoriesExpandTimer.callOnce(kWaitTillAllowStoriesExpand);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Widget::customTouchProcess(not_null<QTouchEvent*> e) {
|
||||||
|
const auto type = e->type();
|
||||||
|
customScrollProcess([&] {
|
||||||
|
switch (e->type()) {
|
||||||
|
case QEvent::TouchBegin: return Qt::ScrollBegin;
|
||||||
|
case QEvent::TouchUpdate: return Qt::ScrollUpdate;
|
||||||
|
case QEvent::TouchEnd:
|
||||||
|
case QEvent::TouchCancel: return Qt::ScrollEnd;
|
||||||
|
}
|
||||||
|
Unexpected("Touch event type in Widdget::customTouchProcess.");
|
||||||
|
}());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Add table
Reference in a new issue