2021-02-23 15:35:40 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "editor/scene_item_sticker.h"
|
|
|
|
|
|
|
|
#include "app.h"
|
|
|
|
#include "chat_helpers/stickers_lottie.h"
|
|
|
|
#include "data/data_document.h"
|
|
|
|
#include "data/data_document_media.h"
|
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "lottie/lottie_common.h"
|
|
|
|
#include "lottie/lottie_single_player.h"
|
|
|
|
#include "main/main_session.h"
|
|
|
|
#include "styles/style_editor.h"
|
|
|
|
|
|
|
|
namespace Editor {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
ItemSticker::ItemSticker(
|
|
|
|
not_null<DocumentData*> document,
|
2021-03-10 07:45:42 +00:00
|
|
|
rpl::producer<float64> zoomValue,
|
2021-02-23 15:35:40 +00:00
|
|
|
std::shared_ptr<float64> zPtr,
|
|
|
|
int size,
|
|
|
|
int x,
|
|
|
|
int y)
|
2021-03-10 07:45:42 +00:00
|
|
|
: ItemBase(std::move(zoomValue), std::move(zPtr), size, x, y)
|
2021-02-23 15:35:40 +00:00
|
|
|
, _document(document)
|
2021-03-10 07:45:42 +00:00
|
|
|
, _mediaView(_document->createMediaView()) {
|
2021-02-23 15:35:40 +00:00
|
|
|
const auto stickerData = document->sticker();
|
|
|
|
if (!stickerData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto updateThumbnail = [=] {
|
2021-03-09 15:12:23 +00:00
|
|
|
const auto guard = gsl::finally([&] {
|
|
|
|
setAspectRatio(_pixmap.isNull()
|
|
|
|
? 1.0
|
|
|
|
: (_pixmap.height() / float64(_pixmap.width())));
|
|
|
|
});
|
2021-02-23 15:35:40 +00:00
|
|
|
if (stickerData->animated) {
|
|
|
|
_lottie.player = ChatHelpers::LottiePlayerFromDocument(
|
|
|
|
_mediaView.get(),
|
|
|
|
ChatHelpers::StickerLottieSize::MessageHistory,
|
|
|
|
QSize(kStickerSideSize, kStickerSideSize)
|
|
|
|
* cIntRetinaFactor(),
|
|
|
|
Lottie::Quality::High);
|
|
|
|
_lottie.player->updates(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
_pixmap = App::pixmapFromImageInPlace(
|
|
|
|
_lottie.player->frame());
|
|
|
|
_lottie.player = nullptr;
|
|
|
|
_lottie.lifetime.destroy();
|
|
|
|
update();
|
|
|
|
}, _lottie.lifetime);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
const auto sticker = _mediaView->getStickerLarge();
|
|
|
|
if (!sticker) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
_pixmap = sticker->pixNoCache(
|
|
|
|
sticker->width() * cIntRetinaFactor(),
|
|
|
|
sticker->height() * cIntRetinaFactor(),
|
|
|
|
Images::Option::Smooth);
|
|
|
|
_pixmap.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
if (!updateThumbnail()) {
|
|
|
|
_document->owner().session().downloaderTaskFinished(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
if (updateThumbnail()) {
|
|
|
|
_loadingLifetime.destroy();
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
}, _loadingLifetime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ItemSticker::paint(
|
|
|
|
QPainter *p,
|
|
|
|
const QStyleOptionGraphicsItem *option,
|
|
|
|
QWidget *w) {
|
2021-03-10 07:45:42 +00:00
|
|
|
p->drawPixmap(contentRect().toRect(), _pixmap);
|
2021-02-23 15:35:40 +00:00
|
|
|
ItemBase::paint(p, option, w);
|
|
|
|
}
|
|
|
|
|
2021-03-14 09:46:17 +00:00
|
|
|
MTPInputDocument ItemSticker::sticker() const {
|
|
|
|
return _document->mtpInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ItemSticker::type() const {
|
|
|
|
return Type;
|
|
|
|
}
|
|
|
|
|
2021-02-23 15:35:40 +00:00
|
|
|
} // namespace Editor
|