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"
|
2018-01-22 16:42:25 +00:00
|
|
|
#include "dialogs/dialogs_key.h"
|
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
|
|
|
|
2016-05-19 12:03:51 +00:00
|
|
|
namespace Window {
|
|
|
|
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2017-09-30 18:26:45 +00:00
|
|
|
class LayerWidget;
|
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
|
|
|
|
, protected base::Subscriber {
|
2017-05-22 15:25:49 +00:00
|
|
|
public:
|
2017-09-13 16:57:44 +00:00
|
|
|
AbstractSectionWidget(
|
|
|
|
QWidget *parent,
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::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;
|
|
|
|
|
|
|
|
// Tabbed selector management.
|
|
|
|
virtual void pushTabbedSelectorToThirdSection(
|
|
|
|
const Window::SectionShow ¶ms) {
|
|
|
|
}
|
|
|
|
virtual bool returnTabbedSelector() {
|
|
|
|
return false;
|
|
|
|
}
|
2019-04-16 14:05:56 +00:00
|
|
|
|
2017-05-22 15:25:49 +00:00
|
|
|
// Float player interface.
|
2017-09-16 16:53:41 +00:00
|
|
|
virtual bool wheelEventFromFloatPlayer(QEvent *e) {
|
2017-05-22 15:25:49 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-08-16 12:44:20 +00:00
|
|
|
[[nodiscard]] virtual QRect rectForFloatPlayer() const {
|
2017-05-22 15:25:49 +00:00
|
|
|
return mapToGlobal(rect());
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2019-08-16 12:44:20 +00:00
|
|
|
[[nodiscard]] not_null<Window::SessionController*> controller() const {
|
2017-05-22 15:25:49 +00:00
|
|
|
return _controller;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2019-08-16 12:44:20 +00:00
|
|
|
const not_null<Window::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:
|
2019-06-06 10:21:40 +00:00
|
|
|
SectionWidget(QWidget *parent, not_null<Window::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
|
|
|
|
|
|
|
// 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).
|
2017-09-16 16:53:41 +00:00
|
|
|
virtual std::unique_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.
|
|
|
|
virtual object_ptr<LayerWidget> moveContentToLayer(
|
2017-09-30 18:26:45 +00:00
|
|
|
QRect bodyGeometry) {
|
2017-09-15 17:34:41 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2019-03-19 13:50:36 +00:00
|
|
|
static void PaintBackground(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(
|
|
|
|
const Window::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
|