2020-04-08 15:09:29 +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 "data/data_reply_preview.h"
|
|
|
|
|
|
|
|
#include "data/data_file_origin.h"
|
|
|
|
#include "data/data_document.h"
|
|
|
|
#include "data/data_document_media.h"
|
|
|
|
#include "data/data_photo.h"
|
2020-05-25 14:16:04 +00:00
|
|
|
#include "data/data_photo_media.h"
|
2020-04-08 15:09:29 +00:00
|
|
|
#include "ui/image/image.h"
|
|
|
|
|
|
|
|
namespace Data {
|
|
|
|
|
|
|
|
ReplyPreview::ReplyPreview(not_null<DocumentData*> document)
|
2020-05-21 11:40:10 +00:00
|
|
|
: _document(document) {
|
2020-04-08 15:09:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ReplyPreview::ReplyPreview(not_null<PhotoData*> photo)
|
|
|
|
: _photo(photo) {
|
|
|
|
}
|
|
|
|
|
2020-05-29 14:08:18 +00:00
|
|
|
ReplyPreview::~ReplyPreview() = default;
|
|
|
|
|
2020-04-08 15:09:29 +00:00
|
|
|
void ReplyPreview::prepare(not_null<Image*> image, Images::Options options) {
|
2020-05-29 15:10:25 +00:00
|
|
|
if (image->isNull()) {
|
2020-04-08 15:09:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
int w = image->width(), h = image->height();
|
|
|
|
if (w <= 0) w = 1;
|
|
|
|
if (h <= 0) h = 1;
|
|
|
|
auto thumbSize = (w > h)
|
|
|
|
? QSize(
|
|
|
|
w * st::msgReplyBarSize.height() / h,
|
|
|
|
st::msgReplyBarSize.height())
|
|
|
|
: QSize(
|
|
|
|
st::msgReplyBarSize.height(),
|
|
|
|
h * st::msgReplyBarSize.height() / w);
|
|
|
|
thumbSize *= cIntRetinaFactor();
|
|
|
|
const auto prepareOptions = Images::Option::Smooth
|
|
|
|
| Images::Option::TransparentBackground
|
|
|
|
| options;
|
|
|
|
auto outerSize = st::msgReplyBarSize.height();
|
|
|
|
auto bitmap = image->pixNoCache(
|
|
|
|
thumbSize.width(),
|
|
|
|
thumbSize.height(),
|
|
|
|
prepareOptions,
|
|
|
|
outerSize,
|
|
|
|
outerSize);
|
2020-05-29 15:10:25 +00:00
|
|
|
_image = std::make_unique<Image>(bitmap.toImage());
|
2020-04-08 15:09:29 +00:00
|
|
|
_good = ((options & Images::Option::Blurred) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Image *ReplyPreview::image(Data::FileOrigin origin) {
|
2020-05-21 11:40:10 +00:00
|
|
|
if (_checked) {
|
|
|
|
return _image.get();
|
|
|
|
}
|
2020-04-08 15:09:29 +00:00
|
|
|
if (_document) {
|
2020-05-25 14:16:04 +00:00
|
|
|
if (!_image || (!_good && _document->hasThumbnail())) {
|
|
|
|
if (!_documentMedia) {
|
|
|
|
_documentMedia = _document->createMediaView();
|
|
|
|
_documentMedia->thumbnailWanted(origin);
|
|
|
|
}
|
|
|
|
const auto thumbnail = _documentMedia->thumbnail();
|
2020-04-08 15:09:29 +00:00
|
|
|
const auto option = _document->isVideoMessage()
|
|
|
|
? Images::Option::Circled
|
|
|
|
: Images::Option::None;
|
2020-04-15 14:06:34 +00:00
|
|
|
if (thumbnail) {
|
2020-04-08 15:09:29 +00:00
|
|
|
prepare(thumbnail, option);
|
2020-05-26 10:13:32 +00:00
|
|
|
} else if (!_image) {
|
2020-04-08 15:09:29 +00:00
|
|
|
if (const auto image = _documentMedia->thumbnailInline()) {
|
|
|
|
prepare(image, option | Images::Option::Blurred);
|
|
|
|
}
|
|
|
|
}
|
2020-05-26 14:32:38 +00:00
|
|
|
if (_good || !_document->hasThumbnail()) {
|
2020-05-21 11:40:10 +00:00
|
|
|
_checked = true;
|
|
|
|
_documentMedia = nullptr;
|
|
|
|
}
|
2020-04-08 15:09:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Assert(_photo != nullptr);
|
2020-05-25 14:16:04 +00:00
|
|
|
if (!_image || !_good) {
|
|
|
|
if (!_photoMedia) {
|
|
|
|
_photoMedia = _photo->createMediaView();
|
|
|
|
_photoMedia->wanted(PhotoSize::Small, origin);
|
|
|
|
}
|
|
|
|
if (const auto small = _photoMedia->image(PhotoSize::Small)) {
|
2020-04-08 15:09:29 +00:00
|
|
|
prepare(small, Images::Option(0));
|
2020-05-25 14:16:04 +00:00
|
|
|
} else if (const auto large = _photoMedia->image(
|
|
|
|
PhotoSize::Large)) {
|
|
|
|
prepare(large, Images::Option(0));
|
2020-05-26 10:13:32 +00:00
|
|
|
} else if (!_image) {
|
|
|
|
if (const auto blurred = _photoMedia->thumbnailInline()) {
|
|
|
|
prepare(blurred, Images::Option::Blurred);
|
|
|
|
}
|
2020-04-08 15:09:29 +00:00
|
|
|
}
|
2020-05-26 14:32:38 +00:00
|
|
|
if (_good) {
|
|
|
|
_checked = true;
|
|
|
|
_photoMedia = nullptr;
|
|
|
|
}
|
2020-04-08 15:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return _image.get();
|
|
|
|
}
|
|
|
|
|
2020-10-12 13:24:45 +00:00
|
|
|
bool ReplyPreview::loaded() const {
|
|
|
|
return _checked;
|
|
|
|
}
|
|
|
|
|
2020-04-08 15:09:29 +00:00
|
|
|
} // namespace Data
|