Lock scroll either horizontal or vertical.
This commit is contained in:
parent
676a3f8cfa
commit
0b32a0a1ea
|
@ -793,7 +793,10 @@ void Widget::setupMainMenuToggle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::setupStories() {
|
void Widget::setupStories() {
|
||||||
trackScroll(_stories.get());
|
_stories->verticalScrollEvents(
|
||||||
|
) | rpl::start_with_next([=](not_null<QWheelEvent*> e) {
|
||||||
|
_scroll->viewportEvent(e);
|
||||||
|
}, _stories->lifetime());
|
||||||
|
|
||||||
_storiesContents.fire(Stories::ContentForSession(
|
_storiesContents.fire(Stories::ContentForSession(
|
||||||
&controller()->session(),
|
&controller()->session(),
|
||||||
|
|
|
@ -152,6 +152,10 @@ rpl::producer<> List::loadMoreRequests() const {
|
||||||
return _loadMoreRequests.events();
|
return _loadMoreRequests.events();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rpl::producer<not_null<QWheelEvent*>> List::verticalScrollEvents() const {
|
||||||
|
return _verticalScrollEvents.events();
|
||||||
|
}
|
||||||
|
|
||||||
void List::requestExpanded(bool expanded) {
|
void List::requestExpanded(bool expanded) {
|
||||||
if (_expanded != expanded) {
|
if (_expanded != expanded) {
|
||||||
_expanded = expanded;
|
_expanded = expanded;
|
||||||
|
@ -635,18 +639,30 @@ void List::validateName(not_null<Item*> item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void List::wheelEvent(QWheelEvent *e) {
|
void List::wheelEvent(QWheelEvent *e) {
|
||||||
const auto horizontal = (e->angleDelta().x() != 0);
|
const auto phase = e->phase();
|
||||||
if (!horizontal || _state == State::Small) {
|
const auto fullDelta = e->pixelDelta().isNull()
|
||||||
|
? e->angleDelta()
|
||||||
|
: e->pixelDelta();
|
||||||
|
if (phase == Qt::ScrollBegin || phase == Qt::ScrollEnd) {
|
||||||
|
_scrollingLock = Qt::Orientation();
|
||||||
|
if (fullDelta.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const auto vertical = qAbs(fullDelta.x()) < qAbs(fullDelta.y());
|
||||||
|
if (_scrollingLock == Qt::Orientation() && phase != Qt::NoScrollPhase) {
|
||||||
|
_scrollingLock = vertical ? Qt::Vertical : Qt::Horizontal;
|
||||||
|
}
|
||||||
|
if (_scrollingLock == Qt::Vertical || (vertical && !_scrollLeftMax)) {
|
||||||
|
_verticalScrollEvents.fire(e);
|
||||||
|
return;
|
||||||
|
} else if (_state == State::Small) {
|
||||||
e->ignore();
|
e->ignore();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto delta = horizontal
|
const auto delta = vertical
|
||||||
? ((style::RightToLeft() ? -1 : 1) * (e->pixelDelta().x()
|
? fullDelta.y()
|
||||||
? e->pixelDelta().x()
|
: ((style::RightToLeft() ? -1 : 1) * fullDelta.x());
|
||||||
: e->angleDelta().x()))
|
|
||||||
: (e->pixelDelta().y()
|
|
||||||
? e->pixelDelta().y()
|
|
||||||
: e->angleDelta().y());
|
|
||||||
|
|
||||||
const auto now = _scrollLeft;
|
const auto now = _scrollLeft;
|
||||||
const auto used = now - delta;
|
const auto used = now - delta;
|
||||||
|
|
|
@ -91,6 +91,9 @@ public:
|
||||||
[[nodiscard]] rpl::producer<> entered() const;
|
[[nodiscard]] rpl::producer<> entered() const;
|
||||||
[[nodiscard]] rpl::producer<> loadMoreRequests() const;
|
[[nodiscard]] rpl::producer<> loadMoreRequests() const;
|
||||||
|
|
||||||
|
[[nodiscard]] auto verticalScrollEvents() const
|
||||||
|
-> rpl::producer<not_null<QWheelEvent*>>;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Layout;
|
struct Layout;
|
||||||
enum class State {
|
enum class State {
|
||||||
|
@ -177,6 +180,7 @@ private:
|
||||||
int _scrollLeft = 0;
|
int _scrollLeft = 0;
|
||||||
int _scrollLeftMax = 0;
|
int _scrollLeftMax = 0;
|
||||||
bool _dragging = false;
|
bool _dragging = false;
|
||||||
|
Qt::Orientation _scrollingLock = {};
|
||||||
|
|
||||||
Ui::Animations::Simple _expandedAnimation;
|
Ui::Animations::Simple _expandedAnimation;
|
||||||
Ui::Animations::Simple _expandCatchUpAnimation;
|
Ui::Animations::Simple _expandCatchUpAnimation;
|
||||||
|
@ -188,6 +192,8 @@ private:
|
||||||
int _selected = -1;
|
int _selected = -1;
|
||||||
int _pressed = -1;
|
int _pressed = -1;
|
||||||
|
|
||||||
|
rpl::event_stream<not_null<QWheelEvent*>> _verticalScrollEvents;
|
||||||
|
|
||||||
base::unique_qptr<Ui::PopupMenu> _menu;
|
base::unique_qptr<Ui::PopupMenu> _menu;
|
||||||
base::has_weak_ptr _menuGuard;
|
base::has_weak_ptr _menuGuard;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue