diff --git a/Telegram/SourceFiles/ui/effects/widget_slide_wrap.cpp b/Telegram/SourceFiles/ui/effects/widget_slide_wrap.cpp deleted file mode 100644 index 36bc5580d0..0000000000 --- a/Telegram/SourceFiles/ui/effects/widget_slide_wrap.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#include "ui/effects/widget_slide_wrap.h" - -namespace Ui { - -PaddingWrap::PaddingWrap( - QWidget *parent, - object_ptr child, - const style::margins &padding) -: Parent(parent, std::move(child)) -, _padding(padding) { - if (auto weak = wrapped()) { - auto margins = weak->getMargins(); - weak->sizeValue() - | rpl::on_next([this](QSize&&) { updateSize(); }) - | rpl::start(lifetime()); - weak->moveToLeft(_padding.left() + margins.left(), _padding.top() + margins.top()); - } -} - -void PaddingWrap::updateSize() { - auto inner = [this] { - if (auto weak = wrapped()) { - return weak->rect(); - } - return QRect(0, 0, _innerWidth, 0); - }(); - resize(inner.marginsAdded(_padding).size()); -} - -int PaddingWrap::naturalWidth() const { - auto inner = [this] { - if (auto weak = wrapped()) { - return weak->naturalWidth(); - } - return RpWidget::naturalWidth(); - }(); - return (inner < 0) - ? inner - : (_padding.left() + inner + _padding.right()); -} - -int PaddingWrap::resizeGetHeight(int newWidth) { - _innerWidth = newWidth; - if (auto weak = wrapped()) { - weak->resizeToWidth(newWidth - - _padding.left() - - _padding.right()); - } else { - updateSize(); - } - return height(); -} - -SlideWrap::SlideWrap( - QWidget *parent, - object_ptr child) -: SlideWrap( - parent, - std::move(child), - style::margins(), - st::slideWrapDuration) { -} - -SlideWrap::SlideWrap( - QWidget *parent, - object_ptr child, - const style::margins &padding) -: SlideWrap( - parent, - std::move(child), - padding, - st::slideWrapDuration) { -} - -SlideWrap::SlideWrap( - QWidget *parent, - object_ptr child, - int duration) -: SlideWrap(parent, std::move(child), style::margins(), duration) { -} - -SlideWrap::SlideWrap( - QWidget *parent, - object_ptr child, - const style::margins &padding, - int duration) -: Parent(parent, object_ptr>(parent, std::move(child), padding)) -, _duration(duration * 10) { - if (auto weak = wrapped()) { - weak->heightValue() - | rpl::on_next([this](int newHeight) { - if (_slideAnimation.animating()) { - animationStep(); - } else if (_visible) { - resize(width(), newHeight); - } - }) | rpl::start(lifetime()); - } -} - -void SlideWrap::animationStep() { - if (wrapped()) { - auto margins = getMargins(); - wrapped()->moveToLeft(margins.left(), margins.top()); - } - auto current = _slideAnimation.current(_visible ? 1. : 0.); - auto newHeight = wrapped() - ? (_slideAnimation.animating() - ? anim::interpolate(0, wrapped()->heightNoMargins(), current) - : (_visible ? wrapped()->height() : 0)) - : 0; - if (newHeight != height()) { - resize(width(), newHeight); - } - auto shouldBeHidden = !_visible && !_slideAnimation.animating(); - if (shouldBeHidden != isHidden()) { - setVisible(!shouldBeHidden); - } -} - -void SlideWrap::toggleAnimated(bool visible) { - if (_visible == visible) { - animationStep(); - return; - } - _visible = visible; - _slideAnimation.start( - [this] { animationStep(); }, - _visible ? 0. : 1., - _visible ? 1. : 0., - _duration, - anim::linear); - animationStep(); -} - -void SlideWrap::toggleFast(bool visible) { - _visible = visible; - finishAnimations(); -} - -void SlideWrap::finishAnimations() { - _slideAnimation.finish(); - animationStep(); -} - -QMargins SlideWrap::getMargins() const { - auto result = wrapped()->getMargins(); - return (animating() || !_visible) - ? QMargins(result.left(), 0, result.right(), 0) - : result; -} - -int SlideWrap::resizeGetHeight(int newWidth) { - if (wrapped()) { - wrapped()->resizeToWidth(newWidth); - } - return height(); -} - -} // namespace Ui diff --git a/Telegram/SourceFiles/ui/effects/widget_slide_wrap.h b/Telegram/SourceFiles/ui/effects/widget_slide_wrap.h deleted file mode 100644 index fe7a5c4237..0000000000 --- a/Telegram/SourceFiles/ui/effects/widget_slide_wrap.h +++ /dev/null @@ -1,272 +0,0 @@ -/* -This file is part of Telegram Desktop, -the official desktop application for the Telegram messaging service. - -For license and copyright information please follow this link: -https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL -*/ -#pragma once - -#include "styles/style_widgets.h" -#include "ui/rp_widget.h" - -namespace Ui { - -template -class Wrap; - -namespace details { - -struct UnwrapHelper { - struct Large { - char data[2]; - }; - static char Check(...); - template - static Large Check(Wrap*); - template - static Large Check(const Wrap*); - - template - static constexpr bool Is() { - return sizeof(Check(std::declval())) - == sizeof(Large); - } - template - static auto Unwrap(Entity *entity, std::true_type) { - return entity - ? entity->entity() - : nullptr; - } - template - static Entity *Unwrap(Entity *entity, std::false_type) { - return entity; - } - template - static auto Unwrap(Entity *entity) { - return Unwrap( - entity, - std::integral_constant()>()); - } -}; - -} // namespace details - -template -class Wrap : public RpWidget { -public: - Wrap(QWidget *parent, object_ptr child); - - Widget *wrapped() { - return _wrapped; - } - const Widget *wrapped() const { - return _wrapped; - } - auto entity() { - return details::UnwrapHelper::Unwrap(wrapped()); - } - auto entity() const { - return details::UnwrapHelper::Unwrap(wrapped()); - } - - QMargins getMargins() const override { - if (auto weak = wrapped()) { - return weak->getMargins(); - } - return RpWidget::getMargins(); - } - int naturalWidth() const override { - if (auto weak = wrapped()) { - return weak->naturalWidth(); - } - return RpWidget::naturalWidth(); - } - -private: - object_ptr _wrapped; - -}; - -template -Wrap::Wrap(QWidget *parent, object_ptr child) -: RpWidget(parent) -, _wrapped(std::move(child)) { - if (_wrapped) { - resize(_wrapped->size()); - AttachParentChild(this, _wrapped); - _wrapped->move(0, 0); - _wrapped->alive() - | rpl::on_done([this] { - _wrapped->setParent(nullptr); - _wrapped = nullptr; - delete this; - }) - | rpl::start(lifetime()); - } -} - -template -class Wrap : public ParentType { -public: - using ParentType::ParentType; - - Widget *wrapped() { - return static_cast(ParentType::wrapped()); - } - const Widget *wrapped() const { - return static_cast(ParentType::wrapped()); - } - auto entity() { - return details::UnwrapHelper::Unwrap(wrapped()); - } - auto entity() const { - return details::UnwrapHelper::Unwrap(wrapped()); - } - -}; - -template -class PaddingWrap; - -template <> -class PaddingWrap : public Wrap { - using Parent = Wrap; - -public: - PaddingWrap( - QWidget *parent, - object_ptr child, - const style::margins &padding); - - PaddingWrap( - QWidget *parent, - const style::margins &padding) - : PaddingWrap(parent, nullptr, padding) { - } - - int naturalWidth() const override; - -protected: - int resizeGetHeight(int newWidth) override; - -private: - void updateSize(); - - int _innerWidth = 0; - style::margins _padding; - -}; - -template -class PaddingWrap : public Wrap> { - using Parent = Wrap>; - -public: - PaddingWrap( - QWidget *parent, - object_ptr child, - const style::margins &padding) - : Parent(parent, std::move(child), padding) { - } - - PaddingWrap(QWidget *parent, const style::margins &padding) - : Parent(parent, padding) { - } - -}; - -template -class SlideWrap; - -template <> -class SlideWrap : public Wrap> { - using Parent = Wrap>; - -public: - SlideWrap(QWidget *parent, object_ptr child); - SlideWrap( - QWidget *parent, - object_ptr child, - const style::margins &padding); - SlideWrap( - QWidget *parent, - object_ptr child, - int duration); - SlideWrap( - QWidget *parent, - object_ptr child, - const style::margins &padding, - int duration); - - void toggleAnimated(bool visible); - void toggleFast(bool visible); - - void showAnimated() { - toggleAnimated(true); - } - void hideAnimated() { - toggleAnimated(false); - } - - void showFast() { - toggleFast(true); - } - void hideFast() { - toggleFast(false); - } - - bool animating() const { - return _slideAnimation.animating(); - } - void finishAnimations(); - - QMargins getMargins() const override; - - bool isHiddenOrHiding() const { - return !_visible; - } - -protected: - int resizeGetHeight(int newWidth) override; - -private: - void animationStep(); - - bool _visible = true; - Animation _slideAnimation; - int _duration = 0; - -}; - -template -class SlideWrap : public Wrap, SlideWrap> { - using Parent = Wrap, SlideWrap>; - -public: - SlideWrap(QWidget *parent, object_ptr child) - : Parent(parent, std::move(child)) { - } - SlideWrap( - QWidget *parent, - object_ptr child, - const style::margins &padding) - : Parent(parent, std::move(child), padding) { - } - SlideWrap( - QWidget *parent, - object_ptr child, - int duration) - : Parent(parent, std::move(child), duration) { - } - SlideWrap( - QWidget *parent, - object_ptr child, - const style::margins &padding, - int duration) - : Parent(parent, std::move(child), padding, duration) { - } - -}; - -} // namespace Ui