2016-05-19 12:03:51 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-05-19 12:03:51 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2021-07-26 20:06:14 +00:00
|
|
|
#include "chat_helpers/bot_command.h"
|
2018-01-22 16:42:25 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
2020-06-25 14:17:37 +00:00
|
|
|
#include "media/player/media_player_float.h" // FloatSectionDelegate
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2019-07-24 11:45:24 +00:00
|
|
|
namespace Main {
|
|
|
|
class Session;
|
|
|
|
} // namespace Main
|
2019-04-16 14:05:56 +00:00
|
|
|
|
2019-09-18 11:19:05 +00:00
|
|
|
namespace Ui {
|
|
|
|
class LayerWidget;
|
|
|
|
} // namespace Ui
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
namespace Window {
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2017-10-03 13:05:58 +00:00
|
|
|
class SlideAnimation;
|
|
|
|
struct SectionShow;
|
|
|
|
enum class SlideDirection;
|
2017-05-22 15:25:49 +00:00
|
|
|
|
|
|
|
enum class Column {
|
|
|
|
First,
|
|
|
|
Second,
|
|
|
|
Third,
|
|
|
|
};
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
class AbstractSectionWidget
|
|
|
|
: public Ui::RpWidget
|
2020-06-25 14:17:37 +00:00
|
|
|
, public Media::Player::FloatSectionDelegate
|
2017-09-13 16:57:44 +00:00
|
|
|
, protected base::Subscriber {
|
2017-05-22 15:25:49 +00:00
|
|
|
public:
|
2017-09-13 16:57:44 +00:00
|
|
|
AbstractSectionWidget(
|
|
|
|
QWidget *parent,
|
2020-08-31 11:17:02 +00:00
|
|
|
not_null<SessionController*> controller)
|
2019-04-16 14:05:56 +00:00
|
|
|
: RpWidget(parent)
|
|
|
|
, _controller(controller) {
|
2017-05-22 15:25:49 +00:00
|
|
|
}
|
|
|
|
|
2019-08-16 12:44:20 +00:00
|
|
|
[[nodiscard]] Main::Session &session() const;
|
2020-08-31 11:17:02 +00:00
|
|
|
[[nodiscard]] not_null<SessionController*> controller() const {
|
2020-06-10 18:08:17 +00:00
|
|
|
return _controller;
|
|
|
|
}
|
2019-08-16 12:44:20 +00:00
|
|
|
|
|
|
|
// Tabbed selector management.
|
2020-05-05 12:55:05 +00:00
|
|
|
virtual bool pushTabbedSelectorToThirdSection(
|
|
|
|
not_null<PeerData*> peer,
|
2020-08-31 11:17:02 +00:00
|
|
|
const SectionShow ¶ms) {
|
2020-05-05 12:55:05 +00:00
|
|
|
return false;
|
2019-08-16 12:44:20 +00:00
|
|
|
}
|
|
|
|
virtual bool returnTabbedSelector() {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-16 14:05:56 +00:00
|
|
|
|
2017-05-22 15:25:49 +00:00
|
|
|
private:
|
2020-08-31 11:17:02 +00:00
|
|
|
const not_null<SessionController*> _controller;
|
2017-05-22 15:25:49 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
class SectionMemento;
|
|
|
|
|
|
|
|
struct SectionSlideParams {
|
|
|
|
QPixmap oldContentCache;
|
|
|
|
bool withTopBarShadow = false;
|
2017-10-03 17:41:44 +00:00
|
|
|
bool withTabs = false;
|
|
|
|
bool withFade = false;
|
2017-01-14 18:50:16 +00:00
|
|
|
|
|
|
|
explicit operator bool() const {
|
|
|
|
return !oldContentCache.isNull();
|
|
|
|
}
|
2016-05-19 12:03:51 +00:00
|
|
|
};
|
|
|
|
|
2017-05-22 15:25:49 +00:00
|
|
|
class SectionWidget : public AbstractSectionWidget {
|
2016-05-19 12:03:51 +00:00
|
|
|
public:
|
2020-06-10 18:08:17 +00:00
|
|
|
SectionWidget(
|
|
|
|
QWidget *parent,
|
2020-08-31 11:17:02 +00:00
|
|
|
not_null<SessionController*> controller);
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2018-01-22 16:42:25 +00:00
|
|
|
virtual Dialogs::RowDescriptor activeChat() const {
|
|
|
|
return {};
|
2016-05-19 12:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
virtual bool hasTopBarShadow() const {
|
|
|
|
return false;
|
|
|
|
}
|
2017-09-16 16:53:41 +00:00
|
|
|
virtual bool forceAnimateBack() const {
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-03 13:05:58 +00:00
|
|
|
void showAnimated(
|
|
|
|
SlideDirection direction,
|
|
|
|
const SectionSlideParams ¶ms);
|
2017-01-14 18:50:16 +00:00
|
|
|
void showFast();
|
2016-05-19 12:03:51 +00:00
|
|
|
|
|
|
|
// This can be used to grab with or without top bar shadow.
|
|
|
|
// This will be protected when animation preparation will be done inside.
|
2019-09-13 12:22:54 +00:00
|
|
|
virtual QPixmap grabForShowAnimation(const SectionSlideParams ¶ms);
|
2016-05-19 12:03:51 +00:00
|
|
|
|
|
|
|
// Attempt to show the required section inside the existing one.
|
|
|
|
// For example if this section already shows exactly the required
|
|
|
|
// memento it can simply return true - it is shown already.
|
2017-06-24 17:05:32 +00:00
|
|
|
//
|
|
|
|
// If this method returns false it is not supposed to modify the memento.
|
|
|
|
// If this method returns true it may modify the memento ("take" heavy items).
|
2017-10-03 13:05:58 +00:00
|
|
|
virtual bool showInternal(
|
|
|
|
not_null<SectionMemento*> memento,
|
|
|
|
const SectionShow ¶ms) = 0;
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2020-08-31 11:17:02 +00:00
|
|
|
virtual bool showMessage(
|
|
|
|
PeerId peerId,
|
|
|
|
const SectionShow ¶ms,
|
|
|
|
MsgId messageId) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-11-21 23:18:58 +00:00
|
|
|
virtual bool preventsClose(Fn<void()> &&continueCallback) const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
// Create a memento of that section to store it in the history stack.
|
2017-06-24 17:05:32 +00:00
|
|
|
// This method may modify the section ("take" heavy items).
|
2020-12-14 14:48:10 +00:00
|
|
|
virtual std::shared_ptr<SectionMemento> createMemento();
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2017-01-14 18:50:16 +00:00
|
|
|
void setInnerFocus() {
|
|
|
|
doSetInnerFocus();
|
2016-05-19 12:03:51 +00:00
|
|
|
}
|
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
virtual rpl::producer<int> desiredHeight() const;
|
|
|
|
|
2017-09-15 17:34:41 +00:00
|
|
|
// Some sections convert to layers on some geometry sizes.
|
2019-09-18 11:19:05 +00:00
|
|
|
virtual object_ptr<Ui::LayerWidget> moveContentToLayer(
|
2017-09-30 18:26:45 +00:00
|
|
|
QRect bodyGeometry) {
|
2017-09-15 17:34:41 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2020-06-10 18:08:17 +00:00
|
|
|
static void PaintBackground(
|
2020-08-31 11:17:02 +00:00
|
|
|
not_null<SessionController*> controller,
|
2020-06-10 18:08:17 +00:00
|
|
|
not_null<QWidget*> widget,
|
|
|
|
QRect clip);
|
2018-01-09 17:08:31 +00:00
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
protected:
|
|
|
|
void paintEvent(QPaintEvent *e) override;
|
|
|
|
|
|
|
|
// Temp variable used in resizeEvent() implementation, that is passed
|
|
|
|
// to setGeometryWithTopMoved() to adjust the scroll position with the resize.
|
|
|
|
int topDelta() const {
|
|
|
|
return _topDelta;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Called after the hideChildren() call in showAnimated().
|
2017-10-03 17:41:44 +00:00
|
|
|
virtual void showAnimatedHook(
|
2020-08-31 11:17:02 +00:00
|
|
|
const SectionSlideParams ¶ms) {
|
2016-05-19 12:03:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Called after the showChildren() call in showFinished().
|
|
|
|
virtual void showFinishedHook() {
|
|
|
|
}
|
|
|
|
|
2017-01-14 18:50:16 +00:00
|
|
|
virtual void doSetInnerFocus() {
|
|
|
|
setFocus();
|
|
|
|
}
|
|
|
|
|
2017-06-18 11:08:14 +00:00
|
|
|
bool animating() const {
|
|
|
|
return _showAnimation != nullptr;
|
|
|
|
}
|
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
~SectionWidget();
|
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
private:
|
|
|
|
void showFinished();
|
|
|
|
|
2017-02-21 13:45:56 +00:00
|
|
|
std::unique_ptr<SlideAnimation> _showAnimation;
|
2016-05-19 12:03:51 +00:00
|
|
|
|
2017-09-13 17:01:23 +00:00
|
|
|
// Saving here topDelta in setGeometryWithTopMoved() to get it passed to resizeEvent().
|
2016-05-19 12:03:51 +00:00
|
|
|
int _topDelta = 0;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace Window
|