| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | /*
 | 
					
						
							|  |  |  | This file is part of Telegram Desktop, | 
					
						
							| 
									
										
										
										
											2018-01-03 13:23:14 +03:00
										 |  |  | the official desktop application for the Telegram messaging service. | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 13:23:14 +03:00
										 |  |  | For license and copyright information please follow this link: | 
					
						
							|  |  |  | https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | */ | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-31 19:28:58 +03:00
										 |  |  | #include "base/flags.h"
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | #include "inline_bots/inline_bot_layout_item.h"
 | 
					
						
							| 
									
										
										
										
											2019-09-13 09:06:02 +03:00
										 |  |  | #include "media/clip/media_clip_reader.h"
 | 
					
						
							| 
									
										
										
										
											2019-04-02 13:13:30 +04:00
										 |  |  | #include "ui/effects/animations.h"
 | 
					
						
							| 
									
										
										
										
											2016-09-28 13:15:03 +03:00
										 |  |  | #include "ui/effects/radial_animation.h"
 | 
					
						
							| 
									
										
										
										
											2016-04-14 14:00:23 +03:00
										 |  |  | #include "ui/text/text.h"
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-02 15:41:50 +02:00
										 |  |  | namespace Lottie { | 
					
						
							|  |  |  | class SinglePlayer; | 
					
						
							|  |  |  | } // namespace Lottie
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 19:09:29 +04:00
										 |  |  | namespace Data { | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | class PhotoMedia; | 
					
						
							| 
									
										
										
										
											2020-04-08 19:09:29 +04:00
										 |  |  | class DocumentMedia; | 
					
						
							|  |  |  | } // namespace Data
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | namespace InlineBots { | 
					
						
							|  |  |  | namespace Layout { | 
					
						
							|  |  |  | namespace internal { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FileBase : public ItemBase { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-06-28 16:01:32 +01:00
										 |  |  | 	FileBase(not_null<Context*> context, not_null<Result*> result); | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// For saved gif layouts.
 | 
					
						
							|  |  |  | 	FileBase(not_null<Context*> context, not_null<DocumentData*> document); | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	DocumentData *getShownDocument() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	int content_width() const; | 
					
						
							|  |  |  | 	int content_height() const; | 
					
						
							|  |  |  | 	int content_duration() const; | 
					
						
							| 
									
										
										
										
											2020-04-15 18:06:34 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DeleteSavedGifClickHandler : public LeftButtonClickHandler { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-06-09 13:36:40 +04:00
										 |  |  | 	DeleteSavedGifClickHandler(not_null<DocumentData*> data) : _data(data) { | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	void onClickImpl() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-06-09 13:36:40 +04:00
										 |  |  | 	const not_null<DocumentData*> _data; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | class Gif final : public FileBase { | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	Gif(not_null<Context*> context, not_null<Result*> result); | 
					
						
							|  |  |  | 	Gif( | 
					
						
							|  |  |  | 		not_null<Context*> context, | 
					
						
							|  |  |  | 		not_null<DocumentData*> document, | 
					
						
							|  |  |  | 		bool hasDeleteButton); | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void setPosition(int32 position) override; | 
					
						
							|  |  |  | 	void initDimensions() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool isFullLine() const override { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	bool hasRightSkip() const override { | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 21:29:32 +03:00
										 |  |  | 	void paint(Painter &p, const QRect &clip, const PaintContext *context) const override; | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 	TextState getState( | 
					
						
							| 
									
										
										
										
											2017-10-13 22:07:04 +03:00
										 |  |  | 		QPoint point, | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 		StateRequest request) const override; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ClickHandlerHost interface
 | 
					
						
							|  |  |  | 	void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-18 18:10:24 +04:00
										 |  |  | 	int resizeGetHeight(int width) override; | 
					
						
							| 
									
										
										
										
											2017-11-14 14:26:12 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 19:09:29 +04:00
										 |  |  | 	void unloadHeavyPart() override; | 
					
						
							| 
									
										
										
										
											2020-03-16 17:38:36 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | private: | 
					
						
							|  |  |  | 	enum class StateFlag { | 
					
						
							| 
									
										
										
										
											2020-04-08 19:09:29 +04:00
										 |  |  | 		Over = (1 << 0), | 
					
						
							| 
									
										
										
										
											2017-09-03 21:36:06 +03:00
										 |  |  | 		DeleteOver = (1 << 1), | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-08-31 19:28:58 +03:00
										 |  |  | 	using StateFlags = base::flags<StateFlag>; | 
					
						
							|  |  |  | 	friend inline constexpr auto is_flag_type(StateFlag) { return true; }; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 19:09:29 +04:00
										 |  |  | 	struct AnimationData { | 
					
						
							|  |  |  | 		template <typename Callback> | 
					
						
							|  |  |  | 		AnimationData(Callback &&callback) | 
					
						
							|  |  |  | 			: radial(std::forward<Callback>(callback)) { | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		bool over = false; | 
					
						
							|  |  |  | 		Ui::Animations::Simple _a_over; | 
					
						
							|  |  |  | 		Ui::RadialAnimation radial; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void ensureDataMediaCreated(not_null<DocumentData*> document) const; | 
					
						
							|  |  |  | 	QSize countFrameSize() const; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 18:37:28 +04:00
										 |  |  | 	void validateThumbnail( | 
					
						
							|  |  |  | 		Image *image, | 
					
						
							|  |  |  | 		QSize size, | 
					
						
							|  |  |  | 		QSize frame, | 
					
						
							|  |  |  | 		bool good) const; | 
					
						
							|  |  |  | 	void prepareThumbnail(QSize size, QSize frame) const; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void ensureAnimation() const; | 
					
						
							| 
									
										
										
										
											2019-04-04 19:24:13 +04:00
										 |  |  | 	bool isRadialAnimation() const; | 
					
						
							|  |  |  | 	void radialAnimationCallback(crl::time now) const; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 13:37:29 +03:00
										 |  |  | 	void clipCallback(Media::Clip::Notification notification); | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 19:09:29 +04:00
										 |  |  | 	StateFlags _state; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Media::Clip::ReaderPointer _gif; | 
					
						
							|  |  |  | 	ClickHandlerPtr _delete; | 
					
						
							|  |  |  | 	mutable QPixmap _thumb; | 
					
						
							|  |  |  | 	mutable bool _thumbGood = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutable std::shared_ptr<Data::DocumentMedia> _dataMedia; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-21 16:45:56 +03:00
										 |  |  | 	mutable std::unique_ptr<AnimationData> _animation; | 
					
						
							| 
									
										
										
										
											2019-04-02 13:13:30 +04:00
										 |  |  | 	mutable Ui::Animations::Simple _a_deleteOver; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Photo : public ItemBase { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	Photo(not_null<Context*> context, not_null<Result*> result); | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	// Not used anywhere currently.
 | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	//Photo(not_null<Context*> context, not_null<PhotoData*> photo);
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void initDimensions() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool isFullLine() const override { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	bool hasRightSkip() const override { | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 21:29:32 +03:00
										 |  |  | 	void paint(Painter &p, const QRect &clip, const PaintContext *context) const override; | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 	TextState getState( | 
					
						
							| 
									
										
										
										
											2017-10-13 22:07:04 +03:00
										 |  |  | 		QPoint point, | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 		StateRequest request) const override; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	void unloadHeavyPart() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | private: | 
					
						
							|  |  |  | 	PhotoData *getShownPhoto() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	QSize countFrameSize() const; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutable QPixmap _thumb; | 
					
						
							| 
									
										
										
										
											2019-01-25 18:37:28 +04: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-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	mutable std::shared_ptr<Data::PhotoMedia> _photoMedia; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Sticker : public FileBase { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	Sticker(not_null<Context*> context, not_null<Result*> result); | 
					
						
							| 
									
										
										
										
											2019-07-02 15:41:50 +02:00
										 |  |  | 	~Sticker(); | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	// Not used anywhere currently.
 | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	//Sticker(not_null<Context*> context, not_null<DocumentData*> document);
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void initDimensions() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool isFullLine() const override { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	bool hasRightSkip() const override { | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	void preload() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 21:29:32 +03:00
										 |  |  | 	void paint(Painter &p, const QRect &clip, const PaintContext *context) const override; | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 	TextState getState( | 
					
						
							| 
									
										
										
										
											2017-10-13 22:07:04 +03:00
										 |  |  | 		QPoint point, | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 		StateRequest request) const override; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ClickHandlerHost interface
 | 
					
						
							|  |  |  | 	void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	void unloadHeavyPart() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-04-09 12:15:47 +04:00
										 |  |  | 	void ensureDataMediaCreated(not_null<DocumentData*> document) const; | 
					
						
							| 
									
										
										
										
											2020-04-09 16:27:53 +04:00
										 |  |  | 	void setupLottie() const; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	QSize getThumbSize() const; | 
					
						
							| 
									
										
										
										
											2019-07-02 15:41:50 +02:00
										 |  |  | 	void prepareThumbnail() const; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-02 13:13:30 +04:00
										 |  |  | 	mutable Ui::Animations::Simple _a_over; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	mutable bool _active = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutable QPixmap _thumb; | 
					
						
							|  |  |  | 	mutable bool _thumbLoaded = false; | 
					
						
							| 
									
										
										
										
											2019-07-02 15:41:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	mutable std::unique_ptr<Lottie::SinglePlayer> _lottie; | 
					
						
							| 
									
										
										
										
											2020-04-09 12:15:47 +04:00
										 |  |  | 	mutable std::shared_ptr<Data::DocumentMedia> _dataMedia; | 
					
						
							| 
									
										
										
										
											2019-07-02 15:41:50 +02:00
										 |  |  | 	mutable rpl::lifetime _lifetime; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Video : public FileBase { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	Video(not_null<Context*> context, not_null<Result*> result); | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void initDimensions() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 21:29:32 +03:00
										 |  |  | 	void paint(Painter &p, const QRect &clip, const PaintContext *context) const override; | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 	TextState getState( | 
					
						
							| 
									
										
										
										
											2017-10-13 22:07:04 +03:00
										 |  |  | 		QPoint point, | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 		StateRequest request) const override; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	void unloadHeavyPart() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | private: | 
					
						
							|  |  |  | 	ClickHandlerPtr _link; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	mutable QPixmap _thumb; | 
					
						
							| 
									
										
										
										
											2020-04-15 18:06:34 +04:00
										 |  |  | 	mutable std::shared_ptr<Data::DocumentMedia> _documentMedia; | 
					
						
							| 
									
										
										
										
											2019-06-12 15:26:04 +02:00
										 |  |  | 	Ui::Text::String _title, _description; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	QString _duration; | 
					
						
							| 
									
										
										
										
											2016-04-08 19:37:14 +04:00
										 |  |  | 	int _durationWidth = 0; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 18:06:34 +04:00
										 |  |  | 	[[nodiscard]] bool withThumbnail() const; | 
					
						
							| 
									
										
										
										
											2019-01-25 18:37:28 +04:00
										 |  |  | 	void prepareThumbnail(QSize size) const; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class OpenFileClickHandler : public LeftButtonClickHandler { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-06-28 16:01:32 +01:00
										 |  |  | 	OpenFileClickHandler(not_null<Result*> result) : _result(result) { | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	void onClickImpl() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2018-06-28 16:01:32 +01:00
										 |  |  | 	not_null<Result*> _result; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CancelFileClickHandler : public LeftButtonClickHandler { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-06-28 16:01:32 +01:00
										 |  |  | 	CancelFileClickHandler(not_null<Result*> result) : _result(result) { | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  | 	void onClickImpl() const override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							| 
									
										
										
										
											2018-06-28 16:01:32 +01:00
										 |  |  | 	not_null<Result*> _result; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class File : public FileBase { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2018-06-28 16:01:32 +01:00
										 |  |  | 	File(not_null<Context*> context, not_null<Result*> result); | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	~File(); | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void initDimensions() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 21:29:32 +03:00
										 |  |  | 	void paint(Painter &p, const QRect &clip, const PaintContext *context) const override; | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 	TextState getState( | 
					
						
							| 
									
										
										
										
											2017-10-13 22:07:04 +03:00
										 |  |  | 		QPoint point, | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 		StateRequest request) const override; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// ClickHandlerHost interface
 | 
					
						
							|  |  |  | 	void clickHandlerActiveChanged(const ClickHandlerPtr &p, bool active) override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	void unloadHeavyPart() override; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-10 22:18:26 +04:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2016-12-07 16:32:25 +03:00
										 |  |  | 	void thumbAnimationCallback(); | 
					
						
							| 
									
										
										
										
											2019-04-04 19:24:13 +04:00
										 |  |  | 	void radialAnimationCallback(crl::time now) const; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void ensureAnimation() const; | 
					
						
							| 
									
										
										
										
											2020-04-10 17:18:51 +04:00
										 |  |  | 	void ensureDataMediaCreated() const; | 
					
						
							| 
									
										
										
										
											2016-12-09 09:19:55 +03:00
										 |  |  | 	void checkAnimationFinished() const; | 
					
						
							| 
									
										
										
										
											2016-04-10 22:18:26 +04:00
										 |  |  | 	bool updateStatusText() const; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-04 19:24:13 +04:00
										 |  |  | 	bool isRadialAnimation() const { | 
					
						
							|  |  |  | 		if (_animation) { | 
					
						
							|  |  |  | 			if (_animation->radial.animating()) { | 
					
						
							|  |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			checkAnimationFinished(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-04-02 13:13:30 +04:00
										 |  |  | 	bool isThumbAnimation() const { | 
					
						
							| 
									
										
										
										
											2016-12-07 16:32:25 +03:00
										 |  |  | 		if (_animation) { | 
					
						
							| 
									
										
										
										
											2019-04-02 13:13:30 +04:00
										 |  |  | 			if (_animation->a_thumbOver.animating()) { | 
					
						
							| 
									
										
										
										
											2016-12-09 09:19:55 +03:00
										 |  |  | 				return true; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			checkAnimationFinished(); | 
					
						
							| 
									
										
										
										
											2016-12-07 16:32:25 +03:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct AnimationData { | 
					
						
							| 
									
										
										
										
											2019-04-01 21:44:54 +04:00
										 |  |  | 		template <typename Callback> | 
					
						
							|  |  |  | 		AnimationData(Callback &&radialCallback) | 
					
						
							|  |  |  | 		: radial(std::forward<Callback>(radialCallback)) { | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-04-02 13:13:30 +04:00
										 |  |  | 		Ui::Animations::Simple a_thumbOver; | 
					
						
							| 
									
										
										
										
											2016-09-28 13:15:03 +03:00
										 |  |  | 		Ui::RadialAnimation radial; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2017-02-21 16:45:56 +03:00
										 |  |  | 	mutable std::unique_ptr<AnimationData> _animation; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-12 15:26:04 +02:00
										 |  |  | 	Ui::Text::String _title, _description; | 
					
						
							| 
									
										
										
										
											2016-04-10 22:18:26 +04:00
										 |  |  | 	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-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-28 16:01:32 +01:00
										 |  |  | 	not_null<DocumentData*> _document; | 
					
						
							| 
									
										
										
										
											2020-04-10 17:18:51 +04:00
										 |  |  | 	mutable std::shared_ptr<Data::DocumentMedia> _documentMedia; | 
					
						
							| 
									
										
										
										
											2018-06-28 16:01:32 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-08 19:37:14 +04:00
										 |  |  | class Contact : public ItemBase { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	Contact(not_null<Context*> context, not_null<Result*> result); | 
					
						
							| 
									
										
										
										
											2016-04-08 19:37:14 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void initDimensions() override; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 21:29:32 +03:00
										 |  |  | 	void paint(Painter &p, const QRect &clip, const PaintContext *context) const override; | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 	TextState getState( | 
					
						
							| 
									
										
										
										
											2017-10-13 22:07:04 +03:00
										 |  |  | 		QPoint point, | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 		StateRequest request) const override; | 
					
						
							| 
									
										
										
										
											2016-04-08 19:37:14 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	mutable QPixmap _thumb; | 
					
						
							| 
									
										
										
										
											2019-06-12 15:26:04 +02:00
										 |  |  | 	Ui::Text::String _title, _description; | 
					
						
							| 
									
										
										
										
											2016-04-08 19:37:14 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 18:37:28 +04:00
										 |  |  | 	void prepareThumbnail(int width, int height) const; | 
					
						
							| 
									
										
										
										
											2016-04-08 19:37:14 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | class Article : public ItemBase { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	Article(not_null<Context*> context, not_null<Result*> result, bool withThumb); | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void initDimensions() override; | 
					
						
							| 
									
										
										
										
											2016-04-08 19:37:14 +04:00
										 |  |  | 	int resizeGetHeight(int width) override; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-13 21:29:32 +03:00
										 |  |  | 	void paint(Painter &p, const QRect &clip, const PaintContext *context) const override; | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 	TextState getState( | 
					
						
							| 
									
										
										
										
											2017-10-13 22:07:04 +03:00
										 |  |  | 		QPoint point, | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 		StateRequest request) const override; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  | 	ClickHandlerPtr _url, _link; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bool _withThumb; | 
					
						
							|  |  |  | 	mutable QPixmap _thumb; | 
					
						
							| 
									
										
										
										
											2019-06-12 15:26:04 +02:00
										 |  |  | 	Ui::Text::String _title, _description; | 
					
						
							| 
									
										
										
										
											2016-04-06 00:24:27 +04:00
										 |  |  | 	QString _thumbLetter, _urlText; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 	int32 _urlWidth; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 18:37:28 +04:00
										 |  |  | 	void prepareThumbnail(int width, int height) const; | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-28 19:23:25 +03:00
										 |  |  | class Game : public ItemBase { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	Game(not_null<Context*> context, not_null<Result*> result); | 
					
						
							| 
									
										
										
										
											2016-09-28 19:23:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void setPosition(int32 position) override; | 
					
						
							|  |  |  | 	void initDimensions() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	void paint(Painter &p, const QRect &clip, const PaintContext *context) const override; | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 	TextState getState( | 
					
						
							| 
									
										
										
										
											2017-10-13 22:07:04 +03:00
										 |  |  | 		QPoint point, | 
					
						
							| 
									
										
										
										
											2018-01-27 16:59:24 +03:00
										 |  |  | 		StateRequest request) const override; | 
					
						
							| 
									
										
										
										
											2016-09-28 19:23:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-08 19:09:29 +04:00
										 |  |  | 	void unloadHeavyPart() override; | 
					
						
							| 
									
										
										
										
											2020-03-16 17:38:36 +04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-28 19:23:25 +03:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	void ensureDataMediaCreated(not_null<PhotoData*> photo) const; | 
					
						
							| 
									
										
										
										
											2020-04-08 19:09:29 +04:00
										 |  |  | 	void ensureDataMediaCreated(not_null<DocumentData*> document) const; | 
					
						
							| 
									
										
										
										
											2016-09-28 19:23:25 +03:00
										 |  |  | 	void countFrameSize(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-25 18:37:28 +04:00
										 |  |  | 	void prepareThumbnail(QSize size) const; | 
					
						
							|  |  |  | 	void validateThumbnail(Image *image, QSize size, bool good) const; | 
					
						
							| 
									
										
										
										
											2016-09-28 19:23:25 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-04 19:24:13 +04:00
										 |  |  | 	bool isRadialAnimation() const; | 
					
						
							|  |  |  | 	void radialAnimationCallback(crl::time now) const; | 
					
						
							| 
									
										
										
										
											2016-09-28 19:23:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void clipCallback(Media::Clip::Notification notification); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-28 23:28:53 +03:00
										 |  |  | 	Media::Clip::ReaderPointer _gif; | 
					
						
							| 
									
										
										
										
											2020-05-25 18:16:04 +04:00
										 |  |  | 	mutable std::shared_ptr<Data::PhotoMedia> _photoMedia; | 
					
						
							|  |  |  | 	mutable std::shared_ptr<Data::DocumentMedia> _documentMedia; | 
					
						
							| 
									
										
										
										
											2016-09-28 19:23:25 +03:00
										 |  |  | 	mutable QPixmap _thumb; | 
					
						
							| 
									
										
										
										
											2019-01-25 18:37:28 +04:00
										 |  |  | 	mutable bool _thumbGood = false; | 
					
						
							| 
									
										
										
										
											2017-02-21 16:45:56 +03:00
										 |  |  | 	mutable std::unique_ptr<Ui::RadialAnimation> _radial; | 
					
						
							| 
									
										
										
										
											2019-06-12 15:26:04 +02:00
										 |  |  | 	Ui::Text::String _title, _description; | 
					
						
							| 
									
										
										
										
											2016-09-28 19:23:25 +03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	QSize _frameSize; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-05 01:09:46 +04:00
										 |  |  | } // namespace internal
 | 
					
						
							|  |  |  | } // namespace Layout
 | 
					
						
							|  |  |  | } // namespace InlineBots
 |