diff --git a/ui/widgets/separate_panel.cpp b/ui/widgets/separate_panel.cpp index 893c287..f302edf 100644 --- a/ui/widgets/separate_panel.cpp +++ b/ui/widgets/separate_panel.cpp @@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/toasts/common_toasts.h" #include "ui/platform/ui_platform_utility.h" #include "ui/layers/layer_widget.h" +#include "ui/layers/show.h" #include "base/debug_log.h" #include "styles/style_widgets.h" #include "styles/style_layers.h" @@ -29,6 +30,64 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include namespace Ui { +namespace { + +class PanelShow final : public Show { +public: + explicit PanelShow(not_null panel); + ~PanelShow(); + void showBox( + object_ptr content, + Ui::LayerOptions options = Ui::LayerOption::KeepOther) const override; + void hideLayer() const override; + [[nodiscard]] not_null toastParent() const override; + [[nodiscard]] bool valid() const override; + operator bool() const override; + +private: + const QPointer _panel; + +}; + +PanelShow::PanelShow(not_null panel) +: _panel(panel.get()) { +} + +PanelShow::~PanelShow() = default; + +void PanelShow::showBox( + object_ptr content, + Ui::LayerOptions options) const { + if (const auto panel = _panel.data()) { + panel->showBox(std::move(content), options, anim::type::normal); + } +} + +void PanelShow::hideLayer() const { + if (const auto panel = _panel.data()) { + panel->showBox( + object_ptr{ nullptr }, + Ui::LayerOption::CloseOther, + anim::type::normal); + } +} + +not_null PanelShow::toastParent() const { + const auto panel = _panel.data(); + + Ensures(panel != nullptr); + return panel; +} + +bool PanelShow::valid() const { + return (_panel.data() != nullptr); +} + +PanelShow::operator bool() const { + return valid(); +} + +} // namespace SeparatePanel::SeparatePanel(QWidget *parent) : RpWidget(parent) @@ -331,8 +390,16 @@ void SeparatePanel::showBox( object_ptr box, Ui::LayerOptions options, anim::type animated) { - ensureLayerCreated(); - _layer->showBox(std::move(box), options, animated); + if (box) { + ensureLayerCreated(); + _layer->showBox(std::move(box), options, animated); + } else if (_layer) { + _layer->hideAll(animated); + } +} + +std::shared_ptr SeparatePanel::uiShow() { + return std::make_shared(this); } void SeparatePanel::showToast(const TextWithEntities &text) { diff --git a/ui/widgets/separate_panel.h b/ui/widgets/separate_panel.h index 5432b33..029dc8f 100644 --- a/ui/widgets/separate_panel.h +++ b/ui/widgets/separate_panel.h @@ -20,6 +20,7 @@ struct MenuCallback; namespace Ui { +class Show; class BoxContent; class IconButton; class PopupMenu; @@ -54,6 +55,7 @@ public: void setBackAllowed(bool allowed); void setMenuAllowed(Fn fill); + [[nodiscard]] std::shared_ptr uiShow(); protected: void paintEvent(QPaintEvent *e) override;