2014-05-30 08:53:19 +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.
|
2014-05-30 08:53:19 +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
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
#include "ui/rp_widget.h"
|
2019-04-02 09:13:30 +00:00
|
|
|
#include "ui/effects/animations.h"
|
2019-09-13 12:22:54 +00:00
|
|
|
#include "base/object_ptr.h"
|
2019-01-04 11:09:48 +00:00
|
|
|
#include "data/data_file_origin.h"
|
2017-09-13 16:57:44 +00:00
|
|
|
|
2019-06-24 15:24:52 +00:00
|
|
|
namespace Lottie {
|
2019-06-28 11:33:47 +00:00
|
|
|
class SinglePlayer;
|
2019-06-24 15:24:52 +00:00
|
|
|
} // namespace Lottie
|
|
|
|
|
2019-09-13 06:06:02 +00:00
|
|
|
class BoxContent;
|
|
|
|
|
|
|
|
enum class LayerOption {
|
|
|
|
CloseOther = (1 << 0),
|
|
|
|
KeepOther = (1 << 1),
|
|
|
|
ShowAfterOther = (1 << 2),
|
|
|
|
};
|
|
|
|
using LayerOptions = base::flags<LayerOption>;
|
|
|
|
inline constexpr auto is_flag_type(LayerOption) { return true; };
|
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
namespace Window {
|
2017-09-30 18:26:45 +00:00
|
|
|
|
2016-11-11 19:51:59 +00:00
|
|
|
class MainMenu;
|
2019-06-06 10:21:40 +00:00
|
|
|
class SessionController;
|
2017-10-03 13:05:58 +00:00
|
|
|
class SectionMemento;
|
|
|
|
struct SectionShow;
|
2016-11-11 19:51:59 +00:00
|
|
|
|
2017-09-13 16:57:44 +00:00
|
|
|
class LayerWidget : public Ui::RpWidget {
|
2014-05-30 08:53:19 +00:00
|
|
|
public:
|
2017-09-13 16:57:44 +00:00
|
|
|
using RpWidget::RpWidget;
|
2016-11-04 08:23:50 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
virtual void parentResized() = 0;
|
2016-11-18 13:34:58 +00:00
|
|
|
virtual void showFinished() {
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
void setInnerFocus();
|
2016-12-20 13:03:51 +00:00
|
|
|
bool setClosing() {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (!_closing) {
|
|
|
|
_closing = true;
|
|
|
|
closeHook();
|
2016-12-20 13:03:51 +00:00
|
|
|
return true;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2016-12-20 13:03:51 +00:00
|
|
|
return false;
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool overlaps(const QRect &globalRect);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-06-04 15:35:11 +00:00
|
|
|
void setClosedCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_closedCallback = std::move(callback);
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
2018-06-04 15:35:11 +00:00
|
|
|
void setResizedCallback(Fn<void()> callback) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_resizedCallback = std::move(callback);
|
2015-10-01 14:05:05 +00:00
|
|
|
}
|
2017-09-19 10:32:34 +00:00
|
|
|
virtual bool takeToThirdSection() {
|
|
|
|
return false;
|
|
|
|
}
|
2017-10-03 13:05:58 +00:00
|
|
|
virtual bool showSectionInternal(
|
|
|
|
not_null<SectionMemento*> memento,
|
|
|
|
const SectionShow ¶ms) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-06-06 11:51:27 +00:00
|
|
|
virtual bool closeByOutsideClick() const {
|
|
|
|
return true;
|
|
|
|
}
|
2015-10-01 14:05:05 +00:00
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
protected:
|
2016-12-13 17:07:56 +00:00
|
|
|
void closeLayer() {
|
2018-11-26 11:00:31 +00:00
|
|
|
if (const auto callback = base::take(_closedCallback)) {
|
|
|
|
callback();
|
2016-12-13 17:07:56 +00:00
|
|
|
}
|
|
|
|
}
|
2016-08-17 15:14:08 +00:00
|
|
|
void mousePressEvent(QMouseEvent *e) override {
|
|
|
|
e->accept();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
void resizeEvent(QResizeEvent *e) override {
|
2016-12-13 17:07:56 +00:00
|
|
|
if (_resizedCallback) {
|
|
|
|
_resizedCallback();
|
|
|
|
}
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
virtual void doSetInnerFocus() {
|
|
|
|
setFocus();
|
|
|
|
}
|
2016-12-13 17:07:56 +00:00
|
|
|
virtual void closeHook() {
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
private:
|
|
|
|
bool _closing = false;
|
2018-06-04 15:35:11 +00:00
|
|
|
Fn<void()> _closedCallback;
|
|
|
|
Fn<void()> _resizedCallback;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2018-04-06 16:23:09 +00:00
|
|
|
class LayerStackWidget : public Ui::RpWidget {
|
2014-05-30 08:53:19 +00:00
|
|
|
public:
|
2018-04-06 16:23:09 +00:00
|
|
|
LayerStackWidget(QWidget *parent);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2017-09-30 19:20:40 +00:00
|
|
|
void finishAnimating();
|
2018-04-06 16:23:09 +00:00
|
|
|
rpl::producer<> hideFinishEvents() const;
|
2014-12-12 16:27:03 +00:00
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void showBox(
|
|
|
|
object_ptr<BoxContent> box,
|
2018-04-06 16:23:09 +00:00
|
|
|
LayerOptions options,
|
2017-09-20 10:23:57 +00:00
|
|
|
anim::type animated);
|
|
|
|
void showSpecialLayer(
|
|
|
|
object_ptr<LayerWidget> layer,
|
|
|
|
anim::type animated);
|
2018-04-06 16:23:09 +00:00
|
|
|
void showMainMenu(
|
2019-06-06 10:21:40 +00:00
|
|
|
not_null<Window::SessionController*> controller,
|
2017-09-20 10:23:57 +00:00
|
|
|
anim::type animated);
|
2017-09-19 10:32:34 +00:00
|
|
|
bool takeToThirdSection();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2015-09-16 13:04:08 +00:00
|
|
|
bool canSetFocus() const;
|
|
|
|
void setInnerFocus();
|
|
|
|
|
2015-10-01 14:05:05 +00:00
|
|
|
bool contentOverlapped(const QRect &globalRect);
|
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
void hideSpecialLayer(anim::type animated);
|
|
|
|
void hideLayers(anim::type animated);
|
|
|
|
void hideAll(anim::type animated);
|
|
|
|
void hideTopLayer(anim::type animated);
|
2018-04-17 15:41:52 +00:00
|
|
|
void setHideByBackgroundClick(bool hide);
|
2018-09-06 14:58:43 +00:00
|
|
|
void removeBodyCache();
|
2016-12-13 17:07:56 +00:00
|
|
|
|
2017-10-03 13:05:58 +00:00
|
|
|
bool showSectionInternal(
|
|
|
|
not_null<SectionMemento*> memento,
|
|
|
|
const SectionShow ¶ms);
|
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
bool layerShown() const;
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
~LayerStackWidget();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-08-16 16:53:10 +00:00
|
|
|
protected:
|
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
|
|
|
void mousePressEvent(QMouseEvent *e) override;
|
|
|
|
void resizeEvent(QResizeEvent *e) override;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
private:
|
2018-04-06 16:23:09 +00:00
|
|
|
void appendBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated);
|
|
|
|
void prependBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated);
|
|
|
|
void replaceBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated);
|
2018-12-12 05:47:24 +00:00
|
|
|
void backgroundClicked();
|
2018-04-06 16:23:09 +00:00
|
|
|
|
2017-09-20 10:23:57 +00:00
|
|
|
LayerWidget *pushBox(
|
|
|
|
object_ptr<BoxContent> box,
|
|
|
|
anim::type animated);
|
2016-11-18 13:34:58 +00:00
|
|
|
void showFinished();
|
2017-09-20 10:23:57 +00:00
|
|
|
void hideCurrent(anim::type animated);
|
2018-11-26 11:00:31 +00:00
|
|
|
void closeLayer(not_null<LayerWidget*> layer);
|
2016-11-18 13:34:58 +00:00
|
|
|
|
|
|
|
enum class Action {
|
|
|
|
ShowMainMenu,
|
|
|
|
ShowSpecialLayer,
|
|
|
|
ShowLayer,
|
2017-09-20 10:23:57 +00:00
|
|
|
HideSpecialLayer,
|
2016-11-18 13:34:58 +00:00
|
|
|
HideLayer,
|
|
|
|
HideAll,
|
|
|
|
};
|
|
|
|
template <typename SetupNew, typename ClearOld>
|
2017-09-19 10:32:34 +00:00
|
|
|
void startAnimation(
|
|
|
|
SetupNew setupNewWidgets,
|
|
|
|
ClearOld clearOldWidgets,
|
|
|
|
Action action,
|
2017-09-20 10:23:57 +00:00
|
|
|
anim::type animated);
|
2016-11-18 13:34:58 +00:00
|
|
|
|
|
|
|
void prepareForAnimation();
|
|
|
|
void animationDone();
|
|
|
|
|
|
|
|
void setCacheImages();
|
2016-08-16 16:53:10 +00:00
|
|
|
void clearLayers();
|
2016-12-13 17:07:56 +00:00
|
|
|
void clearSpecialLayer();
|
2016-11-18 13:34:58 +00:00
|
|
|
void initChildLayer(LayerWidget *layer);
|
|
|
|
void updateLayerBoxes();
|
2016-08-16 16:53:10 +00:00
|
|
|
void fixOrder();
|
2016-08-19 17:26:31 +00:00
|
|
|
void sendFakeMouseEvent();
|
2019-02-17 06:36:44 +00:00
|
|
|
void clearClosingLayers();
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2016-11-18 13:34:58 +00:00
|
|
|
LayerWidget *currentLayer() {
|
2018-11-26 11:00:31 +00:00
|
|
|
return _layers.empty() ? nullptr : _layers.back().get();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
2016-11-18 13:34:58 +00:00
|
|
|
const LayerWidget *currentLayer() const {
|
|
|
|
return const_cast<LayerStackWidget*>(this)->currentLayer();
|
2016-08-16 16:53:10 +00:00
|
|
|
}
|
|
|
|
|
2018-11-26 11:00:31 +00:00
|
|
|
std::vector<std::unique_ptr<LayerWidget>> _layers;
|
2019-02-17 06:36:44 +00:00
|
|
|
std::vector<std::unique_ptr<LayerWidget>> _closingLayers;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<LayerWidget> _specialLayer = { nullptr };
|
2017-09-30 18:26:45 +00:00
|
|
|
object_ptr<MainMenu> _mainMenu = { nullptr };
|
2016-08-16 16:53:10 +00:00
|
|
|
|
|
|
|
class BackgroundWidget;
|
2016-12-13 17:07:56 +00:00
|
|
|
object_ptr<BackgroundWidget> _background;
|
2018-04-17 15:41:52 +00:00
|
|
|
bool _hideByBackgroundClick = true;
|
2016-08-16 16:53:10 +00:00
|
|
|
|
2018-04-06 16:23:09 +00:00
|
|
|
rpl::event_stream<> _hideFinishStream;
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
2015-12-07 13:05:00 +00:00
|
|
|
|
2017-09-30 18:26:45 +00:00
|
|
|
} // namespace Window
|
|
|
|
|
2019-06-12 13:26:04 +00:00
|
|
|
class GenericBox;
|
|
|
|
|
|
|
|
template <typename BoxType = GenericBox, typename ...Args>
|
2017-02-03 20:07:26 +00:00
|
|
|
inline object_ptr<BoxType> Box(Args&&... args) {
|
2019-06-12 13:26:04 +00:00
|
|
|
const auto parent = static_cast<QWidget*>(nullptr);
|
2017-02-21 13:45:56 +00:00
|
|
|
return object_ptr<BoxType>(parent, std::forward<Args>(args)...);
|
2017-02-03 20:07:26 +00:00
|
|
|
}
|