From d2e482dac3e5ddbc200228d14d04d7d624c98af7 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 3 Mar 2022 16:45:48 +0300 Subject: [PATCH] Added Ui::Show implementation for Ui::BoxContent. --- ui/layers/box_content.cpp | 37 +++++++++++++++++++++++++++++++++++++ ui/layers/box_content.h | 17 +++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/ui/layers/box_content.cpp b/ui/layers/box_content.cpp index e089902..f4aae48 100644 --- a/ui/layers/box_content.cpp +++ b/ui/layers/box_content.cpp @@ -271,4 +271,41 @@ void BoxContent::paintEvent(QPaintEvent *e) { } } +BoxShow::BoxShow(not_null box) +: Show() +, _weak(Ui::MakeWeak(box.get())) { +} + +BoxShow::~BoxShow() = default; + +void BoxShow::showBox( + object_ptr content, + LayerOptions options) const { + if (_weak && _weak->isBoxShown()) { + _weak->getDelegate()->show(std::move(content), options); + } +} + +void BoxShow::hideLayer() const { + if (_weak && _weak->isBoxShown()) { + _weak->getDelegate()->hideLayer(); + } +} + +not_null BoxShow::toastParent() const { + if (!_toastParent) { + Assert(_weak != nullptr); + _toastParent = Ui::MakeWeak(_weak->window()); // =( + } + return _toastParent.data(); +} + +bool BoxShow::valid() const { + return _weak; +} + +BoxShow::operator bool() const { + return valid(); +} + } // namespace Ui diff --git a/ui/layers/box_content.h b/ui/layers/box_content.h index 86112dc..9426d88 100644 --- a/ui/layers/box_content.h +++ b/ui/layers/box_content.h @@ -11,6 +11,7 @@ #include "ui/wrap/padding_wrap.h" #include "ui/widgets/labels.h" #include "ui/layers/layer_widget.h" +#include "ui/layers/show.h" #include "ui/effects/animation_value.h" #include "ui/text/text_entity.h" #include "ui/rp_widget.h" @@ -363,4 +364,20 @@ private: }; +class BoxShow : public Show { +public: + explicit BoxShow(not_null box); + ~BoxShow(); + void showBox( + object_ptr content, + LayerOptions options = LayerOption::KeepOther) const override; + void hideLayer() const override; + [[nodiscard]] not_null toastParent() const override; + [[nodiscard]] bool valid() const override; + operator bool() const override; +private: + mutable QPointer _toastParent; + const QPointer _weak; +}; + } // namespace Ui