From a0a857a6dbbcf6d2db5cb92b62fa3b0af5cd22ca Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Fri, 11 Feb 2022 08:24:54 +0300 Subject: [PATCH] Added simple animation of stickers sending from autocomplete field. --- .../chat_helpers/field_autocomplete.cpp | 49 ++++++++++++++++--- .../chat_helpers/field_autocomplete.h | 2 + .../SourceFiles/history/history_widget.cpp | 5 +- .../history_view_compose_controls.cpp | 1 + 4 files changed, 48 insertions(+), 9 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp index 9575eb7b2b..00483372ca 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.cpp @@ -96,6 +96,7 @@ private: void mouseReleaseEvent(QMouseEvent *e) override; void contextMenuEvent(QContextMenuEvent *e) override; + QRect selectedRect(int index) const; void updateSelectedRow(); void setSel(int sel, bool scroll = false); void showPreview(); @@ -1089,7 +1090,25 @@ bool FieldAutocomplete::Inner::chooseAtIndex( if (!_srows->empty()) { if (index < _srows->size()) { const auto document = (*_srows)[index].document; - _stickerChosen.fire({ document, options, method }); + + const auto from = [&]() -> Ui::MessageSendingAnimationFrom { + if (options.scheduled) { + return {}; + } + const auto bounding = selectedRect(index); + auto contentRect = QRect( + QPoint(), + ChatHelpers::ComputeStickerSize( + document, + stickerBoundingBox())); + contentRect.moveCenter(bounding.center()); + return { + _controller->session().data().nextLocalMessageId(), + mapToGlobal(std::move(contentRect)), + }; + }; + + _stickerChosen.fire({ document, options, method, from() }); return true; } } else if (!_mrows->empty()) { @@ -1228,14 +1247,28 @@ void FieldAutocomplete::Inner::leaveEventHook(QEvent *e) { } } +QRect FieldAutocomplete::Inner::selectedRect(int index) const { + if (index < 0) { + return QRect(); + } + if (_srows->empty()) { + return { 0, index * st::mentionHeight, width(), st::mentionHeight }; + } else { + const auto row = int(index / _stickersPerRow); + const auto col = int(index % _stickersPerRow); + return { + st::stickerPanPadding + col * st::stickerPanSize.width(), + st::stickerPanPadding + row * st::stickerPanSize.height(), + st::stickerPanSize.width(), + st::stickerPanSize.height() + }; + } +} + void FieldAutocomplete::Inner::updateSelectedRow() { - if (_sel >= 0) { - if (_srows->empty()) { - update(0, _sel * st::mentionHeight, width(), st::mentionHeight); - } else { - int32 row = _sel / _stickersPerRow, col = _sel % _stickersPerRow; - update(st::stickerPanPadding + col * st::stickerPanSize.width(), st::stickerPanPadding + row * st::stickerPanSize.height(), st::stickerPanSize.width(), st::stickerPanSize.height()); - } + const auto rect = selectedRect(_sel); + if (rect.isValid()) { + update(rect); } } diff --git a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h index b6a3e0e087..abfb65fb2e 100644 --- a/Telegram/SourceFiles/chat_helpers/field_autocomplete.h +++ b/Telegram/SourceFiles/chat_helpers/field_autocomplete.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "api/api_common.h" #include "ui/effects/animations.h" +#include "ui/effects/message_sending_animation_common.h" #include "ui/rp_widget.h" #include "base/timer.h" #include "base/object_ptr.h" @@ -86,6 +87,7 @@ public: not_null sticker; Api::SendOptions options; ChooseMethod method; + Ui::MessageSendingAnimationFrom messageSendingFrom; }; enum class Type { Mentions, diff --git a/Telegram/SourceFiles/history/history_widget.cpp b/Telegram/SourceFiles/history/history_widget.cpp index eb57de9ee3..f276c5aa39 100644 --- a/Telegram/SourceFiles/history/history_widget.cpp +++ b/Telegram/SourceFiles/history/history_widget.cpp @@ -401,7 +401,10 @@ HistoryWidget::HistoryWidget( _fieldAutocomplete->stickerChosen( ) | rpl::start_with_next([=](FieldAutocomplete::StickerChosen data) { - sendExistingDocument(data.sticker, data.options); + controller->sendingAnimation().appendSending( + data.messageSendingFrom); + const auto localId = data.messageSendingFrom.localId; + sendExistingDocument(data.sticker, data.options, localId); }, lifetime()); _fieldAutocomplete->setModerateKeyActivateCallback([=](int key) { diff --git a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp index 13946c0adb..a8c2ec6c8e 100644 --- a/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp +++ b/Telegram/SourceFiles/history/view/controls/history_view_compose_controls.cpp @@ -1254,6 +1254,7 @@ void ComposeControls::initAutocomplete() { _fileChosen.fire(FileChosen{ .document = data.sticker, .options = data.options, + .messageSendingFrom = base::take(data.messageSendingFrom), }); }, _autocomplete->lifetime());