2016-04-04 21:09:46 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 18:31:31 +00:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
2016-04-04 21:09:46 +00:00
|
|
|
*/
|
|
|
|
#include "inline_bots/inline_bot_layout_internal.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"
|
2016-10-27 14:10:28 +00:00
|
|
|
#include "styles/style_stickers.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"
|
2016-10-12 19:34:25 +00:00
|
|
|
#include "media/media_audio.h"
|
2016-06-24 10:37:29 +00:00
|
|
|
#include "media/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"
|
2017-03-04 10:23:56 +00:00
|
|
|
#include "storage/localstorage.h"
|
2017-03-31 15:50:02 +00:00
|
|
|
#include "auth_session.h"
|
2016-04-06 13:46:52 +00:00
|
|
|
#include "lang.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
namespace Layout {
|
|
|
|
namespace internal {
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
FileBase::FileBase(gsl::not_null<Context*> context, Result *result) : ItemBase(context, result) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
FileBase::FileBase(gsl::not_null<Context*> context, DocumentData *document) : ItemBase(context, document) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DocumentData *FileBase::getShownDocument() const {
|
|
|
|
if (DocumentData *result = getDocument()) {
|
|
|
|
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 {
|
2016-04-10 11:13:37 +00:00
|
|
|
DocumentData *document = getShownDocument();
|
|
|
|
if (document->dimensions.width() > 0) {
|
|
|
|
return document->dimensions.width();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2016-04-10 11:13:37 +00:00
|
|
|
if (!document->thumb->isNull()) {
|
|
|
|
return convertScale(document->thumb->width());
|
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 {
|
|
|
|
DocumentData *document = getShownDocument();
|
|
|
|
if (document->dimensions.height() > 0) {
|
|
|
|
return document->dimensions.height();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2016-04-10 11:13:37 +00:00
|
|
|
if (!document->thumb->isNull()) {
|
|
|
|
return convertScale(document->thumb->height());
|
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 {
|
2016-04-10 18:18:26 +00:00
|
|
|
if (DocumentData *document = getShownDocument()) {
|
|
|
|
if (document->duration() > 0) {
|
|
|
|
return document->duration();
|
|
|
|
} else if (SongData *song = document->song()) {
|
|
|
|
if (song->duration) {
|
|
|
|
return song->duration;
|
|
|
|
}
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
return getResultDuration();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr FileBase::content_thumb() const {
|
|
|
|
if (DocumentData *document = getShownDocument()) {
|
|
|
|
if (!document->thumb->isNull()) {
|
|
|
|
return document->thumb;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return getResultThumb();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
Gif::Gif(gsl::not_null<Context*> context, Result *result) : FileBase(context, result) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
Gif::Gif(gsl::not_null<Context*> context, DocumentData *document, bool hasDeleteButton) : FileBase(context, document) {
|
|
|
|
if (hasDeleteButton) {
|
|
|
|
_delete = MakeShared<DeleteSavedGifClickHandler>(document);
|
|
|
|
}
|
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 {
|
2017-03-31 15:50:02 +00:00
|
|
|
auto index = cSavedGifs().indexOf(_data);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (index >= 0) {
|
|
|
|
cRefSavedGifs().remove(index);
|
|
|
|
Local::writeSavedGifs();
|
|
|
|
|
2016-04-09 05:57:55 +00:00
|
|
|
MTP::send(MTPmessages_SaveGif(_data->mtpInput(), MTP_bool(true)));
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2017-03-31 15:50:02 +00:00
|
|
|
AuthSession::Current().data().savedGifsUpdated().notify();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void Gif::paint(Painter &p, const QRect &clip, const PaintContext *context) const {
|
2016-04-10 11:13:37 +00:00
|
|
|
DocumentData *document = getShownDocument();
|
|
|
|
document->automaticLoad(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);
|
2016-09-28 20:28:53 +00:00
|
|
|
that->_gif = Media::Clip::MakeReader(document->location(), document->data(), [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
|
|
|
}
|
|
|
|
|
2016-09-28 20:28:53 +00:00
|
|
|
bool 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
|
|
|
}
|
|
|
|
}
|
|
|
|
bool radial = isRadialAnimation(context->ms);
|
|
|
|
|
|
|
|
int32 height = st::inlineMediaHeight;
|
|
|
|
QSize frame = countFrameSize();
|
|
|
|
|
|
|
|
QRect r(0, 0, _width, height);
|
|
|
|
if (animating) {
|
|
|
|
if (!_thumb.isNull()) _thumb = QPixmap();
|
2016-11-21 20:26:54 +00:00
|
|
|
p.drawPixmap(r.topLeft(), _gif->current(frame.width(), frame.height(), _width, height, ImageRoundRadius::None, ImageRoundCorner::None, context->paused ? 0 : context->ms));
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
|
|
|
prepareThumb(_width, height, frame);
|
|
|
|
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.;
|
2016-04-04 21:09:46 +00:00
|
|
|
if (_animation && _animation->_a_over.animating(context->ms)) {
|
2016-09-26 12:09:59 +00:00
|
|
|
auto over = _animation->_a_over.current();
|
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);
|
2016-09-29 19:42:14 +00:00
|
|
|
auto icon = ([loaded, radial, loading] {
|
|
|
|
if (loaded && !radial) {
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInPlay;
|
2016-09-29 19:42:14 +00:00
|
|
|
} else if (radial || loading) {
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInCancel;
|
2016-09-29 19:42:14 +00:00
|
|
|
}
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInDownload;
|
2016-09-29 19:42:14 +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)));
|
|
|
|
_animation->radial.draw(p, rinner, st::msgFileRadialLine, st::msgInBg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_delete && (_state & StateFlag::Over)) {
|
|
|
|
float64 deleteOver = _a_deleteOver.current(context->ms, (_state & StateFlag::DeleteOver) ? 1 : 0);
|
2016-10-28 08:02:45 +00:00
|
|
|
QPoint deletePos = QPoint(_width - st::stickerPanDelete.width(), 0);
|
2016-04-04 21:09:46 +00:00
|
|
|
p.setOpacity(deleteOver + (1 - deleteOver) * st::stickerPanDeleteOpacity);
|
2016-10-28 08:02:45 +00:00
|
|
|
st::stickerPanDelete.paint(p, deletePos, _width);
|
2016-04-04 21:09:46 +00:00
|
|
|
p.setOpacity(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 15:37:14 +00:00
|
|
|
void Gif::getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (x >= 0 && x < _width && y >= 0 && y < st::inlineMediaHeight) {
|
2016-10-28 08:02:45 +00:00
|
|
|
if (_delete && (rtl() ? _width - x : x) >= _width - st::stickerPanDelete.width() && y < st::stickerPanDelete.height()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
link = _delete;
|
|
|
|
} else {
|
|
|
|
link = _send;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gif::prepareThumb(int32 width, int32 height, const QSize &frame) const {
|
|
|
|
if (DocumentData *document = getShownDocument()) {
|
|
|
|
if (!document->thumb->isNull()) {
|
|
|
|
if (document->thumb->loaded()) {
|
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = document->thumb->pixNoCache(frame.width() * cIntRetinaFactor(), frame.height() * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
document->thumb->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2016-04-05 20:24:27 +00:00
|
|
|
ImagePtr thumb = getResultThumb();
|
|
|
|
if (!thumb->isNull()) {
|
|
|
|
if (thumb->loaded()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = thumb->pixNoCache(frame.width() * cIntRetinaFactor(), frame.height() * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-04-05 20:24:27 +00:00
|
|
|
thumb->load();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Gif::ensureAnimation() const {
|
|
|
|
if (!_animation) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_animation = std::make_unique<AnimationData>(animation(const_cast<Gif*>(this), &Gif::step_radial));
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
bool Gif::isRadialAnimation(TimeMs ms) const {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (!_animation || !_animation->radial.animating()) return false;
|
|
|
|
|
|
|
|
_animation->radial.step(ms);
|
|
|
|
return _animation && _animation->radial.animating();
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void Gif::step_radial(TimeMs ms, bool timer) {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (timer) {
|
|
|
|
update();
|
|
|
|
} else {
|
2016-04-10 11:13:37 +00:00
|
|
|
DocumentData *document = getShownDocument();
|
|
|
|
_animation->radial.update(document->progress(), !document->loading() || document->loaded(), ms);
|
|
|
|
if (!_animation->radial.animating() && document->loaded()) {
|
2016-09-28 16:23:25 +00:00
|
|
|
_animation.reset();
|
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();
|
2016-04-10 11:13:37 +00:00
|
|
|
getShownDocument()->forget();
|
2016-04-04 21:09:46 +00:00
|
|
|
} else if (_gif->ready() && !_gif->started()) {
|
|
|
|
int32 height = st::inlineMediaHeight;
|
|
|
|
QSize frame = countFrameSize();
|
2016-11-21 20:26:54 +00:00
|
|
|
_gif->start(frame.width(), frame.height(), _width, height, ImageRoundRadius::None, ImageRoundCorner::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();
|
2016-04-10 11:13:37 +00:00
|
|
|
getShownDocument()->forget();
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
Sticker::Sticker(gsl::not_null<Context*> context, Result *result) : FileBase(context, result) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Sticker::initDimensions() {
|
|
|
|
_maxw = st::stickerPanSize.width();
|
|
|
|
_minh = st::stickerPanSize.height();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sticker::preload() const {
|
|
|
|
if (DocumentData *document = getShownDocument()) {
|
|
|
|
bool goodThumb = !document->thumb->isNull() && ((document->thumb->width() >= 128) || (document->thumb->height() >= 128));
|
|
|
|
if (goodThumb) {
|
|
|
|
document->thumb->load();
|
|
|
|
} else {
|
|
|
|
document->checkSticker();
|
|
|
|
}
|
2016-04-05 20:24:27 +00:00
|
|
|
} else {
|
|
|
|
ImagePtr thumb = getResultThumb();
|
|
|
|
if (!thumb->isNull()) {
|
|
|
|
thumb->load();
|
|
|
|
}
|
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
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
auto over = _a_over.current(context->ms, _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);
|
|
|
|
}
|
|
|
|
|
|
|
|
prepareThumb();
|
|
|
|
if (!_thumb.isNull()) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 15:37:14 +00:00
|
|
|
void Sticker::getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (x >= 0 && x < _width && y >= 0 && y < st::inlineMediaHeight) {
|
|
|
|
link = _send;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Sticker::prepareThumb() const {
|
|
|
|
if (DocumentData *document = getShownDocument()) {
|
|
|
|
bool goodThumb = !document->thumb->isNull() && ((document->thumb->width() >= 128) || (document->thumb->height() >= 128));
|
|
|
|
if (goodThumb) {
|
|
|
|
document->thumb->load();
|
|
|
|
} else {
|
|
|
|
document->checkSticker();
|
|
|
|
}
|
|
|
|
|
|
|
|
ImagePtr sticker = goodThumb ? document->thumb : document->sticker()->img;
|
|
|
|
if (!_thumbLoaded && sticker->loaded()) {
|
|
|
|
QSize thumbSize = getThumbSize();
|
|
|
|
_thumb = sticker->pix(thumbSize.width(), thumbSize.height());
|
|
|
|
_thumbLoaded = true;
|
|
|
|
}
|
|
|
|
} else {
|
2016-04-05 20:24:27 +00:00
|
|
|
ImagePtr thumb = getResultThumb();
|
|
|
|
if (thumb->loaded()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (!_thumbLoaded) {
|
|
|
|
QSize thumbSize = getThumbSize();
|
2016-04-05 20:24:27 +00:00
|
|
|
_thumb = thumb->pix(thumbSize.width(), thumbSize.height());
|
2016-04-04 21:09:46 +00:00
|
|
|
_thumbLoaded = true;
|
|
|
|
}
|
|
|
|
} else {
|
2016-04-05 20:24:27 +00:00
|
|
|
thumb->load();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
Photo::Photo(gsl::not_null<Context*> context, Result *result) : ItemBase(context, result) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Photo::initDimensions() {
|
2016-04-10 11:13:37 +00:00
|
|
|
PhotoData *photo = getShownPhoto();
|
|
|
|
int32 w = photo->full->width(), h = photo->full->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);
|
|
|
|
|
|
|
|
prepareThumb(_width, height, frame);
|
|
|
|
if (_thumb.isNull()) {
|
|
|
|
p.fillRect(r, st::overviewPhotoBg);
|
|
|
|
} else {
|
|
|
|
p.drawPixmap(r.topLeft(), _thumb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 15:37:14 +00:00
|
|
|
void Photo::getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (x >= 0 && x < _width && y >= 0 && y < st::inlineMediaHeight) {
|
|
|
|
link = _send;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
int32 framew = photo->full->width(), frameh = photo->full->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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Photo::prepareThumb(int32 width, int32 height, const QSize &frame) const {
|
|
|
|
if (PhotoData *photo = getShownPhoto()) {
|
|
|
|
if (photo->medium->loaded()) {
|
|
|
|
if (!_thumbLoaded || _thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = photo->medium->pixNoCache(frame.width() * cIntRetinaFactor(), frame.height() * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
_thumbLoaded = true;
|
|
|
|
} else {
|
|
|
|
if (photo->thumb->loaded()) {
|
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = photo->thumb->pixNoCache(frame.width() * cIntRetinaFactor(), frame.height() * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
photo->medium->load();
|
|
|
|
}
|
|
|
|
} else {
|
2016-04-05 20:24:27 +00:00
|
|
|
ImagePtr thumb = getResultThumb();
|
|
|
|
if (thumb->loaded()) {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = thumb->pixNoCache(frame.width() * cIntRetinaFactor(), frame.height() * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-04-05 20:24:27 +00:00
|
|
|
thumb->load();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
Video::Video(gsl::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() {
|
2016-04-10 18:18:26 +00:00
|
|
|
bool withThumb = !content_thumb()->isNull();
|
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 };
|
2016-04-06 13:46:52 +00:00
|
|
|
QString title = textOneLine(_result->getLayoutTitle());
|
|
|
|
if (title.isEmpty()) {
|
|
|
|
title = lang(lng_media_video);
|
|
|
|
}
|
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
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
bool withThumb = !content_thumb()->isNull();
|
2016-04-04 21:09:46 +00:00
|
|
|
if (withThumb) {
|
|
|
|
prepareThumb(st::inlineThumbSize, st::inlineThumbSize);
|
|
|
|
if (_thumb.isNull()) {
|
|
|
|
p.fillRect(rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width), st::overviewPhotoBg);
|
|
|
|
} else {
|
|
|
|
p.drawPixmapLeft(0, st::inlineRowMargin, _width, _thumb);
|
|
|
|
}
|
|
|
|
} else {
|
2016-10-31 12:29:26 +00:00
|
|
|
p.fillRect(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) {
|
|
|
|
p.fillRect(rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 15:37:14 +00:00
|
|
|
void Video::getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (x >= 0 && x < st::inlineThumbSize && y >= st::inlineRowMargin && y < st::inlineRowMargin + st::inlineThumbSize) {
|
|
|
|
link = _link;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (x >= st::inlineThumbSize + st::inlineThumbSkip && x < _width && y >= 0 && y < _height) {
|
|
|
|
link = _send;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Video::prepareThumb(int32 width, int32 height) const {
|
2016-04-10 18:18:26 +00:00
|
|
|
ImagePtr thumb = content_thumb();
|
2016-04-04 21:09:46 +00:00
|
|
|
if (thumb->loaded()) {
|
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
|
|
|
int32 w = qMax(convertScale(thumb->width()), 1), h = qMax(convertScale(thumb->height()), 1);
|
|
|
|
if (w * height > h * width) {
|
|
|
|
if (height < h) {
|
|
|
|
w = w * height / h;
|
|
|
|
h = height;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (width < w) {
|
|
|
|
h = h * width / w;
|
|
|
|
w = width;
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = thumb->pixNoCache(w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
thumb->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
File::File(gsl::not_null<Context*> context, 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-03-27 18:11:51 +00:00
|
|
|
, _open(MakeShared<OpenFileClickHandler>(result))
|
|
|
|
, _cancel(MakeShared<CancelFileClickHandler>(result)) {
|
2016-04-10 18:18:26 +00:00
|
|
|
updateStatusText();
|
|
|
|
regDocumentItem(getShownDocument(), 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 };
|
2016-12-23 13:21:01 +00:00
|
|
|
_title.setText(st::semiboldTextStyle, textOneLine(_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 {
|
2016-04-04 21:09:46 +00:00
|
|
|
int32 left = st::msgFileSize + st::inlineThumbSkip;
|
|
|
|
|
2016-04-10 11:13:37 +00:00
|
|
|
DocumentData *document = getShownDocument();
|
|
|
|
bool loaded = document->loaded(), displayLoading = document->displayLoading();
|
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
|
|
|
}
|
|
|
|
}
|
2016-04-10 18:18:26 +00:00
|
|
|
bool showPause = updateStatusText();
|
2016-04-04 21:09:46 +00:00
|
|
|
bool radial = isRadialAnimation(context->ms);
|
|
|
|
|
2016-09-29 19:42:14 +00:00
|
|
|
auto inner = rtlrect(0, st::inlineRowMargin, st::msgFileSize, st::msgFileSize, _width);
|
2016-04-04 21:09:46 +00:00
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
if (isThumbAnimation(context->ms)) {
|
2016-11-07 11:24:19 +00:00
|
|
|
auto over = _animation->a_thumbOver.current();
|
|
|
|
p.setBrush(anim::brush(st::msgFileInBg, st::msgFileInBgOver, over));
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
2016-04-10 11:13:37 +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));
|
2016-04-10 18:18:26 +00:00
|
|
|
_animation->radial.draw(p, radialCircle, st::msgFileRadialLine, st::msgInBg);
|
|
|
|
}
|
|
|
|
|
2016-09-29 19:42:14 +00:00
|
|
|
auto icon = ([showPause, radial, document] {
|
|
|
|
if (showPause) {
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInPause;
|
2016-09-29 19:42:14 +00:00
|
|
|
} else if (radial || document->loading()) {
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInCancel;
|
2016-09-29 19:42:14 +00:00
|
|
|
} else if (true || document->loaded()) {
|
|
|
|
if (document->isImage()) {
|
2016-09-30 12:52:03 +00:00
|
|
|
return &st::historyFileInImage;
|
2016-09-29 19:42:14 +00:00
|
|
|
} else if (document->voice() || document->song()) {
|
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;
|
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) {
|
|
|
|
p.fillRect(rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 15:37:14 +00:00
|
|
|
void File::getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (x >= 0 && x < st::msgFileSize && y >= st::inlineRowMargin && y < st::inlineRowMargin + st::msgFileSize) {
|
2016-04-10 11:13:37 +00:00
|
|
|
link = getShownDocument()->loading() ? _cancel : _open;
|
2016-04-04 21:09:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (x >= st::msgFileSize + st::inlineThumbSkip && x < _width && y >= 0 && y < _height) {
|
|
|
|
link = _send;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
unregDocumentItem(getShownDocument(), this);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void File::step_radial(TimeMs ms, bool timer) {
|
2016-04-04 21:09:46 +00:00
|
|
|
if (timer) {
|
2017-03-27 18:11:51 +00:00
|
|
|
update();
|
2016-04-04 21:09:46 +00:00
|
|
|
} else {
|
2016-04-10 11:13:37 +00:00
|
|
|
DocumentData *document = getShownDocument();
|
2016-04-10 18:18:26 +00:00
|
|
|
_animation->radial.update(document->progress(), !document->loading() || document->loaded(), ms);
|
2016-04-04 21:09:46 +00:00
|
|
|
if (!_animation->radial.animating()) {
|
|
|
|
checkAnimationFinished();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void File::ensureAnimation() const {
|
|
|
|
if (!_animation) {
|
2017-03-27 18:11:51 +00:00
|
|
|
_animation = std::make_unique<AnimationData>(animation(const_cast<File*>(this), &File::step_radial));
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-09 06:19:55 +00:00
|
|
|
void File::checkAnimationFinished() const {
|
2016-12-07 13:32:25 +00:00
|
|
|
if (_animation && !_animation->a_thumbOver.animating() && !_animation->radial.animating()) {
|
2016-04-10 11:13:37 +00:00
|
|
|
if (getShownDocument()->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;
|
|
|
|
DocumentData *document = getShownDocument();
|
|
|
|
if (document->status == FileDownloadFailed || document->status == FileUploadFailed) {
|
|
|
|
statusSize = FileStatusSizeFailed;
|
|
|
|
} else if (document->status == FileUploading) {
|
|
|
|
statusSize = document->uploadOffset;
|
|
|
|
} else if (document->loading()) {
|
|
|
|
statusSize = document->loadOffset();
|
|
|
|
} else if (document->loaded()) {
|
2017-01-24 21:24:39 +00:00
|
|
|
using State = Media::Player::State;
|
2016-04-10 18:18:26 +00:00
|
|
|
if (document->voice()) {
|
2016-07-10 13:02:22 +00:00
|
|
|
statusSize = FileStatusSizeLoaded;
|
2017-01-24 21:24:39 +00:00
|
|
|
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Voice);
|
|
|
|
if (state.id == AudioMsgId(document, FullMsgId()) && !Media::Player::IsStopped(state.state) && state.state != State::Finishing) {
|
|
|
|
statusSize = -1 - (state.position / state.frequency);
|
|
|
|
realDuration = (state.duration / state.frequency);
|
|
|
|
showPause = (state.state == State::Playing || state.state == State::Resuming || state.state == State::Starting);
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
} else if (document->song()) {
|
2016-07-10 13:02:22 +00:00
|
|
|
statusSize = FileStatusSizeLoaded;
|
2017-01-24 21:24:39 +00:00
|
|
|
auto state = Media::Player::mixer()->currentState(AudioMsgId::Type::Song);
|
|
|
|
if (state.id == AudioMsgId(document, FullMsgId()) && !Media::Player::IsStopped(state.state) && state.state != State::Finishing) {
|
|
|
|
statusSize = -1 - (state.position / state.frequency);
|
|
|
|
realDuration = (state.duration / state.frequency);
|
|
|
|
showPause = (state.state == State::Playing || state.state == State::Resuming || state.state == State::Starting);
|
2017-01-19 08:24:43 +00:00
|
|
|
}
|
2017-02-10 22:37:37 +00:00
|
|
|
if (!showPause && (state.id == AudioMsgId(document, FullMsgId())) && Media::Player::instance()->isSeeking(AudioMsgId::Type::Song)) {
|
2017-01-19 08:24:43 +00:00
|
|
|
showPause = true;
|
2016-04-10 18:18:26 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
statusSize = FileStatusSizeLoaded;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
statusSize = FileStatusSizeReady;
|
|
|
|
}
|
|
|
|
if (statusSize != _statusSize) {
|
|
|
|
int32 duration = document->song() ? document->song()->duration : (document->voice() ? document->voice()->duration : -1);
|
|
|
|
setStatusSize(statusSize, document->size, duration, realDuration);
|
|
|
|
}
|
|
|
|
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) {
|
2016-04-11 04:02:39 +00:00
|
|
|
_statusText = lang(lng_attach_failed);
|
2016-04-10 18:18:26 +00:00
|
|
|
} else if (_statusSize >= 0) {
|
|
|
|
_statusText = formatDownloadText(_statusSize, fullSize);
|
|
|
|
} else {
|
|
|
|
_statusText = formatPlayedText(-_statusSize - 1, realDuration);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
Contact::Contact(gsl::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 };
|
2016-12-23 13:21:01 +00:00
|
|
|
_title.setText(st::semiboldTextStyle, textOneLine(_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;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32 Contact::resizeGetHeight(int32 width) {
|
|
|
|
_width = qMin(width, _maxw);
|
|
|
|
_height = _minh;
|
|
|
|
return _height;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
prepareThumb(st::msgFileSize, st::msgFileSize);
|
|
|
|
QRect rthumb(rtlrect(0, st::inlineRowMargin, st::msgFileSize, st::msgFileSize, _width));
|
|
|
|
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) {
|
|
|
|
p.fillRect(rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Contact::getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const {
|
|
|
|
int left = (st::msgFileSize + st::inlineThumbSkip);
|
|
|
|
if (x >= 0 && x < left - st::inlineThumbSkip && y >= st::inlineRowMargin && y < st::inlineRowMargin + st::inlineThumbSize) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (x >= left && x < _width && y >= 0 && y < _height) {
|
|
|
|
link = _send;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Contact::prepareThumb(int width, int height) const {
|
|
|
|
ImagePtr thumb = getResultThumb();
|
|
|
|
if (thumb->isNull()) {
|
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
|
|
|
_thumb = getResultContactAvatar(width, height);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thumb->loaded()) {
|
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
|
|
|
int w = qMax(convertScale(thumb->width()), 1), h = qMax(convertScale(thumb->height()), 1);
|
|
|
|
if (w * height > h * width) {
|
|
|
|
if (height < h) {
|
|
|
|
w = w * height / h;
|
|
|
|
h = height;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (width < w) {
|
|
|
|
h = h * width / w;
|
|
|
|
w = width;
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = thumb->pixNoCache(w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-08 15:37:14 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
thumb->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
Article::Article(gsl::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) {
|
2016-04-05 20:24:27 +00:00
|
|
|
LocationCoords location;
|
|
|
|
if (!_link && result->getLocationCoords(&location)) {
|
2017-03-27 18:11:51 +00:00
|
|
|
_link = MakeShared<LocationClickHandler>(location);
|
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 };
|
2016-12-23 13:21:01 +00:00
|
|
|
_title.setText(st::semiboldTextStyle, textOneLine(_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;
|
|
|
|
prepareThumb(st::inlineThumbSize, st::inlineThumbSize);
|
|
|
|
QRect rthumb(rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width));
|
|
|
|
if (_thumb.isNull()) {
|
2016-04-05 20:24:27 +00:00
|
|
|
ImagePtr thumb = getResultThumb();
|
|
|
|
if (thumb->isNull() && !_thumbLetter.isEmpty()) {
|
|
|
|
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) {
|
|
|
|
p.fillRect(rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 15:37:14 +00:00
|
|
|
void Article::getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const {
|
|
|
|
int left = _withThumb ? (st::inlineThumbSize + st::inlineThumbSkip) : 0;
|
2016-04-04 21:09:46 +00:00
|
|
|
if (x >= 0 && x < left - st::inlineThumbSkip && y >= st::inlineRowMargin && y < st::inlineRowMargin + st::inlineThumbSize) {
|
|
|
|
link = _link;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (x >= left && x < _width && y >= 0 && y < _height) {
|
|
|
|
if (_url) {
|
|
|
|
int32 left = st::inlineThumbSize + st::inlineThumbSkip;
|
|
|
|
int32 titleHeight = qMin(_title.countHeight(_width - left), st::semiboldFont->height * 2);
|
|
|
|
int32 descriptionLines = 2;
|
|
|
|
int32 descriptionHeight = qMin(_description.countHeight(_width - left), st::normalFont->height * descriptionLines);
|
|
|
|
if (rtlrect(left, st::inlineRowMargin + titleHeight + descriptionHeight, _urlWidth, st::normalFont->height, _width).contains(x, y)) {
|
|
|
|
link = _url;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
link = _send;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-08 15:37:14 +00:00
|
|
|
void Article::prepareThumb(int width, int height) const {
|
2016-04-05 20:24:27 +00:00
|
|
|
ImagePtr thumb = getResultThumb();
|
|
|
|
if (thumb->isNull()) {
|
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
|
|
|
_thumb = getResultContactAvatar(width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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()) {
|
2016-04-08 15:37:14 +00:00
|
|
|
int w = qMax(convertScale(thumb->width()), 1), h = qMax(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;
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = thumb->pixNoCache(w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-04-05 20:24:27 +00:00
|
|
|
thumb->load();
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-27 18:11:51 +00:00
|
|
|
Game::Game(gsl::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 };
|
2016-12-23 13:21:01 +00:00
|
|
|
_title.setText(st::semiboldTextStyle, textOneLine(_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;
|
|
|
|
auto rthumb = rtlrect(0, st::inlineRowMargin, st::inlineThumbSize, st::inlineThumbSize, _width);
|
|
|
|
|
|
|
|
// Gif thumb
|
|
|
|
auto thumbDisplayed = false, radial = false;
|
|
|
|
auto document = getResultDocument();
|
|
|
|
auto animatedThumb = document && document->isAnimation();
|
|
|
|
if (animatedThumb) {
|
|
|
|
document->automaticLoad(nullptr);
|
|
|
|
|
|
|
|
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);
|
2016-09-28 20:28:53 +00:00
|
|
|
that->_gif = Media::Clip::MakeReader(document->location(), document->data(), [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) {
|
2017-02-21 13:45:56 +00:00
|
|
|
_radial = std::make_unique<Ui::RadialAnimation>(animation(const_cast<Game*>(this), &Game::step_radial));
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
if (!_radial->animating()) {
|
|
|
|
_radial->start(document->progress());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
radial = isRadialAnimation(context->ms);
|
|
|
|
|
|
|
|
if (animating) {
|
|
|
|
if (!_thumb.isNull()) _thumb = QPixmap();
|
2016-11-21 20:26:54 +00:00
|
|
|
auto animationThumb = _gif->current(_frameSize.width(), _frameSize.height(), st::inlineThumbSize, st::inlineThumbSize, ImageRoundRadius::None, ImageRoundCorner::None, context->paused ? 0 : context->ms);
|
2016-09-28 16:23:25 +00:00
|
|
|
p.drawPixmapLeft(rthumb.topLeft(), _width, animationThumb);
|
|
|
|
thumbDisplayed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!thumbDisplayed) {
|
|
|
|
prepareThumb(st::inlineThumbSize, st::inlineThumbSize);
|
|
|
|
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)));
|
|
|
|
_radial->draw(p, rinner, st::msgFileRadialLine, st::msgInBg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
p.fillRect(rtlrect(left, _height - st::inlineRowBorder, _width - left, st::inlineRowBorder, _width), st::inlineRowBorderFg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::getState(ClickHandlerPtr &link, HistoryCursorState &cursor, int x, int y) const {
|
|
|
|
int left = st::inlineThumbSize + st::inlineThumbSkip;
|
|
|
|
if (x >= 0 && x < left - st::inlineThumbSkip && y >= st::inlineRowMargin && y < st::inlineRowMargin + st::inlineThumbSize) {
|
|
|
|
link = _send;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (x >= left && x < _width && y >= 0 && y < _height) {
|
|
|
|
link = _send;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::prepareThumb(int width, int height) const {
|
|
|
|
auto thumb = ([this]() {
|
|
|
|
if (auto photo = getResultPhoto()) {
|
|
|
|
return photo->medium;
|
|
|
|
} else if (auto document = getResultDocument()) {
|
|
|
|
return document->thumb;
|
|
|
|
}
|
|
|
|
return ImagePtr();
|
|
|
|
})();
|
|
|
|
if (thumb->isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (thumb->loaded()) {
|
|
|
|
if (_thumb.width() != width * cIntRetinaFactor() || _thumb.height() != height * cIntRetinaFactor()) {
|
|
|
|
int w = qMax(convertScale(thumb->width()), 1), h = qMax(convertScale(thumb->height()), 1);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (w > width) {
|
|
|
|
h = h * width / w;
|
|
|
|
w = width;
|
|
|
|
}
|
|
|
|
}
|
2016-11-28 15:45:07 +00:00
|
|
|
_thumb = thumb->pixNoCache(w * cIntRetinaFactor(), h * cIntRetinaFactor(), Images::Option::Smooth, width, height);
|
2016-09-28 16:23:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
thumb->load();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
bool Game::isRadialAnimation(TimeMs ms) const {
|
2016-09-28 16:23:25 +00:00
|
|
|
if (!_radial || !_radial->animating()) return false;
|
|
|
|
|
|
|
|
_radial->step(ms);
|
|
|
|
return _radial && _radial->animating();
|
|
|
|
}
|
|
|
|
|
2016-12-01 19:20:33 +00:00
|
|
|
void Game::step_radial(TimeMs ms, bool timer) {
|
2016-09-28 16:23:25 +00:00
|
|
|
if (timer) {
|
|
|
|
update();
|
|
|
|
} else {
|
|
|
|
auto document = getResultDocument();
|
|
|
|
_radial->update(document->progress(), !document->loading() || document->loaded(), ms);
|
|
|
|
if (!_radial->animating() && document->loaded()) {
|
|
|
|
_radial.reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
2016-09-28 16:23:25 +00:00
|
|
|
getResultDocument()->forget();
|
|
|
|
} else if (_gif->ready() && !_gif->started()) {
|
2016-11-21 20:26:54 +00:00
|
|
|
_gif->start(_frameSize.width(), _frameSize.height(), st::inlineThumbSize, st::inlineThumbSize, ImageRoundRadius::None, ImageRoundCorner::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();
|
2016-09-28 16:23:25 +00:00
|
|
|
getResultDocument()->forget();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|