2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-09-02 07:25:46 +00:00

Removed Q_OBJECT from Dialogs::Widget.

This commit is contained in:
23rd
2022-03-14 18:48:39 +03:00
parent c96b2081c4
commit b14b1a415f
3 changed files with 59 additions and 72 deletions

View File

@@ -171,6 +171,7 @@ Widget::Widget(
not_null<Window::SessionController*> 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<InnerWidget>(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());