tdesktop/Telegram/SourceFiles/dialogs/dialogs_widget.h

343 lines
9.8 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/userpic_view.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
namespace Data {
class Forum;
enum class StorySourcesList : uchar;
} // namespace Data
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;
class ContactStatus;
2019-04-24 14:12:35 +00:00
} // namespace HistoryView
namespace Ui {
class AbstractButton;
class IconButton;
class PopupMenu;
class DropdownMenu;
class FlatButton;
class InputField;
class CrossButton;
class PlainShadow;
class DownloadBar;
class GroupCallBar;
class RequestsBar;
class MoreChatsBar;
2022-12-19 11:48:24 +00:00
class JumpDownButton;
2023-07-07 18:49:30 +00:00
class ElasticScroll;
template <typename Widget>
class FadeWrapScaled;
} // namespace Ui
namespace Window {
class SessionController;
2019-02-10 16:29:55 +00:00
class ConnectionState;
struct SectionShow;
} // namespace Window
2023-07-11 07:15:32 +00:00
namespace Dialogs::Stories {
class List;
2023-07-11 15:22:18 +00:00
struct Content;
2023-07-11 07:15:32 +00:00
} // namespace Dialogs::Stories
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:
enum class Layout {
Main,
Child,
};
Widget(
QWidget *parent,
not_null<Window::SessionController*> controller,
Layout layout);
// 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);
void showForum(
not_null<Data::Forum*> forum,
const Window::SectionShow &params);
2019-04-24 10:15:10 +00:00
void searchInChat(Key chat);
2019-04-24 14:12:35 +00:00
void setInnerFocus();
void jumpToTop(bool belowPinned = false);
2023-07-28 08:10:01 +00:00
void raiseWithTooltip();
void startWidthAnimation();
void stopWidthAnimation();
bool hasTopBarShadow() const {
return true;
}
void showAnimated(
Window::SlideDirection direction,
const Window::SectionSlideParams &params);
void showFast();
[[nodiscard]] rpl::producer<float64> shownProgressValue() const;
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 = {});
void searchTopics();
2022-03-14 15:48:39 +00:00
void searchMore();
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:
void chosenRow(const ChosenRow &row);
2022-03-14 15:48:39 +00:00
void listScrollUpdated();
void cancelSearchInChat();
void filterCursorMoved();
2022-03-14 15:48:39 +00:00
void completeHashtag(QString tag);
[[nodiscard]] QString currentSearchQuery() const;
void clearSearchField();
2022-03-14 15:48:39 +00:00
bool searchMessages(bool searchCache = false);
void needSearchMessages();
void slideFinished();
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();
void submit();
2020-02-21 12:57:06 +00:00
void cancelSearchRequest();
[[nodiscard]] PeerData *searchInPeer() const;
[[nodiscard]] Data::ForumTopic *searchInTopic() const;
void setupSupportMode();
2018-05-07 17:44:33 +00:00
void setupConnectingWidget();
void setupMainMenuToggle();
void setupMoreChatsBar();
void setupDownloadBar();
void setupShortcuts();
2023-07-11 07:15:32 +00:00
void setupStories();
void storiesExplicitCollapse();
void collectStoriesUserpicsViews(Data::StorySourcesList list);
void storiesToggleExplicitExpand(bool expand);
2023-07-11 15:22:18 +00:00
void trackScroll(not_null<Ui::RpWidget*> widget);
[[nodiscard]] bool searchForPeersRequired(const QString &query) const;
[[nodiscard]] bool searchForTopicsRequired(const QString &query) const;
bool setSearchInChat(Key chat, PeerData *from = nullptr);
void showCalendar();
void showSearchFrom();
void showMainMenu();
void clearSearchCache();
2022-12-22 07:17:50 +00:00
void setSearchQuery(const QString &query);
2019-04-24 10:15:10 +00:00
void updateControlsVisibility(bool fast = false);
void updateLockUnlockVisibility(
anim::type animated = anim::type::instant);
2019-04-24 10:15:10 +00:00
void updateLoadMoreChatsVisibility();
2023-07-11 15:22:18 +00:00
void updateStoriesVisibility();
void updateJumpToDateVisibility(bool fast = false);
void updateSearchFromVisibility(bool fast = false);
void updateControlsGeometry();
void refreshTopBars();
void showSearchInTopBar(anim::type animated);
void checkUpdateStatus();
void changeOpenedSubsection(
FnMut<void()> change,
bool fromRight,
anim::type animated);
2019-04-24 10:15:10 +00:00
void changeOpenedFolder(Data::Folder *folder, anim::type animated);
void changeOpenedForum(Data::Forum *forum, anim::type animated);
void hideChildList();
2022-12-06 10:12:43 +00:00
void destroyChildListCanvas();
[[nodiscard]] QPixmap grabForFolderSlideAnimation();
void startSlideAnimation(
QPixmap oldContentCache,
QPixmap newContentCache,
Window::SlideDirection direction);
void openChildList(
not_null<Data::Forum*> forum,
const Window::SectionShow &params);
void closeChildList(anim::type animated);
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);
2023-05-23 16:13:02 +00:00
void scrollToDefault(bool verytop = false);
void scrollToDefaultChecked(bool verytop = false);
2019-04-24 10:15:10 +00:00
void setupScrollUpButton();
void updateScrollUpVisibility();
void startScrollUpButtonAnimation(bool shown);
void updateScrollUpPosition();
2023-07-13 16:49:08 +00:00
void updateLockUnlockPosition();
2019-04-24 10:15:10 +00:00
MTP::Sender _api;
bool _dragInScroll = false;
bool _dragForward = false;
2022-03-14 15:48:39 +00:00
base::Timer _chooseByDragTimer;
Layout _layout = Layout::Main;
int _narrowWidth = 0;
2019-04-24 10:15:10 +00:00
object_ptr<Ui::RpWidget> _searchControls;
object_ptr<HistoryView::TopBarWidget> _subsectionTopBar = { nullptr } ;
struct {
object_ptr<Ui::IconButton> toggle;
object_ptr<Ui::AbstractButton> under;
} _mainMenu;
object_ptr<Ui::IconButton> _searchForNarrowFilters;
object_ptr<Ui::InputField> _filter;
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _chooseFromUser;
object_ptr<Ui::FadeWrapScaled<Ui::IconButton>> _jumpToDate;
object_ptr<Ui::CrossButton> _cancelSearch;
object_ptr< Ui::FadeWrapScaled<Ui::IconButton>> _lockUnlock;
std::unique_ptr<Ui::MoreChatsBar> _moreChatsBar;
std::unique_ptr<Ui::PlainShadow> _forumTopShadow;
std::unique_ptr<Ui::GroupCallBar> _forumGroupCallBar;
std::unique_ptr<Ui::RequestsBar> _forumRequestsBar;
std::unique_ptr<HistoryView::ContactStatus> _forumReportBar;
2023-07-07 18:49:30 +00:00
object_ptr<Ui::ElasticScroll> _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;
2023-07-11 07:15:32 +00:00
int _scrollAnimationTo = 0;
std::unique_ptr<Window::SlideAnimation> _showAnimation;
rpl::variable<float64> _shownProgressValue;
Ui::Animations::Simple _scrollToTopShown;
2022-12-19 11:48:24 +00:00
object_ptr<Ui::JumpDownButton> _scrollToTop;
bool _scrollToTopIsShown = false;
bool _forumSearchRequested = false;
2023-07-11 15:22:18 +00:00
Data::Folder *_openedFolder = nullptr;
Data::Forum *_openedForum = nullptr;
Dialogs::Key _searchInChat;
History *_searchInMigrated = nullptr;
PeerData *_searchFromAuthor = nullptr;
QString _lastFilterText;
rpl::event_stream<rpl::producer<Stories::Content>> _storiesContents;
base::flat_map<PeerId, Ui::PeerUserpicView> _storiesUserpicsViewsHidden;
base::flat_map<PeerId, Ui::PeerUserpicView> _storiesUserpicsViewsShown;
Fn<void()> _updateScrollGeometryCached;
2023-07-11 07:15:32 +00:00
std::unique_ptr<Stories::List> _stories;
Ui::Animations::Simple _storiesExplicitExpandAnimation;
rpl::variable<int> _storiesExplicitExpandValue = 0;
int _storiesExplicitExpandScrollTop = 0;
int _aboveScrollAdded = 0;
bool _storiesExplicitExpand = false;
2023-07-11 07:15:32 +00:00
2022-03-14 15:48:39 +00:00
base::Timer _searchTimer;
QString _peerSearchQuery;
bool _peerSearchFull = false;
mtpRequestId _peerSearchRequest = 0;
QString _topicSearchQuery;
TimeId _topicSearchOffsetDate = 0;
MsgId _topicSearchOffsetId = 0;
MsgId _topicSearchOffsetTopicId = 0;
bool _topicSearchFull = false;
mtpRequestId _topicSearchRequest = 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;
PeerData *_lastSearchPeer = nullptr;
MsgId _lastSearchId = 0;
MsgId _lastSearchMigratedId = 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;
std::unique_ptr<Widget> _childList;
std::unique_ptr<Ui::RpWidget> _childListShadow;
rpl::variable<float64> _childListShown;
rpl::variable<PeerId> _childListPeerId;
std::unique_ptr<Ui::RpWidget> _hideChildListCanvas;
};
2019-04-24 10:15:10 +00:00
} // namespace Dialogs