mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-02-22 16:26:52 +00:00
Added simple animation of stickers sending from autocomplete field.
This commit is contained in:
parent
0a2fbb0d70
commit
a0a857a6db
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
@ -1254,6 +1254,7 @@ void ComposeControls::initAutocomplete() {
|
||||
_fileChosen.fire(FileChosen{
|
||||
.document = data.sticker,
|
||||
.options = data.options,
|
||||
.messageSendingFrom = base::take(data.messageSendingFrom),
|
||||
});
|
||||
}, _autocomplete->lifetime());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user