tdesktop/Telegram/SourceFiles/dialogs/dialogs_widget.h

246 lines
6.7 KiB
C
Raw Normal View History

/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
2022-03-14 15:48:39 +00:00
#include "base/timer.h"
#include "dialogs/dialogs_key.h"
#include "window/section_widget.h"
2019-04-02 09:13:30 +00:00
#include "ui/effects/animations.h"
#include "ui/widgets/scroll_area.h"
#include "ui/special_buttons.h"
#include "mtproto/sender.h"
#include "api/api_single_message_search.h"
2021-03-12 12:48:00 +00:00
namespace MTP {
class Error;
} // namespace MTP
2019-07-24 11:45:24 +00:00
namespace Main {
class Session;
} // namespace Main
2019-04-24 14:12:35 +00:00
namespace HistoryView {
class TopBarWidget;
} // namespace HistoryView
namespace Ui {
class IconButton;
class PopupMenu;
class DropdownMenu;
class FlatButton;
class FlatInput;
class CrossButton;
class DownloadBar;
template <typename Widget>
class FadeWrapScaled;
} // namespace Ui
namespace Window {
class SessionController;
2019-02-10 16:29:55 +00:00
class ConnectionState;
} // namespace Window
2019-04-24 10:15:10 +00:00
namespace Dialogs {
2019-04-24 10:15:10 +00:00
struct RowDescriptor;
class Row;
class FakeRow;
class Key;
struct ChosenRow;
class InnerWidget;
enum class SearchRequestType;
class Widget final : public Window::AbstractSectionWidget {
public:
Widget(QWidget *parent, not_null<Window::SessionController*> controller);
// When resizing the widget with top edge moved up or down and we
// want to add this top movement to the scroll position, so inner
// content will not move.
void setGeometryWithTopMoved(const QRect &newGeometry, int topDelta);
void updateDragInScroll(bool inScroll);
2019-04-24 10:15:10 +00:00
void searchInChat(Key chat);
2019-04-24 14:12:35 +00:00
void setInnerFocus();
void jumpToTop();
void startWidthAnimation();
void stopWidthAnimation();
bool hasTopBarShadow() const {
return true;
}
void showAnimated(Window::SlideDirection direction, const Window::SectionSlideParams &params);
void showFast();
2019-04-24 10:15:10 +00:00
void scrollToEntry(const RowDescriptor &entry);
2019-04-24 10:15:10 +00:00
void searchMessages(const QString &query, Key inChat = {});
2022-03-14 15:48:39 +00:00
void searchMore();
void updateForwardBar();
[[nodiscard]] rpl::producer<> closeForwardBarRequests() const;
2022-02-05 15:15:24 +00:00
[[nodiscard]] RowDescriptor resolveChatNext(RowDescriptor from = {}) const;
[[nodiscard]] RowDescriptor resolveChatPrevious(RowDescriptor from = {}) const;
// Float player interface.
bool floatPlayerHandleWheelEvent(QEvent *e) override;
QRect floatPlayerAvailableRect() override;
2022-03-14 15:48:39 +00:00
bool cancelSearch();
2022-03-14 15:48:39 +00:00
~Widget();
protected:
void dragEnterEvent(QDragEnterEvent *e) override;
void dragMoveEvent(QDragMoveEvent *e) override;
void dragLeaveEvent(QDragLeaveEvent *e) override;
void dropEvent(QDropEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
void keyPressEvent(QKeyEvent *e) override;
void paintEvent(QPaintEvent *e) override;
private:
2019-04-24 10:15:10 +00:00
enum class ShowAnimation {
External,
Internal,
};
2022-03-14 15:48:39 +00:00
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(
2019-04-24 10:15:10 +00:00
SearchRequestType type,
const MTPmessages_Messages &result,
mtpRequestId requestId);
void peerSearchReceived(
const MTPcontacts_Found &result,
mtpRequestId requestId);
void escape();
2020-02-21 12:57:06 +00:00
void cancelSearchRequest();
void setupSupportMode();
2018-05-07 17:44:33 +00:00
void setupConnectingWidget();
void setupMainMenuToggle();
void setupDownloadBar();
bool searchForPeersRequired(const QString &query) const;
2020-10-06 12:58:16 +00:00
void setSearchInChat(Key chat, PeerData *from = nullptr);
void showCalendar();
void showSearchFrom();
void showMainMenu();
void clearSearchCache();
2019-04-24 10:15:10 +00:00
void updateControlsVisibility(bool fast = false);
void updateLockUnlockVisibility();
2019-04-24 10:15:10 +00:00
void updateLoadMoreChatsVisibility();
void updateJumpToDateVisibility(bool fast = false);
void updateSearchFromVisibility(bool fast = false);
void updateControlsGeometry();
2019-04-24 14:12:35 +00:00
void refreshFolderTopBar();
void checkUpdateStatus();
2019-04-24 10:15:10 +00:00
void changeOpenedFolder(Data::Folder *folder, anim::type animated);
QPixmap grabForFolderSlideAnimation();
void startSlideAnimation();
void fullSearchRefreshOn(rpl::producer<> events);
void applyFilterUpdate(bool force = false);
void refreshLoadMoreButton(bool mayBlock, bool isBlocked);
void loadMoreBlockedByDate();
2018-11-09 13:54:34 +00:00
void searchFailed(
SearchRequestType type,
2021-03-12 12:48:00 +00:00
const MTP::Error &error,
mtpRequestId requestId);
2021-03-12 12:48:00 +00:00
void peopleFailed(const MTP::Error &error, mtpRequestId requestId);
2019-04-24 10:15:10 +00:00
void scrollToTop();
void setupScrollUpButton();
void updateScrollUpVisibility();
void startScrollUpButtonAnimation(bool shown);
void updateScrollUpPosition();
MTP::Sender _api;
bool _dragInScroll = false;
bool _dragForward = false;
2022-03-14 15:48:39 +00:00
base::Timer _chooseByDragTimer;
object_ptr<Ui::IconButton> _forwardCancel = { nullptr };
2019-04-24 10:15:10 +00:00
object_ptr<Ui::RpWidget> _searchControls;
2019-04-24 14:12:35 +00:00
object_ptr<HistoryView::TopBarWidget> _folderTopBar = { nullptr } ;
object_ptr<Ui::IconButton> _mainMenuToggle;
object_ptr<Ui::IconButton> _searchForNarrowFilters;
object_ptr<Ui::FlatInput> _filter;
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _chooseFromUser;
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _jumpToDate;
object_ptr<Ui::CrossButton> _cancelSearch;
object_ptr<Ui::IconButton> _lockUnlock;
object_ptr<Ui::ScrollArea> _scroll;
2019-04-24 10:15:10 +00:00
QPointer<InnerWidget> _inner;
2018-11-09 13:54:34 +00:00
class BottomButton;
object_ptr<BottomButton> _updateTelegram = { nullptr };
object_ptr<BottomButton> _loadMoreChats = { nullptr };
std::unique_ptr<Ui::DownloadBar> _downloadBar;
2019-02-10 16:29:55 +00:00
std::unique_ptr<Window::ConnectionState> _connecting;
2019-04-02 09:13:30 +00:00
Ui::Animations::Simple _scrollToAnimation;
Ui::Animations::Simple _a_show;
2019-04-24 10:15:10 +00:00
Window::SlideDirection _showDirection = Window::SlideDirection();
QPixmap _cacheUnder, _cacheOver;
2019-04-24 10:15:10 +00:00
ShowAnimation _showAnimationType = ShowAnimation::External;
Ui::Animations::Simple _scrollToTopShown;
bool _scrollToTopIsShown = false;
object_ptr<Ui::HistoryDownButton> _scrollToTop;
2019-04-24 10:15:10 +00:00
Data::Folder *_openedFolder = nullptr;
2020-06-12 14:09:04 +00:00
Dialogs::Key _searchInChat;
History *_searchInMigrated = nullptr;
2020-10-06 12:58:16 +00:00
PeerData *_searchFromAuthor = nullptr;
QString _lastFilterText;
2022-03-14 15:48:39 +00:00
base::Timer _searchTimer;
QString _peerSearchQuery;
bool _peerSearchFull = false;
mtpRequestId _peerSearchRequest = 0;
QString _searchQuery;
2020-10-06 12:58:16 +00:00
PeerData *_searchQueryFrom = nullptr;
int32 _searchNextRate = 0;
bool _searchFull = false;
bool _searchFullMigrated = false;
2020-02-21 12:57:06 +00:00
int _searchInHistoryRequest = 0; // Not real mtpRequestId.
mtpRequestId _searchRequest = 0;
base::flat_map<QString, MTPmessages_Messages> _searchCache;
Api::SingleMessageSearch _singleMessageSearch;
base::flat_map<mtpRequestId, QString> _searchQueries;
base::flat_map<QString, MTPcontacts_Found> _peerSearchCache;
base::flat_map<mtpRequestId, QString> _peerSearchQueries;
QPixmap _widthAnimationCache;
int _topDelta = 0;
rpl::event_stream<> _closeForwardBarRequests;
};
2019-04-24 10:15:10 +00:00
} // namespace Dialogs