From afdfe1c2e89faee284a444ec8c13b5003ca476e3 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 10 Feb 2022 21:53:51 +0300 Subject: [PATCH] Added ability to provide custom view to sending animation controller. --- .../SourceFiles/history/history_widget.cpp | 4 ++-- .../message_sending_animation_controller.cpp | 18 ++++++++++-------- .../message_sending_animation_controller.h | 6 +++++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index c48d91d68..7b8a7d9cc 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -805,7 +805,7 @@ HistoryWidget::HistoryWidget( action.replyTo)); if (action.options.scheduled) { cancelReply(lastKeyboardUsed); - crl::on_main(this, [=, history = action.history]{ + crl::on_main(this, [=, history = action.history] { controller->showSection( std::make_shared(history)); }); @@ -5408,7 +5408,7 @@ void HistoryWidget::startMessageSendingAnimation( sendingAnimation.startAnimation({ .globalEndGeometry = std::move(globalEndGeometry), - .item = item, + .view = [=] { return item->mainView(); }, .theme = _list->theme(), }); } diff --git a/Telegram/SourceFiles/ui/effects/message_sending_animation_controller.cpp b/Telegram/SourceFiles/ui/effects/message_sending_animation_controller.cpp index b971fa2ff..a68cf038e 100644 --- a/Telegram/SourceFiles/ui/effects/message_sending_animation_controller.cpp +++ b/Telegram/SourceFiles/ui/effects/message_sending_animation_controller.cpp @@ -116,7 +116,7 @@ private: void updateCache(); const not_null _controller; - not_null _item; + Fn()> _view; not_null _theme; QImage _cache; QRect _from; @@ -138,9 +138,10 @@ Content::Content( MessageSendingAnimationController::SendingInfoTo &&to) : RpWidget(parent) , _controller(controller) -, _item(to.item) +, _view(std::move(to.view)) , _theme(to.theme) , _from(parent->mapFromGlobal(globalGeometryFrom)) { + Expects(_view != nullptr); show(); setAttribute(Qt::WA_TransparentForMouseEvents); @@ -162,7 +163,7 @@ Content::Content( }, lifetime()); const auto innerContentRect - = _item->mainView()->media()->contentRectForReactions(); + = _view()->media()->contentRectForReactions(); auto animationCallback = [=](float64 value) { auto resultFrom = QRect( QPoint(), @@ -183,7 +184,7 @@ Content::Content( Context::SkipDrawingParts::Content, QRect( QPoint(), - _item->mainView()->innerGeometry().size())), + _view()->innerGeometry().size())), _minScale); _surrounding->show(); _surrounding->raise(); @@ -236,7 +237,7 @@ rpl::producer<> Content::destroyRequests() const { void Content::updateCache() { _cache = drawMedia( Context::SkipDrawingParts::Surrounding, - _item->mainView()->media()->contentRectForReactions()); + _view()->media()->contentRectForReactions()); resize(_cache.size() / style::DevicePixelRatio()); } @@ -255,10 +256,11 @@ QImage Content::drawMedia( auto context = _controller->preparePaintContext({ .theme = _theme, }); + const auto view = _view(); context.skipDrawingParts = skipParts; - context.outbg = _item->mainView()->hasOutLayout(); + context.outbg = view->hasOutLayout(); p.translate(-rect.left(), -rect.top()); - _item->mainView()->media()->draw(p, context); + view->media()->draw(p, context); } return image; } @@ -285,7 +287,7 @@ void MessageSendingAnimationController::startAnimation(SendingInfoTo &&to) { return; } const auto container = _controller->content(); - const auto item = to.item; + const auto item = to.view()->data(); const auto it = _itemSendPending.find(item->fullId().msg); if (it == end(_itemSendPending)) { diff --git a/Telegram/SourceFiles/ui/effects/message_sending_animation_controller.h b/Telegram/SourceFiles/ui/effects/message_sending_animation_controller.h index 0b2f784fc..7d51c616e 100644 --- a/Telegram/SourceFiles/ui/effects/message_sending_animation_controller.h +++ b/Telegram/SourceFiles/ui/effects/message_sending_animation_controller.h @@ -10,6 +10,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/unique_qptr.h" #include "ui/effects/message_sending_animation_common.h" +namespace HistoryView { +class Element; +} // namespace HistoryView + namespace Window { class SessionController; } // namespace Window @@ -26,7 +30,7 @@ public: struct SendingInfoTo { rpl::producer globalEndGeometry; - not_null item; + Fn()> view; not_null theme; };