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 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);
}
}

View File

@ -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<DocumentData*> sticker;
Api::SendOptions options;
ChooseMethod method;
Ui::MessageSendingAnimationFrom messageSendingFrom;
};
enum class Type {
Mentions,

View File

@ -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) {

View File

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