Added animated gif preview when users edits media.

This commit is contained in:
23rd 2019-03-27 09:28:18 +03:00 committed by John Preston
parent d5a2daa8c9
commit 6735605f21
2 changed files with 30 additions and 11 deletions

View File

@ -268,15 +268,26 @@ void EditCaptionBox::updateEmojiPanelGeometry() {
local.x() + _emojiToggle->width() * 3); local.x() + _emojiToggle->width() * 3);
} }
void EditCaptionBox::prepareGifPreview(not_null<DocumentData*> document) { void EditCaptionBox::prepareGifPreview(DocumentData* document) {
if (_gifPreview) { if (_gifPreview) {
return; return;
} else if (document->isAnimation() && document->loaded()) { } else if (!document && _newMediaPath.isEmpty()) {
_gifPreview = Media::Clip::MakeReader(document, _msgId, [this](Media::Clip::Notification notification) { return;
clipCallback(notification);
});
if (_gifPreview) _gifPreview->setAutoplay();
} }
const auto callback = [=](Media::Clip::Notification notification) {
clipCallback(notification);
};
if (document && document->isAnimation() && document->loaded()) {
_gifPreview = Media::Clip::MakeReader(
document,
_msgId,
callback);
} else if (!_newMediaPath.isEmpty()) {
_gifPreview = Media::Clip::MakeReader(
_newMediaPath,
callback);
}
if (_gifPreview) _gifPreview->setAutoplay();
} }
void EditCaptionBox::clipCallback(Media::Clip::Notification notification) { void EditCaptionBox::clipCallback(Media::Clip::Notification notification) {
@ -329,6 +340,11 @@ void EditCaptionBox::prepare() {
_animated = false; _animated = false;
_photo = false; _photo = false;
_doc = false; _doc = false;
_gifPreview = nullptr;
_thumbw = _thumbh = _thumbx = 0;
_gifw = _gifh = _gifx = 0;
auto isGif = false;
using Info = FileMediaInformation; using Info = FileMediaInformation;
if (const auto image = base::get_if<Info::Image>(fileMedia) if (const auto image = base::get_if<Info::Image>(fileMedia)
@ -337,6 +353,7 @@ void EditCaptionBox::prepare() {
} else if (const auto video = } else if (const auto video =
base::get_if<Info::Video>(fileMedia)) { base::get_if<Info::Video>(fileMedia)) {
_animated = true; _animated = true;
isGif = video->isGifv;
} else { } else {
auto nameString = filename; auto nameString = filename;
if (const auto song = if (const auto song =
@ -351,10 +368,6 @@ void EditCaptionBox::prepare() {
_doc = true; _doc = true;
} }
_thumbw = 0;
_thumbh = 0;
_thumbx = 0;
if (!_doc) { if (!_doc) {
_thumb = App::pixmapFromImageInPlace( _thumb = App::pixmapFromImageInPlace(
file->preview.scaled(st::sendMediaPreviewSize, file->preview.scaled(st::sendMediaPreviewSize,
@ -363,6 +376,12 @@ void EditCaptionBox::prepare() {
_thumbw = _thumb.width(); _thumbw = _thumb.width();
_thumbh = _thumb.height(); _thumbh = _thumb.height();
_thumbx = (st::boxWideWidth - _thumbw) / 2; _thumbx = (st::boxWideWidth - _thumbw) / 2;
if (isGif) {
_gifw = _thumbw;
_gifh = _thumbh;
_gifx = _thumbx;
prepareGifPreview();
}
} }
captionResized(); captionResized();
} }

View File

@ -47,7 +47,7 @@ protected:
private: private:
void updateBoxSize(); void updateBoxSize();
void prepareGifPreview(not_null<DocumentData*> document); void prepareGifPreview(DocumentData* document = nullptr);
void clipCallback(Media::Clip::Notification notification); void clipCallback(Media::Clip::Notification notification);
void setupEmojiPanel(); void setupEmojiPanel();