2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-22 18:27:17 +00:00

374 lines
10 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
#include "base/weak_ptr.h"
2018-11-05 15:16:09 +04:00
#include "media/player/media_player_float.h"
2020-06-30 18:26:44 +04:00
#include "mtproto/sender.h"
class HistoryWidget;
class StackItem;
2020-05-29 18:08:18 +04:00
class Image;
namespace Bot {
struct SendCommandRequest;
} // namespace Bot
namespace SendMenu {
struct Details;
} // namespace SendMenu
2019-07-24 13:45:24 +02:00
namespace Main {
class Session;
} // namespace Main
2019-01-03 16:36:01 +04:00
namespace Data {
2022-11-01 08:46:31 +04:00
class Thread;
2019-01-28 16:59:49 +03:00
class WallPaper;
struct ForwardDraft;
class Forum;
2025-05-06 21:22:36 +04:00
class SavedMessages;
struct ReportInput;
2019-01-03 16:36:01 +04:00
} // namespace Data
namespace Dialogs {
struct RowDescriptor;
class Row;
class Key;
2019-04-24 14:15:10 +04:00
class Widget;
} // namespace Dialogs
2016-09-17 22:28:33 +03:00
namespace Media {
namespace Player {
class Widget;
class Panel;
struct TrackState;
2016-09-17 22:28:33 +03:00
} // namespace Player
} // namespace Media
namespace Export {
namespace View {
class TopBar;
class PanelController;
struct Content;
} // namespace View
} // namespace Export
namespace Ui {
class ChatTheme;
class ResizeArea;
class PlainShadow;
template <typename Widget>
2017-09-13 19:57:44 +03:00
class SlideWrap;
} // namespace Ui
namespace Window {
class SessionController;
template <typename Inner>
class TopBarWrapWidget;
class SectionMemento;
class SectionWidget;
class SlideAnimation;
2019-02-10 19:29:55 +03:00
class ConnectionState;
struct SectionSlideParams;
struct SectionShow;
enum class Column;
class HistoryHider;
struct SeparateId;
} // namespace Window
namespace Calls {
class Call;
2020-11-24 17:40:10 +03:00
class GroupCall;
class TopBar;
} // namespace Calls
namespace Core {
class Changelogs;
} // namespace Core
2024-04-12 15:37:14 +04:00
class MainWidget final
2018-11-05 15:16:09 +04:00
: public Ui::RpWidget
, private Media::Player::FloatDelegate {
public:
using SectionShow = Window::SectionShow;
MainWidget(
QWidget *parent,
not_null<Window::SessionController*> controller);
~MainWidget();
[[nodiscard]] Main::Session &session() const;
2020-06-10 22:08:17 +04:00
[[nodiscard]] not_null<Window::SessionController*> controller() const;
[[nodiscard]] Window::SeparateId windowId() const;
[[nodiscard]] bool isPrimary() const;
[[nodiscard]] bool isMainSectionShown() const;
[[nodiscard]] bool isThirdSectionShown() const;
2022-02-05 18:15:24 +03:00
[[nodiscard]] Dialogs::RowDescriptor resolveChatNext(
Dialogs::RowDescriptor from) const;
[[nodiscard]] Dialogs::RowDescriptor resolveChatPrevious(
Dialogs::RowDescriptor from) const;
void returnTabbedSelector();
2015-07-03 11:47:16 +03:00
void showAnimated(QPixmap oldContentCache, bool back = false);
void activate();
void windowShown();
void dialogsToUp();
void checkActivation();
[[nodiscard]] PeerData *peer() const;
[[nodiscard]] Ui::ChatTheme *customChatTheme() const;
int backgroundFromY() const;
void showSection(
2020-12-14 18:48:10 +04:00
std::shared_ptr<Window::SectionMemento> memento,
const SectionShow &params);
void updateColumnLayout();
bool stackIsEmpty() const;
bool showBackFromStack(const SectionShow &params);
void orderWidgets();
QPixmap grabForShowAnimation(const Window::SectionSlideParams &params);
void checkMainSectionToLayer();
[[nodiscard]] SendMenu::Details sendMenuDetails() const;
[[nodiscard]] bool animatingShow() const;
void showDragForwardInfo();
void hideDragForwardInfo();
2022-11-01 08:46:31 +04:00
bool setForwardDraft(
not_null<Data::Thread*> thread,
Data::ForwardDraft &&draft);
bool sendPaths(
not_null<Data::Thread*> thread,
const QStringList &paths);
bool shareUrl(
not_null<Data::Thread*> thread,
const QString &url,
const QString &text) const;
bool filesOrForwardDrop(
2022-11-01 08:46:31 +04:00
not_null<Data::Thread*> thread,
2022-11-01 11:18:56 +04:00
not_null<const QMimeData*> data);
void sendBotCommand(Bot::SendCommandRequest request);
2023-10-10 10:49:22 +04:00
void hideSingleUseKeyboard(FullMsgId replyToId);
void searchMessages(
const QString &query,
Dialogs::Key inChat,
PeerData *searchFrom = nullptr);
2014-08-15 15:19:32 +04:00
void setChatBackground(
const Data::WallPaper &background,
QImage &&image = QImage());
2015-02-03 18:02:46 +03:00
bool chatBackgroundLoading();
float64 chatBackgroundProgress() const;
2015-02-03 18:02:46 +03:00
void checkChatBackground();
Image *newBackgroundThumb();
2015-09-16 16:04:08 +03:00
void setInnerFocus();
2015-10-01 17:05:05 +03:00
bool contentOverlapped(const QRect &globalRect);
void showChooseReportMessages(
not_null<PeerData*> peer,
Data::ReportInput reportInput,
Fn<void(std::vector<MsgId>)> done);
void clearChooseReportMessages();
void toggleChooseChatTheme(
not_null<PeerData*> peer,
std::optional<bool> show);
2021-09-24 19:10:25 +04:00
void showHistory(
PeerId peer,
const SectionShow &params,
MsgId msgId);
2022-11-01 11:18:56 +04:00
void showMessage(
not_null<const HistoryItem*> item,
const SectionShow &params);
void showForum(not_null<Data::Forum*> forum, const SectionShow &params);
bool notify_switchInlineBotButtonReceived(const QString &query, UserData *samePeerBot, MsgId samePeerReplyTo);
2015-12-07 16:05:00 +03:00
using FloatDelegate::floatPlayerAreaUpdated;
void stopAndClosePlayer();
bool preventsCloseSection(Fn<void()> callback) const;
bool preventsCloseSection(
Fn<void()> callback,
const SectionShow &params) const;
void showNonPremiumLimitToast(bool download);
void dialogsCancelled();
void toggleFiltersMenu(bool value) const;
2024-04-12 15:37:14 +04:00
private:
void paintEvent(QPaintEvent *e) override;
void resizeEvent(QResizeEvent *e) override;
bool eventFilter(QObject *o, QEvent *e) override;
2024-04-12 15:37:14 +04:00
[[nodiscard]] bool relevantForDialogsFocus(
not_null<QWidget*> widget) const;
void showFinished();
void handleAdaptiveLayoutUpdate();
void updateWindowAdaptiveLayout();
void handleAudioUpdate(const Media::Player::TrackState &state);
void updateMediaPlaylistPosition(int x);
void updateControlsGeometry();
2024-05-16 13:35:21 +04:00
void updateMainSectionShown();
void updateDialogsWidthAnimated();
void updateThirdColumnToCurrentChat(
Dialogs::Key key,
bool canWrite);
[[nodiscard]] bool saveThirdSectionToStackBack() const;
[[nodiscard]] auto thirdSectionForCurrentMainSection(Dialogs::Key key)
2020-12-14 18:48:10 +04:00
-> std::shared_ptr<Window::SectionMemento>;
2018-05-07 20:44:33 +03:00
void setupConnectingWidget();
void createPlayer();
void playerHeightUpdated();
void setCurrentCall(Calls::Call *call);
2020-11-24 17:40:10 +03:00
void setCurrentGroupCall(Calls::GroupCall *call);
void createCallTopBar(Calls::Call *call, Calls::GroupCall *group);
void destroyCallTopBar();
2017-09-13 19:57:44 +03:00
void callTopBarHeightUpdated(int callTopBarHeight);
void setCurrentExportView(Export::View::PanelController *view);
void createExportTopBar(Export::View::Content &&data);
void destroyExportTopBar();
void exportTopBarHeightUpdated();
Window::SectionSlideParams prepareShowAnimation(
bool willHaveTopBarShadow);
void showNewSection(
2020-12-14 18:48:10 +04:00
std::shared_ptr<Window::SectionMemento> memento,
const SectionShow &params);
2024-05-29 12:08:22 +04:00
void destroyThirdSection();
Window::SectionSlideParams prepareThirdSectionAnimation(Window::SectionWidget *section);
// All this methods use the prepareShowAnimation().
Window::SectionSlideParams prepareMainSectionAnimation(Window::SectionWidget *section);
Window::SectionSlideParams prepareHistoryAnimation(PeerId historyPeerId);
Window::SectionSlideParams prepareDialogsAnimation();
bool saveSectionInStack(
const SectionShow &params,
Window::SectionWidget *newMainSection = nullptr);
int getMainSectionTop() const;
int getThirdSectionTop() const;
void hideAll();
void showAll();
void hiderLayer(base::unique_qptr<Window::HistoryHider> h);
void clearHider(not_null<Window::HistoryHider*> instance);
void closeBothPlayers();
[[nodiscard]] auto floatPlayerDelegate()
-> not_null<Media::Player::FloatDelegate*>;
2018-11-05 15:16:09 +04:00
not_null<Ui::RpWidget*> floatPlayerWidget() override;
void floatPlayerToggleGifsPaused(bool paused) override;
not_null<Media::Player::FloatSectionDelegate*> floatPlayerGetSection(
2018-11-05 15:16:09 +04:00
Window::Column column) override;
void floatPlayerEnumerateSections(Fn<void(
not_null<Media::Player::FloatSectionDelegate*> widget,
2018-11-05 15:16:09 +04:00
Window::Column widgetColumn)> callback) override;
2018-11-05 17:18:54 +04:00
bool floatPlayerIsVisible(not_null<HistoryItem*> item) override;
void floatPlayerClosed(FullMsgId itemId);
void floatPlayerDoubleClickEvent(
not_null<const HistoryItem*> item) override;
void refreshResizeAreas();
template <typename MoveCallback, typename FinishCallback>
void createResizeArea(
object_ptr<Ui::ResizeArea> &area,
MoveCallback &&moveCallback,
FinishCallback &&finishCallback);
void ensureFirstColumnResizeAreaCreated();
void ensureThirdColumnResizeAreaCreated();
bool isReadyChatBackground(
const Data::WallPaper &background,
const QImage &image) const;
void setReadyChatBackground(
const Data::WallPaper &background,
QImage &&image);
2019-01-16 16:39:35 +04:00
void handleHistoryBack();
2022-01-04 19:36:33 +03:00
bool showHistoryInDifferentWindow(
PeerId peerId,
const SectionShow &params,
MsgId showAtMsgId);
bool isOneColumn() const;
bool isNormalColumn() const;
bool isThreeColumn() const;
2020-06-16 18:19:23 +04:00
const not_null<Window::SessionController*> _controller;
std::unique_ptr<Window::SlideAnimation> _showAnimation;
2017-11-12 20:50:58 +04:00
int _dialogsWidth = 0;
int _thirdColumnWidth = 0;
2019-04-02 13:13:30 +04:00
Ui::Animations::Simple _a_dialogsWidth;
const base::unique_qptr<Dialogs::Widget> _dialogs;
const base::unique_qptr<HistoryWidget> _history;
object_ptr<Window::SectionWidget> _mainSection = { nullptr };
object_ptr<Window::SectionWidget> _thirdSection = { nullptr };
2020-12-14 18:48:10 +04:00
std::shared_ptr<Window::SectionMemento> _thirdSectionFromStack;
2019-02-10 19:29:55 +03:00
std::unique_ptr<Window::ConnectionState> _connecting;
const base::unique_qptr<Ui::PlainShadow> _sideShadow;
object_ptr<Ui::PlainShadow> _thirdShadow = { nullptr };
object_ptr<Ui::ResizeArea> _firstColumnResizeArea = { nullptr };
object_ptr<Ui::ResizeArea> _thirdColumnResizeArea = { nullptr };
base::weak_ptr<Calls::Call> _currentCall;
2020-11-24 17:40:10 +03:00
base::weak_ptr<Calls::GroupCall> _currentGroupCall;
2020-06-25 21:57:36 +04:00
rpl::lifetime _currentCallLifetime;
2017-09-13 19:57:44 +03:00
object_ptr<Ui::SlideWrap<Calls::TopBar>> _callTopBar = { nullptr };
Export::View::PanelController *_currentExportView = nullptr;
object_ptr<Window::TopBarWrapWidget<Export::View::TopBar>> _exportTopBar
= { nullptr };
2020-06-25 11:14:05 +04:00
rpl::lifetime _exportViewLifetime;
object_ptr<Window::TopBarWrapWidget<Media::Player::Widget>> _player
= { nullptr };
object_ptr<Media::Player::Panel> _playerPlaylist;
base::unique_qptr<Window::HistoryHider> _hider;
std::vector<std::unique_ptr<StackItem>> _stack;
int _playerHeight = 0;
int _callTopBarHeight = 0;
int _exportTopBarHeight = 0;
int _contentScrollAddToY = 0;
2015-07-03 11:47:16 +03:00
2019-01-16 16:39:35 +04:00
struct SettingBackground;
std::unique_ptr<SettingBackground> _background;
2015-02-03 18:02:46 +03:00
// _changelogs depends on _data, subscribes on chats loading event.
const std::unique_ptr<Core::Changelogs> _changelogs;
};