Moved scroll keys from sections to compose controls.

This commit is contained in:
23rd 2021-01-31 06:22:54 +03:00 committed by John Preston
parent 4ad0837661
commit b13e5ddce9
4 changed files with 36 additions and 12 deletions

View File

@ -721,6 +721,11 @@ rpl::producer<not_null<QKeyEvent*>> ComposeControls::keyEvents() const {
}); });
} }
auto ComposeControls::scrollKeyEvents() const
-> rpl::producer<not_null<QKeyEvent*>> {
return _scrollKeyEvents.events();
}
auto ComposeControls::sendContentRequests(SendRequestType requestType) const { auto ComposeControls::sendContentRequests(SendRequestType requestType) const {
auto filter = rpl::filter([=] { auto filter = rpl::filter([=] {
const auto type = (_mode == Mode::Normal) const auto type = (_mode == Mode::Normal)
@ -947,6 +952,7 @@ void ComposeControls::init() {
initSendButton(); initSendButton();
initWriteRestriction(); initWriteRestriction();
initVoiceRecordBar(); initVoiceRecordBar();
initKeyHandler();
_botCommandStart->setClickedCallback([=] { setText({ "/" }); }); _botCommandStart->setClickedCallback([=] { setText({ "/" }); });
@ -1048,6 +1054,22 @@ void ComposeControls::drawRestrictedWrite(Painter &p, const QString &error) {
style::al_center); style::al_center);
} }
void ComposeControls::initKeyHandler() {
_wrap->events(
) | rpl::filter([=](not_null<QEvent*> event) {
return (event->type() == QEvent::KeyPress);
}) | rpl::start_with_next([=](not_null<QEvent*> e) {
auto keyEvent = static_cast<QKeyEvent*>(e.get());
const auto key = keyEvent->key();
if ((key == Qt::Key_Up)
|| (key == Qt::Key_Down)
|| (key == Qt::Key_PageUp)
|| (key == Qt::Key_PageDown)) {
_scrollKeyEvents.fire(std::move(keyEvent));
}
}, _wrap->lifetime());
}
void ComposeControls::initField() { void ComposeControls::initField() {
_field->setMaxHeight(st::historyComposeFieldMaxHeight); _field->setMaxHeight(st::historyComposeFieldMaxHeight);
updateSubmitSettings(); updateSubmitSettings();

View File

@ -122,6 +122,8 @@ public:
[[nodiscard]] rpl::producer<InlineChosen> inlineResultChosen() const; [[nodiscard]] rpl::producer<InlineChosen> inlineResultChosen() const;
[[nodiscard]] rpl::producer<SendActionUpdate> sendActionUpdates() const; [[nodiscard]] rpl::producer<SendActionUpdate> sendActionUpdates() const;
[[nodiscard]] rpl::producer<not_null<QEvent*>> viewportEvents() const; [[nodiscard]] rpl::producer<not_null<QEvent*>> viewportEvents() const;
[[nodiscard]] auto scrollKeyEvents() const
-> rpl::producer<not_null<QKeyEvent*>>;
using MimeDataHook = Fn<bool( using MimeDataHook = Fn<bool(
not_null<const QMimeData*> data, not_null<const QMimeData*> data,
@ -189,6 +191,7 @@ private:
void initWriteRestriction(); void initWriteRestriction();
void initVoiceRecordBar(); void initVoiceRecordBar();
void initAutocomplete(); void initAutocomplete();
void initKeyHandler();
void updateSubmitSettings(); void updateSubmitSettings();
void updateSendButtonType(); void updateSendButtonType();
void updateHeight(); void updateHeight();
@ -290,6 +293,7 @@ private:
rpl::event_stream<InlineChosen> _inlineResultChosen; rpl::event_stream<InlineChosen> _inlineResultChosen;
rpl::event_stream<SendActionUpdate> _sendActionUpdates; rpl::event_stream<SendActionUpdate> _sendActionUpdates;
rpl::event_stream<QString> _sendCommandRequests; rpl::event_stream<QString> _sendCommandRequests;
rpl::event_stream<not_null<QKeyEvent*>> _scrollKeyEvents;
TextUpdateEvents _textUpdateEvents = TextUpdateEvents() TextUpdateEvents _textUpdateEvents = TextUpdateEvents()
| TextUpdateEvent::SaveDraft | TextUpdateEvent::SaveDraft

View File

@ -488,6 +488,11 @@ void RepliesWidget::setupComposeControls() {
showAtPosition(pos); showAtPosition(pos);
}, lifetime()); }, lifetime());
_composeControls->scrollKeyEvents(
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
_scroll->keyPressEvent(e);
}, lifetime());
_composeControls->keyEvents( _composeControls->keyEvents(
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) { ) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
if (e->key() == Qt::Key_Up) { if (e->key() == Qt::Key_Up) {
@ -501,15 +506,6 @@ void RepliesWidget::setupComposeControls() {
_scroll->keyPressEvent(e); _scroll->keyPressEvent(e);
} }
e->accept(); e->accept();
} else if (e->key() == Qt::Key_Down) {
_scroll->keyPressEvent(e);
e->accept();
} else if (e->key() == Qt::Key_PageDown) {
_scroll->keyPressEvent(e);
e->accept();
} else if (e->key() == Qt::Key_PageUp) {
_scroll->keyPressEvent(e);
e->accept();
} }
}, lifetime()); }, lifetime());

View File

@ -231,6 +231,11 @@ void ScheduledWidget::setupComposeControls() {
showAtPosition(pos); showAtPosition(pos);
}, lifetime()); }, lifetime());
_composeControls->scrollKeyEvents(
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
_scroll->keyPressEvent(e);
}, lifetime());
_composeControls->keyEvents( _composeControls->keyEvents(
) | rpl::start_with_next([=](not_null<QKeyEvent*> e) { ) | rpl::start_with_next([=](not_null<QKeyEvent*> e) {
if (e->key() == Qt::Key_Up) { if (e->key() == Qt::Key_Up) {
@ -246,9 +251,6 @@ void ScheduledWidget::setupComposeControls() {
_scroll->keyPressEvent(e); _scroll->keyPressEvent(e);
} }
e->accept(); e->accept();
} else if (e->key() == Qt::Key_Down) {
_scroll->keyPressEvent(e);
e->accept();
} }
}, lifetime()); }, lifetime());