Added simple animation of stickers sending from autocomplete field.

This commit is contained in:
23rd 2022-02-11 08:24:54 +03:00 committed by John Preston
parent 0a2fbb0d70
commit a0a857a6db
4 changed files with 48 additions and 9 deletions

View File

@ -96,6 +96,7 @@ private:
void mouseReleaseEvent(QMouseEvent *e) override; void mouseReleaseEvent(QMouseEvent *e) override;
void contextMenuEvent(QContextMenuEvent *e) override; void contextMenuEvent(QContextMenuEvent *e) override;
QRect selectedRect(int index) const;
void updateSelectedRow(); void updateSelectedRow();
void setSel(int sel, bool scroll = false); void setSel(int sel, bool scroll = false);
void showPreview(); void showPreview();
@ -1089,7 +1090,25 @@ bool FieldAutocomplete::Inner::chooseAtIndex(
if (!_srows->empty()) { if (!_srows->empty()) {
if (index < _srows->size()) { if (index < _srows->size()) {
const auto document = (*_srows)[index].document; 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; return true;
} }
} else if (!_mrows->empty()) { } 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() { void FieldAutocomplete::Inner::updateSelectedRow() {
if (_sel >= 0) { const auto rect = selectedRect(_sel);
if (_srows->empty()) { if (rect.isValid()) {
update(0, _sel * st::mentionHeight, width(), st::mentionHeight); update(rect);
} 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());
}
} }
} }

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_common.h" #include "api/api_common.h"
#include "ui/effects/animations.h" #include "ui/effects/animations.h"
#include "ui/effects/message_sending_animation_common.h"
#include "ui/rp_widget.h" #include "ui/rp_widget.h"
#include "base/timer.h" #include "base/timer.h"
#include "base/object_ptr.h" #include "base/object_ptr.h"
@ -86,6 +87,7 @@ public:
not_null<DocumentData*> sticker; not_null<DocumentData*> sticker;
Api::SendOptions options; Api::SendOptions options;
ChooseMethod method; ChooseMethod method;
Ui::MessageSendingAnimationFrom messageSendingFrom;
}; };
enum class Type { enum class Type {
Mentions, Mentions,

View File

@ -401,7 +401,10 @@ HistoryWidget::HistoryWidget(
_fieldAutocomplete->stickerChosen( _fieldAutocomplete->stickerChosen(
) | rpl::start_with_next([=](FieldAutocomplete::StickerChosen data) { ) | 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()); }, lifetime());
_fieldAutocomplete->setModerateKeyActivateCallback([=](int key) { _fieldAutocomplete->setModerateKeyActivateCallback([=](int key) {

View File

@ -1254,6 +1254,7 @@ void ComposeControls::initAutocomplete() {
_fileChosen.fire(FileChosen{ _fileChosen.fire(FileChosen{
.document = data.sticker, .document = data.sticker,
.options = data.options, .options = data.options,
.messageSendingFrom = base::take(data.messageSendingFrom),
}); });
}, _autocomplete->lifetime()); }, _autocomplete->lifetime());