diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp index 40aa8f90c..719889fa3 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.cpp +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.cpp @@ -171,6 +171,7 @@ Widget::Widget( not_null controller) : Window::AbstractSectionWidget(parent, controller, nullptr) , _api(&controller->session().mtp()) +, _chooseByDragTimer([=] { _inner->chooseRow(); }) , _searchControls(this) , _mainMenuToggle(_searchControls, st::dialogsMenuToggle) , _searchForNarrowFilters(_searchControls, st::dialogsSearchForNarrowFilters) @@ -185,12 +186,13 @@ Widget::Widget( , _lockUnlock(_searchControls, st::dialogsLock) , _scroll(this) , _scrollToTop(_scroll, st::dialogsToUp) +, _searchTimer([=] { searchMessages(); }) , _singleMessageSearch(&controller->session()) { _inner = _scroll->setOwnedWidget(object_ptr(this, controller)); _inner->updated( ) | rpl::start_with_next([=] { - onListScroll(); + listScrollUpdated(); }, lifetime()); rpl::combine( @@ -233,19 +235,19 @@ Widget::Widget( }, lifetime()); _inner->searchMessages( ) | rpl::start_with_next([=] { - onNeedSearchMessages(); + needSearchMessages(); }, lifetime()); _inner->cancelSearchInChatRequests( ) | rpl::start_with_next([=] { - onCancelSearchInChat(); + cancelSearchInChat(); }, lifetime()); _inner->completeHashtagRequests( ) | rpl::start_with_next([=](const QString &tag) { - onCompleteHashtag(tag); + completeHashtag(tag); }, lifetime()); _inner->refreshHashtagsRequests( ) | rpl::start_with_next([=] { - onFilterCursorMoved(); + filterCursorMoved(); }, lifetime()); _inner->cancelSearchFromUserRequests( ) | rpl::start_with_next([=] { @@ -289,26 +291,26 @@ Widget::Widget( }), lifetime()); _scroll->scrolls( ) | rpl::start_with_next([=] { - onListScroll(); + listScrollUpdated(); }, lifetime()); session().data().chatsListChanges( ) | rpl::filter([=](Data::Folder *folder) { return (folder == _inner->shownFolder()); }) | rpl::start_with_next([=] { - Ui::PostponeCall(this, [=] { onListScroll(); }); + Ui::PostponeCall(this, [=] { listScrollUpdated(); }); }, lifetime()); - connect(_filter, &Ui::FlatInput::cancelled, [=] { + QObject::connect(_filter, &Ui::FlatInput::cancelled, [=] { escape(); }); - connect(_filter, &Ui::FlatInput::changed, [=] { + QObject::connect(_filter, &Ui::FlatInput::changed, [=] { applyFilterUpdate(); }); - connect( + QObject::connect( _filter, &Ui::FlatInput::cursorPositionChanged, - [=](int from, int to) { onFilterCursorMoved(from, to); }); + [=](int from, int to) { filterCursorMoved(from, to); }); if (!Core::UpdaterDisabled()) { Core::UpdateChecker checker; @@ -327,7 +329,7 @@ Widget::Widget( updateForwardBar(); }, lifetime()); - _cancelSearch->setClickedCallback([this] { onCancelSearch(); }); + _cancelSearch->setClickedCallback([this] { cancelSearch(); }); _jumpToDate->entity()->setClickedCallback([this] { showCalendar(); }); _chooseFromUser->entity()->setClickedCallback([this] { showSearchFrom(); }); rpl::single(rpl::empty) | rpl::then( @@ -345,14 +347,8 @@ Widget::Widget( _searchForNarrowFilters->setClickedCallback([=] { Ui::showChatsList(&session()); }); - _chooseByDragTimer.setSingleShot(true); - connect(&_chooseByDragTimer, SIGNAL(timeout()), this, SLOT(onChooseByDrag())); - setAcceptDrops(true); - _searchTimer.setSingleShot(true); - connect(&_searchTimer, SIGNAL(timeout()), this, SLOT(onSearchMessages())); - _inner->setLoadMoreCallback([=] { const auto state = _inner->state(); if (state == WidgetState::Filtered @@ -360,7 +356,7 @@ Widget::Widget( || (_searchInMigrated && _searchFull && !_searchFullMigrated))) { - onSearchMore(); + searchMore(); } else { const auto folder = _inner->shownFolder(); if (!folder || !folder->chatsList()->loaded()) { @@ -570,7 +566,7 @@ void Widget::fullSearchRefreshOn(rpl::producer<> events) { ) | rpl::filter([=] { return !_searchQuery.isEmpty(); }) | rpl::start_with_next([=] { - _searchTimer.stop(); + _searchTimer.cancel(); _searchCache.clear(); _singleMessageSearch.clear(); for (const auto &[requestId, query] : base::take(_searchQueries)) { @@ -579,7 +575,7 @@ void Widget::fullSearchRefreshOn(rpl::producer<> events) { _searchQuery = QString(); _scroll->scrollToY(0); cancelSearchRequest(); - onSearchMessages(); + searchMessages(); }, lifetime()); } @@ -845,7 +841,7 @@ void Widget::animationCallback() { void Widget::escape() { if (controller()->openedFolder().current()) { controller()->closeFolder(); - } else if (!onCancelSearch()) { + } else if (!cancelSearch()) { if (controller()->activeChatEntryCurrent().key) { controller()->content()->dialogsCancelled(); } else if (controller()->activeChatsFilterCurrent()) { @@ -893,7 +889,7 @@ void Widget::loadMoreBlockedByDate() { session().api().requestMoreBlockedByDateDialogs(); } -bool Widget::onSearchMessages(bool searchCache) { +bool Widget::searchMessages(bool searchCache) { auto result = false; auto q = _filter->getLastText().trimmed(); if (q.isEmpty() && !_searchFromAuthor) { @@ -903,7 +899,7 @@ bool Widget::onSearchMessages(bool searchCache) { } if (searchCache) { const auto success = _singleMessageSearch.lookup(q, [=] { - onNeedSearchMessages(); + needSearchMessages(); }); if (!success) { return false; @@ -1036,16 +1032,12 @@ bool Widget::searchForPeersRequired(const QString &query) const { return (query[0] != '#'); } -void Widget::onNeedSearchMessages() { - if (!onSearchMessages(true)) { - _searchTimer.start(AutoSearchTimeout); +void Widget::needSearchMessages() { + if (!searchMessages(true)) { + _searchTimer.callOnce(AutoSearchTimeout); } } -void Widget::onChooseByDrag() { - _inner->chooseRow(); -} - void Widget::showMainMenu() { controller()->widget()->showMainMenu(); } @@ -1065,20 +1057,20 @@ void Widget::searchMessages( }(); if ((_filter->getLastText() != query) || inChatChanged) { if (inChat) { - onCancelSearch(); + cancelSearch(); setSearchInChat(inChat); } _filter->setText(query); _filter->updatePlaceholder(); applyFilterUpdate(true); - _searchTimer.stop(); - onSearchMessages(); + _searchTimer.cancel(); + searchMessages(); session().local().saveRecentSearchHashtags(query); } } -void Widget::onSearchMore() { +void Widget::searchMore() { if (_searchRequest || _searchInHistoryRequest) { return; } @@ -1306,7 +1298,7 @@ void Widget::searchReceived( } _searchRequest = 0; - onListScroll(); + listScrollUpdated(); update(); } @@ -1333,7 +1325,7 @@ void Widget::peerSearchReceived( } _peerSearchRequest = 0; - onListScroll(); + listScrollUpdated(); } } @@ -1386,7 +1378,7 @@ void Widget::dragEnterEvent(QDragEnterEvent *e) { e->setDropAction(Qt::CopyAction); e->accept(); } - _chooseByDragTimer.stop(); + _chooseByDragTimer.cancel(); } void Widget::dragMoveEvent(QDragMoveEvent *e) { @@ -1394,7 +1386,7 @@ void Widget::dragMoveEvent(QDragMoveEvent *e) { if (_dragForward) { updateDragInScroll(true); } else { - _chooseByDragTimer.start(ChoosePeerByDragTimeout); + _chooseByDragTimer.callOnce(ChoosePeerByDragTimeout); } if (_inner->updateFromParentDrag(mapToGlobal(e->pos()))) { e->setDropAction(Qt::CopyAction); @@ -1413,7 +1405,7 @@ void Widget::dragLeaveEvent(QDragLeaveEvent *e) { if (_dragForward) { updateDragInScroll(false); } else { - _chooseByDragTimer.stop(); + _chooseByDragTimer.cancel(); } _inner->dragLeft(); e->accept(); @@ -1431,7 +1423,7 @@ void Widget::updateDragInScroll(bool inScroll) { } void Widget::dropEvent(QDropEvent *e) { - _chooseByDragTimer.stop(); + _chooseByDragTimer.cancel(); if (_scroll->geometry().contains(e->pos())) { if (auto peer = _inner->updateFromParentDrag(mapToGlobal(e->pos()))) { e->acceptProposedAction(); @@ -1444,7 +1436,7 @@ void Widget::dropEvent(QDropEvent *e) { } } -void Widget::onListScroll() { +void Widget::listScrollUpdated() { const auto scrollTop = _scroll->scrollTop(); _inner->setVisibleTopBottom(scrollTop, scrollTop + _scroll->height()); updateScrollUpVisibility(); @@ -1487,7 +1479,7 @@ void Widget::applyFilterUpdate(bool force) { } void Widget::searchInChat(Key chat) { - onCancelSearch(); + cancelSearch(); setSearchInChat(chat); applyFilterUpdate(true); } @@ -1520,7 +1512,7 @@ void Widget::setSearchInChat(Key chat, PeerData *from) { } _inner->searchInChat(_searchInChat, _searchFromAuthor); if (_searchFromAuthor && _lastFilterText == SwitchToChooseFromQuery()) { - onCancelSearch(); + cancelSearch(); } _filter->setFocus(); } @@ -1556,7 +1548,7 @@ void Widget::showSearchFrom() { } } -void Widget::onFilterCursorMoved(int from, int to) { +void Widget::filterCursorMoved(int from, int to) { if (to < 0) to = _filter->cursorPosition(); QString t = _filter->getLastText(); QStringView r; @@ -1572,7 +1564,7 @@ void Widget::onFilterCursorMoved(int from, int to) { _inner->onHashtagFilterUpdate(r); } -void Widget::onCompleteHashtag(QString tag) { +void Widget::completeHashtag(QString tag) { QString t = _filter->getLastText(), r; int cur = _filter->cursorPosition(); for (int start = cur; start > 0;) { @@ -1723,7 +1715,7 @@ void Widget::updateControlsGeometry() { if (_topDelta) { _scroll->scrollToY(newScrollTop); } else { - onListScroll(); + listScrollUpdated(); } if (_scrollToTopIsShown) { updateScrollUpPosition(); @@ -1778,7 +1770,7 @@ void Widget::keyPressEvent(QKeyEvent *e) { _inner->selectSkip(1); _inner->chooseRow(); } else { - onSearchMessages(); + searchMessages(); } } } else if (e->key() == Qt::Key_Down) { @@ -1861,7 +1853,7 @@ void Widget::cancelSearchRequest() { base::take(_searchInHistoryRequest)); } -bool Widget::onCancelSearch() { +bool Widget::cancelSearch() { bool clearing = !_filter->getLastText().isEmpty(); cancelSearchRequest(); if (_searchInChat && !clearing) { @@ -1869,7 +1861,7 @@ bool Widget::onCancelSearch() { if (const auto peer = _searchInChat.peer()) { Ui::showPeerHistory(peer, ShowAtUnreadMsgId); } else { - Unexpected("Empty key in onCancelSearch()."); + Unexpected("Empty key in cancelSearch()."); } } setSearchInChat(Key()); @@ -1882,7 +1874,7 @@ bool Widget::onCancelSearch() { return clearing; } -void Widget::onCancelSearchInChat() { +void Widget::cancelSearchInChat() { cancelSearchRequest(); const auto isOneColumn = controller()->adaptive().isOneColumn(); if (_searchInChat) { @@ -1892,7 +1884,7 @@ void Widget::onCancelSearchInChat() { if (const auto peer = _searchInChat.peer()) { Ui::showPeerHistory(peer, ShowAtUnreadMsgId); } else { - Unexpected("Empty key in onCancelSearchInPeer()."); + Unexpected("Empty key in cancelSearchInPeer()."); } } setSearchInChat(Key()); diff --git a/Telegram/SourceFiles/dialogs/dialogs_widget.h b/Telegram/SourceFiles/dialogs/dialogs_widget.h index 5a0b45133..b9440bf98 100644 --- a/Telegram/SourceFiles/dialogs/dialogs_widget.h +++ b/Telegram/SourceFiles/dialogs/dialogs_widget.h @@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once +#include "base/timer.h" #include "dialogs/dialogs_key.h" #include "window/section_widget.h" #include "ui/effects/animations.h" @@ -15,8 +16,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mtproto/sender.h" #include "api/api_single_message_search.h" -#include - namespace MTP { class Error; } // namespace MTP @@ -57,7 +56,6 @@ class InnerWidget; enum class SearchRequestType; class Widget final : public Window::AbstractSectionWidget { - Q_OBJECT public: Widget(QWidget *parent, not_null controller); @@ -86,7 +84,7 @@ public: void scrollToEntry(const RowDescriptor &entry); void searchMessages(const QString &query, Key inChat = {}); - void onSearchMore(); + void searchMore(); void updateForwardBar(); @@ -99,21 +97,10 @@ public: bool floatPlayerHandleWheelEvent(QEvent *e) override; QRect floatPlayerAvailableRect() override; + bool cancelSearch(); + ~Widget(); -public Q_SLOTS: - void onListScroll(); - bool onCancelSearch(); - void onCancelSearchInChat(); - - void onFilterCursorMoved(int from = -1, int to = -1); - void onCompleteHashtag(QString tag); - - bool onSearchMessages(bool searchCache = false); - void onNeedSearchMessages(); - - void onChooseByDrag(); - protected: void dragEnterEvent(QDragEnterEvent *e) override; void dragMoveEvent(QDragMoveEvent *e) override; @@ -129,6 +116,14 @@ private: Internal, }; + void listScrollUpdated(); + void cancelSearchInChat(); + void filterCursorMoved(int from = -1, int to = -1); + void completeHashtag(QString tag); + + bool searchMessages(bool searchCache = false); + void needSearchMessages(); + void animationCallback(); void searchReceived( SearchRequestType type, @@ -183,7 +178,7 @@ private: bool _dragInScroll = false; bool _dragForward = false; - QTimer _chooseByDragTimer; + base::Timer _chooseByDragTimer; object_ptr _forwardCancel = { nullptr }; object_ptr _searchControls; @@ -219,7 +214,7 @@ private: PeerData *_searchFromAuthor = nullptr; QString _lastFilterText; - QTimer _searchTimer; + base::Timer _searchTimer; QString _peerSearchQuery; bool _peerSearchFull = false; diff --git a/Telegram/SourceFiles/mainwidget.cpp b/Telegram/SourceFiles/mainwidget.cpp index 909cc65a9..f96f51456 100644 --- a/Telegram/SourceFiles/mainwidget.cpp +++ b/Telegram/SourceFiles/mainwidget.cpp @@ -676,7 +676,7 @@ void MainWidget::hiderLayer(base::unique_qptr hider) { _hider->confirmed( ) | rpl::start_with_next([=] { - _dialogs->onCancelSearch(); + _dialogs->cancelSearch(); }, _hider->lifetime()); if (isOneColumn()) {