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
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2017-08-31 16:28:58 +00:00
|
|
|
#include "base/flags.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
#include "inline_bots/inline_bot_layout_item.h"
|
2016-09-28 10:15:03 +00:00
|
|
|
#include "ui/effects/radial_animation.h"
|
2016-04-14 11:00:23 +00:00
|
|
|
#include "ui/text/text.h"
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
namespace InlineBots {
|
|
|
|
namespace Layout {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
class FileBase : public ItemBase {
|
|
|
|
public:
|
2018-06-28 15:01:32 +00:00
|
|
|
FileBase(not_null<Context*> context, not_null<Result*> result);
|
2016-04-04 21:09:46 +00:00
|
|
|
// for saved gif layouts
|
2017-08-17 08:31:24 +00:00
|
|
|
FileBase(not_null<Context*> context, DocumentData *doc);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
DocumentData *getShownDocument() const;
|
|
|
|
|
|
|
|
int content_width() const;
|
|
|
|
int content_height() const;
|
|
|
|
int content_duration() const;
|
2019-01-25 14:37:28 +00:00
|
|
|
Image *content_thumb() const;
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DeleteSavedGifClickHandler : public LeftButtonClickHandler {
|
|
|
|
public:
|
|
|
|
DeleteSavedGifClickHandler(DocumentData *data) : _data(data) {
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DocumentData *_data;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Gif : public FileBase {
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
Gif(not_null<Context*> context, Result *result);
|
|
|
|
Gif(not_null<Context*> context, DocumentData *doc, bool hasDeleteButton);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
void setPosition(int32 position) override;
|
|
|
|
void initDimensions() override;
|
|
|
|
|
|
|
|
bool isFullLine() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool hasRightSkip() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
// ClickHandlerHost interface
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
|
|
|
|
2017-12-18 14:10:24 +00:00
|
|
|
int resizeGetHeight(int width) override;
|
2017-11-14 10:26:12 +00:00
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
private:
|
|
|
|
QSize countFrameSize() const;
|
|
|
|
|
|
|
|
enum class StateFlag {
|
2017-09-03 18:36:06 +00:00
|
|
|
Over = (1 << 0),
|
|
|
|
DeleteOver = (1 << 1),
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
2017-08-31 16:28:58 +00:00
|
|
|
using StateFlags = base::flags<StateFlag>;
|
|
|
|
friend inline constexpr auto is_flag_type(StateFlag) { return true; };
|
2016-04-04 21:09:46 +00:00
|
|
|
StateFlags _state;
|
|
|
|
|
2016-09-28 20:28:53 +00:00
|
|
|
Media::Clip::ReaderPointer _gif;
|
2016-04-04 21:09:46 +00:00
|
|
|
ClickHandlerPtr _delete;
|
|
|
|
mutable QPixmap _thumb;
|
2019-01-25 14:37:28 +00:00
|
|
|
mutable bool _thumbGood = false;
|
|
|
|
void validateThumbnail(
|
|
|
|
Image *image,
|
|
|
|
QSize size,
|
|
|
|
QSize frame,
|
|
|
|
bool good) const;
|
|
|
|
void prepareThumbnail(QSize size, QSize frame) const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
void ensureAnimation() const;
|
2019-04-01 17:44:54 +00:00
|
|
|
bool isRadialAnimation(crl::time now) const;
|
|
|
|
bool radialAnimationCallback(crl::time now) const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-06-24 10:37:29 +00:00
|
|
|
void clipCallback(Media::Clip::Notification notification);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
struct AnimationData {
|
2019-04-01 17:44:54 +00:00
|
|
|
template <typename Callback>
|
|
|
|
AnimationData(Callback &&callback)
|
|
|
|
: radial(std::forward<Callback>(callback)) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2019-04-01 17:44:54 +00:00
|
|
|
bool over = false;
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation _a_over;
|
2016-09-28 10:15:03 +00:00
|
|
|
Ui::RadialAnimation radial;
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
2017-02-21 13:45:56 +00:00
|
|
|
mutable std::unique_ptr<AnimationData> _animation;
|
2016-12-07 13:32:25 +00:00
|
|
|
mutable Animation _a_deleteOver;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Photo : public ItemBase {
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
Photo(not_null<Context*> context, Result *result);
|
2016-04-04 21:09:46 +00:00
|
|
|
// Not used anywhere currently.
|
2017-08-17 08:31:24 +00:00
|
|
|
//Photo(not_null<Context*> context, PhotoData *photo);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
|
|
|
|
bool isFullLine() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool hasRightSkip() const override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
PhotoData *getShownPhoto() const;
|
|
|
|
|
|
|
|
QSize countFrameSize() const;
|
|
|
|
|
|
|
|
mutable QPixmap _thumb;
|
2019-01-25 14:37:28 +00:00
|
|
|
mutable bool _thumbGood = false;
|
|
|
|
void prepareThumbnail(QSize size, QSize frame) const;
|
|
|
|
void validateThumbnail(
|
|
|
|
Image *image,
|
|
|
|
QSize size,
|
|
|
|
QSize frame,
|
|
|
|
bool good) const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Sticker : public FileBase {
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
Sticker(not_null<Context*> context, Result *result);
|
2016-04-04 21:09:46 +00:00
|
|
|
// Not used anywhere currently.
|
2017-08-17 08:31:24 +00:00
|
|
|
//Sticker(not_null<Context*> context, DocumentData *document);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
|
|
|
|
bool isFullLine() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool hasRightSkip() const override {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
void preload() const override;
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
// ClickHandlerHost interface
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
QSize getThumbSize() const;
|
|
|
|
|
2016-12-07 13:32:25 +00:00
|
|
|
mutable Animation _a_over;
|
2016-04-04 21:09:46 +00:00
|
|
|
mutable bool _active = false;
|
|
|
|
|
|
|
|
mutable QPixmap _thumb;
|
|
|
|
mutable bool _thumbLoaded = false;
|
2019-01-25 14:37:28 +00:00
|
|
|
void prepareThumbnail() const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class Video : public FileBase {
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
Video(not_null<Context*> context, Result *result);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ClickHandlerPtr _link;
|
|
|
|
|
|
|
|
mutable QPixmap _thumb;
|
|
|
|
Text _title, _description;
|
|
|
|
QString _duration;
|
2016-04-08 15:37:14 +00:00
|
|
|
int _durationWidth = 0;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void prepareThumbnail(QSize size) const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class OpenFileClickHandler : public LeftButtonClickHandler {
|
|
|
|
public:
|
2018-06-28 15:01:32 +00:00
|
|
|
OpenFileClickHandler(not_null<Result*> result) : _result(result) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
|
|
|
|
private:
|
2018-06-28 15:01:32 +00:00
|
|
|
not_null<Result*> _result;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class CancelFileClickHandler : public LeftButtonClickHandler {
|
|
|
|
public:
|
2018-06-28 15:01:32 +00:00
|
|
|
CancelFileClickHandler(not_null<Result*> result) : _result(result) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void onClickImpl() const override;
|
|
|
|
|
|
|
|
private:
|
2018-06-28 15:01:32 +00:00
|
|
|
not_null<Result*> _result;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
class File : public FileBase {
|
|
|
|
public:
|
2018-06-28 15:01:32 +00:00
|
|
|
File(not_null<Context*> context, not_null<Result*> result);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
// ClickHandlerHost interface
|
|
|
|
void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override;
|
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
~File();
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
private:
|
2016-12-07 13:32:25 +00:00
|
|
|
void thumbAnimationCallback();
|
2019-04-01 17:44:54 +00:00
|
|
|
bool radialAnimationCallback(crl::time now) const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
void ensureAnimation() const;
|
2016-12-09 06:19:55 +00:00
|
|
|
void checkAnimationFinished() const;
|
2016-04-10 18:18:26 +00:00
|
|
|
bool updateStatusText() const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
bool isRadialAnimation(crl::time now) const {
|
|
|
|
return _animation
|
|
|
|
&& _animation->radial.animating()
|
|
|
|
&& radialAnimationCallback(now);
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2019-02-19 06:57:53 +00:00
|
|
|
bool isThumbAnimation(crl::time ms) const {
|
2016-12-07 13:32:25 +00:00
|
|
|
if (_animation) {
|
2016-12-09 06:19:55 +00:00
|
|
|
if (_animation->a_thumbOver.animating(ms)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
checkAnimationFinished();
|
2016-12-07 13:32:25 +00:00
|
|
|
}
|
|
|
|
return false;
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct AnimationData {
|
2019-04-01 17:44:54 +00:00
|
|
|
template <typename Callback>
|
|
|
|
AnimationData(Callback &&radialCallback)
|
|
|
|
: radial(std::forward<Callback>(radialCallback)) {
|
2016-04-04 21:09:46 +00:00
|
|
|
}
|
2016-12-07 13:32:25 +00:00
|
|
|
Animation a_thumbOver;
|
2016-09-28 10:15:03 +00:00
|
|
|
Ui::RadialAnimation radial;
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
2017-02-21 13:45:56 +00:00
|
|
|
mutable std::unique_ptr<AnimationData> _animation;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-10 18:18:26 +00:00
|
|
|
Text _title, _description;
|
|
|
|
ClickHandlerPtr _open, _cancel;
|
|
|
|
|
|
|
|
// >= 0 will contain download / upload string, _statusSize = loaded bytes
|
|
|
|
// < 0 will contain played string, _statusSize = -(seconds + 1) played
|
|
|
|
// 0x7FFFFFF0 will contain status for not yet downloaded file
|
|
|
|
// 0x7FFFFFF1 will contain status for already downloaded file
|
|
|
|
// 0x7FFFFFF2 will contain status for failed to download / upload file
|
|
|
|
mutable int32 _statusSize;
|
|
|
|
mutable QString _statusText;
|
|
|
|
|
|
|
|
// duration = -1 - no duration, duration = -2 - "GIF" duration
|
|
|
|
void setStatusSize(int32 newSize, int32 fullSize, int32 duration, qint64 realDuration) const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2018-06-28 15:01:32 +00:00
|
|
|
not_null<DocumentData*> _document;
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
};
|
|
|
|
|
2016-04-08 15:37:14 +00:00
|
|
|
class Contact : public ItemBase {
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
Contact(not_null<Context*> context, Result *result);
|
2016-04-08 15:37:14 +00:00
|
|
|
|
|
|
|
void initDimensions() override;
|
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const override;
|
2016-04-08 15:37:14 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
mutable QPixmap _thumb;
|
|
|
|
Text _title, _description;
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void prepareThumbnail(int width, int height) const;
|
2016-04-08 15:37:14 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
class Article : public ItemBase {
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
Article(not_null<Context*> context, Result *result, bool withThumb);
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
void initDimensions() override;
|
2016-04-08 15:37:14 +00:00
|
|
|
int resizeGetHeight(int width) override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
2016-04-13 18:29:32 +00:00
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const override;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
ClickHandlerPtr _url, _link;
|
|
|
|
|
|
|
|
bool _withThumb;
|
|
|
|
mutable QPixmap _thumb;
|
|
|
|
Text _title, _description;
|
2016-04-05 20:24:27 +00:00
|
|
|
QString _thumbLetter, _urlText;
|
2016-04-04 21:09:46 +00:00
|
|
|
int32 _urlWidth;
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void prepareThumbnail(int width, int height) const;
|
2016-04-04 21:09:46 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-09-28 16:23:25 +00:00
|
|
|
class Game : public ItemBase {
|
|
|
|
public:
|
2017-08-17 08:31:24 +00:00
|
|
|
Game(not_null<Context*> context, Result *result);
|
2016-09-28 16:23:25 +00:00
|
|
|
|
|
|
|
void setPosition(int32 position) override;
|
|
|
|
void initDimensions() override;
|
|
|
|
|
|
|
|
void paint(Painter &p, const QRect &clip, const PaintContext *context) const override;
|
2018-01-27 13:59:24 +00:00
|
|
|
TextState getState(
|
2017-10-13 19:07:04 +00:00
|
|
|
QPoint point,
|
2018-01-27 13:59:24 +00:00
|
|
|
StateRequest request) const override;
|
2016-09-28 16:23:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void countFrameSize();
|
|
|
|
|
2019-01-25 14:37:28 +00:00
|
|
|
void prepareThumbnail(QSize size) const;
|
|
|
|
void validateThumbnail(Image *image, QSize size, bool good) const;
|
2016-09-28 16:23:25 +00:00
|
|
|
|
2019-04-01 17:44:54 +00:00
|
|
|
bool isRadialAnimation(crl::time now) const;
|
|
|
|
bool radialAnimationCallback(crl::time now) const;
|
2016-09-28 16:23:25 +00:00
|
|
|
|
|
|
|
void clipCallback(Media::Clip::Notification notification);
|
|
|
|
|
2016-09-28 20:28:53 +00:00
|
|
|
Media::Clip::ReaderPointer _gif;
|
2016-09-28 16:23:25 +00:00
|
|
|
mutable QPixmap _thumb;
|
2019-01-25 14:37:28 +00:00
|
|
|
mutable bool _thumbGood = false;
|
2017-02-21 13:45:56 +00:00
|
|
|
mutable std::unique_ptr<Ui::RadialAnimation> _radial;
|
2016-09-28 16:23:25 +00:00
|
|
|
Text _title, _description;
|
|
|
|
|
|
|
|
QSize _frameSize;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-04-04 21:09:46 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace Layout
|
|
|
|
} // namespace InlineBots
|