2016-04-04 21:09:46 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-04 21:09:46 +00:00
|
|
|
*/
|
|
|
|
#include "inline_bots/inline_bot_layout_internal.h"
|
|
|
|
|
2017-09-26 11:49:16 +00:00
|
|
|
#include "data/data_photo.h"
|
|
|
|
#include "data/data_document.h"
|
2018-01-04 10:22:53 +00:00
|
|
|
#include "data/data_session.h"
|
2016-04-21 17:57:29 +00:00
|
|
|
#include "styles/style_overview.h"
|
2016-09-30 12:52:03 +00:00
|
|
|
#include "styles/style_history.h"
|
2017-04-06 14:38:10 +00:00
|
|
|
#include "styles/style_chat_helpers.h"
|
2016-11-16 10:44:06 +00:00
|
|
|
#include "styles/style_widgets.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
#include "inline_bots/inline_bot_result.h"
|
2019-07-02 13:41:50 +00:00
|
|
|
#include "lottie/lottie_single_player.h"
|
2019-02-13 12:36:59 +00:00
|
|
|
#include "media/audio/media_audio.h"
|
|
|
|
#include "media/clip/media_clip_reader.h"
|
2016-09-23 16:04:26 +00:00
|
|
|
#include "media/player/media_player_instance.h"
|
2016-09-27 13:37:18 +00:00
|
|
|
#include "history/history_location_manager.h"
|
2018-01-11 19:33:26 +00:00
|
|
|
#include "history/view/history_view_cursor_state.h"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2018-10-23 09:44:42 +00:00
|
|
|
#include "ui/image/image.h"
|
2019-07-24 11:45:24 +00:00
|
|
|
#include "main/main_session.h"
|
2018-07-16 19:41:43 +00:00
|
|
|
#include "apiwrap.h"
|
2017-04-13 08:27:10 +00:00
|
|
|
#include "lang/lang_keys.h"
|
2019-09-13 06:06:02 +00:00
|
|
|
#include "app.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
namespace Layout {
|
|
|
|
namespace internal {
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
using TextState = HistoryView::TextState;
|
|
|
|
|
2018-06-28 15:01:32 +00:00
|
|
|
FileBase::FileBase(not_null<Context*> context, not_null<Result*> result)
|
|
|
|
: ItemBase(context, result) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2018-06-28 15:01:32 +00:00
|
|
|
FileBase::FileBase(not_null<Context*> context, DocumentData *document)
|
|
|
|
: ItemBase(context, document) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *FileBase::getShownDocument() const {
|
2018-06-03 17:48:00 +00:00
|
|
|
if (const auto result = getDocument()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
return result;
|
|
|
|
}
|
2016-04-05 20:24:27 +00:00
|
|
|
return getResultDocument();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FileBase::content_width() const {
|
2019-01-25 14:37:28 +00:00
|
|
|
if (const auto document = getShownDocument()) {
|
|
|
|
if (document->dimensions.width() > 0) {
|
|
|
|
return document->dimensions.width();
|
|
|
|
}
|
|
|
|
if (const auto thumb = document->thumbnail()) {
|
2019-09-13 10:24:06 +00:00
|
|
|
return style::ConvertScale(thumb->width());
|
2019-01-25 14:37:28 +00:00
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2016-04-10 11:13:37 +00:00
|
|
|
return 0;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 11:13:37 +00:00
|
|
|
int FileBase::content_height() const {
|
2019-01-25 14:37:28 +00:00
|
|
|
if (const auto document = getShownDocument()) {
|
|
|
|
if (document->dimensions.height() > 0) {
|
|
|
|
return document->dimensions.height();
|
|
|
|
}
|
|
|
|
if (const auto thumb = document->thumbnail()) {
|
2019-09-13 10:24:06 +00:00
|
|
|
return style::ConvertScale(thumb->height());
|
2019-01-25 14:37:28 +00:00
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2016-04-10 11:13:37 +00:00
|
|
|
return 0;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int FileBase::content_duration() const {
|
2017-12-10 10:26:58 +00:00
|
|
|
if (const auto document = getShownDocument()) {
|
2019-03-06 08:21:42 +00:00
|
|
|
if (document->getDuration() > 0) {
|
|
|
|
return document->getDuration();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
return getResultDuration();
|
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
Image *FileBase::content_thumb() const {
|
|
|
|
if (const auto document = getShownDocument()) {
|
|
|
|
if (const auto thumb = document->thumbnail()) {
|
|
|
|
return thumb;
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return getResultThumb();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
Gif::Gif(not_null<Context*> context, Result *result) : FileBase(context, result) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
Gif::Gif(not_null<Context*> context, DocumentData *document, bool hasDeleteButton) : FileBase(context, document) {
|
2017-03-27 18:11:51 +00:00
|
|
|
if (hasDeleteButton) {
|
2017-12-18 09:07:18 +00:00
|
|
|
_delete = std::make_shared<DeleteSavedGifClickHandler>(document);
|
2017-03-27 18:11:51 +00:00
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Gif::initDimensions() {
|
|
|
|
int32 w = content_width(), h = content_height();
|
|
|
|
if (w <= 0 || h <= 0) {
|
|
|
|
_maxw = 0;
|
|
|
|
} else {
|
|
|
|
w = w * st::inlineMediaHeight / h;
|
|
|
|
_maxw = qMax(w, int32(st::inlineResultsMinWidth));
|
|
|
|
}
|
|
|
|
_minh = st::inlineMediaHeight + st::inlineResultsSkip;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gif::setPosition(int32 position) {
|
|
|
|
ItemBase::setPosition(position);
|
|
|
|
if (_position < 0) {
|
2016-09-28 20:28:53 +00:00
|
|
|
_gif.reset();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteSavedGifClickHandler::onClickImpl() const {
|
2018-07-16 19:41:43 +00:00
|
|
|
Auth().api().toggleSavedGif(_data, Data::FileOriginSavedGifs(), false);
|
|
|
|
|
|
|
|
const auto index = Auth().data().savedGifs().indexOf(_data);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (index >= 0) {
|
2017-11-05 17:07:27 +00:00
|
|
|
Auth().data().savedGifsRef().remove(index);
|
2016-04-04 21:09:46 +00:00
|
|
|
Local::writeSavedGifs();
|
|
|
|
}
|
2018-01-17 18:20:55 +00:00
|
|
|
Auth().data().notifySavedGifsUpdated();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-12-18 14:10:24 +00:00
|
|
|
int Gif::resizeGetHeight(int width) {
|
|
|
|
_width = width;
|
|
|
|
_height = _minh;
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void Gif::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
|
2018-07-13 21:25:47 +00:00
|
|
|
const auto document = getShownDocument();
|
|
|
|
document->automaticLoad(fileOrigin(), nullptr);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-10 11:13:37 +00:00
|
|
|
bool loaded = document->loaded(), loading = document->loading(), displayLoading = document->displayLoading();
|
2016-09-28 20:28:53 +00:00
|
|
|
if (loaded && !_gif && !_gif.isBad()) {
|
2016-09-28 16:23:25 +00:00
|
|
|
auto that = const_cast<Gif*>(this);
|
2017-05-18 20:18:59 +00:00
|
|
|
that->_gif = Media::Clip::MakeReader(document, FullMsgId(), [that](Media::Clip::Notification notification) {
|
2016-09-26 12:09:59 +00:00
|
|
|
that->clipCallback(notification);
|
|
|
|
});
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif) _gif->setAutoplay();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto animating = (_gif && _gif->started());
|
2016-04-04 21:09:46 +00:00
|
|
|
if (displayLoading) {
|
|
|
|
ensureAnimation();
|
|
|
|
if (!_animation->radial.animating()) {
|
2016-04-10 11:13:37 +00:00
|
|
|
_animation->radial.start(document->progress());
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto radial = isRadialAnimation();
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
int32 height = st::inlineMediaHeight;
|
|
|
|
QSize frame = countFrameSize();
|
|
|
|
|
|
|
|
QRect r(0, 0, _width, height);
|
|
|
|
if (animating) {
|
|
|
|
if (!_thumb.isNull()) _thumb = QPixmap();
|
2017-12-18 17:50:25 +00:00
|
|
|
auto pixmap = _gif->current(frame.width(), frame.height(), _width, height, ImageRoundRadius::None, RectPart::None, context->paused ? 0 : context->ms);
|
2017-04-03 14:13:55 +00:00
|
|
|
p.drawPixmap(r.topLeft(), pixmap);
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
2019-01-25 14:37:28 +00:00
|
|
|
prepareThumbnail({ _width, height }, frame);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (_thumb.isNull()) {
|
|
|
|
p.fillRect(r, st::overviewPhotoBg);
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(r.topLeft(), _thumb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-28 20:28:53 +00:00
|
|
|
if (radial || _gif.isBad() || (!_gif && !loaded && !loading)) {
|
2016-09-26 12:09:59 +00:00
|
|
|
auto radialOpacity = (radial && loaded) ? _animation->radial.opacity() : 1.;
|
2019-04-02 09:13:30 +00:00
|
|
|
if (_animation && _animation->_a_over.animating()) {
|
|
|
|
auto over = _animation->_a_over.value(1.);
|
2016-11-07 11:24:19 +00:00
|
|
|
p.fillRect(r, anim::brush(st::msgDateImgBg, st::msgDateImgBgOver, over));
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
2016-10-31 12:29:26 +00:00
|
|
|
auto over = (_state & StateFlag::Over);
|
|
|
|
p.fillRect(r, over ? st::msgDateImgBgOver : st::msgDateImgBg);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
p.setOpacity(radialOpacity * p.opacity());
|
|
|
|
|
|
|
|
p.setOpacity(radialOpacity);
|
2019-03-01 11:16:55 +00:00
|
|
|
auto icon = [&] {
|
|
|
|
if (radial || loading) {
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInCancel;
|
2019-03-01 11:16:55 +00:00
|
|
|
} else if (loaded) {
|
|
|
|
return &st::historyFileInPlay;
|
2016-09-29 19:42:14 +00:00
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInDownload;
|
2019-03-01 11:16:55 +00:00
|
|
|
}();
|
2016-04-04 21:09:46 +00:00
|
|
|
QRect inner((_width - st::msgFileSize) / 2, (height - st::msgFileSize) / 2, st::msgFileSize, st::msgFileSize);
|
2016-09-29 19:42:14 +00:00
|
|
|
icon->paintInCenter(p, inner);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (radial) {
|
|
|
|
p.setOpacity(1);
|
|
|
|
QRect rinner(inner.marginsRemoved(QMargins(st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine)));
|
2017-12-30 22:28:25 +00:00
|
|
|
_animation->radial.draw(p, rinner, st::msgFileRadialLine, st::historyFileThumbRadialFg);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_delete && (_state & StateFlag::Over)) {
|
2017-09-05 16:34:36 +00:00
|
|
|
auto deleteSelected = (_state & StateFlag::DeleteOver);
|
|
|
|
auto deletePos = QPoint(_width - st::stickerPanDeleteIconBg.width(), 0);
|
|
|
|
p.setOpacity(deleteSelected ? st::stickerPanDeleteOpacityBgOver : st::stickerPanDeleteOpacityBg);
|
|
|
|
st::stickerPanDeleteIconBg.paint(p, deletePos, width());
|
|
|
|
p.setOpacity(deleteSelected ? st::stickerPanDeleteOpacityFgOver : st::stickerPanDeleteOpacityFg);
|
|
|
|
st::stickerPanDeleteIconFg.paint(p, deletePos, width());
|
|
|
|
p.setOpacity(1.);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Gif::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (QRect(0, 0, _width, st::inlineMediaHeight).contains(point)) {
|
2019-09-13 12:22:54 +00:00
|
|
|
if (_delete && style::rtlpoint(point, _width).x() >= _width - st::stickerPanDeleteIconBg.width() && point.y() < st::stickerPanDeleteIconBg.height()) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _delete };
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _send };
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Gif::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
|
|
|
|
if (!p) return;
|
|
|
|
|
|
|
|
if (_delete && p == _delete) {
|
|
|
|
bool wasactive = (_state & StateFlag::DeleteOver);
|
|
|
|
if (active != wasactive) {
|
2016-05-27 10:57:11 +00:00
|
|
|
auto from = active ? 0. : 1., to = active ? 1. : 0.;
|
2016-09-26 12:09:59 +00:00
|
|
|
_a_deleteOver.start([this] { update(); }, from, to, st::stickersRowDuration);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (active) {
|
|
|
|
_state |= StateFlag::DeleteOver;
|
|
|
|
} else {
|
|
|
|
_state &= ~StateFlag::DeleteOver;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p == _delete || p == _send) {
|
|
|
|
bool wasactive = (_state & StateFlag::Over);
|
|
|
|
if (active != wasactive) {
|
2016-04-10 11:13:37 +00:00
|
|
|
if (!getShownDocument()->loaded()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
ensureAnimation();
|
2016-05-27 10:57:11 +00:00
|
|
|
auto from = active ? 0. : 1., to = active ? 1. : 0.;
|
2016-09-26 12:09:59 +00:00
|
|
|
_animation->_a_over.start([this] { update(); }, from, to, st::stickersRowDuration);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
if (active) {
|
|
|
|
_state |= StateFlag::Over;
|
|
|
|
} else {
|
|
|
|
_state &= ~StateFlag::Over;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ItemBase::clickHandlerActiveChanged(p, active);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize Gif::countFrameSize() const {
|
2016-09-28 20:28:53 +00:00
|
|
|
bool animating = (_gif && _gif->ready());
|
2016-04-04 21:09:46 +00:00
|
|
|
int32 framew = animating ? _gif->width() : content_width(), frameh = animating ? _gif->height() : content_height(), height = st::inlineMediaHeight;
|
|
|
|
if (framew * height > frameh * _width) {
|
|
|
|
if (framew < st::maxStickerSize || frameh > height) {
|
|
|
|
if (frameh > height || (framew * height / frameh) <= st::maxStickerSize) {
|
|
|
|
framew = framew * height / frameh;
|
|
|
|
frameh = height;
|
|
|
|
} else {
|
|
|
|
frameh = int32(frameh * st::maxStickerSize) / framew;
|
|
|
|
framew = st::maxStickerSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (frameh < st::maxStickerSize || framew > _width) {
|
|
|
|
if (framew > _width || (frameh * _width / framew) <= st::maxStickerSize) {
|
|
|
|
frameh = frameh * _width / framew;
|
|
|
|
framew = _width;
|
|
|
|
} else {
|
|
|
|
framew = int32(framew * st::maxStickerSize) / frameh;
|
|
|
|
frameh = st::maxStickerSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QSize(framew, frameh);
|
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void Gif::validateThumbnail(
|
|
|
|
Image *image,
|
|
|
|
QSize size,
|
|
|
|
QSize frame,
|
|
|
|
bool good) const {
|
|
|
|
if (!image || (_thumbGood && !good)) {
|
|
|
|
return;
|
|
|
|
} else if (!image->loaded()) {
|
|
|
|
image->load(fileOrigin());
|
|
|
|
return;
|
|
|
|
} else if ((_thumb.size() == size * cIntRetinaFactor())
|
|
|
|
&& (_thumbGood || !good)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_thumbGood = good;
|
|
|
|
_thumb = image->pixNoCache(
|
|
|
|
fileOrigin(),
|
|
|
|
frame.width() * cIntRetinaFactor(),
|
|
|
|
frame.height() * cIntRetinaFactor(),
|
|
|
|
(Images::Option::Smooth
|
|
|
|
| (good ? Images::Option::None : Images::Option::Blurred)),
|
|
|
|
size.width(),
|
|
|
|
size.height());
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gif::prepareThumbnail(QSize size, QSize frame) const {
|
2018-07-13 21:25:47 +00:00
|
|
|
if (const auto document = getShownDocument()) {
|
2019-01-25 14:37:28 +00:00
|
|
|
validateThumbnail(document->thumbnail(), size, frame, true);
|
|
|
|
validateThumbnail(document->thumbnailInline(), size, frame, false);
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
2019-01-25 14:37:28 +00:00
|
|
|
validateThumbnail(getResultThumb(), size, frame, true);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gif::ensureAnimation() const {
|
|
|
|
if (!_animation) {
|
2019-04-01 17:44:54 +00:00
|
|
|
_animation = std::make_unique<AnimationData>([=](crl::time now) {
|
2019-04-04 15:24:13 +00:00
|
|
|
radialAnimationCallback(now);
|
2019-04-01 17:44:54 +00:00
|
|
|
});
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
bool Gif::isRadialAnimation() const {
|
|
|
|
if (_animation) {
|
|
|
|
if (_animation->radial.animating()) {
|
|
|
|
return true;
|
|
|
|
} else if (getShownDocument()->loaded()) {
|
|
|
|
_animation = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
void Gif::radialAnimationCallback(crl::time now) const {
|
2018-09-20 16:39:59 +00:00
|
|
|
const auto document = getShownDocument();
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto updated = [&] {
|
2018-09-20 16:39:59 +00:00
|
|
|
return _animation->radial.update(
|
|
|
|
document->progress(),
|
|
|
|
!document->loading() || document->loaded(),
|
2019-04-01 17:44:54 +00:00
|
|
|
now);
|
|
|
|
}();
|
2019-04-04 15:24:13 +00:00
|
|
|
if (!anim::Disabled() || updated) {
|
2019-04-01 17:44:54 +00:00
|
|
|
update();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2019-04-01 17:44:54 +00:00
|
|
|
if (!_animation->radial.animating() && document->loaded()) {
|
2019-04-04 15:24:13 +00:00
|
|
|
_animation = nullptr;
|
2019-04-01 17:44:54 +00:00
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
void Gif::clipCallback(Media::Clip::Notification notification) {
|
|
|
|
using namespace Media::Clip;
|
2016-04-04 21:09:46 +00:00
|
|
|
switch (notification) {
|
2016-06-24 10:37:29 +00:00
|
|
|
case NotificationReinit: {
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif) {
|
2016-06-24 10:37:29 +00:00
|
|
|
if (_gif->state() == State::Error) {
|
2016-09-28 20:28:53 +00:00
|
|
|
_gif.setBad();
|
2018-10-23 12:57:43 +00:00
|
|
|
getShownDocument()->unload();
|
2016-04-04 21:09:46 +00:00
|
|
|
} else if (_gif->ready() && !_gif->started()) {
|
2017-04-02 16:42:18 +00:00
|
|
|
auto height = st::inlineMediaHeight;
|
|
|
|
auto frame = countFrameSize();
|
2017-12-18 17:50:25 +00:00
|
|
|
_gif->start(frame.width(), frame.height(), _width, height, ImageRoundRadius::None, RectPart::None);
|
2017-03-27 18:11:51 +00:00
|
|
|
} else if (_gif->autoPausedGif() && !context()->inlineItemVisible(this)) {
|
2016-09-28 20:28:53 +00:00
|
|
|
_gif.reset();
|
2018-10-23 12:57:43 +00:00
|
|
|
getShownDocument()->unload();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
} break;
|
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
case NotificationRepaint: {
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif && !_gif->currentDisplayed()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-28 14:15:47 +00:00
|
|
|
Sticker::Sticker(not_null<Context*> context, Result *result)
|
|
|
|
: FileBase(context, result) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 13:41:50 +00:00
|
|
|
Sticker::~Sticker() = default;
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
void Sticker::initDimensions() {
|
|
|
|
_maxw = st::stickerPanSize.width();
|
|
|
|
_minh = st::stickerPanSize.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sticker::preload() const {
|
2018-06-03 17:48:00 +00:00
|
|
|
if (const auto document = getShownDocument()) {
|
2019-01-25 14:37:28 +00:00
|
|
|
document->checkStickerSmall();
|
2018-07-13 21:25:47 +00:00
|
|
|
} else if (const auto thumb = getResultThumb()) {
|
|
|
|
thumb->load(fileOrigin());
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void Sticker::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
|
2016-04-10 11:13:37 +00:00
|
|
|
bool loaded = getShownDocument()->loaded();
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2019-04-02 09:13:30 +00:00
|
|
|
auto over = _a_over.value(_active ? 1. : 0.);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (over > 0) {
|
|
|
|
p.setOpacity(over);
|
|
|
|
App::roundRect(p, QRect(QPoint(0, 0), st::stickerPanSize), st::emojiPanHover, StickerHoverCorners);
|
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
prepareThumbnail();
|
2019-07-02 13:41:50 +00:00
|
|
|
if (_lottie && _lottie->ready()) {
|
|
|
|
const auto frame = _lottie->frame();
|
|
|
|
_lottie->markFrameShown();
|
|
|
|
const auto size = frame.size() / cIntRetinaFactor();
|
|
|
|
const auto pos = QPoint(
|
|
|
|
(st::stickerPanSize.width() - size.width()) / 2,
|
|
|
|
(st::stickerPanSize.height() - size.height()) / 2);
|
|
|
|
p.drawImage(
|
|
|
|
QRect(pos, size),
|
|
|
|
frame);
|
|
|
|
} else if (!_thumb.isNull()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
int w = _thumb.width() / cIntRetinaFactor(), h = _thumb.height() / cIntRetinaFactor();
|
|
|
|
QPoint pos = QPoint((st::stickerPanSize.width() - w) / 2, (st::stickerPanSize.height() - h) / 2);
|
|
|
|
p.drawPixmap(pos, _thumb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Sticker::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (QRect(0, 0, _width, st::inlineMediaHeight).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _send };
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sticker::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
|
|
|
|
if (!p) return;
|
|
|
|
|
|
|
|
if (p == _send) {
|
|
|
|
if (active != _active) {
|
|
|
|
_active = active;
|
|
|
|
|
2016-05-27 10:57:11 +00:00
|
|
|
auto from = active ? 0. : 1., to = active ? 1. : 0.;
|
2016-09-26 12:09:59 +00:00
|
|
|
_a_over.start([this] { update(); }, from, to, st::stickersRowDuration);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
ItemBase::clickHandlerActiveChanged(p, active);
|
|
|
|
}
|
|
|
|
|
|
|
|
QSize Sticker::getThumbSize() const {
|
|
|
|
int width = qMax(content_width(), 1), height = qMax(content_height(), 1);
|
2016-07-07 12:35:14 +00:00
|
|
|
float64 coefw = (st::stickerPanSize.width() - st::buttonRadius * 2) / float64(width);
|
|
|
|
float64 coefh = (st::stickerPanSize.height() - st::buttonRadius * 2) / float64(height);
|
2016-04-04 21:09:46 +00:00
|
|
|
float64 coef = qMin(qMin(coefw, coefh), 1.);
|
|
|
|
int w = qRound(coef * content_width()), h = qRound(coef * content_height());
|
|
|
|
return QSize(qMax(w, 1), qMax(h, 1));
|
|
|
|
}
|
|
|
|
|
2019-07-02 13:41:50 +00:00
|
|
|
void Sticker::setupLottie(not_null<DocumentData*> document) const {
|
|
|
|
_lottie = Stickers::LottiePlayerFromDocument(
|
|
|
|
document,
|
|
|
|
Stickers::LottieSize::InlineResults,
|
|
|
|
QSize(
|
|
|
|
st::stickerPanSize.width() - st::buttonRadius * 2,
|
|
|
|
st::stickerPanSize.height() - st::buttonRadius * 2
|
|
|
|
) * cIntRetinaFactor());
|
|
|
|
|
|
|
|
_lottie->updates(
|
|
|
|
) | rpl::start_with_next([=] {
|
|
|
|
update();
|
|
|
|
}, _lifetime);
|
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void Sticker::prepareThumbnail() const {
|
2018-06-03 17:48:00 +00:00
|
|
|
if (const auto document = getShownDocument()) {
|
2019-07-02 13:41:50 +00:00
|
|
|
if (document->sticker()->animated
|
|
|
|
&& !_lottie
|
|
|
|
&& document->loaded()) {
|
|
|
|
setupLottie(document);
|
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
document->checkStickerSmall();
|
|
|
|
if (const auto sticker = document->getStickerSmall()) {
|
2019-07-02 13:41:50 +00:00
|
|
|
if (!_lottie && !_thumbLoaded && sticker->loaded()) {
|
2018-11-09 15:16:47 +00:00
|
|
|
const auto thumbSize = getThumbSize();
|
|
|
|
_thumb = sticker->pix(
|
|
|
|
document->stickerSetOrigin(),
|
|
|
|
thumbSize.width(),
|
|
|
|
thumbSize.height());
|
|
|
|
_thumbLoaded = true;
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-13 21:25:47 +00:00
|
|
|
const auto origin = fileOrigin();
|
2019-01-25 14:37:28 +00:00
|
|
|
if (const auto thumb = getResultThumb()) {
|
|
|
|
if (thumb->loaded()) {
|
|
|
|
if (!_thumbLoaded) {
|
|
|
|
const auto thumbSize = getThumbSize();
|
|
|
|
_thumb = thumb->pix(
|
|
|
|
origin,
|
|
|
|
thumbSize.width(),
|
|
|
|
thumbSize.height());
|
|
|
|
_thumbLoaded = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
thumb->load(origin);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-28 14:15:47 +00:00
|
|
|
Photo::Photo(not_null<Context*> context, Result *result)
|
|
|
|
: ItemBase(context, result) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Photo::initDimensions() {
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto photo = getShownPhoto();
|
|
|
|
int32 w = photo->width(), h = photo->height();
|
2016-04-04 21:09:46 +00:00
|
|
|
if (w <= 0 || h <= 0) {
|
|
|
|
_maxw = 0;
|
|
|
|
} else {
|
|
|
|
w = w * st::inlineMediaHeight / h;
|
|
|
|
_maxw = qMax(w, int32(st::inlineResultsMinWidth));
|
|
|
|
}
|
|
|
|
_minh = st::inlineMediaHeight + st::inlineResultsSkip;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void Photo::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
|
2016-04-04 21:09:46 +00:00
|
|
|
int32 height = st::inlineMediaHeight;
|
|
|
|
QSize frame = countFrameSize();
|
|
|
|
|
|
|
|
QRect r(0, 0, _width, height);
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
prepareThumbnail({ _width, height }, frame);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (_thumb.isNull()) {
|
|
|
|
p.fillRect(r, st::overviewPhotoBg);
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(r.topLeft(), _thumb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Photo::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (QRect(0, 0, _width, st::inlineMediaHeight).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _send };
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PhotoData *Photo::getShownPhoto() const {
|
|
|
|
if (PhotoData *result = getPhoto()) {
|
|
|
|
return result;
|
|
|
|
}
|
2016-04-05 20:24:27 +00:00
|
|
|
return getResultPhoto();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
QSize Photo::countFrameSize() const {
|
2016-04-10 11:13:37 +00:00
|
|
|
PhotoData *photo = getShownPhoto();
|
2019-01-25 14:37:28 +00:00
|
|
|
int32 framew = photo->width(), frameh = photo->height(), height = st::inlineMediaHeight;
|
2016-04-04 21:09:46 +00:00
|
|
|
if (framew * height > frameh * _width) {
|
|
|
|
if (framew < st::maxStickerSize || frameh > height) {
|
|
|
|
if (frameh > height || (framew * height / frameh) <= st::maxStickerSize) {
|
|
|
|
framew = framew * height / frameh;
|
|
|
|
frameh = height;
|
|
|
|
} else {
|
|
|
|
frameh = int32(frameh * st::maxStickerSize) / framew;
|
|
|
|
framew = st::maxStickerSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (frameh < st::maxStickerSize || framew > _width) {
|
|
|
|
if (framew > _width || (frameh * _width / framew) <= st::maxStickerSize) {
|
|
|
|
frameh = frameh * _width / framew;
|
|
|
|
framew = _width;
|
|
|
|
} else {
|
|
|
|
framew = int32(framew * st::maxStickerSize) / frameh;
|
|
|
|
frameh = st::maxStickerSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return QSize(framew, frameh);
|
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void Photo::validateThumbnail(
|
|
|
|
Image *image,
|
|
|
|
QSize size,
|
|
|
|
QSize frame,
|
|
|
|
bool good) const {
|
|
|
|
if (!image || (_thumbGood && !good)) {
|
|
|
|
return;
|
|
|
|
} else if (!image->loaded()) {
|
|
|
|
image->load(fileOrigin());
|
|
|
|
return;
|
|
|
|
} else if ((_thumb.size() == size * cIntRetinaFactor())
|
|
|
|
&& (_thumbGood || !good)) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-13 21:25:47 +00:00
|
|
|
const auto origin = fileOrigin();
|
2019-01-25 14:37:28 +00:00
|
|
|
_thumb = image->pixNoCache(
|
|
|
|
origin,
|
|
|
|
frame.width() * cIntRetinaFactor(),
|
|
|
|
frame.height() * cIntRetinaFactor(),
|
|
|
|
Images::Option::Smooth | (good ? Images::Option(0) : Images::Option::Blurred),
|
|
|
|
size.width(),
|
|
|
|
size.height());
|
|
|
|
_thumbGood = good;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Photo::prepareThumbnail(QSize size, QSize frame) const {
|
2018-07-13 21:25:47 +00:00
|
|
|
if (const auto photo = getShownPhoto()) {
|
2019-01-25 14:37:28 +00:00
|
|
|
validateThumbnail(photo->thumbnail(), size, frame, true);
|
|
|
|
validateThumbnail(photo->thumbnailSmall(), size, frame, false);
|
|
|
|
validateThumbnail(photo->thumbnailInline(), size, frame, false);
|
|
|
|
} else if (const auto thumbnail = getResultThumb()) {
|
|
|
|
validateThumbnail(thumbnail, size, frame, true);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
Video::Video(not_null<Context*> context, Result *result) : FileBase(context, result)
|
2016-04-05 20:24:27 +00:00
|
|
|
, _link(getResultContentUrlHandler())
|
2016-04-04 21:09:46 +00:00
|
|
|
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
|
|
|
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
|
|
|
if (int duration = content_duration()) {
|
|
|
|
_duration = formatDurationText(duration);
|
2016-04-08 15:37:14 +00:00
|
|
|
_durationWidth = st::normalFont->width(_duration);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Video::initDimensions() {
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto withThumb = (content_thumb() != nullptr);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
_maxw = st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft;
|
|
|
|
int32 textWidth = _maxw - (withThumb ? (st::inlineThumbSize + st::inlineThumbSkip) : 0);
|
|
|
|
TextParseOptions titleOpts = { 0, _maxw, 2 * st::semiboldFont->height, Qt::LayoutDirectionAuto };
|
2017-07-06 11:37:42 +00:00
|
|
|
auto title = TextUtilities::SingleLine(_result->getLayoutTitle());
|
2016-04-06 13:46:52 +00:00
|
|
|
if (title.isEmpty()) {
|
2019-06-19 15:09:03 +00:00
|
|
|
title = tr::lng_media_video(tr::now);
|
2016-04-06 13:46:52 +00:00
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
_title.setText(st::semiboldTextStyle, title, titleOpts);
|
2016-04-04 21:09:46 +00:00
|
|
|
int32 titleHeight = qMin(_title.countHeight(_maxw), 2 * st::semiboldFont->height);
|
|
|
|
|
|
|
|
int32 descriptionLines = withThumb ? (titleHeight > st::semiboldFont->height ? 1 : 2) : 3;
|
|
|
|
|
|
|
|
TextParseOptions descriptionOpts = { TextParseMultiline, _maxw, descriptionLines * st::normalFont->height, Qt::LayoutDirectionAuto };
|
2016-04-06 13:46:52 +00:00
|
|
|
QString description = _result->getLayoutDescription();
|
|
|
|
if (description.isEmpty()) {
|
|
|
|
description = _duration;
|
|
|
|
}
|
2016-12-23 13:21:01 +00:00
|
|
|
_description.setText(st::defaultTextStyle, description, descriptionOpts);
|
2016-04-04 21:09:46 +00:00
|
|
|
int32 descriptionHeight = qMin(_description.countHeight(_maxw), descriptionLines * st::normalFont->height);
|
|
|
|
|
|
|
|
_minh = st::inlineThumbSize;
|
|
|
|
_minh += st::inlineRowMargin * 2 + st::inlineRowBorder;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void Video::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
|
2016-04-08 15:37:14 +00:00
|
|
|
int left = st::inlineThumbSize + st::inlineThumbSkip;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto withThumb = (content_thumb() != nullptr);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (withThumb) {
|
2019-01-25 14:37:28 +00:00
|
|
|
prepareThumbnail({ st::inlineThumbSize, st::inlineThumbSize });
|
2016-04-04 21:09:46 +00:00
|
|
|
if (_thumb.isNull()) {
|
2019-09-13 12:22:54 +00:00
|
|
|
p.fillRect(style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width), st::overviewPhotoBg);
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
|
|
|
p.drawPixmapLeft(0, st::inlineRowMargin, _width, _thumb);
|
|
|
|
}
|
|
|
|
} else {
|
2019-09-13 12:22:54 +00:00
|
|
|
p.fillRect(style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width), st::overviewVideoBg);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!_duration.isEmpty()) {
|
2016-04-08 15:37:14 +00:00
|
|
|
int durationTop = st::inlineRowMargin + st::inlineThumbSize - st::normalFont->height - st::inlineDurationMargin;
|
|
|
|
int durationW = _durationWidth + 2 * st::msgDateImgPadding.x(), durationH = st::normalFont->height + 2 * st::msgDateImgPadding.y();
|
|
|
|
int durationX = (st::inlineThumbSize - durationW) / 2, durationY = st::inlineRowMargin + st::inlineThumbSize - durationH;
|
|
|
|
App::roundRect(p, durationX, durationY - st::msgDateImgPadding.y(), durationW, durationH, st::msgDateImgBg, DateCorners);
|
2016-12-21 15:05:58 +00:00
|
|
|
p.setPen(st::msgDateImgFg);
|
2016-04-04 21:09:46 +00:00
|
|
|
p.setFont(st::normalFont);
|
2016-04-08 15:37:14 +00:00
|
|
|
p.drawText(durationX + st::msgDateImgPadding.x(), durationTop + st::normalFont->ascent, _duration);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::inlineTitleFg);
|
2016-04-04 21:09:46 +00:00
|
|
|
_title.drawLeftElided(p, left, st::inlineRowMargin, _width - left, _width, 2);
|
|
|
|
int32 titleHeight = qMin(_title.countHeight(_width - left), st::semiboldFont->height * 2);
|
|
|
|
|
|
|
|
p.setPen(st::inlineDescriptionFg);
|
|
|
|
int32 descriptionLines = withThumb ? (titleHeight > st::semiboldFont->height ? 1 : 2) : 3;
|
|
|
|
_description.drawLeftElided(p, left, st::inlineRowMargin + titleHeight, _width - left, _width, descriptionLines);
|
|
|
|
|
|
|
|
if (!context->lastRow) {
|
2019-09-13 12:22:54 +00:00
|
|
|
p.fillRect(style::rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Video::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (QRect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _link };
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
if (QRect(st::inlineThumbSize + st::inlineThumbSkip, 0, _width - st::inlineThumbSize - st::inlineThumbSkip, _height).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _send };
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void Video::prepareThumbnail(QSize size) const {
|
|
|
|
Expects(content_thumb() != nullptr);
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
const auto thumb = content_thumb();
|
|
|
|
const auto origin = fileOrigin();
|
2016-04-04 21:09:46 +00:00
|
|
|
if (thumb->loaded()) {
|
2019-01-25 14:37:28 +00:00
|
|
|
if (_thumb.size() != size * cIntRetinaFactor()) {
|
|
|
|
const auto width = size.width();
|
|
|
|
const auto height = size.height();
|
2019-09-13 10:24:06 +00:00
|
|
|
auto w = qMax(style::ConvertScale(thumb->width()), 1);
|
|
|
|
auto h = qMax(style::ConvertScale(thumb->height()), 1);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (w * height > h * width) {
|
|
|
|
if (height < h) {
|
|
|
|
w = w * height / h;
|
|
|
|
h = height;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (width < w) {
|
|
|
|
h = h * width / w;
|
|
|
|
w = width;
|
|
|
|
}
|
|
|
|
}
|
2018-07-13 21:25:47 +00:00
|
|
|
_thumb = thumb->pixNoCache(origin, w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-13 21:25:47 +00:00
|
|
|
thumb->load(origin);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenFileClickHandler::onClickImpl() const {
|
2016-04-05 20:24:27 +00:00
|
|
|
_result->openFile();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CancelFileClickHandler::onClickImpl() const {
|
|
|
|
_result->cancelFile();
|
|
|
|
}
|
|
|
|
|
2018-06-28 15:01:32 +00:00
|
|
|
File::File(not_null<Context*> context, not_null<Result*> result)
|
|
|
|
: FileBase(context, result)
|
2016-04-04 21:09:46 +00:00
|
|
|
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::msgFileSize - st::inlineThumbSkip)
|
2016-04-10 18:18:26 +00:00
|
|
|
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::msgFileSize - st::inlineThumbSkip)
|
2017-12-18 09:07:18 +00:00
|
|
|
, _open(std::make_shared<OpenFileClickHandler>(result))
|
2018-06-28 15:01:32 +00:00
|
|
|
, _cancel(std::make_shared<CancelFileClickHandler>(result))
|
|
|
|
, _document(getShownDocument()) {
|
2016-04-10 18:18:26 +00:00
|
|
|
updateStatusText();
|
2018-06-28 15:01:32 +00:00
|
|
|
|
|
|
|
// We have to save document, not read it from Result every time.
|
|
|
|
// Because we first delete the Result and then delete this File.
|
|
|
|
// So in destructor we have to remember _document, we can't read it.
|
|
|
|
regDocumentItem(_document, this);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void File::initDimensions() {
|
|
|
|
_maxw = st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft;
|
2016-04-06 08:00:37 +00:00
|
|
|
int textWidth = _maxw - (st::msgFileSize + st::inlineThumbSkip);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-06 08:00:37 +00:00
|
|
|
TextParseOptions titleOpts = { 0, _maxw, st::semiboldFont->height, Qt::LayoutDirectionAuto };
|
2017-07-06 11:37:42 +00:00
|
|
|
_title.setText(st::semiboldTextStyle, TextUtilities::SingleLine(_result->getLayoutTitle()), titleOpts);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-06 08:00:37 +00:00
|
|
|
TextParseOptions descriptionOpts = { TextParseMultiline, _maxw, st::normalFont->height, Qt::LayoutDirectionAuto };
|
2016-12-23 13:21:01 +00:00
|
|
|
_description.setText(st::defaultTextStyle, _result->getLayoutDescription(), descriptionOpts);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
_minh = st::msgFileSize;
|
|
|
|
_minh += st::inlineRowMargin * 2 + st::inlineRowBorder;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void File::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
|
2018-06-28 15:01:32 +00:00
|
|
|
const auto left = st::msgFileSize + st::inlineThumbSkip;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2018-06-28 15:01:32 +00:00
|
|
|
const auto loaded = _document->loaded();
|
|
|
|
const auto displayLoading = _document->displayLoading();
|
2016-04-04 21:09:46 +00:00
|
|
|
if (displayLoading) {
|
|
|
|
ensureAnimation();
|
|
|
|
if (!_animation->radial.animating()) {
|
2018-06-28 15:01:32 +00:00
|
|
|
_animation->radial.start(_document->progress());
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto showPause = updateStatusText();
|
|
|
|
const auto radial = isRadialAnimation();
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2019-09-13 12:22:54 +00:00
|
|
|
auto inner = style::rtlrect(0, st::inlineRowMargin, st::msgFileSize, st::msgFileSize, _width);
|
2016-04-04 21:09:46 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
2019-04-02 09:13:30 +00:00
|
|
|
if (isThumbAnimation()) {
|
|
|
|
auto over = _animation->a_thumbOver.value(1.);
|
2016-11-07 11:24:19 +00:00
|
|
|
p.setBrush(anim::brush(st::msgFileInBg, st::msgFileInBgOver, over));
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
2018-06-28 15:01:32 +00:00
|
|
|
bool over = ClickHandler::showAsActive(_document->loading() ? _cancel : _open);
|
2016-11-07 11:24:19 +00:00
|
|
|
p.setBrush(over ? st::msgFileInBgOver : st::msgFileInBg);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-12-03 12:10:35 +00:00
|
|
|
{
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
p.drawEllipse(inner);
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
if (radial) {
|
2016-09-29 19:42:14 +00:00
|
|
|
auto radialCircle = inner.marginsRemoved(QMargins(st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine));
|
2017-12-30 22:28:25 +00:00
|
|
|
_animation->radial.draw(p, radialCircle, st::msgFileRadialLine, st::historyFileInRadialFg);
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
|
2019-03-01 11:16:55 +00:00
|
|
|
auto icon = [&] {
|
|
|
|
if (radial || _document->loading()) {
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInCancel;
|
2019-03-01 11:16:55 +00:00
|
|
|
} else if (showPause) {
|
|
|
|
return &st::historyFileInPause;
|
2018-06-28 15:01:32 +00:00
|
|
|
} else if (true || _document->loaded()) {
|
|
|
|
if (_document->isImage()) {
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInImage;
|
2018-06-28 15:01:32 +00:00
|
|
|
} else if (_document->isVoiceMessage()
|
|
|
|
|| _document->isAudioFile()) {
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInPlay;
|
2016-09-29 19:42:14 +00:00
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInDocument;
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInDownload;
|
2019-03-01 11:16:55 +00:00
|
|
|
}();
|
2016-09-29 19:42:14 +00:00
|
|
|
icon->paintInCenter(p, inner);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
int titleTop = st::inlineRowMargin + st::inlineRowFileNameTop;
|
|
|
|
int descriptionTop = st::inlineRowMargin + st::inlineRowFileDescriptionTop;
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::inlineTitleFg);
|
2016-04-06 08:00:37 +00:00
|
|
|
_title.drawLeftElided(p, left, titleTop, _width - left, _width);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
p.setPen(st::inlineDescriptionFg);
|
2016-04-11 04:02:39 +00:00
|
|
|
bool drawStatusSize = true;
|
|
|
|
if (_statusSize == FileStatusSizeReady || _statusSize == FileStatusSizeLoaded || _statusSize == FileStatusSizeFailed) {
|
|
|
|
if (!_description.isEmpty()) {
|
|
|
|
_description.drawLeftElided(p, left, descriptionTop, _width - left, _width);
|
|
|
|
drawStatusSize = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (drawStatusSize) {
|
2016-04-10 18:18:26 +00:00
|
|
|
p.setFont(st::normalFont);
|
|
|
|
p.drawTextLeft(left, descriptionTop, _width, _statusText);
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
if (!context->lastRow) {
|
2019-09-13 12:22:54 +00:00
|
|
|
p.fillRect(style::rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState File::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (QRect(0, st::inlineRowMargin, st::msgFileSize, st::msgFileSize).contains(point)) {
|
2018-06-28 15:01:32 +00:00
|
|
|
return { nullptr, _document->loading() ? _cancel : _open };
|
2017-10-13 19:07:04 +00:00
|
|
|
} else {
|
|
|
|
auto left = st::msgFileSize + st::inlineThumbSkip;
|
|
|
|
if (QRect(left, 0, _width - left, _height).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _send };
|
2017-10-13 19:07:04 +00:00
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void File::clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) {
|
|
|
|
if (p == _open || p == _cancel) {
|
2016-12-07 13:32:25 +00:00
|
|
|
ensureAnimation();
|
|
|
|
_animation->a_thumbOver.start([this] { thumbAnimationCallback(); }, active ? 0. : 1., active ? 1. : 0., st::msgFileOverDuration);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
File::~File() {
|
2018-06-28 15:01:32 +00:00
|
|
|
unregDocumentItem(_document, this);
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
void File::thumbAnimationCallback() {
|
2017-03-27 18:11:51 +00:00
|
|
|
update();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
void File::radialAnimationCallback(crl::time now) const {
|
|
|
|
const auto updated = [&] {
|
2018-09-20 16:39:59 +00:00
|
|
|
return _animation->radial.update(
|
2018-06-28 15:01:32 +00:00
|
|
|
_document->progress(),
|
|
|
|
!_document->loading() || _document->loaded(),
|
2019-04-01 17:44:54 +00:00
|
|
|
now);
|
|
|
|
}();
|
2019-04-04 15:24:13 +00:00
|
|
|
if (!anim::Disabled() || updated) {
|
2019-04-01 17:44:54 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
if (!_animation->radial.animating()) {
|
|
|
|
checkAnimationFinished();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void File::ensureAnimation() const {
|
|
|
|
if (!_animation) {
|
2019-04-01 17:44:54 +00:00
|
|
|
_animation = std::make_unique<AnimationData>([=](crl::time now) {
|
|
|
|
return radialAnimationCallback(now);
|
|
|
|
});
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 06:19:55 +00:00
|
|
|
void File::checkAnimationFinished() const {
|
2018-06-28 15:01:32 +00:00
|
|
|
if (_animation
|
|
|
|
&& !_animation->a_thumbOver.animating()
|
|
|
|
&& !_animation->radial.animating()) {
|
|
|
|
if (_document->loaded()) {
|
2016-12-07 13:32:25 +00:00
|
|
|
_animation.reset();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
bool File::updateStatusText() const {
|
|
|
|
bool showPause = false;
|
|
|
|
int32 statusSize = 0, realDuration = 0;
|
2018-06-28 15:01:32 +00:00
|
|
|
if (_document->status == FileDownloadFailed || _document->status == FileUploadFailed) {
|
2016-04-10 18:18:26 +00:00
|
|
|
statusSize = FileStatusSizeFailed;
|
2018-06-28 15:01:32 +00:00
|
|
|
} else if (_document->uploading()) {
|
|
|
|
statusSize = _document->uploadingData->offset;
|
|
|
|
} else if (_document->loading()) {
|
|
|
|
statusSize = _document->loadOffset();
|
|
|
|
} else if (_document->loaded()) {
|
2019-02-28 21:03:25 +00:00
|
|
|
statusSize = FileStatusSizeLoaded;
|
2016-04-10 18:18:26 +00:00
|
|
|
} else {
|
|
|
|
statusSize = FileStatusSizeReady;
|
|
|
|
}
|
2019-02-28 21:03:25 +00:00
|
|
|
|
|
|
|
if (_document->isVoiceMessage() || _document->isAudioFile()) {
|
|
|
|
const auto type = _document->isVoiceMessage() ? AudioMsgId::Type::Voice : AudioMsgId::Type::Song;
|
|
|
|
const auto state = Media::Player::instance()->getState(type);
|
|
|
|
if (state.id == AudioMsgId(_document, FullMsgId(), state.id.externalPlayId()) && !Media::Player::IsStoppedOrStopping(state.state)) {
|
|
|
|
statusSize = -1 - (state.position / state.frequency);
|
|
|
|
realDuration = (state.length / state.frequency);
|
|
|
|
showPause = Media::Player::ShowPauseIcon(state.state);
|
|
|
|
}
|
|
|
|
if (!showPause && (state.id == AudioMsgId(_document, FullMsgId(), state.id.externalPlayId())) && Media::Player::instance()->isSeeking(AudioMsgId::Type::Song)) {
|
|
|
|
showPause = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
if (statusSize != _statusSize) {
|
2018-06-28 15:01:32 +00:00
|
|
|
int32 duration = _document->isSong()
|
|
|
|
? _document->song()->duration
|
|
|
|
: (_document->isVoiceMessage()
|
|
|
|
? _document->voice()->duration
|
2017-12-10 10:26:58 +00:00
|
|
|
: -1);
|
2018-06-28 15:01:32 +00:00
|
|
|
setStatusSize(statusSize, _document->size, duration, realDuration);
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
return showPause;
|
|
|
|
}
|
|
|
|
|
|
|
|
void File::setStatusSize(int32 newSize, int32 fullSize, int32 duration, qint64 realDuration) const {
|
|
|
|
_statusSize = newSize;
|
|
|
|
if (_statusSize == FileStatusSizeReady) {
|
2016-04-11 04:02:39 +00:00
|
|
|
_statusText = (duration >= 0) ? formatDurationAndSizeText(duration, fullSize) : (duration < -1 ? formatGifAndSizeText(fullSize) : formatSizeText(fullSize));
|
2016-04-10 18:18:26 +00:00
|
|
|
} else if (_statusSize == FileStatusSizeLoaded) {
|
2016-04-11 04:02:39 +00:00
|
|
|
_statusText = (duration >= 0) ? formatDurationText(duration) : (duration < -1 ? qsl("GIF") : formatSizeText(fullSize));
|
2016-04-10 18:18:26 +00:00
|
|
|
} else if (_statusSize == FileStatusSizeFailed) {
|
2019-06-19 15:09:03 +00:00
|
|
|
_statusText = tr::lng_attach_failed(tr::now);
|
2016-04-10 18:18:26 +00:00
|
|
|
} else if (_statusSize >= 0) {
|
|
|
|
_statusText = formatDownloadText(_statusSize, fullSize);
|
|
|
|
} else {
|
|
|
|
_statusText = formatPlayedText(-_statusSize - 1, realDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
Contact::Contact(not_null<Context*> context, Result *result) : ItemBase(context, result)
|
2016-04-08 15:37:14 +00:00
|
|
|
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
|
|
|
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
|
|
|
}
|
|
|
|
|
|
|
|
void Contact::initDimensions() {
|
|
|
|
_maxw = st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft;
|
|
|
|
int32 textWidth = _maxw - (st::inlineThumbSize + st::inlineThumbSkip);
|
|
|
|
TextParseOptions titleOpts = { 0, _maxw, st::semiboldFont->height, Qt::LayoutDirectionAuto };
|
2017-07-06 11:37:42 +00:00
|
|
|
_title.setText(st::semiboldTextStyle, TextUtilities::SingleLine(_result->getLayoutTitle()), titleOpts);
|
2016-04-08 15:37:14 +00:00
|
|
|
int32 titleHeight = qMin(_title.countHeight(_maxw), st::semiboldFont->height);
|
|
|
|
|
|
|
|
TextParseOptions descriptionOpts = { TextParseMultiline, _maxw, st::normalFont->height, Qt::LayoutDirectionAuto };
|
2016-12-23 13:21:01 +00:00
|
|
|
_description.setText(st::defaultTextStyle, _result->getLayoutDescription(), descriptionOpts);
|
2016-04-08 15:37:14 +00:00
|
|
|
int32 descriptionHeight = qMin(_description.countHeight(_maxw), st::normalFont->height);
|
|
|
|
|
|
|
|
_minh = st::msgFileSize;
|
|
|
|
_minh += st::inlineRowMargin * 2 + st::inlineRowBorder;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void Contact::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
|
2016-04-08 15:37:14 +00:00
|
|
|
int32 left = st::emojiPanHeaderLeft - st::inlineResultsLeft;
|
|
|
|
|
|
|
|
left = st::msgFileSize + st::inlineThumbSkip;
|
2019-01-25 14:37:28 +00:00
|
|
|
prepareThumbnail(st::msgFileSize, st::msgFileSize);
|
2019-09-13 12:22:54 +00:00
|
|
|
QRect rthumb(style::rtlrect(0, st::inlineRowMargin, st::msgFileSize, st::msgFileSize, _width));
|
2016-04-08 15:37:14 +00:00
|
|
|
p.drawPixmapLeft(rthumb.topLeft(), _width, _thumb);
|
|
|
|
|
|
|
|
int titleTop = st::inlineRowMargin + st::inlineRowFileNameTop;
|
|
|
|
int descriptionTop = st::inlineRowMargin + st::inlineRowFileDescriptionTop;
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::inlineTitleFg);
|
2016-04-08 15:37:14 +00:00
|
|
|
_title.drawLeftElided(p, left, titleTop, _width - left, _width);
|
|
|
|
|
|
|
|
p.setPen(st::inlineDescriptionFg);
|
|
|
|
_description.drawLeftElided(p, left, descriptionTop, _width - left, _width);
|
|
|
|
|
|
|
|
if (!context->lastRow) {
|
2019-09-13 12:22:54 +00:00
|
|
|
p.fillRect(style::rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg);
|
2016-04-08 15:37:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Contact::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2017-10-13 19:07:04 +00:00
|
|
|
if (!QRect(0, st::inlineRowMargin, st::msgFileSize, st::inlineThumbSize).contains(point)) {
|
|
|
|
auto left = (st::msgFileSize + st::inlineThumbSkip);
|
|
|
|
if (QRect(left, 0, _width - left, _height).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _send };
|
2017-10-13 19:07:04 +00:00
|
|
|
}
|
2016-04-08 15:37:14 +00:00
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-08 15:37:14 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void Contact::prepareThumbnail(int width, int height) const {
|
2018-07-13 21:25:47 +00:00
|
|
|
const auto thumb = getResultThumb();
|
2019-01-25 14:37:28 +00:00
|
|
|
if (!thumb) {
|
2016-04-08 15:37:14 +00:00
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
|
|
|
_thumb = getResultContactAvatar(width, height);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
const auto origin = fileOrigin();
|
2016-04-08 15:37:14 +00:00
|
|
|
if (thumb->loaded()) {
|
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
2019-09-13 10:24:06 +00:00
|
|
|
auto w = qMax(style::ConvertScale(thumb->width()), 1);
|
|
|
|
auto h = qMax(style::ConvertScale(thumb->height()), 1);
|
2016-04-08 15:37:14 +00:00
|
|
|
if (w * height > h * width) {
|
|
|
|
if (height < h) {
|
|
|
|
w = w * height / h;
|
|
|
|
h = height;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (width < w) {
|
|
|
|
h = h * width / w;
|
|
|
|
w = width;
|
|
|
|
}
|
|
|
|
}
|
2018-07-13 21:25:47 +00:00
|
|
|
_thumb = thumb->pixNoCache(origin, w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-08 15:37:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-13 21:25:47 +00:00
|
|
|
thumb->load(origin);
|
2016-04-08 15:37:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
Article::Article(not_null<Context*> context, Result *result, bool withThumb) : ItemBase(context, result)
|
2016-04-05 20:24:27 +00:00
|
|
|
, _url(getResultUrlHandler())
|
|
|
|
, _link(getResultContentUrlHandler())
|
2016-04-04 21:09:46 +00:00
|
|
|
, _withThumb(withThumb)
|
|
|
|
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
|
|
|
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
2019-06-21 12:27:46 +00:00
|
|
|
if (!_link) {
|
|
|
|
if (const auto point = result->getLocationPoint()) {
|
|
|
|
_link = std::make_shared<LocationClickHandler>(*point);
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2016-04-05 20:24:27 +00:00
|
|
|
_thumbLetter = getResultThumbLetter();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Article::initDimensions() {
|
|
|
|
_maxw = st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft;
|
|
|
|
int32 textWidth = _maxw - (_withThumb ? (st::inlineThumbSize + st::inlineThumbSkip) : 0);
|
|
|
|
TextParseOptions titleOpts = { 0, _maxw, 2 * st::semiboldFont->height, Qt::LayoutDirectionAuto };
|
2017-07-06 11:37:42 +00:00
|
|
|
_title.setText(st::semiboldTextStyle, TextUtilities::SingleLine(_result->getLayoutTitle()), titleOpts);
|
2016-04-04 21:09:46 +00:00
|
|
|
int32 titleHeight = qMin(_title.countHeight(_maxw), 2 * st::semiboldFont->height);
|
|
|
|
|
|
|
|
int32 descriptionLines = (_withThumb || _url) ? 2 : 3;
|
|
|
|
QString description = _result->getLayoutDescription();
|
|
|
|
TextParseOptions descriptionOpts = { TextParseMultiline, _maxw, descriptionLines * st::normalFont->height, Qt::LayoutDirectionAuto };
|
2016-12-23 13:21:01 +00:00
|
|
|
_description.setText(st::defaultTextStyle, description, descriptionOpts);
|
2016-04-04 21:09:46 +00:00
|
|
|
int32 descriptionHeight = qMin(_description.countHeight(_maxw), descriptionLines * st::normalFont->height);
|
|
|
|
|
|
|
|
_minh = titleHeight + descriptionHeight;
|
|
|
|
if (_url) _minh += st::normalFont->height;
|
|
|
|
if (_withThumb) _minh = qMax(_minh, int32(st::inlineThumbSize));
|
|
|
|
_minh += st::inlineRowMargin * 2 + st::inlineRowBorder;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 Article::resizeGetHeight(int32 width) {
|
|
|
|
_width = qMin(width, _maxw);
|
|
|
|
if (_url) {
|
2016-04-05 20:24:27 +00:00
|
|
|
_urlText = getResultUrl();
|
2016-04-04 21:09:46 +00:00
|
|
|
_urlWidth = st::normalFont->width(_urlText);
|
|
|
|
if (_urlWidth > _width - st::inlineThumbSize - st::inlineThumbSkip) {
|
2016-04-05 20:24:27 +00:00
|
|
|
_urlText = st::normalFont->elided(_urlText, _width - st::inlineThumbSize - st::inlineThumbSkip);
|
2016-04-04 21:09:46 +00:00
|
|
|
_urlWidth = st::normalFont->width(_urlText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_height = _minh;
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void Article::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
|
2016-04-04 21:09:46 +00:00
|
|
|
int32 left = st::emojiPanHeaderLeft - st::inlineResultsLeft;
|
|
|
|
if (_withThumb) {
|
|
|
|
left = st::inlineThumbSize + st::inlineThumbSkip;
|
2019-01-25 14:37:28 +00:00
|
|
|
prepareThumbnail(st::inlineThumbSize, st::inlineThumbSize);
|
2019-09-13 12:22:54 +00:00
|
|
|
QRect rthumb(style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width));
|
2016-04-04 21:09:46 +00:00
|
|
|
if (_thumb.isNull()) {
|
2019-01-25 14:37:28 +00:00
|
|
|
const auto thumb = getResultThumb();
|
|
|
|
if (!thumb && !_thumbLetter.isEmpty()) {
|
2016-04-05 20:24:27 +00:00
|
|
|
int32 index = (_thumbLetter.at(0).unicode() % 4);
|
2016-12-23 13:21:01 +00:00
|
|
|
style::color colors[] = {
|
|
|
|
st::msgFile3Bg,
|
|
|
|
st::msgFile4Bg,
|
|
|
|
st::msgFile2Bg,
|
|
|
|
st::msgFile1Bg
|
2016-11-03 10:33:57 +00:00
|
|
|
};
|
|
|
|
|
2016-12-23 13:21:01 +00:00
|
|
|
p.fillRect(rthumb, colors[index]);
|
2016-04-05 20:24:27 +00:00
|
|
|
if (!_thumbLetter.isEmpty()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
p.setFont(st::linksLetterFont);
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::linksLetterFg);
|
2016-04-05 20:24:27 +00:00
|
|
|
p.drawText(rthumb, _thumbLetter, style::al_center);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p.fillRect(rthumb, st::overviewPhotoBg);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
p.drawPixmapLeft(rthumb.topLeft(), _width, _thumb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::inlineTitleFg);
|
2016-04-04 21:09:46 +00:00
|
|
|
_title.drawLeftElided(p, left, st::inlineRowMargin, _width - left, _width, 2);
|
|
|
|
int32 titleHeight = qMin(_title.countHeight(_width - left), st::semiboldFont->height * 2);
|
|
|
|
|
|
|
|
p.setPen(st::inlineDescriptionFg);
|
|
|
|
int32 descriptionLines = (_withThumb || _url) ? 2 : 3;
|
|
|
|
_description.drawLeftElided(p, left, st::inlineRowMargin + titleHeight, _width - left, _width, descriptionLines);
|
|
|
|
|
|
|
|
if (_url) {
|
|
|
|
int32 descriptionHeight = qMin(_description.countHeight(_width - left), st::normalFont->height * descriptionLines);
|
|
|
|
p.drawTextLeft(left, st::inlineRowMargin + titleHeight + descriptionHeight, _width, _urlText, _urlWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!context->lastRow) {
|
2019-09-13 12:22:54 +00:00
|
|
|
p.fillRect(style::rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Article::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2017-06-21 21:38:31 +00:00
|
|
|
if (_withThumb && QRect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _link };
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
auto left = _withThumb ? (st::inlineThumbSize + st::inlineThumbSkip) : 0;
|
|
|
|
if (QRect(left, 0, _width - left, _height).contains(point)) {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (_url) {
|
2017-06-21 21:38:31 +00:00
|
|
|
auto left = st::inlineThumbSize + st::inlineThumbSkip;
|
|
|
|
auto titleHeight = qMin(_title.countHeight(_width - left), st::semiboldFont->height * 2);
|
|
|
|
auto descriptionLines = 2;
|
|
|
|
auto descriptionHeight = qMin(_description.countHeight(_width - left), st::normalFont->height * descriptionLines);
|
2019-09-13 12:22:54 +00:00
|
|
|
if (style::rtlrect(left, st::inlineRowMargin + titleHeight + descriptionHeight, _urlWidth, st::normalFont->height, _width).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _url };
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _send };
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void Article::prepareThumbnail(int width, int height) const {
|
2018-07-13 21:25:47 +00:00
|
|
|
const auto thumb = getResultThumb();
|
2019-01-25 14:37:28 +00:00
|
|
|
if (!thumb) {
|
2016-04-05 20:24:27 +00:00
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
|
|
|
_thumb = getResultContactAvatar(width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-07-13 21:25:47 +00:00
|
|
|
const auto origin = fileOrigin();
|
2016-04-05 20:24:27 +00:00
|
|
|
if (thumb->loaded()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
2019-09-13 10:24:06 +00:00
|
|
|
auto w = qMax(style::ConvertScale(thumb->width()), 1);
|
|
|
|
auto h = qMax(style::ConvertScale(thumb->height()), 1);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (w * height > h * width) {
|
|
|
|
if (height < h) {
|
|
|
|
w = w * height / h;
|
|
|
|
h = height;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (width < w) {
|
|
|
|
h = h * width / w;
|
|
|
|
w = width;
|
|
|
|
}
|
|
|
|
}
|
2018-07-13 21:25:47 +00:00
|
|
|
_thumb = thumb->pixNoCache(origin, w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-13 21:25:47 +00:00
|
|
|
thumb->load(origin);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:31:24 +00:00
|
|
|
Game::Game(not_null<Context*> context, Result *result) : ItemBase(context, result)
|
2016-09-28 16:23:25 +00:00
|
|
|
, _title(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip)
|
|
|
|
, _description(st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft - st::inlineThumbSize - st::inlineThumbSkip) {
|
|
|
|
countFrameSize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::countFrameSize() {
|
|
|
|
if (auto document = getResultDocument()) {
|
|
|
|
if (document->isAnimation()) {
|
|
|
|
auto documentSize = document->dimensions;
|
|
|
|
if (documentSize.isEmpty()) {
|
|
|
|
documentSize = QSize(st::inlineThumbSize, st::inlineThumbSize);
|
|
|
|
}
|
|
|
|
auto resizeByHeight1 = (documentSize.width() > documentSize.height()) && (documentSize.height() >= st::inlineThumbSize);
|
|
|
|
auto resizeByHeight2 = (documentSize.height() >= documentSize.width()) && (documentSize.width() < st::inlineThumbSize);
|
|
|
|
if (resizeByHeight1 || resizeByHeight2) {
|
|
|
|
if (documentSize.height() > st::inlineThumbSize) {
|
|
|
|
_frameSize = QSize((documentSize.width() * st::inlineThumbSize) / documentSize.height(), st::inlineThumbSize);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (documentSize.width() > st::inlineThumbSize) {
|
|
|
|
_frameSize = QSize(st::inlineThumbSize, (documentSize.height() * st::inlineThumbSize) / documentSize.width());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!_frameSize.width()) {
|
|
|
|
_frameSize.setWidth(1);
|
|
|
|
}
|
|
|
|
if (!_frameSize.height()) {
|
|
|
|
_frameSize.setHeight(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::initDimensions() {
|
|
|
|
_maxw = st::emojiPanWidth - st::emojiScroll.width - st::inlineResultsLeft;
|
|
|
|
int32 textWidth = _maxw - (st::inlineThumbSize + st::inlineThumbSkip);
|
|
|
|
TextParseOptions titleOpts = { 0, _maxw, 2 * st::semiboldFont->height, Qt::LayoutDirectionAuto };
|
2017-07-06 11:37:42 +00:00
|
|
|
_title.setText(st::semiboldTextStyle, TextUtilities::SingleLine(_result->getLayoutTitle()), titleOpts);
|
2016-09-28 16:23:25 +00:00
|
|
|
int32 titleHeight = qMin(_title.countHeight(_maxw), 2 * st::semiboldFont->height);
|
|
|
|
|
|
|
|
int32 descriptionLines = 2;
|
|
|
|
QString description = _result->getLayoutDescription();
|
|
|
|
TextParseOptions descriptionOpts = { TextParseMultiline, _maxw, descriptionLines * st::normalFont->height, Qt::LayoutDirectionAuto };
|
2016-12-23 13:21:01 +00:00
|
|
|
_description.setText(st::defaultTextStyle, description, descriptionOpts);
|
2016-09-28 16:23:25 +00:00
|
|
|
int32 descriptionHeight = qMin(_description.countHeight(_maxw), descriptionLines * st::normalFont->height);
|
|
|
|
|
|
|
|
_minh = titleHeight + descriptionHeight;
|
|
|
|
accumulate_max(_minh, st::inlineThumbSize);
|
|
|
|
_minh += st::inlineRowMargin * 2 + st::inlineRowBorder;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::setPosition(int32 position) {
|
|
|
|
ItemBase::setPosition(position);
|
|
|
|
if (_position < 0) {
|
2016-09-28 20:28:53 +00:00
|
|
|
_gif.reset();
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
|
|
|
|
int32 left = st::emojiPanHeaderLeft - st::inlineResultsLeft;
|
|
|
|
|
|
|
|
left = st::inlineThumbSize + st::inlineThumbSkip;
|
2019-09-13 12:22:54 +00:00
|
|
|
auto rthumb = style::rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width);
|
2016-09-28 16:23:25 +00:00
|
|
|
|
|
|
|
// Gif thumb
|
|
|
|
auto thumbDisplayed = false, radial = false;
|
|
|
|
auto document = getResultDocument();
|
|
|
|
auto animatedThumb = document && document->isAnimation();
|
|
|
|
if (animatedThumb) {
|
2018-07-13 21:25:47 +00:00
|
|
|
document->automaticLoad(fileOrigin(), nullptr);
|
2016-09-28 16:23:25 +00:00
|
|
|
|
|
|
|
bool loaded = document->loaded(), loading = document->loading(), displayLoading = document->displayLoading();
|
2016-09-28 20:28:53 +00:00
|
|
|
if (loaded && !_gif && !_gif.isBad()) {
|
2016-09-28 16:23:25 +00:00
|
|
|
auto that = const_cast<Game*>(this);
|
2017-05-18 20:18:59 +00:00
|
|
|
that->_gif = Media::Clip::MakeReader(document, FullMsgId(), [that](Media::Clip::Notification notification) {
|
2016-09-28 16:23:25 +00:00
|
|
|
that->clipCallback(notification);
|
|
|
|
});
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif) _gif->setAutoplay();
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 20:28:53 +00:00
|
|
|
bool animating = (_gif && _gif->started());
|
2016-09-28 16:23:25 +00:00
|
|
|
if (displayLoading) {
|
|
|
|
if (!_radial) {
|
2019-04-01 17:44:54 +00:00
|
|
|
_radial = std::make_unique<Ui::RadialAnimation>([=](crl::time now) {
|
|
|
|
return radialAnimationCallback(now);
|
|
|
|
});
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
if (!_radial->animating()) {
|
|
|
|
_radial->start(document->progress());
|
|
|
|
}
|
|
|
|
}
|
2019-04-04 15:24:13 +00:00
|
|
|
radial = isRadialAnimation();
|
2016-09-28 16:23:25 +00:00
|
|
|
|
|
|
|
if (animating) {
|
|
|
|
if (!_thumb.isNull()) _thumb = QPixmap();
|
2017-12-18 17:50:25 +00:00
|
|
|
auto animationThumb = _gif->current(_frameSize.width(), _frameSize.height(), st::inlineThumbSize, st::inlineThumbSize, ImageRoundRadius::None, RectPart::None, context->paused ? 0 : context->ms);
|
2016-09-28 16:23:25 +00:00
|
|
|
p.drawPixmapLeft(rthumb.topLeft(), _width, animationThumb);
|
|
|
|
thumbDisplayed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!thumbDisplayed) {
|
2019-01-25 14:37:28 +00:00
|
|
|
prepareThumbnail({ st::inlineThumbSize, st::inlineThumbSize });
|
2016-09-28 16:23:25 +00:00
|
|
|
if (_thumb.isNull()) {
|
|
|
|
p.fillRect(rthumb, st::overviewPhotoBg);
|
|
|
|
} else {
|
|
|
|
p.drawPixmapLeft(rthumb.topLeft(), _width, _thumb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (radial) {
|
|
|
|
p.fillRect(rthumb, st::msgDateImgBg);
|
|
|
|
QRect inner((st::inlineThumbSize - st::msgFileSize) / 2, (st::inlineThumbSize - st::msgFileSize) / 2, st::msgFileSize, st::msgFileSize);
|
|
|
|
if (radial) {
|
|
|
|
p.setOpacity(1);
|
|
|
|
QRect rinner(inner.marginsRemoved(QMargins(st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine)));
|
2017-12-30 22:28:25 +00:00
|
|
|
_radial->draw(p, rinner, st::msgFileRadialLine, st::historyFileThumbRadialFg);
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-31 12:29:26 +00:00
|
|
|
p.setPen(st::inlineTitleFg);
|
2016-09-28 16:23:25 +00:00
|
|
|
_title.drawLeftElided(p, left, st::inlineRowMargin, _width - left, _width, 2);
|
|
|
|
int32 titleHeight = qMin(_title.countHeight(_width - left), st::semiboldFont->height * 2);
|
|
|
|
|
|
|
|
p.setPen(st::inlineDescriptionFg);
|
|
|
|
int32 descriptionLines = 2;
|
|
|
|
_description.drawLeftElided(p, left, st::inlineRowMargin + titleHeight, _width - left, _width, descriptionLines);
|
|
|
|
|
|
|
|
if (!context->lastRow) {
|
2019-09-13 12:22:54 +00:00
|
|
|
p.fillRect(style::rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg);
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState Game::getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const {
|
2016-09-28 16:23:25 +00:00
|
|
|
int left = st::inlineThumbSize + st::inlineThumbSkip;
|
2017-06-21 21:38:31 +00:00
|
|
|
if (QRect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _send };
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
2017-06-21 21:38:31 +00:00
|
|
|
if (QRect(left, 0, _width - left, _height).contains(point)) {
|
2017-12-15 16:25:47 +00:00
|
|
|
return { nullptr, _send };
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
2017-10-13 19:07:04 +00:00
|
|
|
return {};
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void Game::prepareThumbnail(QSize size) const {
|
|
|
|
if (const auto photo = getResultPhoto()) {
|
|
|
|
validateThumbnail(photo->thumbnail(), size, true);
|
|
|
|
validateThumbnail(photo->thumbnailInline(), size, false);
|
|
|
|
} else if (const auto document = getResultDocument()) {
|
|
|
|
validateThumbnail(document->thumbnail(), size, true);
|
|
|
|
validateThumbnail(document->thumbnailInline(), size, false);
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
}
|
2016-09-28 16:23:25 +00:00
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void Game::validateThumbnail(Image *image, QSize size, bool good) const {
|
|
|
|
if (!image || (_thumbGood && !good)) {
|
|
|
|
return;
|
|
|
|
} else if (!image->loaded()) {
|
|
|
|
image->load(fileOrigin());
|
|
|
|
return;
|
|
|
|
} else if ((_thumb.size() == size * cIntRetinaFactor())
|
|
|
|
&& (_thumbGood || !good)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const auto width = size.width();
|
|
|
|
const auto height = size.height();
|
2019-09-13 10:24:06 +00:00
|
|
|
auto w = qMax(style::ConvertScale(image->width()), 1);
|
|
|
|
auto h = qMax(style::ConvertScale(image->height()), 1);
|
2019-01-25 14:37:28 +00:00
|
|
|
auto resizeByHeight1 = (w * height > h * width) && (h >= height);
|
|
|
|
auto resizeByHeight2 = (h * width >= w * height) && (w < width);
|
|
|
|
if (resizeByHeight1 || resizeByHeight2) {
|
|
|
|
if (h > height) {
|
|
|
|
w = w * height / h;
|
|
|
|
h = height;
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-01-25 14:37:28 +00:00
|
|
|
if (w > width) {
|
|
|
|
h = h * width / w;
|
|
|
|
w = width;
|
|
|
|
}
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
2019-01-25 14:37:28 +00:00
|
|
|
_thumbGood = good;
|
|
|
|
_thumb = image->pixNoCache(
|
|
|
|
fileOrigin(),
|
|
|
|
w * cIntRetinaFactor(),
|
|
|
|
h * cIntRetinaFactor(),
|
|
|
|
(Images::Option::Smooth
|
|
|
|
| (good ? Images::Option::None : Images::Option::Blurred)),
|
|
|
|
size.width(),
|
|
|
|
size.height());
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
bool Game::isRadialAnimation() const {
|
|
|
|
if (_radial) {
|
|
|
|
if (_radial->animating()) {
|
|
|
|
return true;
|
|
|
|
} else if (getResultDocument()->loaded()) {
|
|
|
|
_radial = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
|
2019-04-04 15:24:13 +00:00
|
|
|
void Game::radialAnimationCallback(crl::time now) const {
|
2018-09-20 16:39:59 +00:00
|
|
|
const auto document = getResultDocument();
|
2019-04-04 15:24:13 +00:00
|
|
|
const auto updated = [&] {
|
2018-09-20 16:39:59 +00:00
|
|
|
return _radial->update(
|
|
|
|
document->progress(),
|
|
|
|
!document->loading() || document->loaded(),
|
2019-04-01 17:44:54 +00:00
|
|
|
now);
|
|
|
|
}();
|
2019-04-04 15:24:13 +00:00
|
|
|
if (!anim::Disabled() || updated) {
|
2019-04-01 17:44:54 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
if (!_radial->animating() && document->loaded()) {
|
2019-04-04 15:24:13 +00:00
|
|
|
_radial = nullptr;
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::clipCallback(Media::Clip::Notification notification) {
|
|
|
|
using namespace Media::Clip;
|
|
|
|
switch (notification) {
|
|
|
|
case NotificationReinit: {
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif) {
|
2016-09-28 16:23:25 +00:00
|
|
|
if (_gif->state() == State::Error) {
|
2016-09-28 20:28:53 +00:00
|
|
|
_gif.setBad();
|
2018-10-23 12:57:43 +00:00
|
|
|
getResultDocument()->unload();
|
2016-09-28 16:23:25 +00:00
|
|
|
} else if (_gif->ready() && !_gif->started()) {
|
2017-12-18 17:50:25 +00:00
|
|
|
_gif->start(_frameSize.width(), _frameSize.height(), st::inlineThumbSize, st::inlineThumbSize, ImageRoundRadius::None, RectPart::None);
|
2017-03-27 18:11:51 +00:00
|
|
|
} else if (_gif->autoPausedGif() && !context()->inlineItemVisible(this)) {
|
2016-09-28 20:28:53 +00:00
|
|
|
_gif.reset();
|
2018-10-23 12:57:43 +00:00
|
|
|
getResultDocument()->unload();
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update();
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case NotificationRepaint: {
|
2016-09-28 20:28:53 +00:00
|
|
|
if (_gif && !_gif->currentDisplayed()) {
|
2016-09-28 16:23:25 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace Layout
|
|
|
|
} // namespace InlineBots
|